Summary
Implement EIP-4788 which makes the parent beacon block root available to the EVM via a system contract at address 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02. Introduced in Cancun.
Specification
System Contract
- Address:
0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02
- Stores beacon block roots indexed by timestamp
- Ring buffer:
HISTORY_BUFFER_LENGTH = 8191
- Storage layout:
- Slot
timestamp % 8191: stores the timestamp
- Slot
(timestamp % 8191) + 8191: stores the root
System Call
At the start of each block (before user txs):
- Call the contract with
parent_beacon_block_root as calldata
- The contract stores
(parent_timestamp → parent_beacon_block_root)
User Reads
Any contract can CALL the system contract with a 32-byte timestamp to retrieve the corresponding beacon root. Returns 0 if timestamp not found in ring buffer.
Implementation Guide
- Create
lib/eevm/system_contracts/beacon_roots.ex — contract logic
- Add
parent_beacon_block_root field to Context.Block
- Execute system call at block start — store root keyed by parent timestamp
- Gate behind hardfork config — Cancun+
- Tests: store root, retrieve by timestamp, ring buffer wrapping, unknown timestamp returns 0
Acceptance Criteria
Reference
Summary
Implement EIP-4788 which makes the parent beacon block root available to the EVM via a system contract at address
0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02. Introduced in Cancun.Specification
System Contract
0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02HISTORY_BUFFER_LENGTH = 8191timestamp % 8191: stores the timestamp(timestamp % 8191) + 8191: stores the rootSystem Call
At the start of each block (before user txs):
parent_beacon_block_rootas calldata(parent_timestamp → parent_beacon_block_root)User Reads
Any contract can
CALLthe system contract with a 32-byte timestamp to retrieve the corresponding beacon root. Returns 0 if timestamp not found in ring buffer.Implementation Guide
lib/eevm/system_contracts/beacon_roots.ex— contract logicparent_beacon_block_rootfield toContext.BlockAcceptance Criteria
Reference