Skip to main content

foundry_evm_core/
lib.rs

1//! # foundry-evm-core
2//!
3//! Generic execution, environment, fork, backend, and state abstractions shared by Foundry tools.
4//!
5//! [`evm::FoundryEvmNetwork`] binds an Alloy network to an [`evm::FoundryEvmFactory`]. The factory
6//! owns the concrete execution types and constructs a Foundry-compatible EVM context, while
7//! `foundry-evm-networks` owns runtime family selection. Keeping those responsibilities separate
8//! allows one compiled binary to dispatch to different execution families at runtime.
9
10#![cfg_attr(not(test), warn(unused_crate_dependencies))]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12
13#[cfg(feature = "optimism")]
14use op_alloy_rpc_types as _;
15
16use crate::constants::DEFAULT_CREATE2_DEPLOYER;
17use alloy_primitives::{Address, map::HashMap};
18use auto_impl::auto_impl;
19use revm::{Inspector, inspector::NoOpInspector, interpreter::CreateInputs};
20use revm_inspectors::access_list::AccessListInspector;
21
22/// Map keyed by breakpoints char to their location (contract address, pc)
23pub type Breakpoints = HashMap<char, (Address, usize)>;
24
25#[macro_use]
26extern crate tracing;
27
28pub mod abi {
29    pub use foundry_cheatcodes_spec::Vm;
30    pub use foundry_evm_abi::*;
31}
32
33pub mod env;
34pub use env::*;
35use foundry_evm_networks::NetworkConfigs;
36
37pub mod backend;
38pub mod buffer;
39pub mod bytecode;
40pub mod constants;
41pub mod decode;
42pub mod eip2935;
43pub mod evm;
44pub mod fork;
45pub mod hardfork;
46pub mod ic;
47pub mod opts;
48pub mod precompiles;
49pub mod state_snapshot;
50pub mod tempo;
51pub mod utils;
52
53/// Foundry-specific inspector methods, decoupled from any particular EVM context type.
54///
55/// This trait holds Foundry-specific extensions (create2 factory, console logging,
56/// network config, deployer address). It has no `Inspector<CTX>` supertrait so it can
57/// be used in generic code with `I: FoundryInspectorExt + Inspector<CTX>`.
58#[auto_impl(&mut, Box)]
59pub trait InspectorExt {
60    /// Determines whether the `DEFAULT_CREATE2_DEPLOYER` should be used for a CREATE2 frame.
61    ///
62    /// If this function returns true, we'll replace CREATE2 frame with a CALL frame to CREATE2
63    /// factory.
64    fn should_use_create2_factory(&mut self, _depth: usize, _inputs: &CreateInputs) -> bool {
65        false
66    }
67
68    /// Simulates `console.log` invocation.
69    fn console_log(&mut self, msg: &str) {
70        let _ = msg;
71    }
72
73    /// Returns configured networks.
74    fn get_networks(&self) -> NetworkConfigs {
75        NetworkConfigs::default()
76    }
77
78    /// Returns the CREATE2 deployer address.
79    fn create2_deployer(&self) -> Address {
80        DEFAULT_CREATE2_DEPLOYER
81    }
82}
83
84/// A combined inspector trait that integrates revm's [`Inspector`] with Foundry-specific
85/// extensions. Automatically implemented for any type that implements both [`Inspector<CTX>`]
86/// and [`InspectorExt`].
87pub trait FoundryInspectorExt<CTX: FoundryContextExt>: Inspector<CTX> + InspectorExt {}
88
89impl<CTX: FoundryContextExt, T> FoundryInspectorExt<CTX> for T where T: Inspector<CTX> + InspectorExt
90{}
91
92impl InspectorExt for NoOpInspector {}
93
94impl InspectorExt for AccessListInspector {}