Overview
What is EIP-2935?
EIP-2935 introduces a system contract that stores block hashes in contract storage, making them accessible to smart contracts for extended periods. This enables protocols requiring verifiable randomness, block-based logic, or historical verification.Key Benefits
- Extended History: Access up to 8192 block hashes (configurable)
- Reliable Access: No longer limited to recent 256 blocks
- Smart Contract Compatibility: Works with existing
BLOCKHASH
opcode - Verifiable Randomness: Enable protocols requiring historical entropy
Implementation Details
Block Hash Storage Mechanism
Cosmos EVM implements EIP-2935 by storing block hashes in a special system contract storage:Configuration Parameter
Thehistory_serve_window
parameter controls how many historical block hashes are stored:
- Type:
uint64
- Default:
8192
(source) - Range: Must be > 0, recommended ≤ 8192
- Storage Impact: Higher values increase storage requirements linearly
Comparison with Ethereum
Similarities
- Same storage contract address:
0x0aae40965e6800cd9b1f4b05ff21581047e3f91e
- Same storage layout: Ring buffer using modulo arithmetic
- Same opcode behavior:
BLOCKHASH
queries contract storage - Same gas costs: Standard SLOAD costs apply (2100 gas for cold access)
Differences
- Configurable window: Cosmos EVM allows custom
history_serve_window
(vs fixed 8192 in Ethereum) - Instant activation: Available immediately on upgrade (not block-based activation)
- No fork logic: Uses consensus parameter instead of fork activation
- Performance tuning: Can be optimized per chain requirements
- Traditional 256-block limit: Ethereum’s original
BLOCKHASH
opcode only provided access to the most recent 256 blocks; EIP-2935 extends this significantly
Usage in Smart Contracts
Basic Block Hash Access
Basic Block Hash Access
Verifiable Randomness Protocol
Verifiable Randomness Protocol
Block-Based State Transitions
Block-Based State Transitions
Configuration Examples
High Compatibility (Default)
Performance Optimized
Extended History
Technical Implementation
BLOCKHASH Opcode Behavior
Before EIP-2935:Storage Layout
The EIP-2935 system contract uses a simple storage mapping:Integration with EVM
The implementation integrates seamlessly with the EVM:- Block Processing: Each new block stores its hash in the system contract
- BLOCKHASH Opcode: Modified to query contract storage for historical hashes
- Gas Costs: Uses standard SLOAD gas costs for historical access
- Compatibility: Maintains full backward compatibility
Comparison with Ethereum
Similarities
- Same storage contract address:
0x0aae40965e6800cd9b1f4b05ff21581047e3f91e
- Same storage layout: Ring buffer using modulo arithmetic
- Same opcode behavior:
BLOCKHASH
queries contract storage - Same gas costs: Standard SLOAD costs apply
Differences
- Configurable window: Cosmos EVM allows custom
history_serve_window
- Instant activation: Available immediately on upgrade (not block-based)
- No fork logic: Uses consensus parameter instead of fork activation
- Performance tuning: Can be optimized per chain requirements
References
- EIP-2935 Specification: https://eips.ethereum.org/EIPS/eip-2935
- Implementation PR: cosmos/evm#407
- System Contract Address:
0x0aae40965e6800cd9b1f4b05ff21581047e3f91e
- Related Documentation: VM Module Parameters