Last active
August 7, 2025 09:44
-
-
Save roninjin10/c93a486bf8d351fa5ffaeb11902572dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Frame represents the entire execution state of the EVM as it executes opcodes | |
/// Layout designed around actual opcode access patterns and data correlations | |
pub const Frame = struct { | |
// ULTRA HOT - Accessed by virtually every opcode | |
stack: Stack, // 33,536 bytes - accessed by every opcode (PUSH/POP/DUP/SWAP/arithmetic/etc) | |
gas_remaining: u64, // 8 bytes - checked/consumed by every opcode for gas accounting | |
// HOT - Accessed by major opcode categories | |
memory: *Memory, // 8 bytes - hot for memory ops (MLOAD/MSTORE/MSIZE/MCOPY/LOG*/KECCAK256) | |
analysis: *const CodeAnalysis, // 8 bytes - hot for control flow (JUMP/JUMPI validation) | |
// Hot execution flags (only the bits that are actually checked frequently) | |
// Packed together to minimize cache footprint - these are checked by different opcode categories | |
hot_flags: packed struct { | |
depth: u10, // 10 bits - call stack depth for CALL/CREATE operations | |
is_static: bool, // 1 bit - static call restriction (checked by SSTORE/TSTORE) | |
is_eip1153: bool, // 1 bit - transient storage validation (TLOAD/TSTORE) | |
_padding: u4 = 0, // 4 bits - align to byte boundary and room for future flags | |
}, | |
// High correlation group | |
// All storage operations (SLOAD/SSTORE/TLOAD/TSTORE) need ALL of these together so pack them together in struct | |
contract_address: primitives.Address.Address, // 20 bytes - FIRST: storage key = hash(contract_address, slot) | |
state: DatabaseInterface, // 16 bytes - actual storage read/write interface | |
access_list: *AccessList, // 8 bytes - LAST: EIP-2929 warm/cold gas cost calculation | |
// Total: 44 bytes - all storage operations cause exactly one cache line fetch for this cluster | |
// TIER 4: COLD - Rarely accessed data | |
allocator: std.mem.Allocator, // 16 | |
input: []const u8, // 16 bytes - only 3 opcodes: CALLDATALOAD/SIZE/COPY (rare in most contracts) | |
output: []const u8, // 16 bytes - only set by RETURN/REVERT at function exit | |
// Cold hardfork detection flags - only used by getHardfork() method for version detection | |
// Packed separately from hot flags to avoid polluting hot cache lines | |
cold_flags: packed struct { | |
is_prague: bool, // 1 bit | |
is_cancun: bool, // 1 bit | |
is_shanghai: bool, // 1 bit | |
is_merge: bool, // 1 bit | |
is_london: bool, // 1 bit | |
is_berlin: bool, // 1 bit | |
is_istanbul: bool, // 1 bit | |
is_petersburg: bool, // 1 bit | |
is_constantinople: bool, // 1 bit | |
is_byzantium: bool, // 1 bit | |
is_homestead: bool, // 1 bit | |
_reserved: u5 = 0, // 5 bits - future expansion | |
}, | |
self_destruct: ?*SelfDestruct, // 8 bytes - extremely rare: only SELFDESTRUCT opcode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment