Skip to content

docs(adr): drop ADR 027 — wash-trading defense is the per-operator gauge cap alone - #488

Merged
alpergundogdu merged 4 commits into
mainfrom
feat/adr-027-diversity-via-feerouter
May 8, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
feat/adr-027-diversity-via-feerouter

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #486. Deletes ADR 027 entirely. The diversity-gate machinery (funded-channel minimum, funding age, per-operator cooldown, distinct-client threshold) is redundant with the ADR 026 §3 per-operator gauge-share cap — the cap is the binding constraint, the gate adds ~$40/operator setup cost (negligible) and a contestable tokenomics opinion (excluding legitimate concentrated-client operators).

Two commits:

  1. 04d4474 — first pass: replaces DeliveryReceipt primitive with FeeRouter diversity counting + per-operator gauge cap. Removes MMR aggregator, OffenseType.ReceiptFraud, submitReceiptFraudChallenge, fraud-challenge window. ADR 027 collapses 423 → 215 lines.
  2. 6818995 — second pass (after `/internal/ideas/wash-trading-economics.md` analysis showed the diversity gate adds nothing the cap doesn't already do): deletes ADR 027 entirely. The remaining content (`bytesPerEpoch` storage map, `Voucher.epochId` field, `enableGauge()` launch prerequisite) lives in ADR 016 / ADR 003 / ADR 026 respectively. ADR 008 §12 rewritten as soft off-chain wash-trading signal rather than hard gauge-eligibility gate.

Why ADR 027 is gone

For wash-trading to be profitable at all the attacker needs ve-boost; the cap-binding self-deal threshold (~$21k/yr per operator with full ve-boost, ~$52k without) is independent of the diversity gate. Whether the attacker uses 1 fake client or 5, the cap binds at the same volume and bounds extraction at 5% of the gauge bucket per operator-identity.

The diversity gate's marginal contributions:

  • $40 per attack operator in increased setup cost (negligible — operator stake of 50k TOKEN dwarfs this)
  • A tokenomics opinion that legitimate concentrated-client operators (single-enterprise CDN customers, dedicated-publisher origin nodes) should be excluded from gauge

The cap does the Sybil work; the tokenomics opinion is contestable and better captured as a reputation signal off-chain.

What's gone

  • ADR 027 file — deleted. Number reclaimed per the same pattern as 029/030/031/032 documented in CLAUDE.md.
  • 4 governance parameters: MIN_DISTINCT_CLIENTS_PER_EPOCH, MIN_CHANNEL_FUNDING_USDC, MIN_CLIENT_AGE, IDENTITY_COOLDOWN
  • 2 FeeRouter storage maps: distinctClientCount, _seenClient
  • `StablePaymentChannel.lifetimeDepositOf()` view + `lifetimeDeposit` storage (had no consumer outside the diversity gate)
  • ADR 008 §12 receipt-tier gating (rewritten as off-chain reputation signal explanation; ~50 lines deleted)
  • `summaryWindow` / `challengeWindow` governable parameters from ADR 026 §11
  • MMR retention buffer from ADR 009
  • Per-receipt fraud-challenge surface that PR docs(adr): resolve corruption at the wire — drop ADR 014 §2 + OffenseType.Corruption #480 already partially trimmed
  • `OffenseType.ReceiptFraud` + `submitReceiptFraudChallenge` from ADR 014 (already gone in commit 1, kept gone in commit 2)
  • Cold-start exception (`gaugeBootstrapEpochs`)
  • DeliveryReceipt EIP-712 typedef
  • MMR aggregator on FeeRouter (`peaks` + `leafCount` per (operator, epoch))
  • `commitEpochReceiptRoot` + `commitEpochSummary` keeper jobs
  • 7-day fraud-challenge window state machine
  • Privacy regression on challenge (per-receipt clientPubKey exposure)

What's preserved

  • `MAX_GAUGE_SHARE_PER_OPERATOR` cap (5% default, governable `[1%, 25%]`) in ADR 026 §3 — the binding wash-trading defense
  • `Voucher.epochId` field in ADR 003 (Tier 3 schema break, bundled with `enableGauge()` cutover)
  • `bytesPerEpoch` storage map on FeeRouter, populated inline at `routeSettlement` (~5–10k gas overhead)
  • Pre-launch gauge accumulation + `enableGauge()` cutover in ADR 026 §2
  • Reputation system (ADR 008) intact; §12 rewritten as off-chain wash-trading signal feeding governance cap-tuning rather than as a hard eligibility gate

Diff

14 files, +46 / −311 (~265 net deletion across both commits). ADR 027 itself: 423 → 0 lines.

Combined with PR #480 (ADR 030 + ADR 014 §2 + OffenseType.Corruption — −190 net) the recent ADR-cleanup wave has cut ~750 lines of speculative production-grade machinery from the protocol design.

Test plan

  • All ADR markdown renders cleanly
  • Zero remaining references to `ADR 027`, `027-distinct-client-receipts`, `OffenseType.ReceiptFraud`, `submitReceiptFraudChallenge`, `commitEpochReceiptRoot`, `commitEpochSummary`, `EpochReceiptSummary`, `DeliveryReceipt`, `distinctClientCount`, `_seenClient`, `lifetimeDepositOf`, `MIN_DISTINCT_CLIENTS`, `MIN_CHANNEL_FUNDING_USDC`, `MIN_CLIENT_AGE`, `IDENTITY_COOLDOWN`, `gaugeBootstrapEpochs` outside of `_history/`
  • Cross-references resolve (`#per-operator-gauge-share-cap`, `docs: convert ASCII art schemas to Mermaid diagrams #3-gauge-boost-formula`, `#pre-launch-gauge-accumulation`)
  • Voucher EIP-712 typedef change (`epochId: uint64` added) is reflected in ADR 003 and IFeeRouter signature in ADR 016
  • CLAUDE.md ADR-number note flags 027 as reclaimed

🤖 Generated with Claude Code

…eceipt primitive + per-operator gauge cap

Wash-trading defense for the gauge bucket previously used a parallel
DeliveryReceipt primitive (EIP-712 typedef per voucher window), an MMR
aggregator on FeeRouter, an OffenseType.ReceiptFraud entry on SlashJudge,
a 7-day fraud-challenge window with bond economics, and ~3 KB of audit
surface. The receipt's signed field set was fully redundant with the
voucher's (same signer = channel.client, same bytes, same channel,
same operator).

Replaces the entire mechanism with two storage maps + an inline check
inside FeeRouter.routeSettlement:

  - distinctClientCount[operator][epoch]
  - bytesPerEpoch[operator][epoch]
  - _seenClient[operator][epoch][client] for idempotency

Diversity threshold is enforced at gauge-claim time against these
contract-computed views. There's no operator-asserted summary, so
nothing to forge and no fraud-challenge mechanism needed.

Adds defense-in-depth via ADR 026 §3: a per-operator gauge-share cap
(MAX_GAUGE_SHARE_PER_OPERATOR, default 5%, governable [1%, 25%]) bounding
wash-trading payoff regardless of Sybil sophistication.

ADR 027 collapses from 423 lines to 215 lines (-50%).

Cascading changes:
- ADR 003: Voucher gains epochId field (Tier 3 schema break, bundled
  with enableGauge() cutover); routeSettlement signature extended to
  carry channel.client + epochId
- ADR 008: footnote no longer claims receipt-fraud as the deterrent
- ADR 014: drop OffenseType.ReceiptFraud, drop submitReceiptFraudChallenge,
  drop ABI for the entry point
- ADR 016: contract diagram + function table reflect the new
  routeSettlement signature; drop CorruptionChallenger / receipt-fraud row;
  drop EpochReceiptSummary + commit* signatures
- ADR 026: gauge formula §3 reads bytesPerEpoch directly; §3 gains
  per-operator gauge-share cap subsection; §11 governable parameters
  table updated; §Risks wash-trading rationale rewritten around the
  layered defenses; section heading "Pre-receipt-launch gauge
  accumulation" → "Pre-launch gauge accumulation"
- ADR 028: offense count 4→3 (phantom, rate, blacklist)
- architecture.md: ADR 014 + ADR 027 descriptions updated
- appendix-fraud-detection.md: rewritten to drop receipt-summary
  fraud detection; reduced to stale-close detection only
- appendix-l2-deployment.md: drop MMR-append cost discussion
- appendix-operator-key-rotation.md: offense count 4→3

Refs: #486

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@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 significantly simplifies the wash-trading defense mechanism by replacing the complex Merkle-based receipt attestation system with inline on-chain bookkeeping within the FeeRouter. Key changes include adding an epochId to vouchers, tracking distinct client counts and bytes per epoch directly during settlement, and introducing a per-operator gauge-share cap. Review feedback correctly identified documentation inconsistencies regarding the lifecycle of long-lived channels and discrepancies between pseudo-code and the updated routeSettlement interface.

Comment thread adr/027-distinct-client-receipts.md Outdated
A voucher attributed to an old epoch past the lag bound reverts. This bounds storage growth (only recent epochs accept new settlements) and prevents manipulation of long-closed gauge accounting.

