Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ members = [
"crates/script-sequence/",
"crates/macros/",
"crates/test-utils/",
"crates/revive-utils",
"crates/revive-env",
"crates/revive-strategy",
"crates/lint/",
Expand Down Expand Up @@ -213,6 +214,7 @@ foundry-wallets = { path = "crates/wallets" }
foundry-linking = { path = "crates/linking" }
revive-env = { path = "crates/revive-env" }
revive-strategy = { path = "crates/revive-strategy" }
revive-utils = { path = "crates/revive-utils" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.20.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ foundry-evm-core.workspace = true
foundry-evm-traces.workspace = true
foundry-wallets.workspace = true
forge-script-sequence.workspace = true
revive-utils.workspace = true

alloy-dyn-abi.workspace = true
alloy-evm.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use function::{Function, Mutability, Visibility};
mod items;
pub use items::{Enum, EnumVariant, Error, Event, Struct, StructField};

mod vm;
pub mod vm;
pub use vm::Vm;

// The `cheatcodes.json` schema.
Expand Down
19 changes: 17 additions & 2 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ use foundry_evm_core::{
constants::{CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS, MAGIC_ASSUME},
evm::{FoundryEvm, new_evm_with_existing_context},
};
use foundry_evm_traces::{TracingInspector, TracingInspectorConfig};
use foundry_evm_traces::TracingInspectorConfig;
use foundry_wallets::multi_wallet::MultiWallet;
use itertools::Itertools;
use proptest::test_runner::{RngAlgorithm, TestRng, TestRunner};
use rand::Rng;
use revive_utils::TraceCollector;
use revm::{
Inspector, Journal,
bytecode::opcode as op,
Expand Down Expand Up @@ -108,9 +109,19 @@ pub trait CheatcodesExecutor {
}

/// Returns a mutable reference to the tracing inspector if it is available.
fn tracing_inspector(&mut self) -> Option<&mut Option<TracingInspector>> {
fn tracing_inspector(&mut self) -> Option<&mut Option<TraceCollector>> {
None
}

fn trace_revive(
&mut self,
ccx_state: &mut Cheatcodes,
ecx: Ecx,
call_traces: Box<dyn std::any::Any>,
) {
let mut inspector = self.get_inspector(ccx_state);
inspector.trace_revive(ecx, call_traces, false);
}
}

/// Constructs [FoundryEvm] and runs a given closure with it.
Expand Down Expand Up @@ -924,6 +935,8 @@ impl Cheatcodes {
self.expected_creates.swap_remove(index);
}
}

self.strategy.runner.revive_remove_duplicate_account_access(self);
}

pub fn call_with_executor(
Expand Down Expand Up @@ -1595,6 +1608,8 @@ impl Inspector<EthEvmContext<&mut dyn DatabaseExt>> for Cheatcodes {
}
}

self.strategy.runner.revive_remove_duplicate_account_access(self);

// At the end of the call,
// we need to check if we've found all the emits.
// We know we've found all the expected emits in the right order
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub use strategy::{
mod string;

mod test;
pub use test::expect::ExpectedCallTracker;
pub use test::expect::{ExpectedCallTracker, handle_expect_emit};

mod toml;

Expand Down
2 changes: 2 additions & 0 deletions crates/cheatcodes/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ pub trait CheatcodeInspectorStrategyExt {
) -> Option<revm::interpreter::CallOutcome> {
None
}
// Remove duplicate accesses in storage_recorder
fn revive_remove_duplicate_account_access(&self, _state: &mut crate::Cheatcodes) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why is this needed ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate placeholder records are added in Inspector::call_with_executor/Inspector::create_common this ideally needs to be refactored and moved to strategies, but i'd rather wait and see how zk-foundry does it

}

// Legacy type aliases for backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/test/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ fn expect_emit(
Ok(Default::default())
}

