Skip to main content

foundry_evm_core/
lib.rs

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