Overview
A Frame represents a single EVM execution context. When a smart contract executes, it runs within a frame that maintains:- Stack - 1024-element LIFO stack of 256-bit values
- Memory - Sparse byte-addressable scratch space
- Gas - Remaining gas for execution
- Call context - Caller, address, value, calldata
Type Definition
Creating a Frame
Frame Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
bytecode | Uint8Array | [] | Contract bytecode to execute |
gas | bigint | 1000000n | Initial gas allocation |
caller | Address | zero address | Message sender (msg.sender) |
address | Address | zero address | Current contract address |
value | bigint | 0n | Wei transferred (msg.value) |
calldata | Uint8Array | [] | Input data (msg.data) |
isStatic | boolean | false | Static call (no state modifications) |
stack | bigint[] | [] | Initial stack state |
gasRemaining | bigint | gas | Override gas (for resuming) |
Stack Operations
pushStack
Push a 256-bit value onto the stack.popStack
Pop the top value from the stack.peekStack
Read a stack value without removing it.Gas Operations
consumeGas
Deduct gas from the frame. ReturnsOutOfGas error if insufficient.
Memory Operations
writeMemory
Write a byte to memory. Memory expands in 32-byte words.readMemory
Read a byte from memory. Uninitialized memory returns 0.memoryExpansionCost
Calculate gas cost for memory expansion.3n + n²/512 where n is word count. This quadratic growth prevents memory DoS attacks.
Error Types
Arithmetic Methods
Frames include bound arithmetic methods for opcodes 0x01-0x0b:Complete Example
API Reference
| Function | Description |
|---|---|
Frame(params?) | Create new execution frame |
pushStack(frame, value) | Push bigint onto stack |
popStack(frame) | Pop and return top value |
peekStack(frame, index) | Read value at depth index |
consumeGas(frame, amount) | Deduct gas from frame |
readMemory(frame, offset) | Read byte from memory |
writeMemory(frame, offset, value) | Write byte to memory |
memoryExpansionCost(frame, endBytes) | Calculate expansion gas |
Related
- EVM Types - Complete type reference
- Instructions - Opcode implementations
- Gas Constants - Gas cost definitions

