Skip to content

test(L1): add OptimismPortal2 invariant suite - #467

Draft
jackchuma wants to merge 1 commit into
mainfrom
test/optimism-portal2-invariant-suite
Draft

jackchuma wants to merge 1 commit into
mainfrom
test/optimism-portal2-invariant-suite

Conversation

@jackchuma

Copy link
Copy Markdown
Collaborator

What changed? Why?

Adds a Foundry invariant suite for OptimismPortal2 in test/invariants/OptimismPortal2.t.sol. It drives the deploy-script proxies (OptimismPortal2, SystemConfig, AnchorStateRegistry, DisputeGameFactory, and AggregateVerifier) through randomized call sequences against independent ghost state. Tests only; no src/ files change.

test/invariants/
  OptimismPortal2.t.sol   # deposit, createGame, prove, finalize, changePause, invalidateGame, resolve, warp

What the suite checks:

  • Withdrawals never replay (finalizeCount[hash] <= 1) and finalizedWithdrawals(hash) matches the handler count.
  • provenWithdrawals(hash, submitter) and numProofSubmitters(hash) match independent ghost state across direct and external-proof flows, catching broken proof-timer resets on re-prove.
  • prove and finalize verify exact revert selectors for pause (OptimismPortal_CallPaused), unsafe target (OptimismPortal_BadTarget), improper game (OptimismPortal_ImproperDisputeGame), invalid game (OptimismPortal_InvalidDisputeGame), invalid proof timestamp (OptimismPortal_InvalidProofTimestamp), mismatched output root (OptimismPortal_InvalidOutputRootProof), replay (OptimismPortal_AlreadyFinalized), unproven withdrawal (OptimismPortal_Unproven), proof maturity (OptimismPortal_ProofNotOldEnough), and invalid root claim (OptimismPortal_InvalidRootClaim).
  • ReentrantWithdrawalTarget checks l2Sender() during callback execution, verifies that reentrant finalization reverts with OptimismPortal_NoReentrancy, and invariant_optimismPortal2 asserts l2Sender() resets to DEFAULT_L2_SENDER.
  • Portal ETH balance equals initial + deposited - withdrawn across depositTransaction, receive, donateETH, accepting targets, and rejecting targets, rolling block.number when per-block ResourceMetering gas headroom is reached.
  • changePause and invalidateGame check PAUSE_EXPIRY boundaries, SystemConfig and AnchorStateRegistry access control selectors, and keep game-creation headroom before updateRetirementTimestamp so retirement does not stall the rest of a run.

Notes to reviewers

  • Split out from test(L1): add ProtocolVersions invariant suite #466 so each invariant suite can be reviewed on its own.
  • Start with OptimismPortal2_Invariant_Test.setUp() (the five fixture withdrawals) and invariant_optimismPortal2(), then read _expectedProveRevert and _expectedFinalizeRevert in OptimismPortal2_Invariant_Harness.
  • Reversibility: git revert removes the test file and leaves no state behind.
  • Blast radius: test suite runtime only (~1.8s under FOUNDRY_PROFILE=ci).

How has it been tested?

  • FOUNDRY_PROFILE=ci forge test --offline --match-path test/invariants/OptimismPortal2.t.sol (64 runs, 2048 calls, 0 reverts): pass in 1.81s.
  • forge test --offline --match-path test/invariants/OptimismPortal2.t.sol (64 runs, 32000 calls, 0 reverts): pass in 11.23s.
  • just lint-check (forge fmt --check): pass.
  • go run ./scripts/checks/test-validation: pass.
  • Verified four temporary src/L1/OptimismPortal2.sol mutations under FOUNDRY_PROFILE=ci (each reverted before committing): removing OptimismPortal_NoReentrancy (FAIL: reentrant finalization succeeded), skipping proof-timer reset on re-prove (FAIL: prove: provenWithdrawals disagrees with ghost state), removing _isUnsafeTarget in proveWithdrawalTransaction (FAIL: prove: unexpected revert selector), and removing rootClaim != hashOutputRootProof (FAIL: prove: ineligible proof succeeded).

@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

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.

2 participants