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 the EIP-8246 delayed clearing of self-destructed accounts is disabled.
77 ///
78 /// When enabled, revm tracks all self-destructed addresses and, at the end of the
79 /// transaction, clears the code, storage and nonce of any that still have a remaining
80 /// balance while preserving the balance ([EIP-8246]). This can be disabled for performance
81 /// reasons as it requires storing and iterating over all self-destructed accounts. When
82 /// disabled, this clearing can be done outside of revm when applying accounts to database
83 /// state.
84 ///
85 /// [EIP-8246]: https://eips.ethereum.org/EIPS/eip-8246
86 fn is_eip8246_delayed_clear_disabled(&self) -> bool;
87
88 /// Returns the limit in bytes for the memory buffer.
89 fn memory_limit(&self) -> u64;
90
91 /// Returns the gas params for the EVM.
92 fn gas_params(&self) -> &GasParams;
93
94 /// Returns whether EIP-8037 (Amsterdam) state creation gas cost increase is enabled.
95 ///
96 /// When enabled, storage creation gas is tracked separately from regular gas
97 /// via the reservoir model. EIP-8037 specifies concrete gas values based on
98 /// `cost_per_state_byte` and adds a hash cost for deployed bytecode.
99 fn is_amsterdam_eip8037_enabled(&self) -> bool;
100
101 /// Returns whether EIP-2780 (Amsterdam) reduced intrinsic transaction gas
102 /// is enabled.
103 ///
104 /// When enabled, the legacy `21,000` intrinsic base is replaced with the
105 /// decomposed `TX_BASE_COST + to-based + value-based` model and top-level
106 /// execution charges are applied for empty recipients with value and
107 /// EIP-7702-delegated recipients.
108 fn is_amsterdam_eip2780_enabled(&self) -> bool;
109}
110
111/// What bytecode analysis to perform
112#[derive(Clone, Default, Debug, Eq, PartialEq, Hash)]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114pub enum AnalysisKind {
115 /// Do not perform bytecode analysis
116 Raw,
117 /// Perform bytecode analysis
118 #[default]
119 Analyse,
120}
121
122/// Transaction destination
123pub type TransactTo = TxKind;
124
125/// Create scheme
126#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Hash)]
127#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
128pub enum CreateScheme {
129 /// Legacy create scheme of `CREATE`
130 #[default]
131 Create,
132 /// Create scheme of `CREATE2`
133 Create2 {
134 /// Salt
135 salt: U256,
136 },
137 /// Custom scheme where we set up the original address
138 Custom {
139 /// Custom contract creation address.
140 address: Address,
141 },
142}