Repository navigation
Description
Summary
Land just PayWord into ADR 003 (Payment Model) — the hash-chained per-MB meter. PR #1652 bundled PayWord with a second decision (best-effort / async voucher persistence) and edited ~17 ADRs. We want PayWord alone, in ADR 003 where the payment model lives (not a new ADR). #1652 is closed pointing here.
Model: amount-anchored, chain is an optional extension
PayWord is not a new object. There is one voucher with an amount (cumulative) field — the settlement anchor — and the hash chain is an optional, signature-free way to advance that amount between vouchers. Redemption is one formula:
claimed = voucher.amount + chain_index × chunk_price
chain_index = 0→ settles exactlyamount, no walk. This is a settlement / closing voucher, and it is identical in shape to the pre-PayWord voucher.chain_index > 0→ the node exhibits a preimage proving the extra chunks streamed past the last signed amount; the contract walks ≤MAX_CHAIN_LENGTH(256) hashes.keccak^k(preimage) == chain_root, amortized (one redeem settles everything prior viaamount).
The type system and the contract only need: an amount, and an optional chain that extends it.
Per-chunk (preimage) cost is one keccak — no signature, no ack, no round trip, nothing to persist. This solves the CPU-bound (per-chunk secp256k1) and FS-bound (fsync-before-ack, ~3.18 ms/voucher) problems the PR set out to fix.
Wire encoding: preimage ‖ index, one byte
Each preimage goes on the wire as preimage ‖ index — 33 bytes, the index a single byte. That fixes MAX_CHAIN_LENGTH = 256: a chain is at most 256 chunks. The one-byte tag lets the node drop each preimage straight into the lane's running total — it verifies keccak^(index − verified)(preimage) == tip against the deepest preimage it holds, ignores any index ≤ verified without hashing, and rejects an over-long skip before walking. Because placement is by index, several concurrent data streams can share one lane: the buyer hands out indexes from a single counter and the node merges their interleaved reveals. So no per-stream capability and no separate payment stream — one lane, one chain, one byte of ordering.
Within one chain epoch this merge is order-free: index is a single byte (mod 256), so a bare reveal does not name its own chain, but every reveal in an epoch verifies against the same fixed chain_root, and the deepest-preimage rule makes cross-stream arrival order irrelevant. The one place order matters is the chain roll — see the next section.
Concurrency: anchor each epoch per stream
Naively merging interleaved reveals is not safe across a chain roll, and this is the one concurrency hazard to call out. The chain_root an index verifies against is delivered by a signed voucher, and index is mod 256, so the only thing that tells the node "reveals now belong to R₁, not R₀" is that voucher. In a single sequential stream the voucher naturally precedes its chunks. Concurrent streams break that ordering — a fast stream can push a reveal for the new chain across before the voucher announcing R₁ lands on any stream:
Stream 1 -> voucher(R0) -> idx0 -> idx1 ...
Stream 2 -> idx0' ............... (belongs to R1; R1's voucher hasn't arrived — unverifiable, rejected)
Because QUIC gives per-stream ordering, the fix is to make each stream self-anchoring: on a stream, send the current chain_root voucher once before the first preimage of that epoch — at stream open, and again each time the chain rolls (~every 256 MB). Not before every preimage — that would delete PayWord's whole point (signature-free advance between vouchers). The re-sent voucher is cumulative and signed, so the node keeps the max: resends are idempotent and dedup is free.
This keeps one shared chain and one global counter — the re-sent voucher is just the epoch delimiter on each stream, strictly cheaper than per-stream chains (which would multiply rolls → more signatures). The skip optimization falls out for free: a fast stream may jump indexes (deepest-preimage-wins) and skip re-sending a voucher the node already holds (cumulative-max). A late-joining stream is the same rule — prefix the current root-voucher before its first preimage. The buyer is one process, so it serializes the counter and roll decision under a local lock while bytes stream concurrently; no node-side rendezvous is needed.
The net invariant: on each stream, the epoch's chain_root voucher precedes that stream's preimages for the epoch.
A 256-chunk chain covers ~256 MB at chunk_bytes ≈ 1 MB, so a multi-GB transfer rolls the chain (a fresh signed voucher with a new chain_root) every ~256 MB — roughly 4× more voucher signatures than a 1024-chain. We accept that CPU cost for the cheaper on-chain walk (≤256 keccaks) and the one-byte wire tag.
Sealed / closing voucher via a zero-hash root
A settlement voucher sets chain_root = 0 (zero-hash) and is redeemed at chain_index = 0 with a zero preimage. keccak preimage-resistance means no one can produce a preimage that hashes to 0 at any index > 0, so the voucher is cryptographically sealed at its amount — nothing can redeem more against it. No optional field, no special contract branch: the fixed schema stays, and index-0 / zero-root simply satisfies the normal keccak^k(p) == chain_root check with zeros (and fails at every higher index). A legit chain's chain_root = keccak^N(seed) is never 0, so 0 is a safe sentinel.
Two payment resolutions
| Path | Resolution | Cost |
|---|---|---|
| Preimage (bulk) | quantized to chunk_bytes |
one hash, signature-free between vouchers |
Voucher amount (exact / remainder / sub-chunk) |
exact to 1 USDC unit | one signature |
A partial trailing chunk, or a whole transfer smaller than chunk_bytes, settles via a fresh amount-voucher (zero-hash, index 0) — not a preimage. Example: 1.5 MB = one preimage (1 MB) + a closing amount-voucher for the exact 1.5 MB (15 USDC units at target), no walk.
- Small transfer (≤ credit window): no chain needed — deliver, then one amount-voucher. 1 signature.
- Large transfer, cooperative: one voucher per chain (
chain_rootpresent) as it rolls every ~256 MB, then a closing amount-voucher (zero-hash, exact). No walk. - Large transfer, client vanishes mid-stream: the last open voucher + the node walks the highest preimage it holds (≤256). The chain is the unilateral fallback; the amount-voucher is the cooperative close.
One signature per ~256 MB chain, never per chunk. The node redeems the best proof it holds; the contract's claimed − paid accounting makes any choice idempotent.
Gas / redeem cost
Redemption is unchanged by PayWord: a periodic sweep that redeems the latest valid voucher per lane, one on-chain call amortized across everything delivered since the last sweep. It was never per-MB. The question is only what that one redeem costs relative to the pre-PayWord voucher.
The walk is fallback-only, not a per-redeem tax. The redeem input is claimed = amount + chain_index × chunk_price. At chain_index = 0 there is no walk and no meaningful preimage — the call is identical in shape to the pre-PayWord voucher. The node pays the ≤256-keccak walk only when it redeems value that no later signed voucher has yet superseded, and in the cooperative path there always is a later signed voucher:
- Rolls (~every 256 MB) each emit a fresh signed voucher whose
amountalready folds in the whole prior chain, so they redeem walk-free. - Close emits the zero-root voucher, walk-free by construction.
So a sweep always redeems the latest signed voucher it holds (roll or close) and never touches a preimage. The un-rolled tail since the last roll is deferred to the next roll/close — cumulative claimed − paid loses nothing, and the deferred exposure is ≤ one chain (256 MB), the credit-window bound already accepted. A preimage walk happens only when the client vanishes mid-chain and the node claims that sub-roll tail: at most once per abandoned stream, capped at ≤256 MB — the case where the alternative is collecting nothing. Amortized across all deliveries, the walk gas is noise.
The zero-root closing voucher is not a special end-of-stream object; it is the same rule as every roll voucher — redeem the latest signed voucher, walk a preimage only on abandonment. Finalized deliveries never touch a preimage.
What is genuinely additive is calldata, not compute. PayWord adds chain_root (32 bytes) and chunk_price to the signed voucher versus the pre-PayWord {pool_id, signer, provider, cumulative, bytes_delivered}, and those ride on every redeem, walk or not. On the compressing L2 calldata that dominates cost here:
- A closing voucher carries
chain_root = 0(32 zero bytes → nearly free compressed) and a smallchunk_price(mostly zero bytes). A cooperative, finalized redeem therefore costs ≈ baseline. - A nonzero
chain_root(32 real bytes) only appears if the node redeems a mid-transfer roll voucher — which it usually need not, since it can redeem once at/after close.
Net: PayWord does not strictly increase redeem gas. Cooperative deliveries pay ≈ baseline (one signed voucher, mostly-zero extra bytes); the ≤256-keccak walk and the nonzero-root calldata are confined to the mid-chain-abandonment path. The schema slimming below offsets part of the flat calldata add by fixing chain_length and chunk_bytes as constants out of the signed voucher.
chunk_bytes — the payment quantum (was garbled in the earlier draft)
chunk_bytes is simultaneously the price quantum, the meter granularity, and the withholding bound. USDC 6-decimal precision floors it: a chunk must price to ≥ 1 unit ($0.000001).
chunk_bytes |
@ target $0.01/GB | @ floor $0.001/GB |
|---|---|---|
| 100 KB | 1 unit (100% granular) | 0 → unpayable |
| 1 MB | 10 units (~10% granular) | 1 unit (payable) |
| 10 MB | 100 units | 10 units |
Fix chunk_bytes ≈ 1 MB — ~10× the single-unit floor, so a chunk prices to ~10 units (~10% granularity) at target and stays payable (≥1 unit) down to the floor price. (The earlier "0.1×" was inverted — 0.1× the floor is unpayable.) Finer chunks lose payability at low prices; coarser ones only matter if the network runs near the floor — [operator/governance call].
Consequence: the meter is ~1 MB-grained — finer than the old 4 MiB voucher interval, but not the 64 KiB the draft reached for — each tick costing one hash. The payability floor is exactly what caps how fine the meter can go.
Voucher schema slimming
Fix invariant policy fields as protocol/governance constants, out of the signed voucher (~20% less redeem calldata on calldata-dominated chains):
chain_length→ alwaysMAX_CHAIN_LENGTH(256).chunk_bytes→ fixed constant (~1 MB, above).
Kept in the signed voucher:
amount(cumulative) +bytes_delivered— the claim.chain_root— dynamic per chain;0for a sealed/closing voucher.chunk_price— kept signed; dropping it couples redemption to a governance rate that can move between sign and redeem (repudiation surface).
chainIndex (a one-byte redeem parameter and wire tag, not a voucher field) is kept — it's what lets the node place each preimage and share a lane across concurrent streams.
So the signed voucher is: identity (pool_id, signer, provider) + amount + bytes_delivered + chain_root + chunk_price.
Split-out work (filed)
- Decision 1 — best-effort async voucher persistence, chain-as-floor watermark seed → design: best-effort async voucher-watermark persistence (chain-floored) — drop fsync-before-ack #1672.
Siblings
- credit-slow-start: feat: credit-slow-start — fixed-ramp credit window (start slow, ramp quick) #1669
- pre-pay defense (parked, discussion): design: pre-pay per-lane abuse defense — full reasoning + why parked (gas) #1671
Activity
alpergundogdu commentedon Aug 14, 2026
Constraint: PayWord is incompatible with lane-wide "voucher on any active stream" routing
Surfacing a cross-issue constraint before the PayWord wire is finalized (came out of the #1676 / #1689 concurrency discussion).
PayWord encodes the payment amount positionally — a preimage
w_{n-i}is worthiticks purely by its depth in the chain, and carries no amount field. On a single stream, position is conveyed implicitly by arrival order (the k-th preimage is tick k). The moment payment ticks can arrive out of order — e.g. spread across multiple concurrent data streams on one lane — that positional signal is lost, and a bare preimage tells the seller nothing about where it sits. It rejects.This is the opposite of the current EIP-712 cumulative voucher, which carries
amountexplicitly. That explicit field is exactly what makes ADR 005's "vouchers are sent on any active stream in the lane — credited lane-wide" routing safe under reordering (higheramountsupersedes, lower is stale, order-independent). PayWord cannot inherit that rule — it has no self-describing field.The trilemma — pick two of three
(signer, provider)accounting → one redemption)indexsteps to place an out-of-order preimage. Or run one chain per data stream (drops 3 — per-stream settlement, no lane aggregation).Ugliest variant
If intervals map to separate sub-chains (e.g. "256 preimages per voucher-interval, next interval is a new segment"), an out-of-order preimage isn't even hash-forward-recoverable — different anchor — so it's a hard reject, not just an efficiency loss.
Ask for the PayWord design
Decide and document one of:
(signer, provider)lane — and ADR 005's "any active stream" routing becomes EIP-712-only, explicitly not applicable under PayWord; orEither way, ADR 005 rule "voucher on any active stream" needs a caveat once PayWord lands, and #1689's concurrency tests should be written against whichever model wins.
docs(adr): apply review dispositions to the PayWord ADR (#1670)
docs(adr): pack chunkPrice and chainIndex into one word, 8-word vouch…
docs(adr): frame the chain index space as 0..=255, not a 255-vs-256 t…
docs(adr): index 0 is payable — 255 is the incremental range, not a c…
docs(adr): land PayWord (hash-chained per-MB meter) into ADR 003 (#1751)