Skip to content

docs(adr): land PayWord (hash-chained per-MB meter) into ADR 003 - #1692

Closed
yigitdot wants to merge 1 commit into
mainfrom
docs/1670-payword-adr-003
Closed

yigitdot wants to merge 1 commit into
mainfrom
docs/1670-payword-adr-003

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Closes #1670.

What this is

PayWord alone, in ADR 003 where the payment model lives — not a new ADR. PR #1652 bundled it with async voucher persistence and edited ~17 ADRs; this touches 10, all docs.

The model: amount-anchored, chain is an optional extension

PayWord is not a new object. One voucher, whose cumulative amount is the settlement anchor. The chain is an optional, signature-free way to advance that anchor between signatures. Redemption is one formula:

claimed = voucher.amount + chain_index × chunk_price
  • chain_index = 0 → settles exactly amount, no walk. Identical in shape to today's voucher.
  • chain_index > 0 → the node exhibits a preimage proving chunks streamed past the last signature; the contract walks ≤ MAX_CHAIN_LENGTH hashes.

Signatures are O(1) per transfer (one, or two on a cooperative close, plus one per rollover), never one per chunk. The contract gains no storage slot — Lane {amount, bytesDelivered} is unchanged, because claimed − paid is idempotent over whatever proof the node presents.

Two resolutions, kept separate

Path Resolves Exact to Cost
Preimage (bulk) whole chunks past the anchor chunk_bytes (1 MiB) one hash
Voucher amount any residual, incl. a partial trailing chunk 1 USDC base unit one signature

A sub-chunk remainder closes with a zero-root amount-voucher, not a preimage. 1.5 MB = one preimage + a closing voucher for exactly 15 base units. The chain is the unilateral fallback; the amount-voucher is the cooperative close.

Sealed voucher, no contract branch

chain_root = 0 redeemed at index 0 with a zero preimage satisfies the ordinary keccak^k(preimage) == chain_root check with zeros. At any higher index it would need a preimage hashing to 0 — infeasible. So the voucher is cryptographically sealed at its amount, with a fixed schema, no optional field, and nothing in the contract testing chainRoot == 0.

Two decisions worth reviewing

chunk_bytes = 1 MiB, fixed. USDC's 6 decimals are the binding constraint — a chunk must price to ≥1 base unit, so the earlier draft's 64 KiB is unpayable at the floor rate. 1 MiB prices to ~10 units at the $0.01/GB target and stays payable down to the governance floor. Because CHUNK_BYTES == BYTES_PER_MB, chunk_price is the advertised rate_per_mb and the payability floor is the existing deliveryFloor — no second price constant, no new governance knob.

MAX_CHAIN_LENGTH = 255, not the 1024 in the issue body. This is a deliberate deviation, not a transcription error. The wire sets the bound, not gas: a preimage travels as preimage ‖ index, 33 bytes flat. 1024 doesn't fit a byte, and 256 would fit only via an index − 1 offset. 255 designs the off-by-one out entirely — index 0 is the redeem-side settlement case and never travels, so releasable indices are 1..=255 and the byte is the index. The trade: ~4× more signatures (255 MiB per chain) for a fixed-width message and a walk capped at 255 hashes (~16k gas at full depth, zero on the cooperative path).

Schema slimming

Out of the signed voucher as protocol constants (~20% less redeem calldata): chain_length → always MAX_CHAIN_LENGTH; chunk_bytes → fixed. Kept signed: chain_root (an unsigned root lets a payer disown a chain it authorized) and chunk_price (an unsigned price settles at whatever governance rate holds at redeem time — a repudiation surface).

Signed voucher: {pool_id, signer, provider, amount, bytes_delivered, chain_root, chunk_price}.

One chain per lane — a payer-side MUST

A preimage is a bearer proof with no payee of its own. A shared chain_root across two providers would let every preimage released to A extend B's voucher, so B claims chunks it never delivered and the signer pays twice per tick. No node can detect it (each sees only its own lane) and the contract never sees two vouchers together. Carried forward from a review finding on #1652 — no split-out issue covers it — with a new Cross-lane preimage spend attack vector.

Out of scope, by design

Cross-ADR consistency

005 gains the unsigned 33-byte ChunkPreimage message and BadPreimage/ChainExhausted reject reasons, and loses voucher_interval_mb negotiation entirely; 016 updates the redeem signature and class diagram; 013 renumbers the ClientMessage tail (pre-launch, no shim per CLAUDE.md); 012/014/038/039, glossary, and architecture track the new vocabulary. Glossary gains Chain root / preimage and Payment chunk — the latter because "chunk" already means the 1024-byte BLAKE3 leaf in this repo.

ADR 003 now leads the code

