Repository navigation
feat(contracts): enforce maxEvidenceAgeUs↔unbondingPeriod mirror on CapacityBond (#778) - #809
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements the ADR-014 paired invariant (maxEvidenceAgeUs < unbondingPeriod * 1e6) across both the CapacityBond and SlashJudge contracts. It introduces the ISlashJudgeEvidenceView interface, adds the setSlashJudge setter to CapacityBond to wire the contracts post-deployment, and updates setUnbondingPeriod to enforce the invariant. Unit and integration tests have been added to verify this behavior. The feedback recommends improving the tests in CapacityBond.t.sol by asserting specific error selectors instead of using vm.expectRevert() without arguments, which helps prevent false positives.
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
This PR closes the ADR-014 paired invariant gap by making CapacityBond enforce the maxEvidenceAgeUs < unbondingPeriod * 1e6 constraint (mirroring SlashJudge), preventing governance from lowering unbondingPeriod below the live evidence-age ceiling and enabling slash-evasion via unbond/withdraw timing.
Changes:
- Introduces
ISlashJudgeEvidenceViewand wires it intoCapacityBondvia a newsetSlashJudgegovernance setter with an invariant check at wire-time. - Adds a strict mirror check to
CapacityBond.setUnbondingPeriod(skipped only whileslashJudgeis unset during the deploy window). - Updates deploy wiring + adds unit and integration tests (mock judge + real
SlashJudge) and regenerates.gas-snapshot.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/test/mocks/MockSlashJudgeEvidence.sol | Adds a minimal mock implementing maxEvidenceAgeUs() for unit testing the invariant mirror. |
| contracts/test/CapacityBondSlashJudgeInvariant.t.sol | Adds an integration test proving the strict boundary against a real SlashJudge. |
| contracts/test/CapacityBond.t.sol | Adds unit tests for setSlashJudge and for the strict setUnbondingPeriod mirror behavior. |
| contracts/src/SlashJudge.sol | Updates header docs to reflect the invariant now being enforced on both sides. |
| contracts/src/interfaces/ISlashJudgeEvidenceView.sol | Adds a narrow read-only interface for CapacityBond to query maxEvidenceAgeUs(). |
| contracts/src/CapacityBond.sol | Adds slashJudge reference + setSlashJudge + strict mirror check in setUnbondingPeriod. |
| contracts/script/BaseProtocolDeploy.s.sol | Wires slashJudge during deployment and asserts binding post-deploy. |
| contracts/.gas-snapshot | Updates gas snapshots to reflect the new code paths and added tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ashJudge binding (PR #809 review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…(PR #809 review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alpergundogdu
left a comment
There was a problem hiding this comment.
Review: approve with nits
Invariant verified exact against ADR-014 §"Interaction with unbonding period": setUnbondingPeriod reverts on newPeriod * 1e6 <= maxEvidenceAgeUs (strict, equal-case reverts), units correct (unbonding stored in seconds, *1e6 → µs to compare against maxEvidenceAgeUs), and the SlashJudge half (ageUs >= unbondingUs) is the correct mirror. Deploy ordering is sound — setSlashJudge runs in _wireCrossContractRoles provably before _handOffGovernance revokes the deployer's GOVERNANCE_ROLE, the script never lowers unbonding in the unset window, and the wire-time invariant re-check prevents pointing in a misconfigured judge. Interface-only link (no SlashJudge bytecode), no W5740 risk, and strong tests including a real-SlashJudge integration test plus a negative deploy-misbind assertion.
Medium — code bound [3d,30d] contradicts ADR-014/009's [7d,60d], and this PR propagates it into new comments/test docstrings
The live constants (CapacityBond.sol:144-145) are [3d, 30d], but ADR-014 (line 167) and ADR-009 state the unbonding safety bounds are [7d, 60d]. This PR didn't introduce the divergence, but it deepens it by asserting [3d,30d] as if canonical in several new authoritative-sounding comments and a test docstring. Overflow safety holds at either bound, but the floor is exactly the quantity that makes the mirror meaningful (how low governance can push unbonding), so a reader trusting the comment is misled. Per the repo's "ADRs are the source of truth" rule: add a one-line note that the live constants intentionally differ from ADR-014's [7d,60d], or open a tracking issue to reconcile. [your call] on blocking for the reconciliation.
Nits
setSlashJudgeis re-settable (GOVERNANCE_ROLE, zero-address-guarded). A future DAO proposal can repoint to a wrong-but-valid judge; it can't violate the invariant (the wire-time check enforcesunbondingUs <= maxAgeUs), so acceptable — already noted in-code.- Minor test gap: no single test drives the transition (low value callable while unwired → same value rejected after wiring); the two halves are tested separately. Optional.
Stacking
Clean — no #809 logic leaked into #800's surface or vice versa; the only overlap is the regenerated .gas-snapshot (expected for a stacked PR). After #800 merges: rebase to main, then regenerate .gas-snapshot once more so the gas diff reflects only this change.
…ion test (PR #809 review) Address Alper's review on #809: - Medium: the new `slashJudge` doc comment and the integration-test docstring asserted the live `[3d,30d]` unbonding bound as canonical. Cross-reference the `UNBONDING_PERIOD_FLOOR/CEILING` deviation note so a reader isn't misled — ADR 014/009 spec is `[7d,60d]`; the testnet window intentionally differs. (Comments only; no bytecode/gas change.) - Nit: add `test_setUnbondingPeriod_sameValueRejectedAfterWiring` driving the full regime change in one test — a value accepted while the judge is unset is rejected once a judge is wired, proving wiring (not the bound) is what tightens the constraint. The re-settable-setter nit needs no change (acceptable, noted in-code). Snapshot: only the new test's line added; the broader gas regen is deferred to the post-#800 rebase per the PR's stacking plan. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed in cfad5ed. Medium (bound divergence) — Took the inline-cross-reference path. The Nit — transition test — Added Nit — re-settable setter — No change; the wire-time invariant re-check bounds it and it's noted in-code, as you confirmed. Snapshot: only the new test's line was added. The broader gas regen stays deferred to the post-#800 rebase per the stacking plan (my local re-snapshot showed solc/forge-version drift across unrelated lines — not committing that noise here). |
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ashJudge binding (PR #809 review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…(PR #809 review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ion test (PR #809 review) Address Alper's review on #809: - Medium: the new `slashJudge` doc comment and the integration-test docstring asserted the live `[3d,30d]` unbonding bound as canonical. Cross-reference the `UNBONDING_PERIOD_FLOOR/CEILING` deviation note so a reader isn't misled — ADR 014/009 spec is `[7d,60d]`; the testnet window intentionally differs. (Comments only; no bytecode/gas change.) - Nit: add `test_setUnbondingPeriod_sameValueRejectedAfterWiring` driving the full regime change in one test — a value accepted while the judge is unset is rejected once a judge is wired, proving wiring (not the bound) is what tightens the constraint. The re-settable-setter nit needs no change (acceptable, noted in-code). Snapshot: only the new test's line added; the broader gas regen is deferred to the post-#800 rebase per the PR's stacking plan. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
cfad5ed to
05d11bd
Compare
…809) Rebased the #809 commits onto main with `--onto` (#800's commits are now squashed on main as fdb69b6, so a plain rebase conflicted add/add). Regenerated the snapshot under FOUNDRY_PROFILE=ci against the main base. The diff is large because (a) #809 grows CapacityBond by +564 B, so every integration suite that deploys the full protocol shows a deployment-gas delta, and (b) main's committed baseline was already stale (a same-env regen of pure main diverges from it by ~413 lines). CI runs `forge snapshot --diff` without `--check`, so the snapshot is informational and non-gating; this regen makes the committed baseline self-consistent with the code at HEAD. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 26952876459 |
Contracts coverageLine coverage: 89.36% (1814/2030 lines) |
Closes #778.
What
Implements the deferred CapacityBond half of the ADR-014 paired invariant
maxEvidenceAgeUs < unbondingPeriod * 1e6(ADR 014 § Interaction with unbonding period).SlashJudgealready enforced its half;CapacityBondhad no mirror, so governance could lowerunbondingPeriodbelow the live evidence-age ceiling and let a node offend → unbond → withdraw before a slash could land.ISlashJudgeEvidenceView(maxEvidenceAgeUs()only) — mirrors theICapacityBondSlasherconvention so CapacityBond links no SlashJudge bytecode.CapacityBond.setSlashJudge(GOVERNANCE_ROLE): wires the judge post-deploy (resolves the deploy-order circular dependency — CapacityBond deploys before SlashJudge). Rejects the zero address and re-checks the invariant at wire time, so a misconfigured judge can't be pointed in.setUnbondingPeriod: revertsUnbondingBelowEvidenceAgewhennewPeriod * 1e6 <= slashJudge.maxEvidenceAgeUs()(strict — equal case reverts), skipped whileslashJudgeis unset (deploy window).bond.setSlashJudge(slashJudge)inside_wireCrossContractRoles(provably before_handOffGovernancerevokes the deployer's GOVERNANCE_ROLE) + a post-deploy binding assertion..gas-snapshot.Why the #778 "size-deferred" blocker is gone
#778 was deferred because CapacityBond was at the EIP-170 ceiling (~124 B headroom). The Genesis Bond Credit removal (#799) freed that space. This change adds +564 B (21,655 → 22,219 B runtime), leaving 2,357 B of margin. (The +564 vs the issue's ~417 B estimate is the added wire-time guard on
setSlashJudge, which fully closes the invariant rather than only guardingsetUnbondingPeriod.)Boundary note
Active on-chain bounds are intentionally narrowed to
[3d,30d]unbonding /[1d,30d]evidence-age for the testnet (documented atCapacityBond.sol:143-146), vs the[7d,60d]ADR-009 spec table. The invariant logic is bound-agnostic; tests use values valid against the active bounds.Verification
forge fmt --check✓ ·FOUNDRY_PROFILE=ci forge build --sizes --deny warnings✓ (2,357 B margin) ·forge test✓ 505 passed.gas-snapshotregeneratedStacking
Stacked on #800 (
feat/adr030-region-ripening-761) — shared files (CapacityBond.sol,SlashJudge.sol, both test files). Merge #800 first, then this retargets tomain(rebase + regenerate.gas-snapshotso the gas diff reflects only this change).🤖 Generated with Claude Code