From 30ed394f24c73a8d1537805f30a43877f1096f4d Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Sat, 11 May 2024 15:22:23 +0800 Subject: [PATCH] avoid code hash for extcodesize --- bus-mapping/src/circuit_input_builder/l2.rs | 8 +++++--- bus-mapping/src/evm/opcodes/extcodesize.rs | 10 +++++++++- zkevm-circuits/src/witness/mpt.rs | 11 +---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder/l2.rs b/bus-mapping/src/circuit_input_builder/l2.rs index 0f840b94e2..c035503751 100644 --- a/bus-mapping/src/circuit_input_builder/l2.rs +++ b/bus-mapping/src/circuit_input_builder/l2.rs @@ -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 } @@ -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:?}"); diff --git a/bus-mapping/src/evm/opcodes/extcodesize.rs b/bus-mapping/src/evm/opcodes/extcodesize.rs index db04a50c08..f35520a9e0 100644 --- a/bus-mapping/src/evm/opcodes/extcodesize.rs +++ b/bus-mapping/src/evm/opcodes/extcodesize.rs @@ -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()) diff --git a/zkevm-circuits/src/witness/mpt.rs b/zkevm-circuits/src/witness/mpt.rs index 92788c61a2..26b3720111 100644 --- a/zkevm-circuits/src/witness/mpt.rs +++ b/zkevm-circuits/src/witness/mpt.rs @@ -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(