Skip to main content

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
Each CALL, DELEGATECALL, STATICCALL, CREATE, or CREATE2 creates a new nested frame. The EVM supports up to 1024 call depth.

Type Definition

Creating a Frame

Frame Parameters

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. Returns OutOfGas 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.
Memory cost formula: 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