Skip to main content

revm_rwasm_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    /// Returns whether legacy bytecode creation is enabled.
80    fn is_legacy_bytecode_enabled(&self) -> bool;
81}
82
83/// What bytecode analysis to perform
84#[derive(Clone, Default, Debug, Eq, PartialEq, Hash)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
86pub enum AnalysisKind {
87    /// Do not perform bytecode analysis
88    Raw,
89    /// Perform bytecode analysis
90    #[default]
91    Analyse,
92}
93
94/// Transaction destination
95pub type TransactTo = TxKind;
96
97/// Create scheme
98#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Hash)]
99#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
100pub enum CreateScheme {
101    /// Legacy create scheme of `CREATE`
102    #[default]
103    Create,
104    /// Create scheme of `CREATE2`
105    Create2 {
106        /// Salt
107        salt: U256,
108    },
109    /// Custom scheme where we set up the original address
110    Custom {
111        /// Custom contract creation address.
112        address: Address,
113    },
114}