Skip to content

fix(fork): use difficulty as prevrandao on more chains - #16456

Merged
mattsse merged 1 commit into
masterfrom
mattsse/fork-prevrandao-difficulty
Aug 29, 2026
Merged

fix(fork): use difficulty as prevrandao on more chains#16456
mattsse merged 1 commit into
masterfrom
mattsse/fork-prevrandao-difficulty

Conversation

@mattsse

@mattsse mattsse commented Aug 29, 2026

Copy link
Copy Markdown
Member

Polygon, Avalanche and Arbitrum keep the difficulty header field in use and return it from the PREVRANDAO opcode, the same way BSC does. Foundry derives prevrandao from mixHash, which is zero on Polygon and Avalanche and carries packed L1 metadata on Arbitrum, so a contract reading block.prevrandao saw 0 or a chunk of Arbitrum L1 header data instead of what the chain returns. BSC already had this handled by #9942; the other chains now share the same treatment, and the Arbitrum arm picks it up alongside the existing l1BlockNumber remap.

Measured with a PREVRANDAO probe deployed through an eth_call state override, comparing the node's answer against local execution at the same pinned block:

chain on-chain before after
Polygon / Amoy 1 0 1
Avalanche / Fuji 1 0 1
Arbitrum One / Nova / Sepolia 1 0x00000000000286310000… 1
BSC 2 2 2
Ethereum / Optimism / Base randao same same

Nothing else in the survey diverged: Gnosis, Linea, Scroll, Sonic, Celo, Mantle, Berachain and Cronos already matched.


This PR was written by Claude Code, including the survey behind it and this description. Verified against live nodes for every chain in the table.

Polygon, Avalanche and Arbitrum keep the `difficulty` header field in use
and return it from the `PREVRANDAO` opcode. Foundry took `prevrandao`
from `mixHash`, which is zero on Polygon and Avalanche and carries packed
L1 metadata on Arbitrum, so `block.prevrandao` diverged from the chain in
forks and replays.

BSC already had this treatment; the other chains now share it. Verified
against live nodes: `PREVRANDAO` returns 1 on Polygon, Polygon Amoy,
Avalanche, Avalanche Fuji, Arbitrum One, Nova and Sepolia, and Foundry
now returns the same. Ethereum, Optimism and Base are unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

@mattsse
mattsse merged commit b12e413 into master Aug 29, 2026
27 checks passed
@mattsse
mattsse deleted the mattsse/fork-prevrandao-difficulty branch August 29, 2026 08:11
@github-project-automation github-project-automation Bot moved this to Done in Foundry Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants