Repository navigation
feat(contracts): add ContentBlacklist.getBlacklistVersion() monotonic counter - #1291
Conversation
… counter ADR 011 § Blacklist version specifies a monotonically increasing counter that nodes poll to decide whether a blacklist re-sync is needed, but the contract never implemented it. Without it a node has no O(1) way to ask "did anything change?" and must replay the full event history from the deploy block on every restart. Adds `_blacklistVersion`, bumped in the two internal choke points every add and every remove funnels through (`_addHash`, `_removeHashRegional`), and exposes it as `getBlacklistVersion()`. The appeal-driven `suspended` toggle is a per-entry liveness flag rather than an entry-set change, so it does not bump the counter; it stays readable via `getHashEntry`. Existing event signatures are untouched — no indexed `version` field is added, so the event ABI and its off-chain decoders are unaffected. Refs #1181 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (3)
Walkthrough
ChangesBlacklist revision tracking
Estimated code review effort: 3 (Moderate) | ~20 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.95% (2495/2805 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a monotonic blacklist revision counter (_blacklistVersion and getBlacklistVersion()) in ContentBlacklist.sol to allow nodes to poll for changes in O(1) time, along with corresponding unit tests. The reviewer identifies a critical correctness issue: the version counter is only incremented on hash additions and removals, but not when a hash's suspension status is toggled (e.g., during fast-track, rejection, or reversal of appeals). Since nodes determine active blacklist status based on both presence and suspension status, omitting these updates would cause nodes to miss suspension/unsuspension events. The reviewer recommends incrementing the version counter on all suspension state changes and updating the unit tests and documentation accordingly.
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.
Review caught that the version counter skipped the appeal-driven `suspended` toggle. ADR 011 § 248 and § 325 both specify operators detect appeal resumption off the getBlacklistVersion() poll cycle, which only holds if the toggle moves the counter. Suspension flips what isBlacklisted reports (_isLive is `addedAt != 0 && !suspended`), so it changes the enforced blacklist exactly as an add/remove does. A poller that missed it would over-enforce a suspended hash — blocking content and exposing operators to slashing for serving it — and, worse, silently under-enforce a resumed one. All five appeal write sites now funnel through a _setEntrySuspended choke point that writes the flag and bumps, matching the existing _addHash / _removeHashRegional pattern so no call site has to remember. The re-add path in _addHash already bumps and is left alone (no double count). Two new tests cover suspend and resume; both verified to fail without the bump (1 != 2 and 1 != 3). .gas-snapshot regenerated for the extra SSTORE on the appeal paths. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Coverage reportTotal: 81.84% (was 81.84%, ● 0.00%) — 49374/60331 lines No Rust files changed in this PR. History
|
… + fix stale docstring Review follow-ups on the blacklist-version counter: - Reconcile the `_blacklistVersion` storage docstring with the shipped behavior. Commit 2 added `_setEntrySuspended` as a third choke point, but the field's `@notice`/`@dev` still described "two internal choke points / add and removal only", omitting the safety-critical suspend/resume bump — contradicting the `getBlacklistVersion()` doc two functions down. Also fix the auto-getter name (`_blacklistVersion()`, underscore preserved). - Assert the version bump on the three resume/clear paths that route through `_setEntrySuspended(false)` but had no bump coverage: perjury-reject and cleanup-lapse (added assertions to existing tests) and plain reject-from- fast-tracked (new `test_getBlacklistVersion_bumpsOnRejectAfterFastTrack`, the one path with no existing host). All four clear paths are now guarded against a future re-inline silently dropping the bump. .gas-snapshot regenerated under FOUNDRY_PROFILE=ci (new test entry + the ContentBlacklistTest selector-dispatch shift from the added method). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…al entry (#1297, #1298, #1299) (#1304) * fix(contracts): no phantom blacklist version bump on removed-mid-appeal entry (#1297, #1298, #1299) `removeHashGlobal`/`removeHashRegional` carry no `hasActiveAppeal` guard (only `_addHash` does), so governance can delete an entry while its appeal is still Open or FastTracked — a supported path with its own lapse reason code (3, GlobalOverride). Every terminal appeal path then called `_setEntrySuspended` on a zeroed struct, writing `suspended = false` (already false) and incrementing `_blacklistVersion`: a phantom revision advancing the counter with zero change to what any `isHashBlacklisted*` view reports, costing every polling node a wasted fleet-wide delta fetch. Only `cleanupExpiredBlacklistAppeal` guarded it. Fixed inside the helper rather than at each call site, so all five callers are covered at once and the documented precondition holds by construction. The guard also closes the suspend-side direction: fast-tracking an appeal whose entry was already removed no longer writes a stale `suspended = true` onto a zeroed slot — a flag that outlived the appeal (cleanup skips the clear exactly when the entry is gone) and would have left a later re-add of the same hash permanently unenforceable. Tests (#1298, #1299): the `entryGone` branch of `cleanupExpiredBlacklistAppeal` — the contract's only conditional bump site — now asserts the version does NOT move; the three previously-unguarded terminal paths (reject, perjury-reject, reverse) each get a no-phantom-bump regression test; and the suspend-side case is pinned. Every new assertion was mutation-checked by removing the corresponding guard and confirming it fails. Docs (#1297): replace the `§ 248` / `§ 325` line-number citations with the stable section names (§ Authority and flow, § Compliance Window), correct `isBlacklisted` to the real externals `isHashBlacklisted*` in contract and test comments, drop the false appeal-ratification claim from `test_getBlacklistVersion_bumpsOnEveryAddAndRemove`'s docblock, move the misplaced ratification comment onto the fast-track bump it actually describes, and amend ADR 011 § Blacklist version to cover suspend/resume so the three contract comments citing it as authority are supported. Several sub-items of #1297 and #1298 were already fixed by #1291's second commit and are dropped; #1300 is deferred to the joint #1296/#1181 design. Closes #1297 Closes #1298 Closes #1299 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(contracts): correct overstated comments and cover the ratify path (#1304 review) Follow-up to 4505b99 from a four-agent review of the PR. No behavior change to the guard itself — the review confirmed the predicate (`addedAt == 0`) is right, relief-cap accounting stays balanced, and gas cost is nil. What it found is that the previous commit's own comments overstate, which matters because #1297 is a comment-accuracy issue. Doc corrections, all self-inflicted: - `_blacklistVersion` NatSpec still claimed the counter bumps on suspend/resume "across every path" — the guard made that false, leaving the file contradicting itself across three doc blocks about the same counter. This is the same rot class #1297 exists to eliminate, re-introduced by its own fix. - "All toggles funnel through `_setEntrySuspended`" is false: `_addHash` writes the flag directly. Qualified to appeal-driven toggles. - "governance can delete an entry mid-appeal" mis-attributed the actor: `removeHashRegional` is `REGIONAL_BODY_ROLE`, and regional entries are the appeal-relevant ones. Both actors now named. - The `_addHash` stale-flag enumeration was loose (ratify never calls `_setEntrySuspended`; the others clear only on the FastTracked branch). The conclusion was verified sound; only the wording is tightened. - `test_fastTrack_afterEntryRemoved_doesNotSuspendOrBump` claimed a later re-add would be "permanently unenforceable" without the guard. False — `_addHash`'s reset recovers it, so that test's trailing assertions hold either way. The docstring now states the actual belt-and-braces relationship and marks which assertions carry the mutation coverage. Tests: - `test_ratify_entryRemovedMidAppeal_reverts` — ratify is the one FastTracked terminal path that does not route through `_setEntrySuspended`; it reverts `EntryNotBlacklisted` and rolls back. Pinned because this change teaches a "no-op on a removed entry" instinct, and applying it to `_removeHashRegional` would silently flip ratify to succeed-and-refund with nothing failing. Also records that the cleanup fallback skips `lastRatifiedSuccessAt`, so a blocked filer dodges the 90-day frequency cooldown. - Relief-slot assertions: fast-tracking over a gone entry still charges both capped tiers while suspending nothing, and cleanup returns them. Both new assertions mutation-checked: making `_removeHashRegional` no-op, and gating the cap increments on entry existence, each fail the corresponding test. The docstring also stops blessing the surrounding fast-track behavior (status FastTracked + two consumed relief slots over a non-existent entry); that is pre-existing and filed separately rather than bundled here. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(contracts): fail loudly on moot fast-track + tighten review comments (#1304 review) Addresses the #1304 review findings: - Important: fastTrackBlacklistAppeal now reverts EntryNotBlacklisted when the entry was already removed mid-appeal, instead of silently advancing a moot appeal to FastTracked and burning two scarce relief slots on a _setEntrySuspended that no-ops. Mirrors ratify's revert on the same precondition; the working exit stays cleanupExpiredBlacklistAppeal (reason 3, refund). Guard mutation-checked. Renamed the suspend-side test to test_fastTrack_afterEntryRemoved_reverts and rewrote it to pin the revert, the zero relief-slot charge, no version bump, and the cleanup+re-add recovery. - Medium: corrected the #1299 test banner — cleanup is call-site-guarded (if (!entryGone)), not an internal _setEntrySuspended no-op path; only reject/perjury/reverse hit the internal no-op. - Low: tightened _addHash's flag-clearing attribution (global-override removal also deletes the struct, not just ratify). - Added test_rejectAppeal_entryRemovedViaGlobalOverride_doesNotBumpVersion to drive the guard through removeHashGlobal explicitly. - Regenerated .gas-snapshot (FOUNDRY_PROFILE=ci). Pre-existing ADR 011 role drift (removeHashRegional GOVERNANCE_ROLE vs REGIONAL_BODY_ROLE) filed as #1313. Gates: forge fmt, CI build --deny warnings, 751 tests, aderyn (no High), slither (exit 0). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Ant Somers <[email protected]>
Scope: contract half of #1181 only
Refs #1181 — the issue stays open. It mandates two changes; this PR lands one.
Done here (contract): ADR 011 § Blacklist version specifies a monotonic
getBlacklistVersion()that nodes poll to decide whether a blacklist re-sync is needed, butContentBlacklist.solnever implemented it.Not done here (node delta sync):
crates/node/src/blacklist_watcher.rsdeliberately encodes the opposite design — its module header and the testcursor_start_is_full_replay_never_persistedare marked "COMPLIANCE PIN: the blacklist watcher must full-replay from the deploy floor." Delta sync only pays off with a persisted last-seen version, and neither #1181 nor ADR 011 § Polling says where that cursor lives or how the compliance pin gets retired. That is a design decision, not an implementation detail, so the node half is left open pending it. No Rust code is touched by this PR.Implementation
uint256 internal _blacklistVersion, incremented in the two internal choke points every add and every remove funnels through —_addHashand_removeHashRegional— so no call site has to remember to bump it. Exposed viagetBlacklistVersion()(ADR 011 names that accessor, hence the explicit getter over apublicauto-getter).The appeal-driven
suspendedtoggle also bumps the counter, via a_setEntrySuspended(region, hash, bool)choke point that all five appeal write sites route through. Suspension flips whatisBlacklistedreports (_isLiveisaddedAt != 0 && !suspended), so it changes the enforced blacklist exactly as an add/remove does. Thee.suspended = falseinside_addHashis not routed through it — that path already bumps, and doing so would double-count a re-add.No event-ABI change. ADR 011 also sketches an indexed
versionfield onHashBlacklisted/HashRemoved; that is deliberately out of scope here, since it would ripple through the event ABI and the Rust decoder. The polling contract in ADR 011 § Polling works off the view alone for the "did anything change?" check.Resolved during review — suspension bumps the counter
The PR originally shipped the narrower "add/remove only" reading and flagged the ambiguity here. Review (gemini-code-assist) pushed back, and ADR 011 settles it: § 248 and § 325 both say operators detect appeal resumption via the
getBlacklistVersion()poll cycle, which is only true if the toggle moves the counter.Both directions are real bugs under the narrow reading. A node that misses a suspension keeps enforcing a hash the contract no longer considers blacklisted — blocking content and exposing operators to slashing for serving it. A node that misses a resumption silently under-enforces a live entry, which is the compliance failure the poll cycle exists to prevent.
Fixed in ed58786.
Tests
Two new tests in
contracts/test/ContentBlacklist.t.sol, both verified to fail before the change and pass after (temporarily removing the two increments yieldsFAIL: assertion failed: 0 != 1on both):test_getBlacklistVersion_bumpsOnEveryAddAndRemove— starts at 0, advances by exactly one across global add, regional add, global remove, regional remove, and re-add.test_getBlacklistVersion_unaffectedByNonEntryOperations— operator/origin blacklisting, governance setters, reads, and merely filing an appeal leave it untouched; ratification (a real removal) does bump it.test_getBlacklistVersion_bumpsOnSuspend— fast-track flipsisBlacklistedto false and advances the counter by one.test_getBlacklistVersion_bumpsOnResume— reversal re-arms enforcement and advances it again (add → suspend → resume = +2).The two suspension tests were verified to fail before the fix (
assertion failed: 1 != 2and1 != 3) by removing the increment from_setEntrySuspended.Verification — the exact CI commands
forge fmt --checkFOUNDRY_PROFILE=ci forge build --sizes --deny warningsforge testaderyn -o /tmp/aderyn.md --no-snippets --skip-update-checkslither . --config-file slither.config.json.gas-snapshotregenerated underFOUNDRY_PROFILE=ciper CONTRIBUTING (the baseline is an enforced gate). Every moved deterministic entry belongs to a suite that touchesContentBlacklist— theContentBlacklist/CapacityBondRegionE2Etests for the extra SSTORE, and the deploy/E2E/governance suites for the ~11k deployment-bytecode delta.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests