Skip to content

Implement beacon block root contract (EIP-4788) #82

@mw2000

Description

@mw2000

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):

  1. Call the contract with parent_beacon_block_root as calldata
  2. 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

  1. Create lib/eevm/system_contracts/beacon_roots.ex — contract logic
  2. Add parent_beacon_block_root field to Context.Block
  3. Execute system call at block start — store root keyed by parent timestamp
  4. Gate behind hardfork config — Cancun+
  5. Tests: store root, retrieve by timestamp, ring buffer wrapping, unknown timestamp returns 0

Acceptance Criteria

  • Beacon roots stored correctly in ring buffer
  • CALL to contract retrieves root by timestamp
  • Unknown timestamp returns empty/zero
  • System call at block start works
  • Gated to Cancun+ hardfork
  • Tests pass

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreCore EVM functionalityeipEIP specification implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions