Skip to main content

ethrex_levm/
constants.rs

1use ethrex_common::{H256, U256};
2use std::sync::LazyLock;
3
4pub const WORD_SIZE_IN_BYTES_USIZE: usize = 32;
5pub const WORD_SIZE_IN_BYTES_U64: u64 = 32;
6
7pub const SUCCESS: U256 = U256::one();
8pub const FAIL: U256 = U256::zero();
9pub const WORD_SIZE: usize = 32;
10
11pub const STACK_LIMIT: usize = 1024;
12
13pub const EMPTY_CODE_HASH: H256 = H256([
14    0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0,
15    0xe5, 0x00, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x04, 0x5d, 0x85, 0xa4, 0x70,
16]);
17
18pub const MEMORY_EXPANSION_QUOTIENT: u64 = 512;
19
20// Dedicated gas limit for system calls according to EIPs 2935, 4788, 7002 and 7251
21pub const SYS_CALL_GAS_LIMIT: u64 = 30000000;
22
23// EIP-8037: system transactions
24// receive an extra state-gas reservoir of
25// `STATE_BYTES_PER_STORAGE_SET * cost_per_state_byte * SYSTEM_MAX_SSTORES_PER_CALL`
26// on top of `SYS_CALL_GAS_LIMIT`, so SSTORE-heavy system contracts (EIP-2935,
27// EIP-4788) cannot OOG on state-gas growth alone.
28pub const SYSTEM_MAX_SSTORES_PER_CALL: u64 = 16;
29
30// Transaction costs in gas
31pub const TX_BASE_COST: u64 = 21000;
32
33// https://eips.ethereum.org/EIPS/eip-7825
34pub use ethrex_common::constants::POST_OSAKA_GAS_LIMIT_CAP;
35pub use ethrex_common::constants::TX_MAX_GAS_LIMIT_AMSTERDAM;
36
37pub const MAX_CODE_SIZE: u64 = 0x6000;
38pub const INIT_CODE_MAX_SIZE: usize = 49152;
39// EIP-7954 (Amsterdam): increased limits
40pub const AMSTERDAM_MAX_CODE_SIZE: u64 = 0x8000;
41#[allow(clippy::as_conversions)]
42pub const AMSTERDAM_INIT_CODE_MAX_SIZE: usize = 2 * AMSTERDAM_MAX_CODE_SIZE as usize;
43
44// https://eips.ethereum.org/EIPS/eip-3541
45pub const EOF_PREFIX: u8 = 0xef;
46
47pub mod create_opcode {
48    use ethrex_common::U256;
49
50    pub const INIT_CODE_WORD_COST: U256 = U256([2, 0, 0, 0]);
51    pub const CODE_DEPOSIT_COST: U256 = U256([200, 0, 0, 0]);
52    pub const CREATE_BASE_COST: U256 = U256([32000, 0, 0, 0]);
53}
54
55pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;
56
57// Blob constants
58pub const TARGET_BLOB_GAS_PER_BLOCK: u32 = 393216; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
59pub const TARGET_BLOB_GAS_PER_BLOCK_PECTRA: u32 = 786432; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
60
61pub const MIN_BASE_FEE_PER_BLOB_GAS: u64 = 1;
62
63// WARNING: Do _not_ use the BLOB_BASE_FEE_UPDATE_FRACTION_* family of
64// constants as is. Use the `get_blob_base_fee_update_fraction_value`
65// function instead
66pub const BLOB_BASE_FEE_UPDATE_FRACTION: u64 = 3338477;
67pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: u64 = 5007716; // Defined in [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691)
68
69// WARNING: Do _not_ use the MAX_BLOB_COUNT_* family of constants as
70// is. Use the `max_blobs_per_block` function instead
71pub const MAX_BLOB_COUNT: u32 = 6;
72pub const MAX_BLOB_COUNT_ELECTRA: u32 = 9;
73// Max blob count per tx (introduced by Osaka fork)
74pub const MAX_BLOB_COUNT_TX: usize = 6;
75
76pub const VALID_BLOB_PREFIXES: [u8; 1] = [VERSIONED_HASH_VERSION_KZG];
77
78// Block constants
79pub const LAST_AVAILABLE_BLOCK_LIMIT: u64 = 256;
80
81// EIP7702 - EOA Load Code
82// secp256k1 curve order: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
83pub static SECP256K1_ORDER: LazyLock<U256> = LazyLock::new(|| {
84    U256::from_big_endian(&[
85        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
86        0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36,
87        0x41, 0x41,
88    ])
89});
90pub static SECP256K1_ORDER_OVER2: std::sync::LazyLock<U256> =
91    LazyLock::new(|| *SECP256K1_ORDER / U256::from(2));
92pub const MAGIC: u8 = 0x05;
93pub const SET_CODE_DELEGATION_BYTES: [u8; 3] = [0xef, 0x01, 0x00];
94// Set the code of authority to be 0xef0100 || address. This is a delegation designation.
95// len(SET_CODE_DELEGATION_BYTES) == 3 + len(Address) == 20 -> 23
96pub const EIP7702_DELEGATED_CODE_LEN: usize = 23;
97pub const PER_AUTH_BASE_COST: u64 = 7500;
98pub const PER_EMPTY_ACCOUNT_COST: u64 = 25000;
99// EIP-7702: refund per existing authority (pre-Amsterdam)
100pub const REFUND_AUTH_PER_EXISTING_ACCOUNT: u64 = 12500;
101
102/// EIP-7708: keccak256('Transfer(address,address,uint256)')
103pub const TRANSFER_EVENT_TOPIC: H256 = H256([
104    0xdd, 0xf2, 0x52, 0xad, 0x1b, 0xe2, 0xc8, 0x9b, 0x69, 0xc2, 0xb0, 0x68, 0xfc, 0x37, 0x8d, 0xaa,
105    0x95, 0x2b, 0xa7, 0xf1, 0x63, 0xc4, 0xa1, 0x16, 0x28, 0xf5, 0x5a, 0x4d, 0xf5, 0x23, 0xb3, 0xef,
106]);
107
108/// EIP-7708: keccak256('Burn(address,uint256)')
109pub const BURN_EVENT_TOPIC: H256 = H256([
110    0xcc, 0x16, 0xf5, 0xdb, 0xb4, 0x87, 0x32, 0x80, 0x81, 0x5c, 0x1e, 0xe0, 0x9d, 0xbd, 0x06, 0x73,
111    0x6c, 0xff, 0xcc, 0x18, 0x44, 0x12, 0xcf, 0x7a, 0x71, 0xa0, 0xfd, 0xb7, 0x5d, 0x39, 0x7c, 0xa5,
112]);