-
Notifications
You must be signed in to change notification settings - Fork 391
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
Conversation
319780d
to
d7cd21d
Compare
@@ -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()), |
There was a problem hiding this comment.
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:
- enlarge changing scope, copy event related files (like files under
evm/opcodes
folder here) - 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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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.
overall, will pick some code into original PR but remain bytecode_map for above reasons. |
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 Dream pr is like "add an auxiliary component", while this pr is more like a "wired local optimum" I will not pick suggestions here. |
Description
[PR description]
Issue Link
[link issue here]
Type of change
Contents
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.
Design choices
RECOMMENDED to: