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// EIP-2780 (merged EIPs#11645) — ECDSA recovery + sender account access + write.
33// At Amsterdam the flat 21000 base is decomposed into resource-based charges;
34// this is the sender-side base (recovery + sender access + write).
35pub const TX_BASE_COST_AMSTERDAM: u64 = 12000;
36
37// https://eips.ethereum.org/EIPS/eip-7825
38pub use ethrex_common::constants::POST_OSAKA_GAS_LIMIT_CAP;
39pub use ethrex_common::constants::TX_MAX_GAS_LIMIT_AMSTERDAM;
40
41pub const MAX_CODE_SIZE: u64 = 0x6000;
42pub const INIT_CODE_MAX_SIZE: usize = 49152;
43// EIP-7954 (Amsterdam): increase code size to 64 KiB and initcode to 128 KiB
44pub const AMSTERDAM_MAX_CODE_SIZE: u64 = 0x10000;
45#[allow(clippy::as_conversions)]
46pub const AMSTERDAM_INIT_CODE_MAX_SIZE: usize = 2 * AMSTERDAM_MAX_CODE_SIZE as usize;
47
48// https://eips.ethereum.org/EIPS/eip-3541
49pub const EOF_PREFIX: u8 = 0xef;
50
51pub mod create_opcode {
52    use ethrex_common::U256;
53
54    pub const INIT_CODE_WORD_COST: U256 = U256([2, 0, 0, 0]);
55    pub const CODE_DEPOSIT_COST: U256 = U256([200, 0, 0, 0]);
56    pub const CREATE_BASE_COST: U256 = U256([32000, 0, 0, 0]);
57}
58
59pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;
60
61// Blob constants
62pub const TARGET_BLOB_GAS_PER_BLOCK: u32 = 393216; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
63pub const TARGET_BLOB_GAS_PER_BLOCK_PECTRA: u32 = 786432; // TARGET_BLOB_NUMBER_PER_BLOCK * GAS_PER_BLOB
64
65pub const MIN_BASE_FEE_PER_BLOB_GAS: u64 = 1;
66
67// WARNING: Do _not_ use the BLOB_BASE_FEE_UPDATE_FRACTION_* family of
68// constants as is. Use the `get_blob_base_fee_update_fraction_value`
69// function instead
70pub const BLOB_BASE_FEE_UPDATE_FRACTION: u64 = 3338477;
71pub const BLOB_BASE_FEE_UPDATE_FRACTION_PRAGUE: u64 = 5007716; // Defined in [EIP-7691](https://eips.ethereum.org/EIPS/eip-7691)
72
73// WARNING: Do _not_ use the MAX_BLOB_COUNT_* family of constants as
74// is. Use the `max_blobs_per_block` function instead
75pub const MAX_BLOB_COUNT: u32 = 6;
76pub const MAX_BLOB_COUNT_ELECTRA: u32 = 9;
77// Max blob count per tx (introduced by Osaka fork)
78pub const MAX_BLOB_COUNT_TX: usize = 6;
79
80pub const VALID_BLOB_PREFIXES: [u8; 1] = [VERSIONED_HASH_VERSION_KZG];
81
82// Block constants
83pub const LAST_AVAILABLE_BLOCK_LIMIT: u64 = 256;
84
85// EIP7702 - EOA Load Code
86// secp256k1 curve order: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
87pub static SECP256K1_ORDER: LazyLock<U256> = LazyLock::new(|| {
88    U256::from_big_endian(&[
89        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
90        0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36,
91        0x41, 0x41,
92    ])
93});
94pub static SECP256K1_ORDER_OVER2: std::sync::LazyLock<U256> =
95    LazyLock::new(|| *SECP256K1_ORDER / U256::from(2));
96pub const MAGIC: u8 = 0x05;
97pub const SET_CODE_DELEGATION_BYTES: [u8; 3] = [0xef, 0x01, 0x00];
98// Set the code of authority to be 0xef0100 || address. This is a delegation designation.
99// len(SET_CODE_DELEGATION_BYTES) == 3 + len(Address) == 20 -> 23
100pub const EIP7702_DELEGATED_CODE_LEN: usize = 23;
101pub const PER_AUTH_BASE_COST: u64 = 7500;
102pub const PER_EMPTY_ACCOUNT_COST: u64 = 25000;
103// EIP-7702: refund per existing authority (pre-Amsterdam)
104pub const REFUND_AUTH_PER_EXISTING_ACCOUNT: u64 = 12500;
105
106/// EIP-7708: keccak256('Transfer(address,address,uint256)')
107pub const TRANSFER_EVENT_TOPIC: H256 = H256([
108    0xdd, 0xf2, 0x52, 0xad, 0x1b, 0xe2, 0xc8, 0x9b, 0x69, 0xc2, 0xb0, 0x68, 0xfc, 0x37, 0x8d, 0xaa,
109    0x95, 0x2b, 0xa7, 0xf1, 0x63, 0xc4, 0xa1, 0x16, 0x28, 0xf5, 0x5a, 0x4d, 0xf5, 0x23, 0xb3, 0xef,
110]);
111
112/// EIP-7708: keccak256('Burn(address,uint256)')
113pub const BURN_EVENT_TOPIC: H256 = H256([
114    0xcc, 0x16, 0xf5, 0xdb, 0xb4, 0x87, 0x32, 0x80, 0x81, 0x5c, 0x1e, 0xe0, 0x9d, 0xbd, 0x06, 0x73,
115    0x6c, 0xff, 0xcc, 0x18, 0x44, 0x12, 0xcf, 0x7a, 0x71, 0xa0, 0xfd, 0xb7, 0x5d, 0x39, 0x7c, 0xa5,
116]);