diff --git a/Cargo.lock b/Cargo.lock index e143a18d4..b2f5852de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5237,7 +5237,6 @@ dependencies = [ "foundry-evm-traces", "foundry-zksync-core", "indicatif", - "itertools 0.13.0", "parking_lot 0.12.3", "proptest", "revm", diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index f036e55ea..f8954a882 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -27,6 +27,7 @@ use foundry_evm_core::{ abi::{Vm::stopExpectSafeMemoryCall, HARDHAT_CONSOLE_ADDRESS}, backend::{DatabaseError, DatabaseExt, LocalForkId, RevertDiagnostic}, constants::{CHEATCODE_ADDRESS, CHEATCODE_CONTRACT_HASH, DEFAULT_CREATE2_DEPLOYER_CODE}, + decode::decode_console_log, utils::new_evm_with_existing_context, InspectorExt, }; @@ -341,11 +342,6 @@ pub struct Cheatcodes { /// Dual compiled contracts pub dual_compiled_contracts: DualCompiledContracts, - /// Logs printed during ZK-VM execution. - /// EVM logs have the value `None` so they can be interpolated later, since - /// they are recorded by [foundry_evm::inspectors::LogCollector] tracer. - pub combined_logs: Vec>, - /// Starts the cheatcode inspector in ZK mode. /// This is set to `false`, once the startup migration is completed. pub startup_zk: bool, @@ -438,7 +434,6 @@ impl Cheatcodes { mapping_slots: Default::default(), pc: Default::default(), breakpoints: Default::default(), - combined_logs: Default::default(), use_zk_vm: Default::default(), persisted_factory_deps: Default::default(), } @@ -929,7 +924,21 @@ impl Cheatcodes { emitter: log.address, })); } - self.combined_logs.extend(result.logs.clone().into_iter().map(Some)); + + // append console logs from zkEVM to the current executor's LogTracer + let executor = &mut TransparentCheatcodesExecutor; + result.logs.iter().filter_map(decode_console_log).for_each(|decoded_log| { + executor.console_log( + &mut CheatsCtxt { + state: self, + ecx: &mut ecx.inner, + precompiles: &mut ecx.precompiles, + gas_limit: create_inputs.gas_limit, + caller: create_inputs.caller, + }, + decoded_log, + ); + }); // for each log in cloned logs call handle_expect_emit if !self.expected_emits.is_empty() { @@ -1150,7 +1159,6 @@ impl Cheatcodes { } if call.target_address == HARDHAT_CONSOLE_ADDRESS { - self.combined_logs.push(None); return None; } @@ -1394,8 +1402,22 @@ impl Cheatcodes { emitter: log.address, })); } - self.combined_logs.extend(result.logs.clone().into_iter().map(Some)); - //for each log in cloned logs call handle_expect_emit + + // append console logs from zkEVM to the current executor's LogTracer + result.logs.iter().filter_map(decode_console_log).for_each(|decoded_log| { + executor.console_log( + &mut CheatsCtxt { + state: self, + ecx: &mut ecx.inner, + precompiles: &mut ecx.precompiles, + gas_limit: call.gas_limit, + caller: call.caller, + }, + decoded_log, + ); + }); + + // for each log in cloned logs call handle_expect_emit if !self.expected_emits.is_empty() { for log in result.logs { expect::handle_expect_emit(self, &log); @@ -1537,7 +1559,6 @@ impl Inspector for Cheatcodes { emitter: log.address, }); } - self.combined_logs.push(None); } fn call( diff --git a/crates/evm/evm/Cargo.toml b/crates/evm/evm/Cargo.toml index 384a88d6b..f861784fe 100644 --- a/crates/evm/evm/Cargo.toml +++ b/crates/evm/evm/Cargo.toml @@ -50,5 +50,4 @@ parking_lot.workspace = true proptest.workspace = true thiserror.workspace = true tracing.workspace = true -itertools.workspace = true indicatif = "0.17" diff --git a/crates/evm/evm/src/executors/mod.rs b/crates/evm/evm/src/executors/mod.rs index 0f67c332e..a75b81639 100644 --- a/crates/evm/evm/src/executors/mod.rs +++ b/crates/evm/evm/src/executors/mod.rs @@ -25,7 +25,6 @@ use foundry_evm_core::{ use foundry_evm_coverage::HitMaps; use foundry_evm_traces::{CallTraceArena, TraceMode}; use foundry_zksync_core::ZkTransactionMetadata; -use itertools::Itertools; use revm::{ db::{DatabaseCommit, DatabaseRef}, interpreter::{return_ok, InstructionResult}, @@ -936,32 +935,9 @@ fn convert_executed_result( _ => Bytes::new(), }; - let combined_logs = - inspector.cheatcodes.as_ref().map(|cheatcodes| cheatcodes.combined_logs.clone()); - let InspectorData { mut logs, labels, traces, coverage, cheatcodes, chisel_state } = + let InspectorData { logs, labels, traces, coverage, cheatcodes, chisel_state } = inspector.collect(); - let logs = match combined_logs { - Some(combined_logs) => { - let new_logs = combined_logs - .into_iter() - // .map(|log| log.unwrap_or_else(|| logs.remove(0))) - .map(|log| { - log.unwrap_or_else(|| { - if !logs.is_empty() { - logs.remove(0) - } else { - Default::default() - } - }) - }) - .collect_vec(); - assert!(logs.is_empty(), "logs were not fully combined"); - new_logs - } - None => logs, - }; - let transactions = cheatcodes .as_ref() .map(|c| c.broadcastable_transactions.clone())