Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mason/bytecode refactor 2 #1402

Closed
wants to merge 14 commits into from

Conversation

z2trillion
Copy link

Description

[PR description]

Issue Link

[link issue here]

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Contents

  • [item]

Rationale

[design decisions and extended information]

How Has This Been Tested?

[explanation]


How to fill a PR description

Please give a concise description of your PR.

The target readers could be future developers, reviewers, and auditors. By reading your description, they should easily understand the changes proposed in this pull request.

MUST: Reference the issue to resolve

Single responsibility

Is RECOMMENDED to create single responsibility commits, but not mandatory.

Anyway, you MUST enumerate the changes in a unitary way, e.g.

This PR contains:
- Cleanup of xxxx, yyyy
- Changed xxxx to yyyy in order to bla bla
- Added xxxx function to ...
- Refactored ....

Design choices

RECOMMENDED to:

  • What types of design choices did you face?
  • What decisions you have made?
  • Any valuable information that could help reviewers to think critically

@z2trillion z2trillion marked this pull request as ready for review August 21, 2024 20:17
@z2trillion z2trillion force-pushed the mason/bytecode_refactor_2 branch from 319780d to d7cd21d Compare August 22, 2024 03:48
@@ -69,7 +69,7 @@ fn gen_copy_event(
state.gen_copy_steps_for_bytecode(exec_step, &bytecode, src_addr, dst_addr, length)?;

Ok(CopyEvent {
src_type: CopyDataType::Bytecode,
src_type: CopyDataType::Bytecode(Default::default()),
Copy link

@DreamWuGit DreamWuGit Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hh, have tried similar solution at earlier time when starting to implement byte code refractor:
added is_first_bytecode info into CopyEvent and set it to correct value in block_convert method. but what not good of the solution are:

  1. enlarge changing scope, copy event related files (like files under evm/opcodes folder here)
  2. more complex code: first time CopyDataType::Bytecode not correct, correct it in different place.

so later changed to remain CopyEvent unchanged(no any bus mapping related changes), only get the bytecode information when required(CopyTable::assignment).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first time CopyDataType::Bytecode not correct, correct it in different place.
I think "fixing" it in block_convert is fine, because that's also the place where we partition the bytecodes. we partition the bytecodes at https://github.com/scroll-tech/zkevm-circuits/pull/1402/files#diff-e71dae4a71b5661aaa2385201c4554b7d56790191c6e5d0a54ebdcac4c63dd92R593 and then two lines after, we update the copy events.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can avoid to set it twice, would that be better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be better. i'm not sure it's possible though, since the bus code mapping can't know which tables the bytecodes will end up in until the whole block has been seen.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep CopyEvent unchanged and only get the bytecode table information when required(CopyTable::assignment).

first_bytecodes
.iter()
.map(|bytecode| bytecode.bytes.len() + 1)
#[cfg(feature = "dual_bytecode")]
Copy link

@DreamWuGit DreamWuGit Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of bytecode_map functionality is used to check if configure feature dual_bytecode. code like:

if bytecode_map.is_some(){
// enable dual_bytecode` feature case
}else{
// default : no feature case
}

this can save multiple code cfg(feature) statement like used here.
#[cfg(feature = "dual_bytecode")] {
....
}
#[cfg(not(feature = "dual_bytecode"))]{
.....
}
not let many #[cfg(feature) code mess up the codes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to directly check using #[cfg(feature = "dual_bytecode") than checking that bytecode_map is None.

checking using #[cfg(feature = "dual_bytecode") is done at compile time, which ensures that both cases are handled correctly, since we check with and without the dual_bytecode feature enabled. This prevents other people from mistakenly setting bytecode_map = Some(...) when the dual_bytecode feature is enabled.

Copy link

@DreamWuGit DreamWuGit Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the beginning, we tried to make all dual_bytecode related changes to use #[cfg(feature = "dual_bytecode")],so codes are identical to old one bytecode if not enable feature = "dual_bytecode" . However, during the refactoring stage, we realized that having many feature cfg checking codes, even though they are at compile time, are not ideal for long-term code maintenance purposes. tried to reduce most of them later, including making "is_first_bytecode_table" a default (not feature-related, with a default value of true), as long as it is compatible with existing functionality.


(first_subcircuit_bytecodes, second_subcircuit_bytecodes)
self.bytecodes.get(code_hash).map_or(true, |b| {
#[cfg(feature = "dual_bytecode")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also what i mean feature declare statement.
#[cfg(feature = "dual_bytecode")] {
....
}
#[cfg(not(feature = "dual_bytecode"))]{
.....
}

pub fn get_bytecodes(code_db: &CodeDB) -> BTreeMap<Word, Bytecode> {
// Generate bytecode map from CodeDB.
fn get_bytecodes(code_db: &CodeDB) -> BTreeMap<Word, Bytecode> {
#[cfg(feature = "dual_bytecode")]
Copy link

@DreamWuGit DreamWuGit Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more feature configure declare required and the code behind as well this way.

@DreamWuGit
Copy link

overall, will pick some code into original PR but remain bytecode_map for above reasons.

@lispc
Copy link

lispc commented Aug 29, 2024

in general, the dual bytecode table design is more like a tmp trick to reduce proving cost, not a long-term good design.

So i also prefer not add the notion "dual bytecode" into bus-mapping, and don't use CopyDataType { ... Bytecode(BytecodeTable) ... }. I want to "split the wired stuff" as a "aux" piece.

Dream pr is like "add an auxiliary component", while this pr is more like a "wired local optimum"

I will not pick suggestions here.

@lispc lispc closed this Aug 29, 2024
@z2trillion z2trillion deleted the mason/bytecode_refactor_2 branch August 29, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants