From b779133ef9b4586e174ee2089926431d6d2ec622 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Sat, 2 Sep 2023 15:15:00 +0800 Subject: [PATCH 1/2] feat: check post tx account --- bus-mapping/src/circuit_input_builder.rs | 27 +++++++++++++++++++ .../src/circuit_input_builder/tracer_tests.rs | 1 + eth-types/src/l2_types.rs | 5 ++-- eth-types/src/lib.rs | 5 ++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder.rs b/bus-mapping/src/circuit_input_builder.rs index 557f418270..c364f52245 100644 --- a/bus-mapping/src/circuit_input_builder.rs +++ b/bus-mapping/src/circuit_input_builder.rs @@ -330,6 +330,33 @@ impl<'a> CircuitInputBuilder { self.block_ctx.rwc, self.block_ctx.cumulative_gas_used ); + for account_post_state in &geth_trace.account_after { + let account_post_state: eth_types::l2_types::AccountProofWrapper = + account_post_state.clone(); + if let Some(address) = account_post_state.address { + let local_acc = self.sdb.get_account(&address).1; + log::trace!("local acc {local_acc:?}, trace acc {account_post_state:?}"); + if local_acc.balance != account_post_state.balance.unwrap() { + log::error!("incorrect balance") + } + if local_acc.nonce != account_post_state.nonce.unwrap().into() { + log::error!("incorrect nonce") + } + if local_acc.code_hash != account_post_state.poseidon_code_hash.unwrap() { + log::error!("incorrect poseidon_code_hash") + } + if local_acc.keccak_code_hash != account_post_state.keccak_code_hash.unwrap() { + log::error!("incorrect keccak_code_hash") + } + if let Some(storage) = account_post_state.storage { + let k = storage.key.unwrap(); + let local_v = self.sdb.get_storage(&address, &k).1; + if *local_v != storage.value.unwrap() { + log::error!("incorrect storage for k = {k}"); + } + } + } + } } if handle_rwc_reversion { self.set_value_ops_call_context_rwc_eor(); diff --git a/bus-mapping/src/circuit_input_builder/tracer_tests.rs b/bus-mapping/src/circuit_input_builder/tracer_tests.rs index d8b2d0e08f..5850da253e 100644 --- a/bus-mapping/src/circuit_input_builder/tracer_tests.rs +++ b/bus-mapping/src/circuit_input_builder/tracer_tests.rs @@ -51,6 +51,7 @@ impl CircuitInputBuilderTx { failed: false, return_value: "".to_owned(), struct_logs: vec![geth_step.clone()], + account_after: vec![], }, false, ) diff --git a/eth-types/src/l2_types.rs b/eth-types/src/l2_types.rs index 436ab34bda..d7b41c669e 100644 --- a/eth-types/src/l2_types.rs +++ b/eth-types/src/l2_types.rs @@ -196,6 +196,7 @@ impl From<&ExecutionResult> for GethExecTrace { failed: e.failed, return_value: e.return_value.clone(), struct_logs, + account_after: e.account_after.clone(), } } } @@ -267,7 +268,7 @@ impl ExtraData { } /// account wrapper for account status -#[derive(Serialize, Deserialize, Clone, Default, Debug)] +#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq)] #[doc(hidden)] pub struct AccountProofWrapper { pub address: Option
, @@ -281,7 +282,7 @@ pub struct AccountProofWrapper { } /// storage wrapper for storage status -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[doc(hidden)] pub struct StorageProofWrapper { pub key: Option, diff --git a/eth-types/src/lib.rs b/eth-types/src/lib.rs index 04588e6d92..b0a693690f 100644 --- a/eth-types/src/lib.rs +++ b/eth-types/src/lib.rs @@ -475,6 +475,10 @@ pub struct GethExecTrace { /// Vector of geth execution steps of the trace. #[serde(rename = "structLogs")] pub struct_logs: Vec, + #[serde(rename = "accountAfter", default)] + /// List of accounts' (coinbase etc) status AFTER execution + /// Only viable for scroll mode + pub account_after: Vec, } #[macro_export] @@ -599,6 +603,7 @@ mod tests { gas: Gas(26809), failed: false, return_value: "".to_owned(), + account_after: Vec::new(), struct_logs: vec![ GethExecStep { pc: ProgramCounter(0), From b44dcb7c358c2ea9f44616e987aace62410a7b5b Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Sat, 2 Sep 2023 15:57:53 +0800 Subject: [PATCH 2/2] fix --- Makefile | 6 +++--- bus-mapping/src/lib.rs | 1 + testool/src/statetest/spec.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 69a6905d7d..e42caf73b9 100644 --- a/Makefile +++ b/Makefile @@ -22,13 +22,13 @@ test-heavy: ## Run heavy tests serially to avoid OOM test: test-light test-heavy ## Run tests for all the workspace members -test_doc: ## Test the docs +test-doc: ## Test the docs @cargo test --release --all --all-features --doc -test_benches: ## Compiles the benchmarks +test-benches: ## Compiles the benchmarks @cargo test --verbose --release --all-features -p circuit-benchmarks --no-run -test-all: fmt doc clippy test_doc test_benches test ## Run all the CI checks locally (in your actual toolchain) +test-all: fmt doc clippy test-doc test-benches test ## Run all the CI checks locally (in your actual toolchain) super_bench: ## Run Super Circuit benchmarks @cargo test --profile bench bench_super_circuit_prover -p circuit-benchmarks --features benches -- --nocapture diff --git a/bus-mapping/src/lib.rs b/bus-mapping/src/lib.rs index cfca225f0f..f3b97e19f5 100644 --- a/bus-mapping/src/lib.rs +++ b/bus-mapping/src/lib.rs @@ -138,6 +138,7 @@ //! //! let geth_steps: Vec = serde_json::from_str(input_trace).unwrap(); //! let geth_trace = GethExecTrace { +//! account_after: Vec::new(), //! l1_fee: 0, //! return_value: "".to_string(), //! gas: Gas(block.eth_block.transactions[0].gas.as_u64()), diff --git a/testool/src/statetest/spec.rs b/testool/src/statetest/spec.rs index 1a9ba9d603..1dff6ddea3 100644 --- a/testool/src/statetest/spec.rs +++ b/testool/src/statetest/spec.rs @@ -6,7 +6,7 @@ use std::{ str::FromStr, }; -/// https://github.com/ethereum/tests/pull/857 "set default gasPrice to 10" +/// "set default gasPrice to 10" pub const DEFAULT_BASE_FEE: u32 = 10; #[derive(PartialEq, Eq, Debug, Clone)]