Repository navigation
fix(contracts): enforce per-byte price floor at settlement (#846) - #891
Conversation
Payment vouchers had no on-chain binding between the USDC `amount` and `bytesDelivered`, so an operator acting as its own client could settle `amount = 1` against `bytesDelivered = 2^200`, stamping arbitrary served bytes for ~zero cost. Because ADR 036 sources governance vote weight from those served bytes, this let an established operator mint near-free voting power (and inflate the quorum denominator) — invalidating the ADR 036 cost model, which assumes uniform per-byte pricing that no contract enforced. The fix wires the already-existing, governance-settable `deliveryFloor` (USDC base units per MB, default 1 — ADR 003's documented "anti-abuse minimum") into the settlement chokepoint. `_advanceClaimWatermark` now enforces `bytesDelivered <= Math.mulDiv(amount, BYTES_PER_MB, deliveryFloor)` across all three entry points (withdraw, closeChannel, disputeChannel), reverting `RateFloorViolation`. The `mulDiv` bytes-ceiling makes a malicious `bytesDelivered` near `type(uint256).max` revert cleanly rather than panic. `deliveryCeiling` stays advisory. The serving node mirrors the floor off-chain: `collect_voucher` re-checks the voucher delta against `delivery_floor` at zero tolerance (vs the advertised-rate check's 1%), so a synced node never countersigns a voucher it could not redeem on-chain. The check is inert at the default `delivery_floor = 0` (the deliberate free-serving config, #864); the always-`>= 1` on-chain floor is authoritative there. Adds a `voucher_rate_floor_rejections` metric. ADR 003 (new "Rate-floor enforcement" section + §924) and ADR 036 (§139-141 threat model) updated to match; the ADR 036 cost estimate is revised to note a cost-minimizing attacker pays at the floor (~10x below market). Companion snapshot issue #847 already merged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 27455789146 |
Contracts coverageLine coverage: 89.86% (1844/2052 lines) |
There was a problem hiding this comment.
Code Review
This pull request implements on-chain and off-chain rate-floor enforcement to prevent served-byte vote-weight inflation (ADR 036). On-chain, PaymentChannel.sol now enforces the deliveryFloor price floor during settlement in _advanceClaimWatermark using an overflow-safe check. Off-chain, the Rust node handler is updated to enforce this floor with zero tolerance before countersigning vouchers, and corresponding metrics and tests have been added. There are no review comments, so 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.
There was a problem hiding this comment.
Pull request overview
This PR closes a governance-abuse vector by binding served bytes to paid USDC at settlement time via the already-governable deliveryFloor, preventing near-free served-bytes (and thus vote-weight) inflation.
Changes:
- Enforces a per-byte price floor in
PaymentChannel._advanceClaimWatermarkusing an overflow-safeMath.mulDiv-based bytes ceiling and a newRateFloorViolationrevert. - Mirrors the floor check in the serving node (
collect_voucher) and adds a newvoucher_rate_floor_rejectionsmetric. - Updates ADR 003 and ADR 036 to document the new enforcement point and the revised attack-cost model.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/metrics.rs | Adds a counter + helper for tracking vouchers rejected by the protocol floor check. |
| crates/node/src/handlers/client.rs | Adds an off-chain floor check during voucher collection to avoid countersigning non-redeemable vouchers. |
| crates/incentive/src/rate.rs | Adds tests clarifying zero-tolerance floor semantics (floor=0 inert, floor>0 rejects inflation). |
| contracts/src/PaymentChannel.sol | Enforces the deliveryFloor at the settlement chokepoint and introduces RateFloorViolation. |
| contracts/test/PaymentChannel.t.sol | Adds Foundry tests covering the floor enforcement across entry points and edge cases. |
| adr/003-payments.md | Documents rate-floor enforcement and clarifies which bounds are enforced vs advisory. |
| adr/036-served-bytes-voting-weight.md | Updates threat model/cost estimate to depend on and reflect the enforced floor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 86.15% (was 86.16%, ▼ 0.01%) — 35538/41252 lines
History
|
Address PR review: the off-chain floor check validated the per-voucher delta (amount_delta / delta_bytes), but the on-chain `_advanceClaimWatermark` guard floors the cumulative `amount / bytesDelivered` watermark. The delta form diverges from the chain in two ways: it false- accepts a later in-floor delta when an earlier under-floor voucher (taken while delivery_floor was 0) still drags the cumulative ratio below the floor, and it false-rejects a delta drawing down an earlier overpayment surplus the chain would settle. Pass the cumulative `(amount, new_bytes)` pair to `verify_rate` so the node's accept decision matches on-chain redemption exactly. Updates the handler and metric docs to cumulative semantics. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ Solidity security review — passedRan a focused security pass over the contract change ( Static analysis: Slither exit 0 (fail-on: medium), Aderyn High = 0 (fail-on: high). Manual checklist (applied to the diff):
Core invariant confirmed: The one substantive finding across all review passes (off-chain delta-vs-cumulative watermark) was addressed in b42f070. 🤖 Generated with Claude Code |
Summary
Fixes #846. A payment voucher's
bytesDeliveredhad no on-chain binding to the USDCamountit carried, so an operator acting as its own client could settleamount = 1againstbytesDelivered = 2^200— stamping arbitrary served bytes for ~zero cost. Because ADR 036 sources governance vote weight from served bytes, this let an established operator mint near-free voting power and inflate the quorum denominator, invalidating the ADR 036 cost model (which assumes uniform per-byte pricing that no contract enforced).The fix wires the already-existing, governance-settable
deliveryFloor(USDC base units per MB, default 1 — ADR 003's documented "anti-abuse minimum") into the settlement chokepoint. No new parameter, constructor arg, or deploy change.Changes
PaymentChannel._advanceClaimWatermark(the single chokepoint forwithdraw/closeChannel/disputeChannel) now enforcesbytesDelivered <= Math.mulDiv(amount, BYTES_PER_MB, deliveryFloor), revertingRateFloorViolation.mulDivmakes abytesDeliveredneartype(uint256).maxrevert cleanly instead of panicking.deliveryCeilingstays advisory.collect_voucher): a zero-toleranceverify_rateagainstdelivery_floorafter the advertised-rate check, so a synced node never countersigns a voucher it could not redeem on-chain. Inert at the defaultdelivery_floor = 0(the deliberate free-serving config, Low-severity follow-ups from the 2026-06-10 full-repository review (umbrella) #864); the always->= 1on-chain floor is authoritative there. Newvoucher_rate_floor_rejectionsmetric.Scope notes
deliveryFloorvalue unchanged (still 1 base unit/MB) →finance/params.pyuntouched. Enforcement, not re-parameterization.Testing
PaymentChannel.t.sol): attack reverts on all 3 entry points,type(uint256).maxoverflow-safety, exact + non-unit-floor truncation boundaries, honest path unaffected, governance tunability, routed-bytes ceiling, and a straddling fuzz test. 539 contract tests pass.rate.rs): zero-tolerance floor semantics (rejects byte inflation, inert at floor 0). 759 incentive+node tests pass.forge fmt --check,FOUNDRY_PROFILE=ci forge build --sizes --deny warnings(PaymentChannel 11,314 B), slither (exit 0), aderyn (High = 0),cargo clippy --all-targets,cargo fmt --check, doctests.Reviewed
Multi-agent review (code/tests/comments/errors/types) run pre-merge; all findings addressed — CI-blocking
too_many_lines, exhaustivematchon the floor check (silent-failure hardening, #845 pattern), comment-accuracy fixes (off-chain check is inert at default config; the real value is the 0% vs 1% tolerance delta), a fixed ADR citation, and two test tightenings (load-bearing ceiling assertion + truncation boundary).🤖 Generated with Claude Code