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 ic;
40pub mod opts;
41pub mod precompiles;
42pub mod state_snapshot;
43pub mod utils;
44
45/// An extension trait that allows us to add additional hooks to Inspector for later use in
46/// handlers.
47#[auto_impl(&mut, Box)]
48pub trait InspectorExt: for<'a> Inspector<EthEvmContext<&'a mut dyn DatabaseExt>> {
49    /// Determines whether the `DEFAULT_CREATE2_DEPLOYER` should be used for a CREATE2 frame.
50    ///
51    /// If this function returns true, we'll replace CREATE2 frame with a CALL frame to CREATE2
52    /// factory.
53    fn should_use_create2_factory(
54        &mut self,
55        _context: &mut EthEvmContext<&mut dyn DatabaseExt>,
56        _inputs: &CreateInputs,
57    ) -> bool {
58        false
59    }
60
61    /// Simulates `console.log` invocation.
62    fn console_log(&mut self, msg: &str) {
63        let _ = msg;
64    }
65
66    /// Returns configured networks.
67    fn get_networks(&self) -> NetworkConfigs {
68        NetworkConfigs::default()
69    }
70
71    /// Returns the CREATE2 deployer address.
72    fn create2_deployer(&self) -> Address {
73        DEFAULT_CREATE2_DEPLOYER
74    }
75}
76
77impl InspectorExt for NoOpInspector {}
78
79impl InspectorExt for AccessListInspector {}