Skip to content

feat(portal): verify dispute game l2ChainId for non-super games#20924

Open
stevennevins wants to merge 4 commits into
developfrom
stevennevins/portal-verify-game-chainid
Open

feat(portal): verify dispute game l2ChainId for non-super games#20924
stevennevins wants to merge 4 commits into
developfrom
stevennevins/portal-verify-game-chainid

Conversation

@stevennevins
Copy link
Copy Markdown
Contributor

@stevennevins stevennevins commented May 20, 2026

Summary

OptimismPortal2.proveWithdrawalTransaction binds super-game roots to the portal's L2 chain ID via rootClaimByChainId(systemConfig.l2ChainId()), but the non-super branch called rootClaim() directly with no chain-ID check. A non-super dispute game implementation misconfigured (via OPCM, migration, or owner upgrade) for a different L2 could let a proposer prove a withdrawal against another chain's output root and finalize through this portal.

Changes

  • Add fail-closed check in the non-super branch: revert OptimismPortal_UnknownChainId() when disputeGameProxy.l2ChainId() != systemConfig.l2ChainId(). Super-game path is untouched.
  • Add l2ChainId() to the base IDisputeGame interface (already implemented by all concrete game types).
  • Bump OptimismPortal2 semver 5.6.1 → 5.6.2 and regenerate snapshots.
  • Add test_proveWithdrawalTransaction_wrongChainIdNonSuperGame_reverts. Align existing portal/invariant test fixtures so the deployed FaultDisputeGame impl uses the same L2 chain ID as SystemConfig

fixes #20883

OptimismPortal2.proveWithdrawalTransaction relied on rootClaimByChainId
to bind super-game roots to the portal's L2 chain ID. The non-super
branch called rootClaim() directly with no chain-ID check, so a
misconfigured FaultDisputeGame implementation registered for a different
L2 could let a proposer prove a withdrawal against another chain's
output root and finalize through this portal.

Add a fail-closed check that the game's l2ChainId() matches
systemConfig.l2ChainId() before reading rootClaim(). Adds
OptimismPortal_UnknownChainId error and exposes l2ChainId() on the
base IDisputeGame interface. Bumps semver to 5.6.2.

Aligns the existing OptimismPortal2 test fixtures so the FaultDisputeGame
implementation is deployed with the same chain ID as SystemConfig.
@stevennevins stevennevins requested review from a team and wwared May 20, 2026 18:50
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.0%. Comparing base (6e38f8a) to head (a7048c4).
⚠️ Report is 20 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #20924     +/-   ##
==========================================
+ Coverage     76.3%    82.0%   +5.7%     
==========================================
  Files          185      130     -55     
  Lines        10698     6665   -4033     
==========================================
- Hits          8166     5469   -2697     
+ Misses        2388     1196   -1192     
+ Partials       144        0    -144     
Flag Coverage Δ
cannon-go-tests-64 ?
contracts-bedrock-tests 82.0% <100.0%> (-0.4%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...kages/contracts-bedrock/src/L1/OptimismPortal2.sol 98.1% <100.0%> (+<0.1%) ⬆️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The new test_proveWithdrawalTransaction_wrongChainIdNonSuperGame_reverts
only exercises the non-super branch of proveWithdrawalTransaction. On
op-mainnet upgrade-fork runs with SUPER_ROOT_GAMES_MIGRATION enabled the
respected game type is a super game, so the portal takes the
rootClaimByChainId path and never reaches the new chain ID check. The
test then sees no revert and fails. Skip when the respected game type
is a super game.
Comment thread packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
The previous fix skipped the test when respected game type was super,
but that defeats the purpose — we want to exercise the non-super chain
ID check regardless of which game type happens to be respected in the
environment. Mock the game's gameType to CANNON so the portal takes the
non-super branch, then assert the chain ID mismatch reverts.
@Inphi
Copy link
Copy Markdown
Contributor

Inphi commented May 21, 2026

An alternative approach would be to (and we did this for the non-super ZKDIsputeGame) require rootClaimById to revert if the portal input chain ID does not match the dispute game's. This way we can avoid modifying the portal and rely on the dispute game to check this.
Could you consider doing that instead?

@stevennevins
Copy link
Copy Markdown
Contributor Author

An alternative approach would be to (and we did this for the non-super ZKDIsputeGame) require rootClaimById to revert if the portal input chain ID does not match the dispute game's. This way we can avoid modifying the portal and rely on the dispute game to check this. Could you consider doing that instead?

The check was originally written this way because FDG that existed before we added the rootClaimByChainId wouldn't have that selector to call. The Zk games don't have that same issue, so I think they need different solutions

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.

fix: cantina #30 portal misses chain-ID check for non-super game roots

2 participants