Repository navigation
docs(adr): land PayWord (hash-chained per-MB meter) into ADR 003 - #1751
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Replace the 4 MiB signed-voucher interval with a 1 MiB payment chunk metered
by a PayWord hash chain. One voucher keeps its cumulative `amount` as the
settlement anchor; `chain_root` heads an optional chain that advances that
anchor with no signature, and redemption resolves both with one formula:
claimed = amount + chain_index * chunk_price
A tick costs one keccak instead of one secp256k1 signature, so signatures are
O(1) per transfer (stream open, each 255 MiB rollover, close) rather than one
per interval. A zero `chain_root` seals a closing voucher at exactly `amount`
with no contract branch.
Resolves the concurrency constraint raised on #1670 as option (b): preimages
travel as `preimage || index` (33 bytes, MAX_CHAIN_LENGTH = 255 so the byte is
the index), are placed deepest-first rather than by arrival order, and each
stream re-sends the epoch's `chain_root` voucher before its first preimage of
that epoch. One chain per lane stays shared across concurrent streams.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review of this PR — 30 findingsThree independent reviews (project-convention, documentation-accuracy, adversarial design), de-duplicated. Five findings are design-breaking. Everything below is in text this PR adds.
Blocking — the design does not work as written (5)B1. The zero-root sentinel collides with the root-reuse MUST. B2. The voucher resends the anchoring rule mandates are always rejected. B3. Rollover terminates sibling streams on a multi-stream lane. B4. B5. The rollover fold is undefined for early rolls, and the sweep advice is unsafe. Important (11)
Minor / accuracy (9)
Rigor / style (5)
What actually needs redesigningB1, B2 and B3 are one defect wearing three hats: per-stream epoch anchoring does not work. Making anchoring lane-scoped dissolves all three:
B4 needs a normative rule (node MUST reject a voucher whose Also worth deciding: the 4 MiB → 1 MiB quantum retarget is not required by PayWord — the chain works at any quantum — and it is what produces most of this PR's blast radius, including I3. 🤖 Generated with Claude Code |
Response — resolutions for all 30 findingsThanks for the review. The problems are almost all real; several of the proposed solutions are heavier than they need to be, and two rest on a misread. This comment supersedes the review and records the disposition of every finding. This PR is ADR-only — findings that cite code ( HeadlineB1, B2, and B3 are not "one defect — per-stream anchoring doesn't work." Anchoring stays per-stream; each of the three has an independent, minimal fix. Going lane-scoped is not required and we are not taking it. Blocking
Important
Minor / accuracy
Rigor / styleAll five accepted.
On the retargetWe keep the 4 MiB → 1 MiB quantum retarget. It is not required by PayWord, but the quantum is node policy, so it carries no protocol-level blast radius — only the doc sync in I3, which lands here. Follow-ups (separate from this ADR PR)
|
Applies the maintainer's rulings on all 30 review findings. Design changes: - Delete ChainRootReuse as a node-side reason. Root reuse pays the node and costs the payer, so a node-side rejection protects nobody who would run it, and enforcing it needs unbounded node-global state. Reuse-avoidance is a payer-side invariant. This also removes the zero-root sentinel collision at its source, since nothing retires a root any more. - Per-stream self-anchoring: each stream carries its own (anchor voucher, chain_root, verified, tip), and the payer sends the new-root voucher on every active stream at rollover. QUIC in-stream ordering then keeps a sibling stream'\''s old-chain preimages valid, so a rollover cannot strand it. The lane claim is a maximum over per-stream extensions, never a sum. - The node MUST reject a voucher whose chunk_price is not its quoted rate_per_mb (new ChunkPriceMismatch reason); a sealed voucher carries chunk_price = 0. - The rollover fold is amount_old + verified_index * chunk_price on both axes, covering early rolls, and a sweep redeems the strongest claim held rather than the latest signed voucher. Corrections: an at-or-below-watermark voucher is already-satisfied, not a rejection (handler behaviour since #1699); the persisted lane record keeps the tip preimage so the frontier survives a restart; owed and M include the chain frontier; the credit window is lane-collective; claimed/claimedBytes are bounded by check rather than by construction; ADR 037 and ADR 011 reconciled to the chunk meter; ClientMessage lists all six variants; voucher width stated in words. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
All 30 dispositions applied in Design changesB1 — B3 — per-stream self-anchoring. Each stream now holds its own Two things I had to pin down for the rule to be complete, flagging them since they are mine rather than yours:
B4 — B5 — fold and sweep. Fold is B2 — you were right and I was wrong. I read the primitive at Everything elseI1–I6, I8–I11 and M1–M9 applied as ruled. S1–S5 done, including the STE rewrites ("footgun", "the walk is noise", "255 buys", "three things at once", "gives away", the off-by-one idiom) and the 52-word sentence split.
Two things for you1. M1 — the 8-word target does not reconcile. 2. M6 and I3 were described as already applied, and were not. The response says ADR 011 is "applied in this PR" and ADR 037 "is reconciled in this PR", but neither file was in the diff and no commits had landed on the branch. Both are in now — ADR 011:460 terminates at the next chunk boundary after the preimage is revealed, and ADR 037's five statements are reconciled including the normative Deferred code work — noted, not filedPer your split, these stay out of this ADR PR. Recording them here rather than opening issues; they belong against the existing PayWord implementation issue #1752:
🤖 Generated with Claude Code |
…er (#1670) Closes the M1 gap raised in review: LaneVoucher was heading for 9 words / 288 B, against a target of 8 / 256 B. chunkPrice needs 64 bits and chainIndex needs 8, so both ride one packed `chainMeter` word: reserved 23 bytes (MUST be zero) | chunkPrice (u64) | chainIndex (u8), big-endian. Redemption splits it with a shift and a mask, and rejects a non-zero reserved span rather than masking it, so the word stays extendable. The struct stays static — uint256 is fixed-width — so an array of LaneVoucher still carries no offsets, length words or padding. Adds a per-word struct table and a byte-layout diagram, and states that the EIP-712 typehash keeps `uint256 chunkPrice`: the contract decodes the packed word and widens it back before rebuilding the struct hash, so no signer sees the packing and no digest changes. chainIndex is a redemption parameter, not a signed field, so packing it alongside is signature-neutral. Consequence worth noting: extracting chainIndex as a uint8 caps it at 255 on-chain the same way the wire byte does, so the chainIndex <= MAX_CHAIN_LENGTH require is now unreachable at both layers and is replaced by the reserved-span check. Flags the 255-vs-256 boundary explicitly in both ADRs — u8 reaches 255, index 0 is settlement, so releasable indices are 1..=255 and 256 would need an index-1 offset encoding. Docs only. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
M1 closed in
The struct stays static — No signature changes. The reserved 23 bytes MUST be zero and redemption MUST reject a non-zero span rather than masking it — one comparison, and it keeps the word extendable without any voucher signed today becoming reinterpretable. One consequence worth flaggingExtracting That also makes the index one representation from wire to calldata: the 255 vs 256, stated explicitlyFlagged in both ADRs as you asked. A Docs only; 🤖 Generated with Claude Code |
|
On the packing — agreed, it's sound: On 255 vs 256 — we don't actually disagree on the mechanism, only on how the passage frames it, and the framing overstates a tradeoff that isn't there. The mechanism, to be explicit:
So "256" counts index slots and "255" counts payable chunks. Both are right; they count different things. The The part worth cutting is the closing tradeoff at 003:154 — "a 256-chunk chain would need an Everything else in both comments looks right to me — including the two corollaries you flagged as yours (lane claim as a max not a sum, in-memory-only anchors); both are correct and necessary under the per-stream fix. |
|
One correction to my own wording above: I wrote "meters up to 255 chunks," which quietly implies index 0 pays nothing. It doesn't. Index 0 is payable. It resolves to So the precise framing is:
"255 payable chunks" conflates the two. It's 255 incremental chain steps over an already-payable base voucher. Worth saying it that way in the passage so index 0 doesn't read as a dead slot. |
…radeoff (#1670) 256 and 255 count different things and both are right: the u8 index space is 0..=255 — 256 slots, exactly one byte — and index 0 is chain_root itself, which meters no chunk and never travels the wire. That leaves 1..=255 as the releasable preimages, so a chain meters 255 payable chunks. The previous wording presented 255 as a concession, claiming a 256-chunk chain would need an index-1 offset encoding not worth the hazard. There was never a 256-payable-chunk design to give up: the root occupies index 0 by construction. Framing it as a tradeoff implied a cost that does not exist. No mechanism changes. MAX_CHAIN_LENGTH stays 255 (the highest index), the wire index stays a direct u8, the packed chainMeter word keeps its 23 reserved bytes and uint8 low byte, and LaneVoucher stays 8 words / 256 B. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…hunk count (#1670) Follow-up to 01abd9e, which still implied index 0 was a dead slot. Index 0 names chain_root and resolves to the voucher's own cumulative amount, so the base voucher is payable with no chain at all — and that base may already fold in a whole retired chain through the rollover fold. What index 0 does not do is add an increment, which is why it never travels the wire: a reveal there would prove nothing the voucher does not already carry. So the 256 slots are one payable base plus 255 incremental steps over it, not 256 minus a wasted one. "255 payable chunks" conflated the two. No mechanism changes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Both corrections applied — On the framing. Agreed there was never a tradeoff to describe. The passage now states the mechanism plainly: the On index 0 being payable. This is the one I would have shipped wrong. My first pass replaced "255 vs 256" with "256 index slots yield 255 payable chunks — the root occupies one slot" — which is exactly the dead-slot reading you flagged. Corrected to:
§ Chain length and rollover now opens on the same distinction — index 0 resolves to the voucher's own Nothing mechanical moved in either commit: Noted that the packing is agreed and that the two corollaries stand — lane claim as a max rather than a sum, and per-stream anchors being in-memory only with the durable record keeping the strongest claim's chain state.
🤖 Generated with Claude Code |
…ad of reverting (#1753) * feat(payments): soft delivery-rate floor — clamp credited bytes instead of reverting The deliveryFloor's purpose is to stop cheap bytes from inflating the served-bytes metric (the ADR 036 governance vote weight), not to police payment. Replace the hard `RateFloorViolation` revert in `PaymentPool` redemption with a clamp: a sub-floor voucher settles its full `cumulative` USDC and credits only `min(bytesDelivered, cumulative * BYTES_PER_MB / deliveryFloor)` bytes toward the served-bytes counter that feeds `DecdnGovernor` vote weight. This removes the batch-poisoning failure mode where one sub-floor voucher reverted a whole `redeemMany` (every pool and lane). The realistic trigger is a governance floor-raise landing on a voucher a node already served and accepted in good faith. Credit stays bounded by real, floor-priced routed USDC, so cheap bytes still cannot buy vote weight; `cumulative` needs no extra bound because credit is paid-proportional. Contract: - PaymentPool: clamp in `_applyVoucher`; delete `RateFloorViolation`; the redeemMany skip-vs-revert taxonomy now reverts only on a structural error (bad signature / closed pool). Tests rewritten to soft-floor semantics (+ batch-no-poison, after-floor-raise, fuzz). Gas snapshot regenerated. Off-chain (the seller no longer hard-rejects either): - Remove the acceptance-time floor check in the client voucher handler; the advertised-rate check still protects per-delta revenue. `rate_bounds` now only clamps the node's own quote up to the floor before signing. - Remove the now-unproducible `RateFloorRaised` wire reason end to end: the enum variant, its buyer-side cache-miss retry classifier (collapses to `PoolExhausted`), the metric, the public-API snapshot, and its ADR 005 definition. ADRs: 003 (§Rate-floor enforcement rewrite + call sites), 036 (threat-model dependency), 005 (VoucherRejectReason). ADR 016 unchanged — the contract surface (routeSettlement pipe, constructor args) is unchanged and it never enumerated the error. Contract-side follow-up to the ADR-only PR #1751. Co-Authored-By: Claude Opus 4.8 <[email protected]> * test(node): drop dead handler setup from two verify_voucher unit tests `verify_voucher` is now an associated fn, so `stale_voucher_is_benign_*` and `divergent_voucher_at_equal_amount_*` no longer need the `handler_over_store` fixture (they sign with a local EIP-712 domain and `verify_voucher` skips the signature). Remove the unused handler/store/metrics setup and downgrade both to sync `#[test]` — no `.await` remains. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
…h-chain-meter # Conflicts: # adr/003-payments.md # adr/005-protocol.md
Closes #1670. Implementation follow-up: #1752.
Lands PayWord alone into ADR 003, where the payment model lives. No new ADR. The two split-out siblings — credit slow-start (#1669 → #1691) and async voucher persistence (#1672 → #1706) — are already merged and are not touched here.
The model
One voucher, whose cumulative
amountis the settlement anchor. The hash chain is an optional, signature-free way to advance that anchor between signatures. Redemption is one formula:chain_index = 0settles exactlyamountand walks nothing — identical in shape to the pre-PayWord voucher.chain_index > 0exhibits a preimage for the chunks streamed past the last signature, and the contract walks ≤MAX_CHAIN_LENGTHhashes. A closing voucher setschain_root = 0, which seals it atamountwith no contract branch and no optional field.A tick costs one keccak, not one secp256k1 signature — which is the CPU cost the original PR set out to remove.
Settled parameters
chunk_byteschunk_pricerate_per_mbCHUNK_BYTES == BYTES_PER_MB, so no second price unit and no new governance knob — the payability floor is the existingdeliveryFloor. Stays signed, so redemption never depends on a rate that moved after signingMAX_CHAIN_LENGTH1..=255encode directly in the one wire byte with no offset, so no off-by-one can exist. Index 0 is the redeem-time settlement case and never travels the wire{pool_id, signer, provider, amount, bytes_delivered, chain_root, chunk_price}chain_lengthandchunk_bytesstay out as protocol constants (the calldata saving the issue asked for)Deviation from the issue body, flagged for review: the issue says
MAX_CHAIN_LENGTH = 256. This PR writes 255. 256 needs indices1..=256, which does not fit one byte without encodingindex − 1— reintroducing exactly the off-by-one a fixed-width tag is meant to design out. Happy to switch if you prefer the literal 256.Answers the concurrency constraint (@alpergundogdu's comment on #1670)
The comment asked for an explicit decision between (a) a single ordered payment stream per lane and (b) index-carrying ticks. This lands (b), plus a second rule the trilemma implies but the earlier draft never wrote down:
index ≤ verifiedis ignored without hashing;index > MAX_CHAIN_LENGTHis rejected before any hashing; otherwisekeccak^(index − verified)(preimage)must reach the deepest preimage held. Placement is by index, never arrival order, so cross-stream interleaving is free within an epoch.indexis one byte, so the invariant is: on each stream, the epoch'schain_rootvoucher precedes that stream's preimages for that epoch — sent at stream open and again on each rollover, never before every preimage. Resends are cumulative and signed, so dedup is free.ADR 005's "voucher on any active stream" rule survives for vouchers (self-describing cumulative
amount) and is explicitly scoped away from preimages. One chain per lane is kept; per-stream chains would multiply rollovers and therefore signatures.Gas, honestly
The walk is fallback-only. A sweep redeems the latest signed voucher (rollover or close), both of which redeem at index 0 and walk nothing. A preimage walk happens only when the payer vanishes mid-chain — at most once per abandoned stream, ≤ 255 keccaks (~16k gas), where the alternative is collecting nothing. What is genuinely additive is calldata:
LaneVoucherwidens from 160 to 288 static bytes, but a closing voucher's added bytes are zeros and compress to almost nothing on an L2, so a cooperative redemption stays near baseline.Files
adr/003-payments.md— newChunk CadenceandHash-chain metering (PayWord)sections (payment resolutions, sealed voucher, payability floor, one-chain-per-lane, chain length and rollover);Concurrent Streamsgains the two rules;Redemption and Closegains claim resolution while preserving currentredeemMany(PoolBatch[])grouping and skip-not-revert semantics; newChain walk and redemption costandCross-lane preimage spendsections; EIP-712 typehash, rejection table, persistence tuple, and consequences updated.adr/005-protocol.md—ChunkPreimage { preimage, index },CHUNK_BYTES/MAX_CHAIN_LENGTH,VOUCHER_INTERVAL_BYTESretired, lanes section rewritten, four newVoucherRejectReasonvariants with retry semantics.adr/016,adr/architecture.md,adr/glossary.md,adr/013,adr/038,adr/039— redeem description, payment one-liners, new glossary rows,ClientMessagerenumbering, framing size, renamed anchor.adr/012,adr/024,adr/appendix-operator-key-rotation.mdall argued for session keys from "25 signatures per 100 MB" — PayWord makes that two, so the arithmetic is corrected while the conclusion is left intact (the residual stream-open/rollover/close signatures and per-responseslash_sigstill rule out hardware-wallet-only operation).adr/017P-0x volume inference now counts 1 MiB chunks. Worth a look if you'd rather ADR 024 re-argue its premise properly in a separate PR.Docs only — no Rust, no Solidity. Implementation is #1752, filed as one issue rather than the three (#1693 / #1694 / #1695) that were split and closed.
🤖 Generated with Claude Code