Skip to content

fix(contracts): no phantom blacklist version bump on removed-mid-appeal entry (#1297, #1298, #1299) - #1304

Merged
thiras merged 3 commits into
mainfrom
worktree/silver-cloud-7a8f
Jul 19, 2026
Merged

thiras merged 3 commits into
mainfrom
worktree/silver-cloud-7a8f

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Batch fix for the #1291 review follow-ups. Closes #1297, #1298, #1299. #1300 is deferred — see below.

Scope correction

The issues overstate what is still broken: #1291 landed in two commits and the second already fixed several of the flagged items. Verified against the current tree:

Issue Claim Actual
#1297 _blacklistVersion NatSpec says "two choke points" Already fixed — it says three and includes suspend/resume. Dropped.
#1297 § 248/§ 325 are line numbers Live — fixed
#1297 comments say isBlacklisted Live — fixed
#1297 test docblock/comment rot Live — fixed
#1297 ADR § Blacklist version omits suspend/resume Live — fixed
#1298 3 of 6 suspend/resume sites unasserted Mostly fixed — reject and perjury already assert; and the !entryGone cleanup branch is already covered. Only the entryGone branch was genuinely missing.
#1299 spurious bump on removed-mid-appeal entry Live and confirmed

The bug (#1299)

removeHashGlobal/removeHashRegional carry no hasActiveAppeal guard (only _addHash does), so governance can delete an entry mid-appeal — a supported path with its own lapse reason code (3, GlobalOverride). Every terminal appeal path then called _setEntrySuspended on a zeroed struct: writes suspended = false (already false) and bumps _blacklistVersion. That is a phantom revision — the counter advances with zero change to what any isHashBlacklisted* view reports, so every polling node pays a wasted fleet-wide delta fetch. Failure direction is over-fetch, never under-enforce.

Fixed with option (a), the guard inside the helper: covers all five callers at once and makes the documented precondition true by construction.

The guard also closes a second direction the issue only noted in passing. Fast-tracking an appeal whose entry was already removed used to write suspended = true onto a zeroed slot; cleanup skips the clear exactly when the entry is gone, so that stale flag outlived the appeal and would have made a later re-add of the same hash permanently unenforceable (_isLive false forever). The guard makes that write a no-op. Consequently _addHash's e.suspended = false is no longer load-bearing — I found this via mutation-testing (removing it did not fail the test), so the comment there documents it as deliberate defense-in-depth rather than repeating the issue's now-stale claim.

Tests

  • entryGone branch of cleanupExpiredBlacklistAppeal — the only conditional bump site — asserts the version does not move.
  • Three no-phantom-bump regression tests, one per previously-unguarded terminal path (reject / perjury-reject / reverse). Each asserts the appeal still reaches its terminal status, so they pin "no bump" rather than "call reverted".
  • Suspend-side test for the removed-then-fast-tracked case.
  • Suite-invariant comment banner: every test asserting suspended changed should also assert the version moved — asserting the flag alone is what let the original missing-bump bug through.

Every new assertion was mutation-checked: removed the corresponding guard/bump and confirmed the assertion fails. This is what caught the vacuous _addHash test described above.

Why #1300 is deferred

Two findings from this pass, both worth having before that design starts (posted on the issue):

  1. The ADR/impl divergence is wider than ContentBlacklist: events carry no indexed version, so ADR 011 § Polling delta fetch is not implementable #1300 describes. adr/011-content-takedown.md:109-110 declares events ABI-incompatible with the shipped ones — indexed blake3Hash vs the implementation's indexed region (different topic0 and opposite topic1 meaning), plus effectiveAt/emergency/string region fields that do not exist. Adding uint256 indexed version is not a small delta; reconciling § Interface overlaps ContentBlacklist: reconcile getBlacklistVersion() vs ADR 011 on origin blacklisting #1296 wholesale.
  2. The under-enforcement risk in ContentBlacklist: events carry no indexed version, so ADR 011 § Polling delta fetch is not implementable #1300 §2 is not live. blacklist_watcher.rs:19-25 retains suspended entries in known and re-scopes them every on_tick_complete pass, precisely because an appeal reversal/lapse emits no event — so a resume is caught by the re-scope pass, not missed.

No event ABI, sol! binding, or watcher changes here.

Verification

Full CI gate run locally: forge fmt --check, FOUNDRY_PROFILE=ci forge build --sizes --deny warnings, forge test (749 passed / 0 failed), aderyn (no High), slither (exit 0), cargo clippy --workspace --all-targets. .gas-snapshot regenerated — the non-ContentBlacklist deltas are uniform small deployment-cost increases from the slightly larger bytecode.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved blacklist revision counter accuracy to prevent “phantom” bumps when blacklist entries are removed mid-appeal.
    • Suspension/resumption and appeal operations now no-op or revert appropriately when targeting non-existent entries, preserving expected enforcement and polling behavior.
  • Tests
    • Added regression coverage for version tracking and bond/slot behavior across mid-appeal removals, including fast-tracking, terminal appeal paths, and cleanup/refund scenarios.
    • Updated existing assertions to align precisely with revision bump timing.
  • Chores
    • Refreshed ADR wording and recalibrated gas measurement snapshots (no functional change).

…al 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]>
@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: beb4a21b-858e-4ae4-a811-db8aee970546

📥 Commits

Reviewing files that changed from the base of the PR and between b4deb50 and 7190c27.

📒 Files selected for processing (3)
  • contracts/.gas-snapshot
  • contracts/src/ContentBlacklist.sol
  • contracts/test/ContentBlacklist.t.sol
🚧 Files skipped from review as they are similar to previous changes (1)
  • contracts/src/ContentBlacklist.sol

Walkthrough

ContentBlacklist now avoids phantom blacklist-version increments when appeals act on removed entries. Tests cover terminal and fast-track appeal paths, ADR wording is aligned, and gas snapshots are refreshed.

Changes

Blacklist versioning

Layer / File(s) Summary
Suspension version semantics
contracts/src/ContentBlacklist.sol, adr/011-content-takedown.md
Suspension changes on removed entries now no-op without incrementing _blacklistVersion; fast-tracking removed entries reverts, re-added hashes reset suspended to false, and the ADR documents the rules.
Appeal regression coverage
contracts/test/ContentBlacklist.t.sol
Tests cover version stability across removal, cleanup, rejection, perjury rejection, reversal, fast-tracking, and ratification paths.
Gas snapshot refresh
contracts/.gas-snapshot
Gas benchmark values were refreshed for ContentBlacklist and several other contract test suites.

Estimated code review effort: 3 (Moderate) | ~25 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

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.96% (2498/2808 lines)
▲ +0.01pp vs base (88.95% → 88.96%)
Run: 29691100937

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@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 addresses "phantom version bumps" in the ContentBlacklist contract when a blacklist entry is removed mid-appeal. It updates _setEntrySuspended to no-op if the entry has already been removed, updates the ADR documentation, and adds comprehensive test coverage to verify this behavior. The reviewer suggests an optimization in _setEntrySuspended to also return early if the new suspended state matches the current state, preventing redundant storage writes.

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 on lines +938 to +939
if (e.addedAt == 0) return;
e.suspended = suspended;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent redundant storage writes (SSTORE) and ensure absolute protection against phantom version bumps, we should also return early if the new suspended state is already equal to the current e.suspended state. This acts as a robust defense-in-depth measure against any unexpected state transitions or future code modifications.

        if (e.addedAt == 0 || e.suspended == suspended) return;
        e.suspended = suspended;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not taking this one — the state it guards against is unreachable, so it would add a permanently uncoverable branch.

Structural argument. The redundant write needs e.addedAt != 0 (past the first guard) and e.suspended == suspended:

  • Suspend (true) — only fastTrackBlacklistAppeal calls with true, and it requires status == Open. For the entry to already be suspended there must be an un-cleared FastTracked appeal on the same (region, hash) — but then hasActiveAppeal would have rejected opening this appeal at :546 (AppealAlreadyActive). Contradiction.
  • Resume (false) — all four callers require status == FastTracked, which means fast-track already set suspended = true (or no-opped because the entry was gone, in which case addedAt == 0 and the first guard catches it). Nothing can flip the flag back while the entry exists and the status stays FastTracked: _addHash is blocked by hasActiveAppeal at :887, _removeHashRegional zeroes addedAt, and every other terminal path moves status off FastTracked.

Empirical check. I armed the branch with require(e.suspended != suspended, "REDUNDANT_WRITE_REACHED") and ran the full suite: 749 passed, 0 failed — the condition is never reached, including by the fuzz/invariant runs under FOUNDRY_PROFILE=ci.

So there is no redundant SSTORE happening today to eliminate. The cost of adding it is a branch no test can cover (this repo gates on line coverage) and one I can't mutation-verify — deleting it would fail nothing, which is the bar I held every other assertion in this PR to.

The invariant you're pointing at is real and worth stating — "bump iff the enforced set actually changed" — I'd just rather state it in the helper's NatSpec (where it already is) than encode it as a silent early-return that reads like it handles a live case. If you'd prefer it enforced rather than documented, an invariant test asserting the flag always flips is the coverable version; say the word and I'll add that instead.

@yigitdot

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 prevents phantom version bumps in the ContentBlacklist contract when a blacklisted entry is removed mid-appeal. Specifically, the _setEntrySuspended function is updated to no-op if the entry has already been deleted, ensuring that the blacklist version only increments when actual changes to the enforced set occur. The changes also include updates to the ADR documentation and new unit tests to verify this behavior across all terminal appeal paths. 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.

…#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]>
@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.48% (was 81.48%, ● 0.00%) — 49712/61008 lines

No Rust files changed in this PR.

History
Commit Total Δ vs base
b4deb50 81.77% ● 0.00%
7190c27 (HEAD) 81.48% ● 0.00%

…nts (#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]>
@thiras
thiras merged commit 469e7d3 into main Jul 19, 2026
23 checks passed
@thiras
thiras deleted the worktree/silver-cloud-7a8f branch July 19, 2026 14:45
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.

ContentBlacklist: comment and ADR-citation rot around getBlacklistVersion()

2 participants