Skip to content

Commit

Permalink
avoid code hash for extcodesize
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed May 11, 2024
1 parent 67461a9 commit 30ed394
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 5 additions & 3 deletions bus-mapping/src/circuit_input_builder/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ fn trace_code(
None => {
let hash = CodeDB::hash(&code);
log::debug!(
"hash_code done: addr {addr:?}, size {}, hash {hash:?}",
&code.len()
"hash_code done: addr {addr:?}, size {}, hash {hash:?}, code {}, op {:?}",
&code.len(),
hex::encode(&code[..std::cmp::min(20, code.len())]),
step.op,
);
hash
}
Expand Down Expand Up @@ -225,7 +227,7 @@ fn update_codedb(cdb: &mut CodeDB, sdb: &StateDB, block: &BlockTrace) -> Result<
// bustmapping do this job
unreachable!()
}
OpcodeId::EXTCODESIZE | OpcodeId::EXTCODECOPY => {
OpcodeId::EXTCODECOPY => {
let code = data.get_code_at(0);
if code.is_none() {
log::warn!("unable to fetch code from step. {step:?}");
Expand Down
10 changes: 9 additions & 1 deletion bus-mapping/src/evm/opcodes/extcodesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ impl Opcode for Extcodesize {
let (code_hash, code_size) = if exists {
(
account.code_hash,
state.code(account.code_hash)?.len().into(),
if cfg!(feature = "scroll") {
debug_assert_eq!(
account.code_size,
state.code(account.code_hash)?.len().into()
);
account.code_size
} else {
state.code(account.code_hash)?.len().into()
},
)
} else {
(H256::zero(), Word::zero())
Expand Down
11 changes: 1 addition & 10 deletions zkevm-circuits/src/witness/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,12 @@ impl MptUpdates {
MptUpdate::from_rows(key, rows, i, rows_len, old_root, new_root)
})
.collect();
let mpt_updates = MptUpdates {
MptUpdates {
old_root,
new_root,
updates,
..Default::default()
};
// FIXME: we can remove this assert after the code runs a while and everything is ok?
#[cfg(debug_assertions)]
{
let mut rows = rows.to_vec();
rows.sort_by_key(Rw::as_key);
let old_updates = Self::from_rws_with_mock_state_roots(&rows, old_root, new_root);
assert_eq!(old_updates.updates, mpt_updates.updates);
}
mpt_updates
}

pub(crate) fn from_rws_with_mock_state_roots(
Expand Down

0 comments on commit 30ed394

Please sign in to comment.