Repository navigation
feat(contracts): enforce ADR 030 region-ripening predicate in blacklist scope/slash (#761) - #800
Conversation
…st scope/slash (#761) Wire the ADR 030 § Region-stability window ripening predicate into on-chain enforcement. A node is in scope for a blacklist entry iff the entry is global, OR entry.region == current regionHint, OR (block.timestamp - effective < REGION_STABILITY_WINDOW AND entry.region == regionPrev), where effective = regionLastChanged != 0 ? regionLastChanged : max(firstBondedAt, regionGateActivatedAt). Previously SlashJudge only checked GLOBAL entries, so regional/ripening scope was entirely unenforced (CapacityBond stored regionPrev / regionLastChanged but no contract read them). - RegionScopeLib (new, internal-only -> inlines into consumers, 0 bytes added to the near-EIP-170 CapacityBond): pack(string)->bytes32, effectiveSince, and scopedRegions (the single source of truth for the non-global legs: GLOBAL/empty exclusion, window check, prev!=current dedup). - ICapacityBondRegionView (new): aggregate regionScopeData getter. - CapacityBond: regionGateActivatedAt immutable (constructor-stamped, since non-upgradeable) + regionScopeData; refreshed the storage doc. - SlashJudge: _checkBlacklistedBefore now enforces global U current-region U ripening-prev-region, anchored before the served response; global leg preserves BlacklistAfterResponse. - ContentBlacklist: isHashBlacklistedForOperator read view + ADR 011 path-2 (Operator) hard current-region-match in openBlacklistAppeal (no in-window auto-reject -- soft norm per ADR 011). Tests: 490 pass. RegionScopeLib units, CapacityBond regionScopeData / gate, SlashJudge regional+ripening+global-rescue+suspended cases, and real-verifier cross-contract slash E2E (closes #689 scope item 3). CI mirror green: forge fmt, FOUNDRY_PROFILE=ci build --sizes --deny warnings, forge test, aderyn (0 high), slither (no medium+). Closes #761 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contracts coverageLine coverage: 89.26% (1795/2011 lines) |
Gas snapshotGas changes vs baseRun: 26950958779 |
There was a problem hiding this comment.
Code Review
This pull request implements the ADR 030 region-stability window ripening predicate across CapacityBond, ContentBlacklist, and SlashJudge using a new RegionScopeLib library. While the implementation successfully integrates regional and previous-region scopes, several critical issues were identified: SlashJudge._regionalLiveBefore incorrectly uses block.timestamp instead of the response timestamp, enabling evasion and retroactive slashing; RegionScopeLib.pack is vulnerable to an assembly underflow if a string of length 32 or greater is passed; and RegionScopeLib.scopedRegions can underflow and revert if nowTs < effective.
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 implements on-chain enforcement of ADR 030’s region-ripening predicate for blacklist scope/slash eligibility by wiring CapacityBond’s regionPrev/regionLastChanged data into SlashJudge and ContentBlacklist, with shared predicate logic centralized in a new internal-only library.
Changes:
- Introduces
RegionScopeLibandICapacityBondRegionViewto provide a single-source-of-truth implementation and a single-call read surface for region scope inputs. - Updates
SlashJudgeto enforce blacklist scope as global ∪ current-region ∪ (within stability window) previous-region, while preserving the richer global-only error behavior. - Updates
ContentBlacklistwith a new operator-scope read view and an operator-standing region match check inopenBlacklistAppeal, plus comprehensive unit/e2e coverage.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| contracts/src/RegionScopeLib.sol | Adds the shared ADR 030 predicate helpers (packing, effective-since fallback, scoped region keys). |
| contracts/src/interfaces/ICapacityBondRegionView.sol | Adds a narrow aggregate getter interface for region scope inputs to reduce cross-contract calls/decoding. |
| contracts/src/CapacityBond.sol | Implements ICapacityBondRegionView, adds regionGateActivatedAt, and exposes regionScopeData. |
| contracts/src/SlashJudge.sol | Enforces ADR 030 regional + ripening-prev-region blacklist scope in _checkBlacklistedBefore. |
| contracts/src/ContentBlacklist.sol | Adds isHashBlacklistedForOperator and enforces operator path-2 current-region match in openBlacklistAppeal. |
| contracts/test/RegionScopeLib.t.sol | Adds unit tests for packing, effective fallback, and scoped-region window behavior. |
| contracts/test/SlashJudge.t.sol | Extends tests to cover current/prev-region scoping, window expiry, and global-vs-regional edge cases. |
| contracts/test/ContentBlacklist.t.sol | Adds tests for operator region-match standing, “soft norm” in-window acceptance, and new scope view. |
| contracts/test/CapacityBondRegionE2E.t.sol | Adds end-to-end tests driving a real SlashJudge + ContentBlacklist against live CapacityBond region data. |
| contracts/test/CapacityBond.t.sol | Adds unit coverage for regionGateActivatedAt constructor stamping and regionScopeData return values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
External review (Gemini) flagged two unreachable-but-cheap hardening gaps in the shared RegionScopeLib pure helpers: - pack: guard the mask shift against `len >= 32` underflow. Real callers only pass <= 16-byte regions (MAX_REGION_HINT_BYTES), but a longer string would underflow `sub(32, len)`; now truncated to the first 32 bytes instead of mis-masked. - scopedRegions: saturating `nowTs - effective`. In production `effective` is always a past stamp (block timestamps increase monotonically), so this is unreachable; the guard only matters under a test-time clock rewind, where it avoids an underflow revert and conservatively treats the change as just-made (prev still applies). Added unit tests for both. 492 tests pass; slither/aderyn clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ts (PR #800 review) The header @dev and the openBlacklistAppeal in-function comment claimed standing was enforced only by enum-range check; the PR now enforces the StandingPath.Operator current-region match (ADR 011 path 2). Clarify that Operator standing is region-gated while the TokenHolder synthetic-standing clawback remains deferred. 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
Predicate logic matches ADR 030 leg-by-leg — strict < window boundary (RegionScopeLib.sol:360), underflow saturates to 0, pack masks dirty trailing bytes and handles len >= 32, GLOBAL/empty exclusion, prev==current dedup — all correct and covered by both unit and cross-contract integration tests. RegionScopeLib is genuinely internal-only (inlines, 0 bytes added to CapacityBond). Region-flip slash-evasion is foreclosed by the regionPrev-in-window leg and tested end-to-end. CI green. ADR 011 path-2 soft-norm reconciliation is correct.
Medium — dead mock setters leave the effective fallback untested through the real cross-contract read
contracts/test/SlashJudge.t.sol:1236 and contracts/test/ContentBlacklist.t.sol:862 add setFirstBondedAt / setGate, but neither is ever called. Every integrated SlashJudge/ContentBlacklist test runs with firstBondedAt == 0, gate == 0, and the default 7-day window, so the effective = regionLastChanged != 0 ? regionLastChanged : max(firstBondedAt, gate) fallback — the never-changed-node path — is only exercised in the isolated RegionScopeLib.t.sol unit, never through the real regionScopeData read. Either add a SlashJudge integration test using those setters (assert a never-changed node ripens only window seconds after max(firstBondedAt, gate)), or delete the dead setters.
Low / Nit
CapacityBond.sol:627(updateRegion) accepts"GLOBAL"and""as a region; safe only becauseRegionScopeLib.scopedRegionsdefensively excludes them andContentBlacklist.addHashRegionalrejects empty regions. Latent footgun — [your call] on rejecting these at input vs documenting the library as the sole guard.ContentBlacklist.sol:175isHashBlacklistedForOperatorhas no in-repo caller — pure external read surface (+ bytecode). [your call] keep if a node/indexer is expected to call it.ContentBlacklist.sol:227-232— a one-line pointer to ADR 011 §"soft norm" would preempt a future reader thinking the in-window check is missing (ADR 030 states the window requirement more strongly; they reconcile via ADR 011).
None blocking — recommend addressing M1 (test or remove the dead setters) before merge.
…#800 review) Addresses alpergundogdu's M1: the setFirstBondedAt/setGate mock setters added in SlashJudge.t.sol and ContentBlacklist.t.sol were never called, so the `effective = regionLastChanged != 0 ? regionLastChanged : max(firstBondedAt, gate)` fallback — the never-changed-region path — was only exercised in the isolated RegionScopeLib unit, never through the real cross-contract regionScopeData read. - Add SlashJudge integration tests driving the fallback through submitBlacklistChallenge: one proves the window ripens from the gate (the `max` operand) and slashes in-window; one proves it closes from `max(firstBondedAt, gate)` and reverts once ripened. - Add the analogous ContentBlacklist test through isHashBlacklistedForOperator. - Both setters are now exercised in each file (no dead mock surface). Also (L1, doc-only): note in CapacityBond.updateRegion that "GLOBAL"/"" are intentionally accepted and filtered downstream by RegionScopeLib (the canonical guard) rather than rejected here, which would only add bytecode to a near-EIP-170-ceiling contract; and correct the now-stale "not active in this revision" clause (the predicate is enforced on-chain as of #800). 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]>
…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]>
…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]>
Summary
Wires the ADR 030 § Region-stability window ripening predicate into on-chain enforcement. A node is in scope for a blacklist entry iff the entry is global, OR
entry.region == regionHint(current), OR (block.timestamp - effective < REGION_STABILITY_WINDOWANDentry.region == regionPrev), whereeffective = regionLastChanged != 0 ? regionLastChanged : max(firstBondedAt, regionGateActivatedAt).Previously
SlashJudge._checkBlacklistedBeforechecked GLOBAL entries only —CapacityBondstoredregionPrev/regionLastChangedbut no contract read them (the storage doc literally said "the ripening leg lands with the ADR 030 enforcement PR"). This is that PR. The third leg keeps the previous region's entries — and slash exposure under them — applying until a region change ripens, foreclosing reactive region-flip evasion.Closes #761. Builds on #689 (e2e harness) and #669 (production Ed25519Verifier), both merged.
Changes
RegionScopeLib.sol(new,internal-only → inlines into consumers; 0 bytes added to the near-EIP-170CapacityBond) —pack(string)→bytes32(left-aligned packing matchingbytes32("literal")),effectiveSince, andscopedRegions(single source of truth for the non-global legs: GLOBAL/empty exclusion, window check,prev != currentdedup).ICapacityBondRegionView.sol(new) — aggregateregionScopeDatagetter (one cross-contract call; avoids decoding the fullNodeInfo).CapacityBond—regionGateActivatedAtimmutable (constructor-stamped — contracts are non-upgradeable, so fresh deploy = gate activation) +regionScopeData; refreshed the storage doc.SlashJudge—_checkBlacklistedBeforeenforces global ∪ current-region ∪ ripening-prev-region, anchored strictly before the served response. The global leg preserves the richerBlacklistAfterResponseerror (no test/ABI churn).ContentBlacklist—isHashBlacklistedForOperatorread view + ADR 011 path-2 (Operator) hard current-region-match inopenBlacklistAppeal. Per ADR 011 the ripening window is a soft norm (in-window filings "not auto-rejected … multisig discretion"), so no window revert — only the hard region match.Design notes
RegionScopeLiband is inlined into the two consumers, keeping the assembly and predicate math out ofCapacityBond's bytecode (mirrors theBondMath/SlashEscrowLibprecedent). CapacityBond runtime: 21,655 / 24,576 bytes.regionGateActivatedAtdiverges from the ADR's "upgrade initializer" wording because these contracts are constructor-deployed/non-upgradeable (no pre-upgrade cohort) — documented in-code.Testing
490 tests pass. Highlights:
RegionScopeLib.t.sol— packing/masking (dirty trailing bytes),effectiveSincefallback orderings,scopedRegions(window boundary exclusive,prev==currentdedup, GLOBAL/empty handling).SlashJudge.t.sol— current-region / prev-in-window / prev-after-window / unrelated-region / global-post-dates-but-regional-rescues / both-after→BlacklistAfterResponse/ suspended-regional.ContentBlacklist.t.sol— path-2 region-match revert, in-window soft-norm accept, global/non-operator skip,isHashBlacklistedForOperator(incl. suspended).CapacityBondRegionE2E.t.sol— real-verifier cross-contract slash through a liveSlashJudge(current-region, prev-in-window, prev-after-window) — closes test(contracts): full ADR 030 updateRegion e2e — EIP-712 + ed25519 registerNode signing harness #689 scope item 3, which had no production code to test.CI mirror — all green:
forge fmt --check·FOUNDRY_PROFILE=ci forge build --sizes --deny warnings·forge test· aderyn (0 high) · slither (no medium+).This PR was reviewed by the multi-agent PR-review toolkit; the consensus finding (a dead
inScopelibrary function with the predicate triplicated inline) was resolved by introducingscopedRegionsas the single source of truth, and the flagged test gaps were closed.🤖 Generated with Claude Code