This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode: 0xa2
Introduced: Frontier (EVM genesis)
LOG2 emits a log entry with two indexed topics. This is the standard form for binary relationships like token transfers (from → to) or state transitions with two parameters.
Specification
Stack Input:
Stack Output:
Gas Cost: 375 + (2 × 375) + (8 × data_length) + memory_expansion_cost
Operation:
Behavior
LOG2 pops four values from the stack:
- Offset: Starting position in memory (256-bit value)
- Length: Number of bytes to read from memory (256-bit value)
- Topic0: First indexed parameter (256-bit value)
- Topic1: Second indexed parameter (256-bit value)
Topics are stored in the order they’re popped, enabling efficient filtering by either or both topics.
Topic Values
Both topics are preserved as full 256-bit values. For dynamic types, keccak256 hashes are used:
Memory Expansion
Memory expands to word boundaries with associated gas costs.
Static Call Protection
LOG2 cannot execute in static call context (EIP-214).
Examples
Transfer Event (Most Common)
Transfer with Value Data
ERC20 Token Transfer
Swap Event
State Transition Event
Gas Cost
Base Cost: 375 gas
Topic Cost: 375 gas per topic = 750 gas (for 2 topics)
Data Cost: 8 gas per byte
Memory Expansion: Proportional to new memory range
Examples:
- Empty data: 375 + 750 = 1125 gas
- 1 byte: 1125 + 8 = 1133 gas
- 32 bytes: 1125 + 256 = 1381 gas
- 64 bytes: 1125 + 512 + 3 (memory expansion) = 1640 gas
- 256 bytes: 1125 + 2048 + 6 (memory expansion) = 3179 gas
Edge Cases
Topic Boundary Values
Identical Topics
Large Data
Stack Underflow
Out of Gas
Common Usage
Event Filtering
Off-chain filtering:
Dual Authorization
Pair Operations
Security
Topic Filtering Security
Topics enable efficient filtering, but are visible off-chain:
Address Topic Semantics
When filtering by address topics, ensure zero-extension understanding:
Static Call Context
LOG2 reverts in view/pure functions:
Implementation
Testing
References