pub(crate) fn handle_expect_emit(
pub fn handle_expect_emit(
state: &mut Cheatcodes,
log: &alloy_primitives::Log,
interpreter: &mut Interpreter,
Expand Down
10 changes: 10 additions & 0 deletions crates/evm/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod precompiles;
pub mod state_snapshot;
pub mod utils;

pub type Ecx<'a, 'b, 'c> = &'a mut EthEvmContext<&'b mut (dyn DatabaseExt + 'c)>;

/// An extension trait that allows us to add additional hooks to Inspector for later use in
/// handlers.
#[auto_impl(&mut, Box)]
Expand Down Expand Up @@ -66,6 +68,14 @@ pub trait InspectorExt: for<'a> Inspector<EthEvmContext<&'a mut dyn DatabaseExt>
fn create2_deployer(&self) -> Address {
DEFAULT_CREATE2_DEPLOYER
}

fn trace_revive(
&mut self,
_context: Ecx<'_, '_, '_>,
_call_traces: Box<dyn std::any::Any>,
_record_top_call: bool,
) {
}
}

impl InspectorExt for NoOpInspector {}
Expand Down
2 changes: 2 additions & 0 deletions crates/evm/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ foundry-evm-core.workspace = true
foundry-evm-coverage.workspace = true
foundry-evm-fuzz.workspace = true
foundry-evm-traces.workspace = true
revive-utils.workspace = true

alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] }
alloy-evm.workspace = true
Expand Down Expand Up @@ -55,3 +56,4 @@ indicatif.workspace = true
serde_json.workspace = true
serde.workspace = true
uuid.workspace = true

33 changes: 29 additions & 4 deletions crates/evm/evm/src/inspectors/stack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
Cheatcodes, CheatsConfig, ChiselState, CustomPrintTracer, Fuzzer, LineCoverageCollector,
LogCollector, RevertDiagnostic, ScriptExecutionInspector, TracingInspector,
LogCollector, RevertDiagnostic, ScriptExecutionInspector,
};
use alloy_evm::{Evm, eth::EthEvmContext};
use alloy_primitives::{
Expand All @@ -9,12 +9,13 @@ use alloy_primitives::{
};
use foundry_cheatcodes::{CheatcodesExecutor, Wallets};
use foundry_evm_core::{
ContextExt, Env, InspectorExt,
ContextExt, Ecx, Env, InspectorExt,
backend::{DatabaseExt, JournaledState},
evm::new_evm_with_inspector,
};
use foundry_evm_coverage::HitMaps;
use foundry_evm_traces::{SparsedTraceArena, TraceMode};
use revive_utils::TraceCollector;
use revm::{
Inspector,
context::{
Expand Down Expand Up @@ -308,7 +309,7 @@ pub struct InspectorStackInner {
pub printer: Option<CustomPrintTracer>,
pub revert_diag: Option<RevertDiagnostic>,
pub script_execution_inspector: Option<ScriptExecutionInspector>,
pub tracer: Option<TracingInspector>,
pub tracer: Option<TraceCollector>,

// InspectorExt and other internal data.
pub enable_isolation: bool,
Expand All @@ -335,7 +336,7 @@ impl CheatcodesExecutor for InspectorStackInner {
Box::new(InspectorStackRefMut { cheatcodes: Some(cheats), inner: self })
}

fn tracing_inspector(&mut self) -> Option<&mut Option<TracingInspector>> {
fn tracing_inspector(&mut self) -> Option<&mut Option<TraceCollector>> {
Some(&mut self.tracer)
}
}
Expand Down Expand Up @@ -1092,6 +1093,20 @@ impl InspectorExt for InspectorStackRefMut<'_> {
fn create2_deployer(&self) -> Address {
self.inner.create2_deployer
}
fn trace_revive(
&mut self,
ecx: Ecx<'_, '_, '_>,
call_traces: Box<dyn std::any::Any>, /* TODO(merge): should be moved elsewhere,
* represents `Vec<Call>` */
record_top_call: bool,
) {
call_inspectors!([&mut self.tracer], |inspector| InspectorExt::trace_revive(
inspector,
ecx,
call_traces,
record_top_call
));
}
}

impl Inspector<EthEvmContext<&mut dyn DatabaseExt>> for InspectorStack {
Expand Down Expand Up @@ -1183,6 +1198,16 @@ impl InspectorExt for InspectorStack {
fn create2_deployer(&self) -> Address {
self.create2_deployer
}

fn trace_revive(
&mut self,
ecx: Ecx<'_, '_, '_>,
call_traces: Box<dyn std::any::Any>, /* TODO(merge): should be moved elsewhere,
* represents `Vec<Call>` */
record_top_call: bool,
) {
self.as_mut().trace_revive(ecx, call_traces, record_top_call);
}
}

impl<'a> Deref for InspectorStackRefMut<'a> {
Expand Down
Loading
Loading