Skip to content

fix(contracts)!: security review fixes (24 findings) - #2833

Merged
alpergundogdu merged 29 commits into
mainfrom
claude/contract-security-audit-bfede0
Nov 3, 2026
Merged

alpergundogdu merged 29 commits into
mainfrom
claude/contract-security-audit-bfede0

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes from a security review of contracts/: a pashov solidity-auditor run (3 passes, all agents), an x-ray pre-audit report, and a Medusa fuzz campaign (fizz). There is one small commit per finding, and each commit carries its tests and the ADR text that describes the behavior.

Pre-mainnet rules apply: wire-breaking changes go in with every side updated in the same PR. Rust touches are limited to the e2e evidence-hash mirror, doc comments, and the decdn node unbond disclosure.

Fixes

CapacityBond

  • Remove forceResolveStuckAppeal. It settled a slash as upheld but stranded the appeal bond in SlashAppeal.
  • A partial unbond that keeps the bond at or above the floor no longer deactivates the operator. isActive now checks only the floor, and requestUnbond already moves the released amount out of activeBond. The decdn node unbond CLI tells the operator which case applies.
  • registerNode always records the live minBond as the entry floor. A stale higher floor from an earlier bond() left a registered operator inactive.
  • A re-registration into a new region snapshots regionPrev, so the old region's blacklist scope ripens out as it does for updateRegion. Both paths share one helper (+6 B).
  • firstBondedAt is stamped at the first minBond crossing, so a 1-wei bond cannot pre-age an address for the governance age ramp.
  • An inactive operator's declareMbps(0) tier release works during a pause, like the other exit paths.

SlashJudge / SlashAppeal

  • An operator with no NodeId binding stays slashable while it has active or unbonding bond. Before this, reclaimNodeId on its own NodeId made it unslashable.
  • The evidence hash binds challengedNode, so evidence signed by a zero-bond address cannot be spent first. The rate-manipulation hash is keyed on the stream alone, so one overcharge gives one slash, not a ladder of escalating tiers. Breaking: the e2e mirror is updated.
  • Evidence signatures are checked by ECDSA recovery only, never ERC-1271 (ADR 024 § The signature partition). An EIP-7702 delegate can no longer reject a proof.
  • One open appeal per operator, so concurrent appeals cannot all pass the 365-day cap.
  • openSlashAppeal stays open while SlashAppeal is paused. Otherwise finalizeUnappealedSlash could close the window while the operator was locked out.

ContentBlacklist

  • A re-add or ratification of a live entry keeps addedAt and effectiveAt. It updates only the reason, clears the emergency flag, or escalates the category.

PaymentPool

  • A zero-cap or expired capability is never recorded, so it cannot claim the signer's registration slot.
  • The owner's capability signature is checked by ECDSA first and ERC-1271 second, so an EIP-7702 owner cannot revoke after nodes served against the capability.
  • Each redemption's byte credit is also bounded by that call's own payment, so byte credit banked by zero-byte payments cannot be released by a dust payment.
  • Breaking: redeemMany pays only a payee with a NodeId binding, and routes bytes only while that payee isActive. A capability holder can no longer draw its cap to itself, and an unbonded address can no longer pump the quorum total. The cost is about 9k gas per call; the pinned gas figures and .gas-snapshot are updated.

DecdnGovernor

  • Breaking: the vote is zeroed for any standing slash with slashedAt in [window start, timepoint], read from the slash records. A later slash can no longer hide an earlier one, and a slash early in the current epoch zeroes later snapshots. slashedAtEpoch remains as an indexer read and is dropped from ICapacityBond.
  • The per-operator cap is sized from the other operators' bytes, so self-dealt bytes never raise the operator's own cap. As a consequence, a lone serving operator has a zero cap, and governance needs at least two serving operators. The slash_appeal e2e now has both operators serve. Accepted: the bootstrap multisig covers the thin-network phase.
  • A direct delegate() consumes the delegation nonce, so an unredeemed delegateBySig cannot override a later revocation.
  • propose reverts until the Governor holds the Timelock's PROPOSER_ROLE, so no bootstrap-phase proposal becomes executable after the hand-off.

Buyback / deploy

  • GuardedBuybackBurner.poke is keeper-only.
  • The genesis seed refuses a pool that someone already initialized at another price, and its mint requires 99% of each leg on-chain.
  • The deploy refuses a buyback band that the seeded epoch cap can never admit. The default BUYBACK_USDC_SEED is now 1,000 USDC.
  • On Arbitrum One the emergency multisig must not be the deployer and must hold code. Testnet and e2e deploys still seat the deployer.

