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 the limit in bytes for the memory buffer.
74 fn memory_limit(&self) -> u64;
75
76 /// Returns the gas params for the EVM.
77 fn gas_params(&self) -> &GasParams;
78}
79
80/// What bytecode analysis to perform
81#[derive(Clone, Default, Debug, Eq, PartialEq, Hash)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub enum AnalysisKind {
84 /// Do not perform bytecode analysis
85 Raw,
86 /// Perform bytecode analysis
87 #[default]
88 Analyse,
89}
90
91/// Transaction destination
92pub type TransactTo = TxKind;
93
94/// Create scheme
95#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Hash)]
96#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
97pub enum CreateScheme {
98 /// Legacy create scheme of `CREATE`
99 #[default]
100 Create,
101 /// Create scheme of `CREATE2`
102 Create2 {
103 /// Salt
104 salt: U256,
105 },
106 /// Custom scheme where we set up the original address
107 Custom {
108 /// Custom contract creation address.
109 address: Address,
110 },
111}