Repository navigation
fix(contracts): no phantom blacklist version bump on removed-mid-appeal entry (#1297, #1298, #1299) - #1304
Conversation
…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]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesBlacklist versioning
Estimated code review effort: 3 (Moderate) | ~25 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 |
Contracts coverageLine coverage: 88.96% (2498/2808 lines) |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
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.
| if (e.addedAt == 0) return; | ||
| e.suspended = suspended; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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) — onlyfastTrackBlacklistAppealcalls withtrue, and it requiresstatus == Open. For the entry to already be suspended there must be an un-clearedFastTrackedappeal on the same(region, hash)— but thenhasActiveAppealwould have rejected opening this appeal at:546(AppealAlreadyActive). Contradiction. - Resume (
false) — all four callers requirestatus == FastTracked, which means fast-track already setsuspended = true(or no-opped because the entry was gone, in which caseaddedAt == 0and the first guard catches it). Nothing can flip the flag back while the entry exists and the status staysFastTracked:_addHashis blocked byhasActiveAppealat:887,_removeHashRegionalzeroesaddedAt, and every other terminal path movesstatusoffFastTracked.
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.
|
/gemini review |
There was a problem hiding this comment.
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]>
Coverage reportTotal: 81.48% (was 81.48%, ● 0.00%) — 49712/61008 lines No Rust files changed in this PR. History
|
…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]>
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:
_blacklistVersionNatSpec says "two choke points"§ 248/§ 325are line numbersisBlacklisted!entryGonecleanup branch is already covered. Only theentryGonebranch was genuinely missing.The bug (#1299)
removeHashGlobal/removeHashRegionalcarry nohasActiveAppealguard (only_addHashdoes), 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_setEntrySuspendedon a zeroed struct: writessuspended = false(already false) and bumps_blacklistVersion. That is a phantom revision — the counter advances with zero change to what anyisHashBlacklisted*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 = trueonto 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 (_isLivefalse forever). The guard makes that write a no-op. Consequently_addHash'se.suspended = falseis 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
entryGonebranch ofcleanupExpiredBlacklistAppeal— the only conditional bump site — asserts the version does not move.suspendedchanged 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
_addHashtest described above.Why #1300 is deferred
Two findings from this pass, both worth having before that design starts (posted on the issue):
adr/011-content-takedown.md:109-110declares events ABI-incompatible with the shipped ones — indexedblake3Hashvs the implementation's indexedregion(different topic0 and opposite topic1 meaning), pluseffectiveAt/emergency/string regionfields that do not exist. Addinguint256 indexed versionis not a small delta; reconciling § Interface overlaps ContentBlacklist: reconcile getBlacklistVersion() vs ADR 011 on origin blacklisting #1296 wholesale.blacklist_watcher.rs:19-25retains suspended entries inknownand re-scopes them everyon_tick_completepass, 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-snapshotregenerated — the non-ContentBlacklist deltas are uniform small deployment-cost increases from the slightly larger bytecode.🤖 Generated with Claude Code
Summary by CodeRabbit