Skip to main content
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: 0xa4 Introduced: Frontier (EVM genesis) LOG4 emits a log entry with four indexed topics, the maximum allowed. This enables filtering events with up to four indexed parameters, supporting complex multi-dimensional queries like buyer-seller-token-amount combinations.

Specification

Stack Input:
Stack Output:
Gas Cost: 375 + (4 × 375) + (8 × data_length) + memory_expansion_cost Operation:

Behavior

LOG4 pops six values from the stack:
  1. Offset: Starting position in memory (256-bit value)
  2. Length: Number of bytes to read from memory (256-bit value)
  3. Topic0: First indexed parameter (256-bit value)
  4. Topic1: Second indexed parameter (256-bit value)
  5. Topic2: Third indexed parameter (256-bit value)
  6. Topic3: Fourth indexed parameter (256-bit value)
This represents the maximum topic capacity, enabling four-dimensional filtering without on-chain computation.

Topic Values

All four topics are preserved as full 256-bit values. For dynamic types, keccak256 hashes are used.

Memory Expansion

Memory expands in 32-byte word increments with proportional gas costs.

Static Call Protection

LOG4 cannot execute in static call context (EIP-214).

Examples

Complex Event with Four Dimensions

Marketplace Event with Full Metadata

Order Book Entry

MultiHop Swap Event

Cross-Chain Bridge Event

Permission Grant Event

Gas Cost

Base Cost: 375 gas Topic Cost: 375 gas per topic = 1500 gas (for 4 topics) Data Cost: 8 gas per byte Memory Expansion: Proportional to new memory range Examples:
  • Empty data: 375 + 1500 = 1875 gas
  • 1 byte: 1875 + 8 = 1883 gas
  • 32 bytes: 1875 + 256 = 2131 gas
  • 64 bytes: 1875 + 512 + 3 = 2390 gas
  • 256 bytes: 1875 + 2048 + 6 = 3929 gas
  • 1024 bytes: 1875 + 8192 + 15 = 10082 gas

Edge Cases

All Topics Identical

Mixed Topic Values

Large Data with Maximum Topics

Stack Underflow

Out of Gas

Common Usage

Four-Dimensional Event Filtering

Off-chain filtering:

Dimensional Data Warehouse

Maximum Filtering Capability

Security

Topic Visibility and Privacy

All topics are visible off-chain. Maximum topics = maximum visibility:

Filtering Logic

Ensure consistent topic interpretation:

Static Call Context

LOG4 reverts in view/pure functions:

Implementation

Testing

References