Deliberate. PaymentPool.sol and crates/{incentive,protocol,client-pull} still implement the pre-PayWord model; no hash-chain code exists yet. Implementation follow-ups are filed separately.

Verification

  • make -C adr check-refs — 1703 anchors resolve, no bare refs, no numeric §N
  • make -C adr check-book-list — in sync (24 ADRs + 11 appendices)
  • markdownlint — clean on all 10 files
  • Mermaid: all diagrams in 005 and 016 render individually via mmdc. The full make -C adr book fails on 028-slashing-appeals.md, which this branch does not touch — pre-existing on main.
  • Grep sweep: voucher_interval_mb, cumulative − paid, and every offset-encoding pattern (index − 1, index_tag, tag + 1) all return zero hits.

🤖 Generated with Claude Code

Payers currently sign one EIP-712 voucher per delivery interval: ~2,500
signatures for a 10 GB transfer at the 4 MiB cadence, 10,000 at the 1 MB
wire default. That is CPU-bound on secp256k1 and FS-bound on the
fsync-before-continue rule, and it forces a coarse interval — which is
exactly the amount a payer can withhold.

PayWord is not a new object. There is one voucher whose cumulative
`amount` is the settlement anchor, and the hash chain is an optional,
signature-free way to advance that anchor between signatures.
Redemption is one formula:

    claimed = voucher.amount + chain_index * chunk_price

`chain_index = 0` settles exactly `amount` and walks nothing — the same
shape as today's voucher. Above 0 the node exhibits a preimage proving
the chunks it streamed past the last signature, and the contract walks
at most MAX_CHAIN_LENGTH hashes. Signatures become O(1) per transfer
(one, or two on a cooperative close, plus one per rollover), never one
per chunk. The contract gains no storage slot and no second settlement
object.

Two resolutions, deliberately kept separate: a preimage settles whole
chunks for one hash, and a voucher `amount` settles any residual exact
to one USDC base unit. A partial trailing chunk or a sub-chunk transfer
closes with a zero-root amount-voucher, not a preimage. The chain is the
unilateral fallback; the amount-voucher is the cooperative close.

A sealed voucher sets `chain_root = 0` and redeems at index 0 with a
zero preimage. Those zeros satisfy the ordinary check, and keccak
preimage resistance makes any higher index infeasible — so the voucher
is cryptographically sealed at its `amount` with no optional field and
no contract branch.

chunk_bytes is fixed at 1 MiB. USDC's 6 decimals are the binding
constraint: a chunk must price to at least one base unit, so the earlier
draft's 64 KiB is unpayable. 1 MiB prices to ~10 base units at the
$0.01/GB target and stays payable down to the governance floor. Because
CHUNK_BYTES == BYTES_PER_MB, chunk_price is the advertised rate_per_mb
and the payability floor is the existing deliveryFloor — no second
price constant.

MAX_CHAIN_LENGTH is 255, not the 1024 the issue names. The wire sets
this bound, not gas: a preimage travels as `preimage || index`, 33 bytes
flat, and 255 is the largest chain whose releasable indices fit one byte
directly. Index 0 is the redeem-side settlement case and never travels,
so releasable indices are 1..=255 and the byte IS the index — no offset
tag, no +1 on receipt, nowhere for an off-by-one to live. The trade is
~4x more signatures (255 MiB per chain) for a fixed-width message and a
walk capped at 255 hashes.

Schema slimming: chain_length and chunk_bytes are protocol constants
outside the signed voucher (~20% less redeem calldata). chain_root and
chunk_price stay signed — an unsigned root lets a payer disown a chain
it authorized, and an unsigned price settles at whatever governance rate
holds at redeem time.

One chain per lane is a payer-side MUST. A preimage is a bearer proof
with no payee of its own, so a shared chain_root would let preimages
released to one node be spent against another's voucher. No node can
detect it and the contract never sees two vouchers together, hence the
new Cross-lane preimage spend attack vector.

Cross-ADR consistency: 005 gains the unsigned 33-byte ChunkPreimage
message and BadPreimage/ChainExhausted reject reasons, and loses
voucher_interval_mb negotiation; 016 updates the redeem signature; 013
renumbers the ClientMessage tail (pre-launch, no shim); glossary and
architecture track the new vocabulary.

Deliberately out of scope, owned by their own issues: async voucher
persistence (#1672) and the credit-window rewrite (#1669). ADR 003 now
leads the code — PaymentPool.sol and crates/{incentive,protocol,
client-pull} still implement the pre-PayWord model, tracked separately.

Closes #1670

Co-Authored-By: Claude Opus 5 (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.

docs(adr): land just PayWord (hash-chained per-MB meter) into ADR 003

1 participant