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