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_evm::eth::EthEvmContext;
10use alloy_primitives::{Address, map::HashMap};
11use auto_impl::auto_impl;
12use backend::DatabaseExt;
13use revm::{Inspector, inspector::NoOpInspector, interpreter::CreateInputs};
14use revm_inspectors::access_list::AccessListInspector;
15
16/// Map keyed by breakpoints char to their location (contract address, pc)
17pub type Breakpoints = HashMap<char, (Address, usize)>;
18
19#[macro_use]
20extern crate tracing;
21
22pub mod abi {
23    pub use foundry_cheatcodes_spec::Vm;
24    pub use foundry_evm_abi::*;
25}
26
27pub mod env;
28pub use env::*;
29use foundry_evm_networks::NetworkConfigs;
30
31pub mod backend;
32pub mod buffer;
33pub mod bytecode;
34pub mod constants;
35pub mod decode;
36pub mod either_evm;
37pub mod evm;
38pub mod fork;
39pub mod hardfork;
40pub mod ic;
41pub mod opts;
42pub mod precompiles;
43pub mod state_snapshot;
44pub mod utils;
45
46/// An extension trait that allows us to add additional hooks to Inspector for later use in
47/// handlers.
48#[auto_impl(&mut, Box)]
49pub trait InspectorExt: for<'a> Inspector<EthEvmContext<&'a mut dyn DatabaseExt>> {
50    /// Determines whether the `DEFAULT_CREATE2_DEPLOYER` should be used for a CREATE2 frame.
51    ///
52    /// If this function returns true, we'll replace CREATE2 frame with a CALL frame to CREATE2
53    /// factory.
54    fn should_use_create2_factory(
55        &mut self,
56        _context: &mut EthEvmContext<&mut dyn DatabaseExt>,
57        _inputs: &CreateInputs,
58    ) -> 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
78impl InspectorExt for NoOpInspector {}
79
80impl InspectorExt for AccessListInspector {}