Receipts are signed by *requester* EVM keys (channel funder, not operator), and identity diversity is computed in the EVM-address space because channel deposits are USDC. Ed25519 is reserved for wire-level operator authentication ([ADR 005](005-protocol.md)); on-chain Ed25519 verification was already rejected as too expensive ([ADR 014 Alternatives](014-on-chain-verification.md#alternatives-considered)).
For long-lived channels spanning multiple epochs, the client signs separate per-epoch vouchers (incrementing `voucherNonce` across them per [ADR 003 Voucher Nonce Convention](003-payments.md)). The operator submits each at the relevant `settleChannel` call cadence — typically once per epoch boundary per active channel.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This sentence seems to contradict the behavior of settleChannel as described in adr/003-payments.md, which states that settleChannel sets the channel status to Closed. If a channel is closed, it cannot be used for subsequent epochs. This implies that with the new design, all bytes from a long-lived channel are attributed to a single epoch from the final voucher, which seems like a regression from the previous design that supported multi-epoch attribution. Could you clarify how byte attribution is supposed to work for long-lived channels that span multiple epochs to ensure internal consistency?

References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions, field lists, and edge-case logic are aligned across all sections of the document.

Comment thread adr/027-distinct-client-receipts.md Outdated
Comment on lines +50 to +69
```solidity
function routeSettlement(
bytes32 channelId,
Voucher calldata voucher,
bytes calldata clientSignature
) external {
// ... existing voucher verification, USDC routing per ADR 026 §2 ...

Channel storage ch = channels[channelId];
address operator = ch.provider;
address client = ch.client;
uint64 epoch = epochOf(voucher); // see §2 below

if (!_seenClient[operator][epoch][client]) {
_seenClient[operator][epoch][client] = true;
distinctClientCount[operator][epoch] += 1;
}
bytesPerEpoch[operator][epoch] += voucher.bytesDelivered;
}
```

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

The pseudo-code for routeSettlement here is inconsistent with the interface defined in adr/016-contract-interactions.md and adr/003-payments.md. Those ADRs specify the signature as routeSettlement(address operator, address client, uint256 bytesDelivered, uint256 amount, uint64 epochId). To maintain consistency across the documentation, this pseudo-code should be updated to reflect the correct on-chain interface. The current signature and implementation details (like deriving operator and client from channelId) are misleading and fail to distinguish between operator-asserted values and on-chain state.

Suggested change
```solidity
function routeSettlement(
bytes32 channelId,
Voucher calldata voucher,
bytes calldata clientSignature
) external {
// ... existing voucher verification, USDC routing per ADR 026 §2 ...
Channel storage ch = channels[channelId];
address operator = ch.provider;
address client = ch.client;
uint64 epoch = epochOf(voucher); // see §2 below
if (!_seenClient[operator][epoch][client]) {
_seenClient[operator][epoch][client] = true;
distinctClientCount[operator][epoch] += 1;
}
bytesPerEpoch[operator][epoch] += voucher.bytesDelivered;
}
```
function routeSettlement(
address operator,
address client,
uint256 bytesDelivered,
uint256 amount,
uint64 epochId
) external {
// ... existing USDC routing per ADR 026 §2 ...
if (!_seenClient[operator][epochId][client]) {
_seenClient[operator][epochId][client] = true;
distinctClientCount[operator][epochId] += 1;
}
bytesPerEpoch[operator][epochId] += bytesDelivered;
}
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions, field lists, and edge-case logic are aligned across all sections of the document.
  2. Clearly distinguish between operator-asserted values (verified post-hoc via challenges) and values derived directly from on-chain state in protocol documentation.

…he per-operator gauge cap

Cuts the diversity gate (funded-channel minimum, funding age, per-operator
cooldown, distinct-client threshold) from the gauge security model. Analysis
showed:

1. The cap is the binding constraint. The cap-binding self-deal threshold
   (~$21k/yr per operator with full ve-boost, ~$52k without) is independent
   of the diversity gate. Whether the attacker uses 1 fake client or 5,
   the math is identical.
2. The diversity gate's marginal Sybil-cost contribution is $40 per attack
   operator ($50 vs $10 in client-channel deposits). Negligible.
3. The "diverse client base" tokenomics signal the gate encoded was
   contestable: legitimate operators with concentrated client bases (single
   enterprise customer, dedicated-publisher origin nodes) would be excluded
   from gauge despite being honest. Diversity-of-service is captured better
   as a reputation signal (off-chain, ADR 008 §12) than as an on-chain hard
   gate.

Drops:
- ADR 027 entirely (the file is deleted; number is reclaimed per the same
  pattern as 029/030/031/032 documented in CLAUDE.md)
- 4 governance parameters: MIN_DISTINCT_CLIENTS_PER_EPOCH,
  MIN_CHANNEL_FUNDING_USDC, MIN_CLIENT_AGE, IDENTITY_COOLDOWN
- 2 storage maps from FeeRouter: distinctClientCount, _seenClient
- ~15k gas per routeSettlement (only bytesPerEpoch SSTORE remains, ~5-10k)
- StablePaymentChannel.lifetimeDepositOf() view + lifetimeDeposit storage
  (had no consumer outside the diversity gate)
- ADR 008 §12 receipt-tier gating (replaced with off-chain reputation
  signal explanation)
- summaryWindow / challengeWindow governable parameters from ADR 026 §11
- MMR retention buffer from ADR 009

The wash-trading defense is now purely the ADR 026 §3 per-operator
gauge-share cap (5% default, governable [1%, 25%]) combined with the
closed-pool gauge bucket structure and the 8% treasury+safety leakage
per self-deal. Quantitative analysis lives in
internal/ideas/wash-trading-economics.md.

Net: ~310 lines deleted across 14 files. Routes everything through
FeeRouter.bytesPerEpoch[operator][epoch] feeding ADR 026 §3's gauge
formula directly, with no separate ADR for the trivial state map.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu alpergundogdu changed the title docs(adr): simplify ADR 027 — diversity counting in FeeRouter + per-operator gauge cap docs(adr): drop ADR 027 — wash-trading defense is the per-operator gauge cap alone May 8, 2026
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Pushed 6818995 — second pass: ADR 027 deleted entirely. The diversity gate adds nothing the per-operator gauge-share cap doesn't already do, and the cap is the binding constraint regardless of how many distinct clients an attacker has. Net diff is now -265 lines across 14 files.

@alpergundogdu

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 simplifies the protocol's wash-trading defense by removing the complex 'Distinct-Client Delivery Receipts' (ADR 027) mechanism and its associated on-chain verification and slashing logic. It introduces a per-operator gauge-share cap (default 5%) in ADR 026 as the primary defense, while reframing reputation as an off-chain signal. The FeeRouter.routeSettlement interface is updated to include epochId and client parameters to support these changes. Feedback was provided to ensure the client parameter is consistently included in function signatures and descriptions across all affected ADR documentation.

Comment on lines 128 to 133
function routeSettlement(
address operator,
uint256 bytesDelivered,
uint256 amount
uint256 amount,
uint64 epochId // voucher.epochId per ADR 003
) external;

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

The routeSettlement function signature in the IFeeRouter interface is missing the client parameter. This parameter is present in the call table (line 478) and is required to populate the Settled event (line 250) for off-chain analytics and reputation signals as described in ADR 008 Section 12.

Suggested change
function routeSettlement(
address operator,
uint256 bytesDelivered,
uint256 amount
uint256 amount,
uint64 epochId // voucher.epochId per ADR 003
) external;
function routeSettlement(
address operator,
address client, // channel.client for reputation
uint256 bytesDelivered,
uint256 amount,
uint64 epochId // voucher.epochId per ADR 003
) external;
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions and field lists are aligned across all sections of the document.

class FeeRouter {
+routeSettlement(op, bytes, amount)
+commitEpochReceiptRoot(epochId, root)
+routeSettlement(op, bytes, amount, epochId)

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

The class diagram for FeeRouter should be updated to include the client parameter in the routeSettlement method to maintain consistency with the rest of the ADR.

Suggested change
+routeSettlement(op, bytes, amount, epochId)
+routeSettlement(op, client, bytes, amount, epochId)
References
  1. Ensure consistent use of canonical function names across all documentation artifacts, including class diagrams and Mermaid graphs.

Comment thread adr/016-contract-interactions.md Outdated
| --- | --- | --- |
| `routeSettlement(operator, bytesDelivered, amount)` | `IERC20.safeTransfer()` × 4 (operator base 40%, BuybackBurner 5%, Treasury 5%, SafetyReserve 3%; gauge 40% and delegator 7% retained in epoch USDC buckets, no transfer), `StakingRegistry.recordSettlement(operator)`. State updates: increments per-epoch USDC accumulators for the gauge and delegator buckets. Byte counters and receipt-root commitments do **not** flow through this call — gauge eligibility (`bytes_i` and `sum(working_bytes)` in the [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula) formula) is sourced from per-(operator, epoch) receipt summaries via the separate `commitEpochReceiptRoot` / `commitEpochSummary` entry points ([ADR 027 §4](027-distinct-client-receipts.md#4-on-chain-anchoring-merkle-batched)). | `nonReentrant`, checks-effects-interactions, `ROUTER_CALLER_ROLE` |
| `commitEpochReceiptRoot(epochId, root)` | None (state-only). Appends one leaf to the per-(`msg.sender`, `epochId`) MMR receipt accumulator (per [ADR 027 §4](027-distinct-client-receipts.md#4-on-chain-anchoring-merkle-batched)). | None — `msg.sender` is the credited operator; the operator is self-authorising for their own gauge eligibility. |
| `routeSettlement(operator, bytesDelivered, amount, epochId)` | `IERC20.safeTransfer()` × 4 (operator base 40%, BuybackBurner 5%, Treasury 5%, SafetyReserve 3%; gauge 40% and delegator 7% retained in epoch USDC buckets, no transfer), `StakingRegistry.recordSettlement(operator)`. State updates: increments per-epoch USDC accumulators for the gauge and delegator buckets; increments `bytesPerEpoch[operator][epochId]` for the gauge formula. Gauge eligibility (`bytes_i` in the [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula) formula) is sourced from this view at gauge-claim time, with the per-operator share cap binding the output. | `nonReentrant`, checks-effects-interactions, `ROUTER_CALLER_ROLE` |

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

The reentrancy table entry for routeSettlement is missing the client parameter in the function signature, which is inconsistent with the call table on line 478.

Suggested change
| `routeSettlement(operator, bytesDelivered, amount, epochId)` | `IERC20.safeTransfer()` × 4 (operator base 40%, BuybackBurner 5%, Treasury 5%, SafetyReserve 3%; gauge 40% and delegator 7% retained in epoch USDC buckets, no transfer), `StakingRegistry.recordSettlement(operator)`. State updates: increments per-epoch USDC accumulators for the gauge and delegator buckets; increments `bytesPerEpoch[operator][epochId]` for the gauge formula. Gauge eligibility (`bytes_i` in the [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula) formula) is sourced from this view at gauge-claim time, with the per-operator share cap binding the output. | `nonReentrant`, checks-effects-interactions, `ROUTER_CALLER_ROLE` |
| routeSettlement(operator, client, bytesDelivered, amount, epochId) | IERC20.safeTransfer() × 4 (operator base 40%, BuybackBurner 5%, Treasury 5%, SafetyReserve 3%; gauge 40% and delegator 7% retained in epoch USDC buckets, no transfer), StakingRegistry.recordSettlement(operator). State updates: increments per-epoch USDC accumulators for the gauge and delegator buckets; increments bytesPerEpoch[operator][epochId] for the gauge formula. Gauge eligibility (bytes_i in the [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula) formula) is sourced from this view at gauge-claim time, with the per-operator share cap binding the output. | nonReentrant, checks-effects-interactions, ROUTER_CALLER_ROLE |
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions and field lists are aligned across all sections of the document.

Comment thread adr/003-payments.md
1. **`closeChannel`** — callable by client or provider only. Records the submitted voucher's `amount` in `claimedAmount`, `nonce` in `claimedNonce`, and `bytesDelivered` in `claimedBytes`, sets status to `Closing`, starts the dispute window. **No fee deduction, no router call.** **Zero-voucher close:** when **either party** calls `closeChannel` with `amount=0`, `nonce=0`, `bytesDelivered=0`, and an empty signature (`signature.length == 0`) on a channel with `claimedNonce == 0`, the signature verification is skipped — no client-signed voucher is needed. All other `closeChannel` calls — any call with `signature.length > 0`, or any call where `amount != 0`, `nonce != 0`, or `bytesDelivered != 0` — require normal EIP-712/ECDSA voucher verification. This is safe because voucher nonces start at 1 (nonce 0 is the sentinel for "no voucher submitted"; see [Voucher Nonce Convention](#voucher-nonce-convention)), so any real voucher has nonce ≥ 1 and can always be submitted via `disputeChannel` (which requires strictly higher nonce than `claimedNonce`). The dispute window still applies: if a valid voucher exists, any party can submit it via `disputeChannel`. At settlement, `claimedAmount=0` means the full deposit is refunded to the client and the provider receives nothing — no router call is made for a zero-amount settlement.
2. **`disputeChannel`** (during dispute window) — callable by any address. If the submitted voucher has a strictly higher nonce, updates both `claimedAmount`, `claimedNonce`, and `claimedBytes` (see [Voucher Bytes-Delivered Field](#voucher-bytes-delivered-field)) to the new values. Still **no fee deduction, no router call**. Submissions with an equal or lower nonce revert with no state change.
3. **`settleChannel`** (after dispute window expires) — callable by anyone. If `claimedAmount > 0`, computes `bytesDelivered` from the final voucher, transfers the full `claimedAmount` of USDC to the `FeeRouter`, and invokes `FeeRouter.routeSettlement(channel.provider, bytesDelivered, claimedAmount)` in the same transaction. Refunds `deposit - claimedAmount` to the client. Sets status to `Closed`. The router (not `StablePaymentChannel`) is responsible for forwarding the operator's 40% base share, dispatching the same-tx legs (5% buyback-and-burn, 5% treasury, 3% safety reserve), and accumulating the epoch-bucketed gauge and delegator pools per [ADR 026 §2](026-gauge-boost-tokenomics.md#2-feerouter-split-40407553). Gauge-eligibility receipt commitments are decoupled from channel settlement — operators commit per-epoch receipt roots directly to `FeeRouter` (see [ADR 027 §4](027-distinct-client-receipts.md#4-on-chain-anchoring-merkle-batched)). `settleChannel` is purely the USDC payment path; whether and when the bytes settled here count toward gauge eligibility depends on whether the operator commits a per-epoch root for the corresponding epoch.
3. **`settleChannel`** (after dispute window expires) — callable by anyone. If `claimedAmount > 0`, computes `bytesDelivered` from the final voucher, transfers the full `claimedAmount` of USDC to the `FeeRouter`, and invokes `FeeRouter.routeSettlement(channel.provider, bytesDelivered, claimedAmount, voucher.epochId)` in the same transaction. Refunds `deposit - claimedAmount` to the client. Sets status to `Closed`. The router (not `StablePaymentChannel`) is responsible for forwarding the operator's 40% base share, dispatching the same-tx legs (5% buyback-and-burn, 5% treasury, 3% safety reserve), accumulating the epoch-bucketed gauge and delegator pools per [ADR 026 §2](026-gauge-boost-tokenomics.md#2-feerouter-split-40407553), and incrementing `bytesPerEpoch[operator][epochId]` for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense; gauge bytes flow through `settleChannel` directly with no separate commit step.

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

The description of settleChannel is missing the channel.client argument in the call to FeeRouter.routeSettlement. This argument is required by the updated IFeeRouter interface in ADR 016 to support off-chain reputation signals.

Suggested change
3. **`settleChannel`** (after dispute window expires) — callable by anyone. If `claimedAmount > 0`, computes `bytesDelivered` from the final voucher, transfers the full `claimedAmount` of USDC to the `FeeRouter`, and invokes `FeeRouter.routeSettlement(channel.provider, bytesDelivered, claimedAmount, voucher.epochId)` in the same transaction. Refunds `deposit - claimedAmount` to the client. Sets status to `Closed`. The router (not `StablePaymentChannel`) is responsible for forwarding the operator's 40% base share, dispatching the same-tx legs (5% buyback-and-burn, 5% treasury, 3% safety reserve), accumulating the epoch-bucketed gauge and delegator pools per [ADR 026 §2](026-gauge-boost-tokenomics.md#2-feerouter-split-40407553), and incrementing `bytesPerEpoch[operator][epochId]` for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense; gauge bytes flow through `settleChannel` directly with no separate commit step.
3. settleChannel (after dispute window expires) — callable by anyone. If claimedAmount > 0, computes bytesDelivered from the final voucher, transfers the full claimedAmount of USDC to the FeeRouter, and invokes FeeRouter.routeSettlement(channel.provider, channel.client, bytesDelivered, claimedAmount, voucher.epochId) in the same transaction. Refunds deposit - claimedAmount to the client. Sets status to Closed. The router (not StablePaymentChannel) is responsible for forwarding the operator's 40% base share, dispatching the same-tx legs (5% buyback-and-burn, 5% treasury, 3% safety reserve), accumulating the epoch-bucketed gauge and delegator pools per [ADR 026 §2](026-gauge-boost-tokenomics.md#2-feerouter-split-40407553), and incrementing bytesPerEpoch[operator][epochId] for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense; gauge bytes flow through settleChannel directly with no separate commit step.
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions and field lists are aligned across all sections of the document.

Comment thread adr/003-payments.md
- `closeChannel` → requires status `Open`. **Callable by `channel.client` or `channel.provider` only** (`require(msg.sender == channel.client || msg.sender == channel.provider)`). Sets status to `Closing`, records `claimedAmount`, `claimedNonce`, and `claimedBytes` from the submitted voucher, emits `ChannelCloseInitiated`. No fund transfers. Third parties cannot initiate a close — they act only via `disputeChannel` (during the dispute window) or `settleChannel` (after expiration). **Zero-voucher close:** when **either party** calls with `amount == 0`, `nonce == 0`, `bytesDelivered == 0`, an empty signature (`signature.length == 0`), and `channel.claimedNonce == 0`, the voucher signature is not verified — this is the symmetric mechanism for releasing channels where no vouchers were ever signed (a provider releasing an abandoned channel; a client recovering their deposit when the node failed before the first voucher boundary). Since voucher nonces start at 1, any real voucher has a strictly higher nonce than the recorded `claimedNonce=0`, so `disputeChannel` works normally. The dispute window applies; the counterparty (or any third party) holding a real voucher can dispute.
- `disputeChannel` → requires status `Closing` and `block.timestamp < disputeDeadline`. Callable by any address holding a valid voucher with a strictly higher nonce. Updates `claimedAmount`, `claimedNonce`, and `claimedBytes`, emits `ChannelDisputed`. No fund transfers. Unrestricted caller access is intentional: third-party fraud detectors ([Appendix: Fraud Detection](appendix-fraud-detection.md)) must be able to submit higher-nonce vouchers on behalf of an offline party during the dispute window.
- `settleChannel` → requires status `Closing` and `block.timestamp >= disputeDeadline`. Callable by any address. Refunds `deposit - claimedAmount` to the client and, if `claimedAmount > 0`, transfers `claimedAmount` USDC to the configured `FeeRouter` and invokes `FeeRouter.routeSettlement(channel.provider, claimedBytes, claimedAmount)` in the same transaction. Sets status to `Closed`, emits `ChannelSettled`. **No fee is computed or skimmed inside this contract** — the router applies the [ADR 026](026-gauge-boost-tokenomics.md) six-bucket split and pays the operator's 40% base share same-tx (see [FeeRouter Integration](#feerouter-integration)). Gauge-eligibility receipt commitments are not part of this call — operators commit per-epoch roots directly to `FeeRouter.commitEpochReceiptRoot` (see [ADR 027 §4](027-distinct-client-receipts.md#4-on-chain-anchoring-merkle-batched)), independent of settlement timing and unaffected by which address calls `settleChannel`.
- `settleChannel` → requires status `Closing` and `block.timestamp >= disputeDeadline`. Callable by any address. Refunds `deposit - claimedAmount` to the client and, if `claimedAmount > 0`, transfers `claimedAmount` USDC to the configured `FeeRouter` and invokes `FeeRouter.routeSettlement(channel.provider, claimedBytes, claimedAmount, voucher.epochId)` in the same transaction. Sets status to `Closed`, emits `ChannelSettled`. **No fee is computed or skimmed inside this contract** — the router applies the [ADR 026](026-gauge-boost-tokenomics.md) six-bucket split and pays the operator's 40% base share same-tx (see [FeeRouter Integration](#feerouter-integration)). The router also increments `bytesPerEpoch[operator][epochId]` for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula); the per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense.

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

The summary description for settleChannel is missing the channel.client argument in the routeSettlement call, which is inconsistent with the updated interface requirements.

Suggested change
- `settleChannel` → requires status `Closing` and `block.timestamp >= disputeDeadline`. Callable by any address. Refunds `deposit - claimedAmount` to the client and, if `claimedAmount > 0`, transfers `claimedAmount` USDC to the configured `FeeRouter` and invokes `FeeRouter.routeSettlement(channel.provider, claimedBytes, claimedAmount, voucher.epochId)` in the same transaction. Sets status to `Closed`, emits `ChannelSettled`. **No fee is computed or skimmed inside this contract** — the router applies the [ADR 026](026-gauge-boost-tokenomics.md) six-bucket split and pays the operator's 40% base share same-tx (see [FeeRouter Integration](#feerouter-integration)). The router also increments `bytesPerEpoch[operator][epochId]` for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula); the per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense.
- settleChannel → requires status Closing and block.timestamp >= disputeDeadline. Callable by any address. Refunds deposit - claimedAmount to the client and, if claimedAmount > 0, transfers claimedAmount USDC to the configured FeeRouter and invokes FeeRouter.routeSettlement(channel.provider, channel.client, claimedBytes, claimedAmount, voucher.epochId) in the same transaction. Sets status to Closed, emits ChannelSettled. No fee is computed or skimmed inside this contract — the router applies the [ADR 026](026-gauge-boost-tokenomics.md) six-bucket split and pays the operator's 40% base share same-tx (see [FeeRouter Integration](#feerouter-integration)). The router also increments bytesPerEpoch[operator][epochId] for the gauge formula in [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula); the per-operator gauge-share cap from [ADR 026 §3](026-gauge-boost-tokenomics.md#per-operator-gauge-share-cap) is the binding wash-trading defense.
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions and field lists are aligned across all sections of the document.

Comment thread adr/003-payments.md
#### Settlement-path interface

`StablePaymentChannel.settleChannel` MUST invoke `FeeRouter.routeSettlement(address operator, uint256 bytesDelivered, uint256 amount)` in the same transaction as the USDC `safeTransferFrom` to the router. The router pays the operator's 40% base share in that transaction and dispatches the 5% / 5% / 3% same-tx legs. Gauge eligibility does not flow through this call; the operator credits gauge bytes via `FeeRouter.commitEpochReceiptRoot` per [ADR 027 §4](027-distinct-client-receipts.md#4-on-chain-anchoring-merkle-batched). The full `IFeeRouter` interface (claim paths, epoch views, `commitEpochReceiptRoot`) is canonical in [ADR 016](016-contract-interactions.md).
`StablePaymentChannel.settleChannel` MUST invoke `FeeRouter.routeSettlement(address operator, uint256 bytesDelivered, uint256 amount, uint64 epochId)` in the same transaction as the USDC `safeTransferFrom` to the router. The router pays the operator's 40% base share in that transaction, dispatches the 5% / 5% / 3% same-tx legs, and increments `bytesPerEpoch[operator][epochId]` for the gauge formula per [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The full `IFeeRouter` interface is canonical in [ADR 016](016-contract-interactions.md).

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

The settlement-path interface requirement for StablePaymentChannel.settleChannel is missing the address client parameter in the routeSettlement signature.

Suggested change
`StablePaymentChannel.settleChannel` MUST invoke `FeeRouter.routeSettlement(address operator, uint256 bytesDelivered, uint256 amount, uint64 epochId)` in the same transaction as the USDC `safeTransferFrom` to the router. The router pays the operator's 40% base share in that transaction, dispatches the 5% / 5% / 3% same-tx legs, and increments `bytesPerEpoch[operator][epochId]` for the gauge formula per [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The full `IFeeRouter` interface is canonical in [ADR 016](016-contract-interactions.md).
StablePaymentChannel.settleChannel MUST invoke FeeRouter.routeSettlement(address operator, address client, uint256 bytesDelivered, uint256 amount, uint64 epochId) in the same transaction as the USDC safeTransferFrom to the router. The router pays the operator's 40% base share in that transaction, dispatches the 5% / 5% / 3% same-tx legs, and increments bytesPerEpoch[operator][epochId] for the gauge formula per [ADR 026 §3](026-gauge-boost-tokenomics.md#3-gauge-boost-formula). The full IFeeRouter interface is canonical in [ADR 016](016-contract-interactions.md).
References
  1. Ensure protocol documentation is internally consistent by verifying that function descriptions and field lists are aligned across all sections of the document.

Per gemini-code-assist review on PR #488: dropped channel.client from
routeSettlement signature in commit 6818995, but the Settled event still
emits client (for ADR 008 §12 off-chain reputation signals) and the call
table at ADR 016 line 478 still shows client in the args. Re-adds client
to the signature and propagates the consistent shape across all references:

- ADR 016: function signature, class diagram, reentrancy table — all
  show (operator, client, bytesDelivered, amount, epochId)
- ADR 003: §settleChannel description, settlement-path interface,
  §3 callable-anyone description — all show the same signature
- ADR 003 §31, §110: high-level fee-routing prose updated
- ADR 016 §348, §399: deployment + role-grant prose updated
- appendix-l2-deployment.md: gas-overhead description updated
- appendix-poc-production-seams.md: PoC/production seam table updated

The client param exists for the Settled event (off-chain analytics +
reputation indexing); on-chain logic does not key on it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Addressed in 189672e:

Re-added address client to the routeSettlement signature so the Settled event has the data to emit, and propagated the consistent (operator, client, bytesDelivered, amount, epochId) shape everywhere (IFeeRouter signature, class diagram, reentrancy table, all ADR 003 settlement-path descriptions, deployment prose, appendices). The client param exists for the off-chain reputation signal per ADR 008 §12; on-chain logic doesn't key on it.

Per offline review: the client field on FeeRouter.Settled was redundant
data. Off-chain reputation indexers can recover it by joining via tx
hash with StablePaymentChannel's events:

- ChannelSettled(channelId, provider, ...) is emitted in the same tx
  as routeSettlement (settleChannel calls routeSettlement inline)
- ChannelOpened(channelId, client, provider, ...) was emitted at
  channel-open time, providing the channelId → client mapping
- Standard subgraph join pattern (TheGraph, Dune, et al. all support it)

So the client field on FeeRouter's signature/event was duplicating data
StablePaymentChannel already exposes. Drops it everywhere:

- IFeeRouter.routeSettlement signature: 5-arg → 4-arg
- IFeeRouter.Settled event: removed indexed client
- FeeRouter class diagram in ADR 016
- ADR 016 reentrancy table + call table
- ADR 003: §settleChannel description (line 116), summary (line 423),
  fee-routing prose (line 31, 110), settlement-path interface (line 498)
- ADR 016 §348 deployment prose, §397 role-grant authorization
- appendix-poc-production-seams.md
- appendix-l2-deployment.md

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Pushed 212231c — dropped client from routeSettlement and Settled entirely.

The reputation/analytics signal it provided is fully recoverable off-chain by joining via tx hash:

  • StablePaymentChannel.ChannelSettled(channelId, provider, ...) is emitted in the same tx as routeSettlement (settleChannel calls routeSettlement inline)
  • StablePaymentChannel.ChannelOpened(channelId, client, provider, ...) was emitted at channel-open time, giving the channelId → client mapping

Standard subgraph join pattern. The client field on FeeRouter's signature/event was duplicating data StablePaymentChannel already exposes — gone.

Net effect on this PR: signature is now (operator, bytesDelivered, amount, epochId) everywhere, simpler than where it started. ADR 008 §12 wash-trading signal still works (indexers consume the joined view, not a denormalized FeeRouter event).

@alpergundogdu
alpergundogdu merged commit c2c8eeb into main May 8, 2026
10 checks passed
@alpergundogdu
alpergundogdu deleted the feat/adr-027-diversity-via-feerouter branch May 8, 2026 18:45
thiras added a commit that referenced this pull request May 10, 2026
Same root cause as the original fix: the §8 abuse-model table referenced
`reputation-≥-medium` (prose form of `medium_rep_threshold`) and asserted
reputation is "gauge-eligibility-gated" — both surfaces dropped by #488
when ADR 008 §12 was rewritten. The original test-plan grep matched the
literal parameter name and missed the hyphenated prose form.

Also drops "gauge-eligibility-gated" from the sybil-ring counter, which
directly contradicts ADR 008 §12 ("There is no on-chain gauge-eligibility
gate keyed on reputation"). The remaining "peer-aggregated" property
still carries the sybil-cost argument.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thiras added a commit that referenced this pull request May 10, 2026
… bullet

Two external reviews on PR #500 (Copilot + gemini-code-assist) flagged:

1. The "good reputation standing" phrase introduced in this PR is not
   defined in ADR 008. Switching to "reputable peer operator" matches
   evidence type (b)'s prior-art phrasing on the line above
   ("≥3 reputable peers per ADR 008") — terminology consistent within
   the doc and using language ADR 008 already supports. Applied at the
   §3 (c) row, §8 sybil-counter row, and §8 sybil-drain row.

2. The §Risks "Gauge-eligibility tier loss persists across appeal"
   bullet still asserted reputation drives a binary "tier transition"
   out of "gauge-pool eligibility" — three claims that contradict
   ADR 008 §12 post-#488 ("There is no on-chain gauge-eligibility gate
   keyed on reputation"). Reframed as a continuous selection-probability
   penalty (matches ADR 008 line 320 phrasing): the reputation hit
   lowers selection probability via ADR 001 node selection, which
   reduces real `bytes_delivered`, which reduces gauge share via the
   ADR 026 §3 formula. The legitimate underlying concern (preserved
   reputation hit costs more than the restituted slash for high-volume
   operators) is preserved; the false binary-gate framing is removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thiras added a commit that referenced this pull request May 10, 2026
…quences (#500)

* docs(adr): drop stale gauge-eligibility tier bullets in ADR 008 Consequences

PR #488 rewrote ADR 008 §12 from a hard gauge-eligibility gate
(High/Medium/Low tiers, receipt-tier thresholds, full exclusion at Low)
to a soft off-chain wash-trading signal, but two bullets in the
Consequences section still described the dropped surface — including
references to `high_rep_threshold` / `medium_rep_threshold` and a
non-existent §12.1. Delete both stale bullets.

Also rewords ADR 028 §3 evidence type (c) which cited
`medium_rep_threshold` "per ADR 008"; that parameter is no longer
defined anywhere in ADR 008. Replace with soft-standing language
consistent with evidence type (b) above (which already says
"≥3 reputable peers per ADR 008" with no numeric threshold).

Closes #492

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* docs(adr): clean up two more stale rep-tier references in ADR 028 §8

Same root cause as the original fix: the §8 abuse-model table referenced
`reputation-≥-medium` (prose form of `medium_rep_threshold`) and asserted
reputation is "gauge-eligibility-gated" — both surfaces dropped by #488
when ADR 008 §12 was rewritten. The original test-plan grep matched the
literal parameter name and missed the hyphenated prose form.

Also drops "gauge-eligibility-gated" from the sybil-ring counter, which
directly contradicts ADR 008 §12 ("There is no on-chain gauge-eligibility
gate keyed on reputation"). The remaining "peer-aggregated" property
still carries the sybil-cost argument.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* docs(adr): adopt 'reputable peer' terminology + rewrite line-188 risk bullet

Two external reviews on PR #500 (Copilot + gemini-code-assist) flagged:

1. The "good reputation standing" phrase introduced in this PR is not
   defined in ADR 008. Switching to "reputable peer operator" matches
   evidence type (b)'s prior-art phrasing on the line above
   ("≥3 reputable peers per ADR 008") — terminology consistent within
   the doc and using language ADR 008 already supports. Applied at the
   §3 (c) row, §8 sybil-counter row, and §8 sybil-drain row.

2. The §Risks "Gauge-eligibility tier loss persists across appeal"
   bullet still asserted reputation drives a binary "tier transition"
   out of "gauge-pool eligibility" — three claims that contradict
   ADR 008 §12 post-#488 ("There is no on-chain gauge-eligibility gate
   keyed on reputation"). Reframed as a continuous selection-probability
   penalty (matches ADR 008 line 320 phrasing): the reputation hit
   lowers selection probability via ADR 001 node selection, which
   reduces real `bytes_delivered`, which reduces gauge share via the
   ADR 026 §3 formula. The legitimate underlying concern (preserved
   reputation hit costs more than the restituted slash for high-volume
   operators) is preserved; the false binary-gate framing is removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[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.

Simplify ADR 027: drop DeliveryReceipt primitive, compute distinct-client diversity directly from settled vouchers

1 participant