Not fixed in this PR

  • Router-pause redemption (reclaim during a FeeRouter pause): accepted, because a pause is a collective operator action.
  • Accepted: PAYMENT_DELIVERY_FLOOR = 1 means self-dealt vote bytes cost the delivery floor, not the market rate. This is an economics decision; governance raises the floor once the market rate is known.
  • Accepted: an offender can self-report through a second address and take the challenger's 50%, so the effective penalty is half the slash. ADR 014 now records this.
  • Accepted: a 5% slash on an operator bonded exactly at its floor makes isActive false while auto-eject keeps it.
  • Accepted: _getVotes zeroes weight only for a slash, so a blacklisted or fully exited operator keeps its window bytes for up to 13 epochs. This PR stops new bytes from inactive operators.
  • [your call] Two capabilities for one unregistered signer (ADR 003 open question). This PR blocks only the dead ones (zero cap or expired).
  • The challenge bond is returned in the same transaction, so a reversed slash costs the challenger nothing.
  • SlashJudge reads the live regionStabilityWindow, so a later increase can reopen serves that were out of scope.
  • _checkStaleness does not extend evidence age by pause time.
  • New fizz lead: a zero-TOKEN slash still increments lifetimeOffenseCount.
  • The auditor's 54 lower-confidence leads are not addressed here.

Test plan

  • forge fmt --check, FOUNDRY_PROFILE=ci forge build --sizes --deny warnings (CapacityBond 23,648 B, 928 B margin)
  • forge test: all suites pass, with new tests per fix
  • FOUNDRY_PROFILE=ci forge snapshot --snap .gas-snapshot regenerated
  • cargo test --no-run -p decdn-e2e --features anvil-e2e
  • anvil e2e: g_node_06_unbond, g_gov_03_real_evidence, slash_appeal, g_node_04_blacklist_compliance, anvil_pool_redeem, cli_fetch_delegated
  • full anvil e2e suite: 141/141 after the slash_appeal update
  • slither: 0 results
  • cargo clippy --all-targets --all-features and cargo doc (deny warnings) on the touched crates
  • aderyn: CI's aderyn-ci is authoritative. The local 0.1.9 flags internal unused returns, which already fire on unchanged main lines.

🤖 Generated with Claude Code

alpergundogdu and others added 25 commits November 3, 2026 14:53
The escape hatch settled a slash as upheld but left the appeal bond in
SlashAppeal with no way out. An open appeal resolves through SlashAppeal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ve its floor

isActive no longer has a no-unbonding-request conjunct. requestUnbond
moves the released amount out of activeBond at once, so the floor check
alone decides: an unbond that retains the floor keeps the node active,
one that drops below it deactivates the node immediately. The unbond
CLI discloses which case applies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…egistration

A floor left by an earlier bond() crossing could sit above a since-lowered
minBond, so an operator that met the registration gate stayed inactive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e region

registerNode overwrote regionHint without a snapshot, so a deregister and
re-register into another region dropped the old region's blacklist scope
at once instead of after the stability window. updateRegion and
registration now share one region-change path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A 1-wei bond stamped firstBondedAt, so an address could be pre-aged for
the age_ramp at negligible cost. The stamp now lands with the first
crossing of minBond, alongside the grandfathered entry floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
declareMbps(0) from an inactive operator is the step that lowers the
requestUnbond floor, so a pause could freeze that operator's exit even
though requestUnbond and deregisterNode stay open. Only the release
branch skips the pause.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An offender could call reclaimNodeId on its own NodeId, clear its
binding, and make every challenge revert NodeNotRegistered. SlashJudge
now accepts an unbound operator that still holds active or unbonding
bond.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…vercharged stream

The evidence hash now carries challengedNode, so an offender cannot have
a zero-bond address sign the same response and spend the evidence first.
The rate-manipulation hash drops the probe: one overcharged stream paired
with several probes is one offense, not a ladder of escalating slashes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SignatureChecker consulted ERC-1271 code at the operator's address, so an
operator with an EIP-7702 delegate could reject every slash proof against
itself. Evidence is re-verified after the paid action, which ADR 024
places outside ERC-1271; SlashJudge now recovers the signer directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The frequency cap was checked only at open, against granted appeals, so
an operator could open appeals on several slashes before any grant and
have all of them granted inside one 365-day window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A SlashAppeal pause blocked openSlashAppeal, but finalizeUnappealedSlash
on CapacityBond stayed callable, and the open pause was not yet in
pausedTotal, so a challenger could finalize a slash the operator was
locked out of appealing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A re-add or governance ratification restamped addedAt and effectiveAt,
which moved effectiveAt later and voided slash evidence for serves made
after the entry first took effect. A live entry now keeps its stamps;
only the reason, the emergency flag and an escalated category move.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A pool owner could register a capability that pays nothing for a live
signer before any node redeemed, voiding every voucher that signer had
already given and letting the owner reclaim the deposit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1271

