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_evm::eth::EthEvmContext;
10use alloy_primitives::Address;
11use auto_impl::auto_impl;
12use backend::DatabaseExt;
13use revm::{Inspector, inspector::NoOpInspector, interpreter::CreateInputs};
14use revm_inspectors::access_list::AccessListInspector;
15
16#[macro_use]
17extern crate tracing;
18
19pub mod abi {
20    pub use foundry_cheatcodes_spec::Vm;
21    pub use foundry_evm_abi::*;
22}
23
24pub mod env;
25pub use env::*;
26pub mod backend;
27pub mod buffer;
28pub mod constants;
29pub mod decode;
30pub mod either_evm;
31pub mod evm;
32pub mod fork;
33pub mod ic;
34pub mod opts;
35pub mod precompiles;
36pub mod state_snapshot;
37pub mod utils;
38
39pub type Ecx<'a, 'b, 'c> = &'a mut EthEvmContext<&'b mut (dyn DatabaseExt + 'c)>;
40
41/// An extension trait that allows us to add additional hooks to Inspector for later use in
42/// handlers.
43#[auto_impl(&mut, Box)]
44pub trait InspectorExt: for<'a> Inspector<EthEvmContext<&'a mut dyn DatabaseExt>> {
45    /// Determines whether the `DEFAULT_CREATE2_DEPLOYER` should be used for a CREATE2 frame.
46    ///
47    /// If this function returns true, we'll replace CREATE2 frame with a CALL frame to CREATE2
48    /// factory.
49    fn should_use_create2_factory(
50        &mut self,
51        _context: &mut EthEvmContext<&mut dyn DatabaseExt>,
52        _inputs: &CreateInputs,
53    ) -> bool {
54        false
55    }
56
57    /// Simulates `console.log` invocation.
58    fn console_log(&mut self, msg: &str) {
59        let _ = msg;
60    }
61
62    /// Returns `true` if the current network is Odyssey.
63    fn is_odyssey(&self) -> bool {
64        false
65    }
66
67    /// Returns the CREATE2 deployer address.
68    fn create2_deployer(&self) -> Address {
69        DEFAULT_CREATE2_DEPLOYER
70    }
71
72    fn trace_revive(
73        &mut self,
74        _context: Ecx<'_, '_, '_>,
75        _call_traces: Box<dyn std::any::Any>,
76        _record_top_call: bool,
77    ) {
78    }
79}
80
81impl InspectorExt for NoOpInspector {}
82
83impl InspectorExt for AccessListInspector {}