Skip to main content

revm_context_interface/
cfg.rs

1//! Configuration for the EVM. Containing [`SpecId`].
2
3pub mod gas;
4pub mod gas_params;
5
6pub use gas_params::{GasId, GasParams};
7
8use auto_impl::auto_impl;
9use core::{fmt::Debug, hash::Hash};
10use primitives::{hardfork::SpecId, Address, TxKind, U256};
11
12/// Configuration for the EVM.
13#[auto_impl(&, &mut, Box, Arc)]
14pub trait Cfg {
15    /// Specification id type, it requires to be convertible to `SpecId` so it can be used
16    /// by default in mainnet.
17    type Spec: Into<SpecId> + Clone;
18
19    /// Returns the chain ID of the EVM that is compared with the transaction's chain ID.
20    fn chain_id(&self) -> u64;
21
22    /// Returns whether the transaction's chain ID check is enabled.
23    fn tx_chain_id_check(&self) -> bool;
24
25    /// Returns the gas limit cap for the transaction.
26    ///
27    /// Cap is introduced in [`EIP-7825: Transaction Gas Limit Cap`](https://eips.ethereum.org/EIPS/eip-7825)
28    /// with initial cap of 30M gas.
29    ///
30    /// Value before EIP-7825 is `u64::MAX`.
31    fn tx_gas_limit_cap(&self) -> u64;
32
33    /// Specification id
34    fn spec(&self) -> Self::Spec;
35
36    /// Returns the maximum number of blobs allowed per transaction.
37    /// If it is None, check for max count will be skipped.
38    fn max_blobs_per_tx(&self) -> Option<u64>;
39
40    /// Returns the maximum code size for the given spec id.
41    fn max_code_size(&self) -> usize;
42
43    /// Returns the max initcode size for the given spec id.
44    fn max_initcode_size(&self) -> usize;
45
46    /// Returns whether the EIP-3607 (account clearing) is disabled.
47    fn is_eip3607_disabled(&self) -> bool;
48
49    /// Returns whether the EIP-3541 (disallowing new contracts with 0xEF prefix) is disabled.
50    fn is_eip3541_disabled(&self) -> bool;
51
52    /// Returns whether the EIP-7623 (increased calldata cost) is disabled.
53    fn is_eip7623_disabled(&self) -> bool;
54
55    /// Returns whether the balance check is disabled.
56    fn is_balance_check_disabled(&self) -> bool;
57
58    /// Returns whether the block gas limit check is disabled.
59    fn is_block_gas_limit_disabled(&self) -> bool;
60
61    /// Returns whether the nonce check is disabled.
62    fn is_nonce_check_disabled(&self) -> bool;
63
64    /// Returns whether the base fee check is disabled.
65    fn is_base_fee_check_disabled(&self) -> bool;
66
67    /// Returns whether the priority fee check is disabled.
68    fn is_priority_fee_check_disabled(&self) -> bool;
69
70    /// Returns whether the fee charge is disabled.
71    fn is_fee_charge_disabled(&self) -> bool;
72
73    /// Returns whether EIP-7708 (ETH transfers emit logs) is disabled.
74    fn is_eip7708_disabled(&self) -> bool;
75
76    /// Returns whether EIP-7708 delayed burn logging is disabled.
77    ///
78    /// When enabled, revm tracks all self-destructed addresses and emits logs for
79    /// accounts that still have remaining balance at the end of the transaction.
80    /// This can be disabled for performance reasons as it requires storing and
81    /// iterating over all self-destructed accounts. When disabled, the logging
82    /// can be done outside of revm when applying accounts to database state.
83    fn is_eip7708_delayed_burn_disabled(&self) -> bool;
84
85    /// Returns the limit in bytes for the memory buffer.
86    fn memory_limit(&self) -> u64;
87
88    /// Returns the gas params for the EVM.
89    fn gas_params(&self) -> &GasParams;
90
91    /// Returns whether EIP-8037 (Amsterdam) state creation gas cost increase is enabled.
92    ///
93    /// When enabled, storage creation gas is tracked separately from regular gas
94    /// via the reservoir model. EIP-8037 specifies concrete gas values based on
95    /// `cost_per_state_byte` and adds a hash cost for deployed bytecode.
96    fn is_amsterdam_eip8037_enabled(&self) -> bool;
97}
98
99/// What bytecode analysis to perform
100#[derive(Clone, Default, Debug, Eq, PartialEq, Hash)]
101#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
102pub enum AnalysisKind {
103    /// Do not perform bytecode analysis
104    Raw,
105    /// Perform bytecode analysis
106    #[default]
107    Analyse,
108}
109
110/// Transaction destination
111pub type TransactTo = TxKind;
112
113/// Create scheme
114#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Hash)]
115#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
116pub enum CreateScheme {
117    /// Legacy create scheme of `CREATE`
118    #[default]
119    Create,
120    /// Create scheme of `CREATE2`
121    Create2 {
122        /// Salt
123        salt: U256,
124    },
125    /// Custom scheme where we set up the original address
126    Custom {
127        /// Custom contract creation address.
128        address: Address,
129    },
130}