Skip to content

feat(contracts): add ContentBlacklist.getBlacklistVersion() monotonic counter - #1291

Merged
thiras merged 3 commits into
mainfrom
feat/1181-blacklist-version-counter
Jul 18, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/1181-blacklist-version-counter

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

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, but ContentBlacklist.sol never implemented it.

Not done here (node delta sync): crates/node/src/blacklist_watcher.rs deliberately encodes the opposite design — its module header and the test cursor_start_is_full_replay_never_persisted are 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 — _addHash and _removeHashRegional — so no call site has to remember to bump it. Exposed via getBlacklistVersion() (ADR 011 names that accessor, hence the explicit getter over a public auto-getter).

The appeal-driven suspended toggle also bumps the counter, via a _setEntrySuspended(region, hash, bool) choke point that all five appeal write sites route through. Suspension flips what isBlacklisted reports (_isLive is addedAt != 0 && !suspended), so it changes the enforced blacklist exactly as an add/remove does. The e.suspended = false inside _addHash is 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 version field on HashBlacklisted/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 yields FAIL: assertion failed: 0 != 1 on 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 flips isBlacklisted to 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 != 2 and 1 != 3) by removing the increment from _setEntrySuspended.

Verification — the exact CI commands

Command Result
forge fmt --check clean
FOUNDRY_PROFILE=ci forge build --sizes --deny warnings clean, no warnings
forge test 744 passed, 0 failed, 12 skipped
aderyn -o /tmp/aderyn.md --no-snippets --skip-update-check High: 0 (gate is fail-on high); no finding names the new symbol
slither . --config-file slither.config.json exit 0 (gate is fail_on medium); no finding names the new symbol

.gas-snapshot regenerated under FOUNDRY_PROFILE=ci per CONTRIBUTING (the baseline is an enforced gate). Every moved deterministic entry belongs to a suite that touches ContentBlacklist — the ContentBlacklist/CapacityBondRegionE2E tests 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

    • Added a public blacklist revision counter that increases whenever enforced content changes, including additions, removals, suspensions, and reinstatements.
    • Added a read-only method to retrieve the current blacklist revision, enabling clients to efficiently detect updates through polling.
  • Bug Fixes

    • Ensured blacklist revision updates are consistently recorded across appeal, reversal, rejection, and cleanup workflows.
  • Tests

    • Expanded coverage for revision changes and verified gas measurements across key contract scenarios.

… 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]>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 88219577-0d3c-4e51-9fa0-dc8070276d07

📥 Commits

Reviewing files that changed from the base of the PR and between 0de44e6 and fd5f944.

📒 Files selected for processing (3)
  • contracts/.gas-snapshot
  • contracts/src/ContentBlacklist.sol
  • contracts/test/ContentBlacklist.t.sol

Walkthrough

ContentBlacklist now exposes a monotonic revision counter that increments when enforced blacklist entries are added, removed, suspended, or resumed. Tests cover these transitions, and gas snapshots are refreshed across multiple contract test suites.

Changes

Blacklist revision tracking

Layer / File(s) Summary
Revision counter and lifecycle handling
contracts/src/ContentBlacklist.sol, contracts/test/ContentBlacklist.t.sol
Adds getBlacklistVersion(), centralizes suspension updates, increments the counter on enforcement changes, and tests add, remove, suspend, resume, rejection, and cleanup flows.
Gas snapshot refresh
contracts/.gas-snapshot
Re-records gas metrics and increases selected fuzz profiles to 1024 runs across contract test suites.

Estimated code review effort: 3 (Moderate) | ~20 minutes


Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.95% (2495/2805 lines)
▲ +0.03pp vs base (88.92% → 88.95%)
Run: 29663049470

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread contracts/src/ContentBlacklist.sol Resolved
Comment thread contracts/test/ContentBlacklist.t.sol Resolved
Comment thread contracts/test/ContentBlacklist.t.sol Resolved
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]>
@yigitdot yigitdot changed the title feat(contracts): ContentBlacklist.getBlacklistVersion() monotonic counter feat(contracts): add ContentBlacklist.getBlacklistVersion() monotonic counter Jul 18, 2026
@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.84% (was 81.84%, ● 0.00%) — 49374/60331 lines

No Rust files changed in this PR.

History
Commit Total Δ vs base
ed58786 81.47% ● 0.00%
fd5f944 (HEAD) 81.84% ● 0.00%

… + 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]>
@thiras
thiras merged commit 66eb828 into main Jul 18, 2026
22 checks passed
@thiras
thiras deleted the feat/1181-blacklist-version-counter branch July 18, 2026 22:15
thiras added a commit that referenced this pull request Jul 19, 2026
…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]>
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