From f8a07c3d089dc57c39d15fb97f579d89a5e0b709 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 22 Aug 2023 23:13:16 +0200 Subject: [PATCH] Revert "feat(evm): Use latest revm main commit (#5669)" (#5695) * Revert "feat(`evm`): Use latest `revm` main commit (#5669)" This reverts commit efedf1f9e8323bdb1c0fcf0ce728115d0a4a92f4. * test: add basic coverage test * bump --- Cargo.lock | 61 ++++++------------- Cargo.toml | 2 +- crates/anvil/src/eth/backend/mem/inspector.rs | 21 +++++-- crates/anvil/src/eth/error.rs | 8 +-- crates/anvil/src/genesis.rs | 2 +- crates/evm/src/executor/backend/mod.rs | 2 +- crates/evm/src/executor/fork/cache.rs | 17 ++---- .../evm/src/executor/inspector/access_list.rs | 1 + .../executor/inspector/cheatcodes/mapping.rs | 2 +- .../src/executor/inspector/cheatcodes/mod.rs | 8 ++- .../src/executor/inspector/chisel_state.rs | 1 + crates/evm/src/executor/inspector/coverage.rs | 6 +- crates/evm/src/executor/inspector/debugger.rs | 3 + crates/evm/src/executor/inspector/fuzzer.rs | 3 + crates/evm/src/executor/inspector/logs.rs | 1 + crates/evm/src/executor/inspector/printer.rs | 10 ++- crates/evm/src/executor/inspector/stack.rs | 26 +++++--- crates/evm/src/executor/inspector/tracer.rs | 10 ++- crates/evm/src/fuzz/strategies/state.rs | 2 +- crates/forge/tests/cli/coverage.rs | 6 ++ crates/forge/tests/cli/main.rs | 1 + 21 files changed, 106 insertions(+), 87 deletions(-) create mode 100644 crates/forge/tests/cli/coverage.rs diff --git a/Cargo.lock b/Cargo.lock index 949d33496f88..c40e8931cea9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,12 +69,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "alloy-rlp" version = "0.3.2" @@ -631,9 +625,6 @@ name = "bitflags" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" -dependencies = [ - "serde", -] [[package]] name = "bitvec" @@ -1484,9 +1475,9 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.5.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" +checksum = "edd72493923899c6f10c641bdbdeddc7183d6396641d99c1a0d1597f37f92e28" dependencies = [ "cfg-if", "hashbrown 0.14.0", @@ -3189,11 +3180,6 @@ name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -dependencies = [ - "ahash 0.8.3", - "allocator-api2", - "serde", -] [[package]] name = "hashers" @@ -5300,11 +5286,9 @@ dependencies = [ [[package]] name = "revm" version = "3.3.0" -source = "git+https://github.com/bluealloy/revm/?rev=eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2#eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" +source = "git+https://github.com/bluealloy/revm/?branch=release/v25#88337924f4d16ed1f5e4cde12a03d0cb755cd658" dependencies = [ "auto_impl", - "once_cell", - "rayon", "revm-interpreter", "revm-precompile", "serde", @@ -5314,7 +5298,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "1.1.2" -source = "git+https://github.com/bluealloy/revm/?rev=eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2#eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" +source = "git+https://github.com/bluealloy/revm/?branch=release/v25#88337924f4d16ed1f5e4cde12a03d0cb755cd658" dependencies = [ "derive_more", "enumn", @@ -5326,7 +5310,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "2.0.3" -source = "git+https://github.com/bluealloy/revm/?rev=eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2#eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" +source = "git+https://github.com/bluealloy/revm/?branch=release/v25#88337924f4d16ed1f5e4cde12a03d0cb755cd658" dependencies = [ "k256", "num", @@ -5342,16 +5326,15 @@ dependencies = [ [[package]] name = "revm-primitives" version = "1.1.2" -source = "git+https://github.com/bluealloy/revm/?rev=eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2#eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" +source = "git+https://github.com/bluealloy/revm/?branch=release/v25#88337924f4d16ed1f5e4cde12a03d0cb755cd658" dependencies = [ "auto_impl", - "bitflags 2.4.0", "bitvec 1.0.1", "bytes", "derive_more", "enumn", "fixed-hash", - "hashbrown 0.14.0", + "hashbrown 0.13.2", "hex", "hex-literal", "primitive-types", @@ -5359,7 +5342,6 @@ dependencies = [ "ruint", "serde", "sha3", - "to-binary", ] [[package]] @@ -5638,7 +5620,7 @@ checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", - "rustls-webpki 0.101.3", + "rustls-webpki 0.101.4", "sct", ] @@ -5665,9 +5647,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.100.1" +version = "0.100.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +checksum = "e98ff011474fa39949b7e5c0428f9b4937eda7da7848bbb947786b7be0b27dab" dependencies = [ "ring", "untrusted", @@ -5675,9 +5657,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.3" +version = "0.101.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261e9e0888cba427c3316e6322805653c9425240b6fd96cee7cb671ab70ab8d0" +checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" dependencies = [ "ring", "untrusted", @@ -6157,9 +6139,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] @@ -6582,15 +6564,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "to-binary" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424552bc848fd1afbcd81f0e8a54b7401b90fd81bb418655ad6dc6d0823bbe3" -dependencies = [ - "hex", -] - [[package]] name = "tokio" version = "1.32.0" @@ -7097,9 +7070,9 @@ dependencies = [ [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] @@ -7428,7 +7401,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" dependencies = [ - "rustls-webpki 0.100.1", + "rustls-webpki 0.100.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 59b5c182f8fa..d799d70f4b66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,4 +154,4 @@ solang-parser = "=0.3.1" #ethers-solc = { path = "../ethers-rs/ethers-solc" } [patch.crates-io] -revm = { git = "https://github.com/bluealloy/revm/", rev = "eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" } +revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" } diff --git a/crates/anvil/src/eth/backend/mem/inspector.rs b/crates/anvil/src/eth/backend/mem/inspector.rs index 9ca7686c618b..ca409b734a1f 100644 --- a/crates/anvil/src/eth/backend/mem/inspector.rs +++ b/crates/anvil/src/eth/backend/mem/inspector.rs @@ -53,17 +53,23 @@ impl revm::Inspector for Inspector { &mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>, + is_static: bool, ) -> InstructionResult { call_inspectors!([&mut self.tracer], |inspector| { - inspector.initialize_interp(interp, data); + inspector.initialize_interp(interp, data, is_static); }); InstructionResult::Continue } #[inline] - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter, + data: &mut EVMData<'_, DB>, + is_static: bool, + ) -> InstructionResult { call_inspectors!([&mut self.tracer], |inspector| { - inspector.step(interp, data); + inspector.step(interp, data, is_static); }); InstructionResult::Continue } @@ -86,10 +92,11 @@ impl revm::Inspector for Inspector { &mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>, + is_static: bool, eval: InstructionResult, ) -> InstructionResult { call_inspectors!([&mut self.tracer], |inspector| { - inspector.step_end(interp, data, eval); + inspector.step_end(interp, data, is_static, eval); }); eval } @@ -99,9 +106,10 @@ impl revm::Inspector for Inspector { &mut self, data: &mut EVMData<'_, DB>, call: &mut CallInputs, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { call_inspectors!([&mut self.tracer, Some(&mut self.log_collector)], |inspector| { - inspector.call(data, call); + inspector.call(data, call, is_static); }); (InstructionResult::Continue, Gas::new(call.gas_limit), Bytes::new()) @@ -115,9 +123,10 @@ impl revm::Inspector for Inspector { remaining_gas: Gas, ret: InstructionResult, out: Bytes, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { call_inspectors!([&mut self.tracer], |inspector| { - inspector.call_end(data, inputs, remaining_gas, ret, out.clone()); + inspector.call_end(data, inputs, remaining_gas, ret, out.clone(), is_static); }); (ret, remaining_gas, out) } diff --git a/crates/anvil/src/eth/error.rs b/crates/anvil/src/eth/error.rs index 8289fd289b37..888f185d5647 100644 --- a/crates/anvil/src/eth/error.rs +++ b/crates/anvil/src/eth/error.rs @@ -181,9 +181,6 @@ pub enum InvalidTransactionError { /// Thrown when a legacy tx was signed for a different chain #[error("Incompatible EIP-155 transaction, signed for another chain")] IncompatibleEIP155, - /// Thrown when an access list is used before the berlin hard fork. - #[error("Access lists are not supported before the Berlin hardfork")] - AccessListNotSupported, } impl From for InvalidTransactionError { @@ -206,7 +203,7 @@ impl From for InvalidTransactionError { }) } InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA, - InvalidTransaction::LackOfFundForMaxFee { .. } => { + InvalidTransaction::LackOfFundForGasLimit { .. } => { InvalidTransactionError::InsufficientFunds } InvalidTransaction::OverflowPaymentInTransaction => { @@ -220,9 +217,6 @@ impl From for InvalidTransactionError { } InvalidTransaction::NonceTooHigh { .. } => InvalidTransactionError::NonceTooHigh, InvalidTransaction::NonceTooLow { .. } => InvalidTransactionError::NonceTooLow, - InvalidTransaction::AccessListNotSupported => { - InvalidTransactionError::AccessListNotSupported - } } } } diff --git a/crates/anvil/src/genesis.rs b/crates/anvil/src/genesis.rs index 71b64feebd68..3ab285a1018a 100644 --- a/crates/anvil/src/genesis.rs +++ b/crates/anvil/src/genesis.rs @@ -146,7 +146,7 @@ impl From for AccountInfo { AccountInfo { balance: balance.into(), nonce: nonce.unwrap_or_default(), - code_hash: code.as_ref().map(|code| code.hash_slow()).unwrap_or(KECCAK_EMPTY), + code_hash: code.as_ref().map(|code| code.hash).unwrap_or(KECCAK_EMPTY), code, } } diff --git a/crates/evm/src/executor/backend/mod.rs b/crates/evm/src/executor/backend/mod.rs index 3e468f223513..d286cb8a84b7 100644 --- a/crates/evm/src/executor/backend/mod.rs +++ b/crates/evm/src/executor/backend/mod.rs @@ -1099,7 +1099,7 @@ impl DatabaseExt for Backend { // prevent issues in the new journalstate, e.g. assumptions that accounts are loaded // if the account is not touched, we reload it, if it's touched we clone it for (addr, acc) in journaled_state.state.iter() { - if acc.is_touched() { + if acc.is_touched { merge_journaled_state_data( b160_to_h160(*addr), journaled_state, diff --git a/crates/evm/src/executor/fork/cache.rs b/crates/evm/src/executor/fork/cache.rs index bf1429589a0f..dbd4cfe747c8 100644 --- a/crates/evm/src/executor/fork/cache.rs +++ b/crates/evm/src/executor/fork/cache.rs @@ -1,10 +1,9 @@ //! Cache related abstraction use crate::executor::backend::snapshot::StateSnapshot; +use hashbrown::HashMap as Map; use parking_lot::RwLock; use revm::{ - primitives::{ - Account, AccountInfo, AccountStatus, HashMap as Map, B160, B256, KECCAK_EMPTY, U256, - }, + primitives::{Account, AccountInfo, B160, B256, KECCAK_EMPTY, U256}, DatabaseCommit, }; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; @@ -257,17 +256,13 @@ impl MemDb { let mut storage = self.storage.write(); let mut accounts = self.accounts.write(); for (add, mut acc) in changes { - if acc.is_empty() || acc.is_selfdestructed() { + if acc.is_empty() || acc.is_destroyed { accounts.remove(&add); storage.remove(&add); } else { // insert account - if let Some(code_hash) = acc - .info - .code - .as_ref() - .filter(|code| !code.is_empty()) - .map(|code| code.hash_slow()) + if let Some(code_hash) = + acc.info.code.as_ref().filter(|code| !code.is_empty()).map(|code| code.hash) { acc.info.code_hash = code_hash; } else if acc.info.code_hash.is_zero() { @@ -276,7 +271,7 @@ impl MemDb { accounts.insert(add, acc.info); let acc_storage = storage.entry(add).or_default(); - if acc.status.contains(AccountStatus::Created) { + if acc.storage_cleared { acc_storage.clear(); } for (index, value) in acc.storage { diff --git a/crates/evm/src/executor/inspector/access_list.rs b/crates/evm/src/executor/inspector/access_list.rs index 65e15c300add..88619de35da0 100644 --- a/crates/evm/src/executor/inspector/access_list.rs +++ b/crates/evm/src/executor/inspector/access_list.rs @@ -56,6 +56,7 @@ impl Inspector for AccessListTracer { &mut self, interpreter: &mut Interpreter, _data: &mut EVMData<'_, DB>, + _is_static: bool, ) -> InstructionResult { let pc = interpreter.program_counter(); let op = interpreter.contract.bytecode.bytecode()[pc]; diff --git a/crates/evm/src/executor/inspector/cheatcodes/mapping.rs b/crates/evm/src/executor/inspector/cheatcodes/mapping.rs index 0ae5439a938b..cf81dc447eb1 100644 --- a/crates/evm/src/executor/inspector/cheatcodes/mapping.rs +++ b/crates/evm/src/executor/inspector/cheatcodes/mapping.rs @@ -91,7 +91,7 @@ pub fn on_evm_step( _data: &mut EVMData<'_, DB>, ) { match interpreter.contract.bytecode.bytecode()[interpreter.program_counter()] { - opcode::KECCAK256 => { + opcode::SHA3 => { if interpreter.stack.peek(1) == Ok(revm::primitives::U256::from(0x40)) { let address = interpreter.contract.address; let offset = interpreter.stack.peek(0).expect("stack size > 1").to::(); diff --git a/crates/evm/src/executor/inspector/cheatcodes/mod.rs b/crates/evm/src/executor/inspector/cheatcodes/mod.rs index e8900054929a..2a0a24b7b06e 100644 --- a/crates/evm/src/executor/inspector/cheatcodes/mod.rs +++ b/crates/evm/src/executor/inspector/cheatcodes/mod.rs @@ -294,6 +294,7 @@ impl Inspector for Cheatcodes { &mut self, _: &mut Interpreter, data: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { // When the first interpreter is initialized we've circumvented the balance and gas checks, // so we apply our actual block data with the correct fees and all. @@ -311,6 +312,7 @@ impl Inspector for Cheatcodes { &mut self, interpreter: &mut Interpreter, data: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { self.pc = interpreter.program_counter(); @@ -511,7 +513,7 @@ impl Inspector for Cheatcodes { (CALLCODE, 5, 6, true), (STATICCALL, 4, 5, true), (DELEGATECALL, 4, 5, true), - (KECCAK256, 0, 1, false), + (SHA3, 0, 1, false), (LOG0, 0, 1, false), (LOG1, 0, 1, false), (LOG2, 0, 1, false), @@ -566,6 +568,7 @@ impl Inspector for Cheatcodes { &mut self, data: &mut EVMData<'_, DB>, call: &mut CallInputs, + is_static: bool, ) -> (InstructionResult, Gas, bytes::Bytes) { if call.contract == h160_to_b160(CHEATCODE_ADDRESS) { let gas = Gas::new(call.gas_limit); @@ -674,7 +677,7 @@ impl Inspector for Cheatcodes { // because we only need the from, to, value, and data. We can later change this // into 1559, in the cli package, relatively easily once we // know the target chain supports EIP-1559. - if !call.is_static { + if !is_static { if let Err(err) = data .journaled_state .load_account(h160_to_b160(broadcast.new_origin), data.db) @@ -739,6 +742,7 @@ impl Inspector for Cheatcodes { remaining_gas: Gas, status: InstructionResult, retdata: bytes::Bytes, + _: bool, ) -> (InstructionResult, Gas, bytes::Bytes) { if call.contract == h160_to_b160(CHEATCODE_ADDRESS) || call.contract == h160_to_b160(HARDHAT_CONSOLE_ADDRESS) diff --git a/crates/evm/src/executor/inspector/chisel_state.rs b/crates/evm/src/executor/inspector/chisel_state.rs index 958e33cb5cd9..cb7a2a6c17e7 100644 --- a/crates/evm/src/executor/inspector/chisel_state.rs +++ b/crates/evm/src/executor/inspector/chisel_state.rs @@ -26,6 +26,7 @@ impl Inspector for ChiselState { &mut self, interp: &mut Interpreter, _: &mut revm::EVMData<'_, DB>, + _: bool, eval: InstructionResult, ) -> InstructionResult { // If we are at the final pc of the REPL contract execution, set the state. diff --git a/crates/evm/src/executor/inspector/coverage.rs b/crates/evm/src/executor/inspector/coverage.rs index 32a1f29839ad..b7af6f660901 100644 --- a/crates/evm/src/executor/inspector/coverage.rs +++ b/crates/evm/src/executor/inspector/coverage.rs @@ -20,8 +20,9 @@ impl Inspector for CoverageCollector { &mut self, interpreter: &mut Interpreter, _: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { - let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow()); + let hash = b256_to_h256(interpreter.contract.bytecode.hash()); self.maps.entry(hash).or_insert_with(|| { HitMap::new(Bytes::copy_from_slice( interpreter.contract.bytecode.original_bytecode_slice(), @@ -36,8 +37,9 @@ impl Inspector for CoverageCollector { &mut self, interpreter: &mut Interpreter, _: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { - let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow()); + let hash = b256_to_h256(interpreter.contract.bytecode.hash()); self.maps.entry(hash).and_modify(|map| map.hit(interpreter.program_counter())); InstructionResult::Continue diff --git a/crates/evm/src/executor/inspector/debugger.rs b/crates/evm/src/executor/inspector/debugger.rs index a21a0f3247a8..e051ad73cf53 100644 --- a/crates/evm/src/executor/inspector/debugger.rs +++ b/crates/evm/src/executor/inspector/debugger.rs @@ -55,6 +55,7 @@ impl Inspector for Debugger { &mut self, interpreter: &mut Interpreter, data: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { let pc = interpreter.program_counter(); let op = interpreter.contract.bytecode.bytecode()[pc]; @@ -97,6 +98,7 @@ impl Inspector for Debugger { &mut self, data: &mut EVMData<'_, DB>, call: &mut CallInputs, + _: bool, ) -> (InstructionResult, Gas, Bytes) { self.enter( data.journaled_state.depth() as usize, @@ -124,6 +126,7 @@ impl Inspector for Debugger { gas: Gas, status: InstructionResult, retdata: Bytes, + _: bool, ) -> (InstructionResult, Gas, Bytes) { self.exit(); diff --git a/crates/evm/src/executor/inspector/fuzzer.rs b/crates/evm/src/executor/inspector/fuzzer.rs index a7363614a01a..17926e887f1d 100644 --- a/crates/evm/src/executor/inspector/fuzzer.rs +++ b/crates/evm/src/executor/inspector/fuzzer.rs @@ -25,6 +25,7 @@ impl Inspector for Fuzzer { &mut self, interpreter: &mut Interpreter, _: &mut EVMData<'_, DB>, + _: bool, ) -> InstructionResult { // We only collect `stack` and `memory` data before and after calls. if self.collect { @@ -39,6 +40,7 @@ impl Inspector for Fuzzer { &mut self, data: &mut EVMData<'_, DB>, call: &mut CallInputs, + _: bool, ) -> (InstructionResult, Gas, Bytes) { // We don't want to override the very first call made to the test contract. if self.call_generator.is_some() && data.env.tx.caller != call.context.caller { @@ -60,6 +62,7 @@ impl Inspector for Fuzzer { remaining_gas: Gas, status: InstructionResult, retdata: Bytes, + _: bool, ) -> (InstructionResult, Gas, Bytes) { if let Some(ref mut call_generator) = self.call_generator { call_generator.used = false; diff --git a/crates/evm/src/executor/inspector/logs.rs b/crates/evm/src/executor/inspector/logs.rs index a4124d4695a6..c848e329c9f7 100644 --- a/crates/evm/src/executor/inspector/logs.rs +++ b/crates/evm/src/executor/inspector/logs.rs @@ -57,6 +57,7 @@ impl Inspector for LogCollector { &mut self, _: &mut EVMData<'_, DB>, call: &mut CallInputs, + _: bool, ) -> (InstructionResult, Gas, Bytes) { if call.contract == h160_to_b160(HARDHAT_CONSOLE_ADDRESS) { let (status, reason) = self.hardhat_log(call.input.to_vec()); diff --git a/crates/evm/src/executor/inspector/printer.rs b/crates/evm/src/executor/inspector/printer.rs index 0f8d9127bf87..6b694f12f0ee 100644 --- a/crates/evm/src/executor/inspector/printer.rs +++ b/crates/evm/src/executor/inspector/printer.rs @@ -12,7 +12,12 @@ pub struct TracePrinter; impl Inspector for TracePrinter { // get opcode by calling `interp.contract.opcode(interp.program_counter())`. // all other information can be obtained from interp. - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter, + data: &mut EVMData<'_, DB>, + _: bool, + ) -> InstructionResult { let opcode = interp.current_opcode(); let opcode_str = opcode::OPCODE_JUMPMAP[opcode as usize]; let gas_remaining = interp.gas.remaining(); @@ -38,12 +43,13 @@ impl Inspector for TracePrinter { &mut self, _data: &mut EVMData<'_, DB>, inputs: &mut CallInputs, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { println!( "SM CALL: {:?},context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}", inputs.contract, inputs.context, - inputs.is_static, + is_static, inputs.transfer, inputs.input.len(), ); diff --git a/crates/evm/src/executor/inspector/stack.rs b/crates/evm/src/executor/inspector/stack.rs index d626fc3d4e33..7c22a4d65d55 100644 --- a/crates/evm/src/executor/inspector/stack.rs +++ b/crates/evm/src/executor/inspector/stack.rs @@ -326,6 +326,7 @@ impl InspectorStack { remaining_gas: Gas, status: InstructionResult, retdata: Bytes, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { call_inspectors!( [ @@ -338,8 +339,14 @@ impl InspectorStack { &mut self.printer ], |inspector| { - let (new_status, new_gas, new_retdata) = - inspector.call_end(data, call, remaining_gas, status, retdata.clone()); + let (new_status, new_gas, new_retdata) = inspector.call_end( + data, + call, + remaining_gas, + status, + retdata.clone(), + is_static, + ); // If the inspector returns a different status or a revert with a non-empty message, // we assume it wants to tell us something @@ -360,6 +367,7 @@ impl Inspector for InspectorStack { &mut self, interpreter: &mut Interpreter, data: &mut EVMData<'_, DB>, + is_static: bool, ) -> InstructionResult { call_inspectors!( [ @@ -371,7 +379,7 @@ impl Inspector for InspectorStack { &mut self.printer ], |inspector| { - let status = inspector.initialize_interp(interpreter, data); + let status = inspector.initialize_interp(interpreter, data, is_static); // Allow inspectors to exit early if status != InstructionResult::Continue { @@ -387,6 +395,7 @@ impl Inspector for InspectorStack { &mut self, interpreter: &mut Interpreter, data: &mut EVMData<'_, DB>, + is_static: bool, ) -> InstructionResult { call_inspectors!( [ @@ -399,7 +408,7 @@ impl Inspector for InspectorStack { &mut self.printer ], |inspector| { - let status = inspector.step(interpreter, data); + let status = inspector.step(interpreter, data, is_static); // Allow inspectors to exit early if status != InstructionResult::Continue { @@ -430,6 +439,7 @@ impl Inspector for InspectorStack { &mut self, interpreter: &mut Interpreter, data: &mut EVMData<'_, DB>, + is_static: bool, status: InstructionResult, ) -> InstructionResult { call_inspectors!( @@ -442,7 +452,7 @@ impl Inspector for InspectorStack { &mut self.chisel_state ], |inspector| { - let status = inspector.step_end(interpreter, data, status); + let status = inspector.step_end(interpreter, data, is_static, status); // Allow inspectors to exit early if status != InstructionResult::Continue { @@ -458,6 +468,7 @@ impl Inspector for InspectorStack { &mut self, data: &mut EVMData<'_, DB>, call: &mut CallInputs, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { call_inspectors!( [ @@ -470,7 +481,7 @@ impl Inspector for InspectorStack { &mut self.printer ], |inspector| { - let (status, gas, retdata) = inspector.call(data, call); + let (status, gas, retdata) = inspector.call(data, call, is_static); // Allow inspectors to exit early if status != InstructionResult::Continue { @@ -489,8 +500,9 @@ impl Inspector for InspectorStack { remaining_gas: Gas, status: InstructionResult, retdata: Bytes, + is_static: bool, ) -> (InstructionResult, Gas, Bytes) { - let res = self.do_call_end(data, call, remaining_gas, status, retdata); + let res = self.do_call_end(data, call, remaining_gas, status, retdata, is_static); if matches!(res.0, return_revert!()) { // Encountered a revert, since cheatcodes may have altered the evm state in such a way diff --git a/crates/evm/src/executor/inspector/tracer.rs b/crates/evm/src/executor/inspector/tracer.rs index c8851edf7ec7..5d5c80ba6b55 100644 --- a/crates/evm/src/executor/inspector/tracer.rs +++ b/crates/evm/src/executor/inspector/tracer.rs @@ -150,7 +150,12 @@ impl Tracer { impl Inspector for Tracer { #[inline] - fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult { + fn step( + &mut self, + interp: &mut Interpreter, + data: &mut EVMData<'_, DB>, + _is_static: bool, + ) -> InstructionResult { if self.record_steps { self.start_step(interp, data); } @@ -162,6 +167,7 @@ impl Inspector for Tracer { &mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>, + _: bool, status: InstructionResult, ) -> InstructionResult { if self.record_steps { @@ -183,6 +189,7 @@ impl Inspector for Tracer { &mut self, data: &mut EVMData<'_, DB>, inputs: &mut CallInputs, + _: bool, ) -> (InstructionResult, Gas, Bytes) { let (from, to) = match inputs.context.scheme { CallScheme::DelegateCall | CallScheme::CallCode => { @@ -211,6 +218,7 @@ impl Inspector for Tracer { gas: Gas, status: InstructionResult, retdata: Bytes, + _: bool, ) -> (InstructionResult, Gas, Bytes) { self.fill_trace( status, diff --git a/crates/evm/src/fuzz/strategies/state.rs b/crates/evm/src/fuzz/strategies/state.rs index ba62a0eb2256..2cad56de2498 100644 --- a/crates/evm/src/fuzz/strategies/state.rs +++ b/crates/evm/src/fuzz/strategies/state.rs @@ -268,7 +268,7 @@ pub fn collect_created_contracts( for (address, account) in state_changeset { if !setup_contracts.contains_key(&b160_to_h160(*address)) { - if let (true, Some(code)) = (&account.is_touched(), &account.info.code) { + if let (true, Some(code)) = (&account.is_touched, &account.info.code) { if !code.is_empty() { if let Some((artifact, (abi, _))) = project_contracts.find_by_code(code.bytes()) { diff --git a/crates/forge/tests/cli/coverage.rs b/crates/forge/tests/cli/coverage.rs new file mode 100644 index 000000000000..05b76a06fdf1 --- /dev/null +++ b/crates/forge/tests/cli/coverage.rs @@ -0,0 +1,6 @@ +use foundry_test_utils::{forgetest, TestCommand, TestProject}; + +forgetest!(basic_coverage, |_prj: TestProject, mut cmd: TestCommand| { + cmd.args(["coverage"]); + cmd.assert_success(); +}); diff --git a/crates/forge/tests/cli/main.rs b/crates/forge/tests/cli/main.rs index 0a05fe038be8..69868c93a7c8 100644 --- a/crates/forge/tests/cli/main.rs +++ b/crates/forge/tests/cli/main.rs @@ -4,6 +4,7 @@ pub mod utils; mod cache; mod cmd; mod config; +mod coverage; mod create; mod doc; mod multi_script;