Repository navigation
Closed
Labels
area:contractsSolidity contracts and Foundrykind:featureNew capability or a change to current behaviorprio:highNext uprustDependabot: a Cargo update; use area: labels for Rust code otherwise
Description
Implements the design landed in ADR 003 by #1751 (closes #1670).
One issue, not three. The earlier attempt split this across #1693 / #1694 / #1695 and all three were closed. The layers cannot land independently anyway: a voucher that gains chain_root breaks the sol! mirror, the InterfaceFreeze typehash pin, and the wire encoding in the same change. #1693–#1695 are superseded by this issue.
Pre-launch, so this is one straight wire/ABI cut — no compatibility shims, no dual-format readers, no version negotiation. Every side changes in the same PR.
Design (canon)
- ADR 003 § Chunk Cadence
- ADR 003 § Hash-chain metering (PayWord)
- ADR 003 § Concurrent Streams — the two placement rules
- ADR 003 § Chain walk and redemption cost
- ADR 005 § Payment quantum and credit window
Key constants: CHUNK_BYTES = 1_048_576 (== BYTES_PER_MB), MAX_CHAIN_LENGTH: u8 = 255, chunk_price ≡ rate_per_mb.
crates/protocol
-
ChunkPreimage { preimage: [u8; 32], index: u8 }— fixed 33-byte encoding, no length prefix, no varint.index == 0on the wire is a protocol error. - Insert it into
ClientMessageat discriminant 4 (besideVoucher), renumberingStreamEndto 5. -
Voucherwire struct gainschain_rootandchunk_price. -
CHUNK_BYTES/MAX_CHAIN_LENGTHconstants; retireVOUCHER_INTERVAL_BYTES. - Four new
VoucherRejectReasonvariants:BadPreimage,ChainIndexTooLarge,UnanchoredPreimage,ChainRootReuse— handler-emitted, so exempt from thePoolErrormirror obligation.
crates/incentive
-
chain_root/chunk_pricein the EIP-712Voucherand itssol!mirror — the two must stay byte-identical to the contract typehash. - Per-lane seed derivation. A signer MUST derive an independent seed and root per
(pool_id, signer, provider)lane; reuse across lanes is the cross-lane preimage spend footgun and costs the payer real money. -
LaneStategainschain_rootand the deepest verified index; deepest-preimage-wins verification (ignoreindex ≤ verifiedwith no hashing, rejectindex > MAX_CHAIN_LENGTHbefore hashing). - Root-reuse rejection: refuse a
chain_rootseen on another lane or retired on this one. -
PoolStateStorerecord widens to(last_amount, last_bytes_delivered, chain_root, highest_index). Keep design: best-effort async voucher-watermark persistence (chain-floored) — drop fsync-before-ack #1672's frontier/redeemed durability split exactly as-is — chain state is frontier, and losing it forfeits the node's own un-signed tail, which is the safe direction.
crates/node + crates/client-pull
- Buyer: one chain-advancing task per lane, serializing the index and the rollover decision under a local lock while streams run concurrently.
- Buyer: send the epoch's
chain_rootvoucher once at stream open and once per rollover, before that stream's first preimage of the epoch. Resends are idempotent (cumulative-max). - Seller: credit-window floor becomes one chunk; pacing resumes on a
ChunkPreimageor aVoucher. Do not disturb feat: credit-slow-start — fixed-ramp credit window (start slow, ramp quick) #1669's ramp. - Redeem planner: prefer the latest signed voucher (rollover or close, walk-free); attach a preimage only for an abandoned sub-rollover tail.
contracts
-
VOUCHER_TYPEHASHgainsbytes32 chainRoot,uint256 chunkPrice. -
LaneVouchergainschainRoot,chunkPrice,chainIndex,preimage— keep the struct static (160 → 288 calldata bytes). - Bounded chain walk in
redeemMany: requirechainIndex <= MAX_CHAIN_LENGTH, hash forward frompreimage, require equality withchainRoot. Never hash from a stored intermediate; store no chain state. -
claimed = cumulative + chainIndex × chunkPriceoverclaimedBytes = bytesDelivered + chainIndex × CHUNK_BYTES;desired = claimed − w.amount; rate floor applies to the extended pair. - New errors
BadPreimage/ChainIndexTooLarge— caller errors that revert the whole call, alongside a bad signature. Zero-paying vouchers stay skipped, not reverted. - Update the
InterfaceFreeze.t.soltypehash pin.
Tests worth naming
- Sealed voucher:
chainRoot = 0at index 0 with a zero preimage settles exactlyamount; any index > 0 against a zero root reverts. - Real-root voucher redeemed at index 0 (root passed as its own preimage) settles exactly
amount. - Full-depth walk at index 255; index 256 reverts
ChainIndexTooLarge. - Rollover: redeeming old-then-new and new-only collect the same total; a superseded chain pays 0 and is skipped.
- Concurrency: two streams on one lane with interleaved, out-of-order, and skipped indexes converge on the same lane total; a preimage before its epoch voucher on that stream is rejected
UnanchoredPreimage. - Partial trailing chunk settles via a closing amount-voucher, exact to 1 USDC base unit.
🤖 Generated with Claude Code
Reacted by github-actions
Metadata
Metadata
Assignees
Labels
area:contractsSolidity contracts and Foundrykind:featureNew capability or a change to current behaviorprio:highNext uprustDependabot: a Cargo update; use area: labels for Rust code otherwise
Type
Fields
Priority
High
Projects
- StatusShow more project fieldsDone
Activity
feat(payments): implement PayWord hash-chained per-MB meter (#1752)