SignatureChecker consulted code at the owner's address first, so an EOA
owner that added an EIP-7702 delegate after nodes served could reject its
own capability at registration and reclaim the deposit. A smart-account
owner still verifies through ERC-1271.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The floor ceiling read the lifetime cumulative, so a signer could pay
early with zero bytes and later release the whole banked byte credit
with a one-unit payment, just before a governance snapshot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tive ones

redeemMany paid any caller, so a capability holder could sign vouchers
to its own address and draw the spending cap as USDC, and any address
could pump the governance byte window with self-paid bytes. A paying call
now requires a NodeId binding for the payee and routes bytes only while
the payee isActive; a bound but inactive operator is still paid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt and snapshot

The Governor read one per-operator epoch watermark, so a second slash
(even a zero-bond self-slash) could move it out of the window and restore
full votes, and a slash in the in-progress epoch left the operator at full
weight for later snapshots in that epoch, including on its own appeal. The
Governor now walks the operator's slash records and zeroes the vote for any
standing slash with slashedAt in [window start, timepoint].

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bytes

The cap was 10% of the window total, which includes the operator's own
bytes, so an operator paying itself raised its own cap and could outvote
every other operator together.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A direct delegate() left the nonce untouched, so a former delegatee
holding a signed but unredeemed delegateBySig could replay it after the
operator revoked and cast the operator's vote.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ROLE

During the bootstrap-multisig phase an attacker could pass a proposal
with the thin early electorate; an unqueued Succeeded proposal never
expires, so it became executable once the roles moved to the Governor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A permissionless poke let anyone move the pool spot, sample it into the
TWAP accumulator and move it back in one transaction, so the floor kept
that false spot until the next sample and could stall buybacks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eed mint

An attacker could initialize the TOKEN/USDC pool first at a low price, or
move it between the create and mint transactions, and the zero-minimum
seed mint deposited the TOKEN leg at that price. The deploy now refuses a
pool whose price differs from the seed price, and the mint requires 99% of
each leg on-chain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…admit

The defaults seeded 100 USDC against a 10% per-epoch cap but required a
100 USDC minimum buyback, so every keeper buyback reverted and nothing
burned. The deploy now reverts when the first epoch's cap is below the
minimum buyback, and the default seed is 1,000 USDC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The deploy checked the emergency multisig only for zero, so a mainnet
deploy could seat the deployer key in every PAUSER_ROLE and emergency
role. On chain 42161 it now refuses the deployer and an address with no
code; testnet and e2e deploys keep seating the deployer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The per-operator vote cap is sized from the other operators' bytes, so
the voting operator needs a second operator's bytes in the window; a
lone serving operator has a zero cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 15:58
@github-code-quality

github-code-quality Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust, Solidity

Rust / code-coverage/cargo-llvm-cov

main 2b6989d claude/contract-secu... 028534a +/-
77% 77% 0%
View coverage of the 5 most impacted files.
File main 2b6989d claude/contract-secu... 028534a +/-
crates/cli/src/...mands/unbond.rs 47% 45% -2%
crates/protocol/src/framing.rs 93% 92% -1%
crates/node/src...s/client/mod.rs 94% 94% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/node/src/dht/publish.rs 77% 78% +1%

Solidity / code-coverage/forge

main 2b6989d claude/contract-secu... 028534a +/-
92% 92% 0%
View coverage of the 8 most impacted files.
File main 2b6989d claude/contract-secu... 028534a +/-
contracts/src/D...cdnGovernor.sol 96% 96% 0%
contracts/scrip...colDeploy.s.sol 96% 96% 0%
contracts/src/CapacityBond.sol 91% 91% 0%
contracts/src/PaymentPool.sol 99% 99% 0%
contracts/src/C...ntBlacklist.sol 98% 98% 0%
contracts/src/SlashAppeal.sol 99% 99% 0%
contracts/src/S...shEscrowLib.sol 100% 100% 0%
contracts/src/SlashJudge.sol 96% 97% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 03, 2026 16:36 UTC

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

Copilot AI 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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

Approval is blocked because there are unresolved correctness issues where the CLI’s active/inactive messaging and help text rely on the current minBond instead of the operator’s stored bondFloorAtActivation, which can misreport whether an operator stays active after governance changes.

2 open issues
What changed in this PR

This pull request implements a broad set of security-review remediations across the Solidity protocol contracts (notably CapacityBond, SlashJudge, SlashAppeal, PaymentPool, DecdnGovernor) with corresponding updates to tests, Rust e2e mirroring (evidence hash changes), CLI/operator messaging, and ADR documentation. Several contract-surface and behavioral changes are explicitly breaking and are accompanied by updated on-chain/off-chain integration expectations.

