Skip to content

test(L1): add ProtocolVersions invariant suite - #466

Draft
jackchuma wants to merge 3 commits into
mainfrom
toshi/contracts-protocolversions-portal-invariants-2eb47af0
Draft

jackchuma wants to merge 3 commits into
mainfrom
toshi/contracts-protocolversions-portal-invariants-2eb47af0

Conversation

@jackchuma

@jackchuma jackchuma commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

What changed? Why?

Adds a Foundry invariant suite for ProtocolVersions in test/invariants/ProtocolVersions.t.sol covering both the deploy-script ProtocolVersions proxy (ProtocolVersions_Invariant_Test) and an imported historical schedule with a static zero hole and active incident responder (ProtocolVersions_ImportedSchedule_Invariant_Test). Tests only; no src/ files change.

test/invariants/
  ProtocolVersions.t.sol  # registerUpgrade, setTimestamp, delayTimestamp, setMinimumProtocolVersion, setIncidentResponder, warp

What the suite checks:

  • State-transition invariants (independent of internal revert ordering): Every schedule write is checked via a single _validateWriteTransition specification against pre/post schedule state — append-only length, non-target entries untouched, MIN_NOTICE floor, frozen-entry immutability (ts <= now + FREEZE_WINDOW), static-hole immutability below scheduled successors, strict increase on delayTimestamp, and unauthorized callers never mutating state.
  • Frozen-entry and hash-chain integrity: Non-zero timestamps stay monotonic, entries pinned at or inside FREEZE_WINDOW (ts <= now + FREEZE_WINDOW) never change, and scheduleId(i) / scheduleId() match a fresh from-seed recomputation across every upgrade id.
  • Activated commitment immutability: activatedScheduleId(t) matches an independent forward-scan prefix recomputation and stays immutable for t < block.timestamp + min(FREEZE_WINDOW, MIN_NOTICE). Each upgrade's (ts - 1) and ts are pinned permanently once inside the immutable window alongside a 16-slot check-before-evict sliding window, verified on every write, on every warp, and via latest-observation checks inside invariant_protocolVersions(). Warps snap to ts - FREEZE_WINDOW - 1, ts - FREEZE_WINDOW, ts - FREEZE_WINDOW + 1, and ts.
  • Minimum protocol version & isolation: Exercises both setMinimumProtocolVersion and registerUpgrade's minProtocolVersion parameter across 0, 1..uint128.max, and > uint128.max, asserting minimumProtocolVersion() stays in 1..uint128.max, matches the model, and never mutates scheduleId or activatedScheduleId.
  • Zero-revert harness enforcement: Concrete invariant_protocolVersions() tests pin fail-on-revert = true across default, ci, ciheavy, and lite profiles so any unintended panic inside the harness fails immediately rather than being discarded.

Notes to reviewers

  • Split from the earlier combined draft; OptimismPortal2 invariants now live in test(L1): add OptimismPortal2 invariant suite #467.
  • Start with ProtocolVersions_Invariant_Base._assertProtocolVersionsInvariants(), ProtocolVersions_Invariant_Harness._validateWriteTransition(), and _verifyAfterWrite(), then read the six mutating handlers.
  • Zero-valued holes below a scheduled successor are legal by design in ProtocolVersions (see test/L1/ProtocolVersions.t.sol). ProtocolVersions_ImportedSchedule_Invariant_Test seeds a historical schedule containing a static hole behind a proxy over the deploy-script implementation.
  • Reversibility: git revert removes the test file and leaves no state behind.
  • Blast radius: test suite runtime only (~0.75s total under FOUNDRY_PROFILE=ci).

How has it been tested?

  • FOUNDRY_PROFILE=ci forge test --offline --match-path test/invariants/ProtocolVersions.t.sol (2 suites, 64 runs × 32 depth = 2048 calls each, 0 reverts): pass in 753ms.
  • FOUNDRY_PROFILE=lite forge test --offline --match-path test/invariants/ProtocolVersions.t.sol (optimizer = false, 2 suites, 8 runs × 8 depth = 64 calls each, 0 reverts): pass in 139ms.
  • forge test --offline --match-path test/invariants/ProtocolVersions.t.sol (2 suites, 64 runs × 500 depth = 32000 calls each, 0 reverts): pass in 15.03s.
  • just lint-check (forge fmt --check): pass.
  • go run ./scripts/checks/test-validation: pass.
  • Verified temporary mutations under FOUNDRY_PROFILE=ci (all reverted before committing):
    • Removing minProtocolVersion > type(uint128).max in registerUpgrade: FAIL on both suites (registerUpgrade: oversized minProtocolVersion succeeded).
    • Removing protocolVersion == 0 || protocolVersion > type(uint128).max in setMinimumProtocolVersion: FAIL on both suites (setMinimumProtocolVersion: invalid version succeeded).
    • Making activatedScheduleId drift past block.timestamp > 100 days + 1 hours (warp-only): FAIL (activatedScheduleId: boundary changed).
    • Injecting a harness revert in warp: FAIL (harness_panic), confirming fail-on-revert = true is enforced on the concrete test contracts.

@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

@jackchuma

This comment has been minimized.

@jackchuma

This comment has been minimized.

@jackchuma

This comment has been minimized.

@jackchuma

This comment has been minimized.

@jackchuma
jackchuma marked this pull request as ready for review December 5, 2026 19:41
@jackchuma
jackchuma marked this pull request as draft December 5, 2026 19:45
@jackchuma
jackchuma force-pushed the toshi/contracts-protocolversions-portal-invariants-2eb47af0 branch from 8482767 to b3ef497 Compare December 6, 2026 02:19
@jackchuma jackchuma changed the title test(L1): add ProtocolVersions and OptimismPortal2 invariant suites test(L1): add ProtocolVersions invariant suite Dec 6, 2026
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