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 evm;
38pub mod fork;
39pub mod hardfork;
40pub mod ic;
41pub mod opts;
42pub mod precompiles;
43pub mod state_snapshot;
44pub mod tempo;
45pub mod utils;
46
47/// Foundry-specific inspector methods, decoupled from any particular EVM context type.
48///
49/// This trait holds Foundry-specific extensions (create2 factory, console logging,
50/// network config, deployer address). It has no `Inspector<CTX>` supertrait so it can
51/// be used in generic code with `I: FoundryInspectorExt + Inspector<CTX>`.
52#[auto_impl(&mut, Box)]
53pub trait InspectorExt {
54    /// Determines whether the `DEFAULT_CREATE2_DEPLOYER` should be used for a CREATE2 frame.
55    ///
56    /// If this function returns true, we'll replace CREATE2 frame with a CALL frame to CREATE2
57    /// factory.
58    fn should_use_create2_factory(&mut self, _depth: usize, _inputs: &CreateInputs) -> bool {
59        false
60    }
61
62    /// Simulates `console.log` invocation.
63    fn console_log(&mut self, msg: &str) {
64        let _ = msg;
65    }
66
67    /// Returns configured networks.
68    fn get_networks(&self) -> NetworkConfigs {
69        NetworkConfigs::default()
70    }
71
72    /// Returns the CREATE2 deployer address.
73    fn create2_deployer(&self) -> Address {
74        DEFAULT_CREATE2_DEPLOYER
75    }
76}
77
78/// A combined inspector trait that integrates revm's [`Inspector`] with Foundry-specific
79/// extensions. Automatically implemented for any type that implements both [`Inspector<CTX>`]
80/// and [`InspectorExt`].
81pub trait FoundryInspectorExt<CTX: FoundryContextExt>: Inspector<CTX> + InspectorExt {}
82
83impl<CTX: FoundryContextExt, T> FoundryInspectorExt<CTX> for T where T: Inspector<CTX> + InspectorExt
84{}
85
86impl InspectorExt for NoOpInspector {}
87
88impl InspectorExt for AccessListInspector {}