Changes:

  • Harden slashing/evidence and appeal flows (evidence-hash binding changes, ECDSA-only evidence verification, slashability/appeal lifecycle tightening).
  • Refine CapacityBond lifecycle semantics (floor-based activity rules, registration floor snapshotting, tenure stamping, region bookkeeping, removal of stuck-appeal escape hatch).
  • Tighten governance/payment invariants (vote-weight/slash zeroing changes, PaymentPool redemption gating + per-call credit bounding, buyback/deploy safety checks) with expanded tests and refreshed gas snapshots.

Unresolved review comments to address before approval:

  • decdn node unbond disclosure should be keyed to bondFloorAtActivation (not live minBond) and may require adding a binding for bondFloorAtActivation(address) in the CLI alloy binding.
  • CLI help text should describe floor-based inactivity (not “below minBond”) to match on-chain isActive.
  • DHT registry watcher should handle NodeId-binding mutation events (NodeIdBound / NodeIdReclaimed) to avoid up-to-REGISTRY_RESYNC_INTERVAL staleness after rotate/reclaim.
  • NodeId↔address binding documentation should reflect the current event coverage and the potential staleness until resync.

Assessment: This pull request requires changes.

File Reviewed
crates/​node/​src/​dht/​node_address.rs Yes
crates/​node/​src/​dht/​capacity_bond_registry.rs Yes
crates/​incentive/​src/​capacity_bond.rs Yes
crates/​e2e/​tests/​slash_appeal.rs Yes
crates/​e2e/​tests/​g_node_06_unbond.rs Yes
crates/​e2e/​tests/​g_node_04_blacklist_compliance.rs Yes
crates/​e2e/​src/​chain.rs Yes
crates/​common/​src/​cli/​node.rs Yes
crates/​client/​src/​discovery/​tests.rs Yes
crates/​cli/​src/​commands/​unbond.rs Yes
crates/​cli/​src/​commands/​node/​tests.rs Yes
crates/​cli/​src/​commands/​deregister.rs Yes
contracts/​test/​SlashJudge.t.sol Yes
contracts/​test/​SlashAppeal.t.sol Yes
contracts/​test/​PaymentPool.t.sol Yes
contracts/​test/​OriginAssignment.t.sol Yes
contracts/​test/​mocks/​MockCapacityBond.sol Yes
contracts/​test/​GenesisBuybackActivation.t.sol Yes
contracts/​test/​GenesisBuybackActivation.fork.t.sol Yes
contracts/​test/​E2EProtocol.t.sol Yes
contracts/​test/​DeployProtocol.t.sol Yes
contracts/​test/​DecdnGovernorDelegation.t.sol Yes
contracts/​test/​DecdnGovernor.t.sol Yes
contracts/​test/​ContentBlacklist.t.sol Yes
contracts/​test/​CapacityBondRegionE2E.t.sol Yes
contracts/​test/​CapacityBond.t.sol Yes
contracts/​test/​BuybackBurnerUniswapV3.t.sol Yes
contracts/​src/​SlashJudge.sol Yes
contracts/​src/​SlashAppeal.sol Yes
contracts/​src/​PaymentPool.sol Yes
contracts/​src/​interfaces/​ICapacityBondSlasher.sol Yes
contracts/​src/​interfaces/​ICapacityBondActivity.sol Yes
contracts/​src/​interfaces/​ICapacityBond.sol Yes
contracts/​src/​GuardedBuybackBurner.sol Yes
contracts/​src/​DecdnGovernor.sol Yes
contracts/​src/​ContentBlacklist.sol Yes
contracts/​src/​CapacityBond.sol Yes
contracts/​src/​BuybackBurnerUniswapV3.sol Yes
contracts/​script/​DeployProtocol.s.sol Yes
contracts/​script/​BaseProtocolDeploy.s.sol Yes
adr/​036-served-bytes-voting-weight.md Yes
adr/​028-slashing-appeals.md Yes
adr/​026-tokenomics.md Yes
adr/​024-account-abstraction.md Yes
adr/​018-liquidity-strategy.md Yes
adr/​016-contract-interactions.md Yes
adr/​014-on-chain-verification.md Yes
adr/​011-content-takedown.md Yes
adr/​009-governance.md Yes
adr/​003-payments.md Yes

Review effort: Balanced

Comment thread crates/cli/src/commands/unbond.rs Resolved
Comment thread crates/common/src/cli/node.rs Resolved
alpergundogdu and others added 2 commits November 3, 2026 16:15
isActive tests bondFloorAtActivation, which a minBond change since
activation leaves in place, so keying the disclosure on the live minBond
could misreport whether the node stays active. The plan reads the
recorded floor (the live minBond for an operator that never activated)
and reports it as below_floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…curity-audit-bfede0

# Conflicts:
#	contracts/.gas-snapshot
@alpergundogdu
alpergundogdu merged commit 560465f into main Nov 3, 2026
38 checks passed
@alpergundogdu
alpergundogdu deleted the claude/contract-security-audit-bfede0 branch November 3, 2026 16:38
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.

3 participants