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