Repository navigation
test(origin-assignment): pin 500-element default-open rebuild gas (#780) - #959
Conversation
Add at-ceiling gas guards for `setDefaultOpenAllowlist`: a fresh 500-element set and a worst-case 500->500 replace (both the clear loop and the add+validate loop run at full width). #780 flagged the DEFAULT_OPEN_MAX_CEILING (500) full-rebuild gas as an audit residual to confirm against the target L2 block gas limit. Finding: a single-tx full rebuild is ~23.4M gas under the mock `isActive`, ~26.6M with the real four-SLOAD `CapacityBond.isActive` (~+3.15M) — roughly 83% of a 32M Arbitrum-class L2 block (~1.2x headroom), well above the audit's 10-15M estimate. Per the #780 disposition the 500 ceiling is kept: governance is never forced into a 500-element atomic tx because incremental add/remove deltas exist and should be preferred for large mutations. The new guards pin the cost so it cannot silently drift toward the block limit; a future ceiling reduction is an optional follow-up. Test-only change (no src/ contract logic touched). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 27858338556 |
Contracts coverageLine coverage: 90.05% (2127/2362 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces gas-limit guard tests for the OriginAssignment contract to ensure that rebuilding or replacing the default-open allowlist at the maximum ceiling of 500 elements does not exceed the block gas limit. Specifically, it adds test_defaultOpen_setAllowlist_atCeiling_gas and test_defaultOpen_replaceAtCeiling_gas to OriginAssignment.t.sol, along with a helper function _makeActiveOps and updated gas snapshots. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds Foundry gas-guard tests around OriginAssignment.setDefaultOpenAllowlist at the DEFAULT_OPEN_MAX_CEILING (500) to prevent silent gas regressions toward the target L2 block gas limit, and updates the committed .gas-snapshot baseline accordingly.
Changes:
- Add helper to generate 500 capacity-bond-active operator addresses in tests, plus two new “at ceiling” gas guard tests.
- Add a hard gas bound assertion for the measured
setDefaultOpenAllowlistcall. - Update
contracts/.gas-snapshotwith the two new snapshot entries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| contracts/test/OriginAssignment.t.sol | Adds 500-element default-open allowlist gas guard tests and helper generator. |
| contracts/.gas-snapshot | Records new baseline gas snapshot entries for the added tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review on #959: - vm.cool() both contracts before the measured call so it pays fresh-transaction EIP-2929 cold first-touch costs. The replace test previously measured the second build with slots warmed by the first build in the same tx, which skewed the number; the fresh-build test likewise had a warm mock isActive. Cold figures: fresh build ~24.5M, 500->500 replace ~19.2M (replace is cheaper — remove-path SSTORE refunds). Real-isActive extrapolation gives ~27.6M worst case (~86% of a 32M L2 block). - Rewrite the doc comment for internal consistency (single ~27.6M real estimate, no stray ~26.6M/~28M figures) and state explicitly that the guardrail is the asserted cold call-delta, NOT the larger .gas-snapshot entry which also includes the in-test setActive setup. - Bound 25M -> 26M to keep margin over the now-cold ~24.5M measurement. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Adds at-ceiling gas guards for
OriginAssignment.setDefaultOpenAllowlistand documents the dispositions of the remaining #780 audit residuals. Test-only change — nosrc/contract logic touched.Why
#780 tracks audit residuals deferred from #777. The one concrete code item was the
DEFAULT_OPEN_MAX_CEILING(500) full-rebuild gas: confirm a 500-element default-open allowlist rebuild stays under the target L2 block gas limit.Finding
A single-tx full rebuild costs:
isActive(1 SLOAD) — measured by the new testsCapacityBond.isActive(~+3.15M over 500 elements)That's ~83% of a 32M Arbitrum-class L2 block (~1.2× headroom) — well above the audit's 10–15M estimate, because each
EnumerableSet.addis ~3 cold SSTOREs, not just theisActivestaticcall.Disposition (per scoping decision on #780)
Keep the 500 ceiling: governance is never forced into a 500-element atomic tx —
addDefaultOpenOperator/removeDefaultOpenOperatordeltas exist and should be preferred for large mutations. The two new guards (test_defaultOpen_setAllowlist_atCeiling_gas,test_defaultOpen_replaceAtCeiling_gas) pin the cost so it cannot silently drift toward the block limit. A future ceiling reduction is an optional follow-up. No ADR / contract-logic change.The other five #780 items are documented in a disposition comment on the issue (already-resolved / wontfix / keep-as-acknowledged).
Verification
forge fmt --check✓FOUNDRY_PROFILE=ci forge build --sizes --deny warnings✓forge test— 631 passed ✓aderyn— 0 high ✓ ·slither— passes (fail-on: medium) ✓.gas-snapshotupdated (2 new entries only)Refs #780
🤖 Generated with Claude Code