Skip to content

feat: implement beacon block root contract (EIP-4788)#109

Merged
mw2000 merged 1 commit intomainfrom
issue-82
Apr 23, 2026
Merged

feat: implement beacon block root contract (EIP-4788)#109
mw2000 merged 1 commit intomainfrom
issue-82

Conversation

@mw2000
Copy link
Copy Markdown
Owner

@mw2000 mw2000 commented Apr 23, 2026

Closes #82.

Summary

Install the parent-beacon-block-root system contract at the canonical
address 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02 (Cancun+) and drive
its block-start deposit through the normal executor.

  • eip_4788 added to HardforkConfig, active from Cancun.
  • parent_beacon_block_root added to Context.Block.
  • New EEVM.SystemContracts.BeaconRoots:
    • install/1 / install_if_enabled/2 — deploy the EIP's exact runtime bytecode.
    • commit/3 — run the block-start system call (caller = SYSTEM_ADDRESS, calldata = 32-byte root) through Executor.run_loop; stores into the 8191-slot ring buffer.
    • lookup/2 — direct storage read.

Design notes

No custom precompile — we deploy the exact runtime bytecode specified by the EIP and call it through the real executor. Any future CALL-semantic changes come along for free, and the tests exercise the real bytecode, not a reimplementation.

commit/3 and lookup/2 take/return a Database, keeping the integration surface small for higher layers (block processing in #86 will hook this in at block boundaries).

Test plan

  • install/1 places bytecode, is idempotent.
  • install_if_enabled/2 gates on Cancun.
  • commit/3 populates both ring-buffer slots (ts % 8191 and + 8191).
  • lookup/2 round-trips a stored root.
  • lookup/2 returns :not_found for unknown timestamps.
  • Ring-buffer collisions overwrite old entries correctly.
  • User CALL with a known timestamp returns the 32-byte root via RETURN.
  • User CALL with an unknown timestamp reverts.

🤖 Generated with Claude Code

Install the parent-beacon-block-root system contract at the canonical
address 0x000F3df6...Beac02 (Cancun+) and drive its block-start deposit
through the normal executor, matching mainnet semantics.

- Add `eip_4788` hardfork flag, active from Cancun.
- Add `parent_beacon_block_root` to `Context.Block` — used by higher
  layers that will drive the system call at block boundaries once block
  processing lands (tracked in #86).
- New `EEVM.SystemContracts.BeaconRoots` with:
  - `install/1` / `install_if_enabled/2` — deploy the EIP's exact runtime
    bytecode into a `Database`.
  - `commit/3` — run the block-start system call (caller = SYSTEM_ADDRESS,
    calldata = 32-byte root) through `Executor.run_loop`, storing the root
    in the 8191-slot ring buffer.
  - `lookup/2` — convenience reader that goes directly to storage; a
    dedicated test also exercises the read path end-to-end via a user
    CALL so we verify the bytecode itself, not just the storage layout.

Closes #82

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mw2000 mw2000 marked this pull request as ready for review April 23, 2026 07:11
@mw2000 mw2000 merged commit 9a5faab into main Apr 23, 2026
2 checks passed
@mw2000 mw2000 deleted the issue-82 branch April 23, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement beacon block root contract (EIP-4788)

1 participant