Repository navigation
Description
Implements the crates/incentive half of the PayWord model landed in ADR 003 by #1692 (issue #1670).
Spec: ADR 003 § Hash-chain metering (PayWord), § One chain per lane, § Voucher ordering.
Scope
crates/incentive/src/voucher.rs
- alloy
sol!struct (:58-71) and the public RustVoucher(:90-104) each gainchain_root: B256andchunk_price: U256. The type string derived bysol!must matchPaymentPool.VOUCHER_TYPEHASHexactly — worth a test that pins the string. - Domain and
Capabilityare unchanged.
crates/incentive/src/lane.rs
LaneStatetracks the chain alongside the anchor: the lane'schain_root, the highest accepted index, and the deepest preimage held. Redemption presents the best proof, so the deepest preimage must survive alongsidelast_amount.stage_vouchermonotonicity moves fromamounttoclaimed = amount + chain_index × chunk_price. A fresh voucher must not reduceclaimedbelow the position the chain already proved.- New
stage_preimage: verifykeccak^k(preimage) == chain_rootat the claimed index, advance the index by one andclaimedby exactly onechunk_price. - Root is one-shot per lane. Reject a
chain_rootalready seen on a different lane, or already retired on this one. A new root supersedes the old and the old index stops advancing.
Chain seed derivation (payer side)
- Derive per lane rather than persisting: the seed MUST be independent per
(pool_id, signer, provider), soprovideris a derivation input. Two lanes' chains MUST NOT be derivable from each other — this is the Cross-lane preimage spend defence and it is payer-side only; neither the contract nor any node can enforce it. chain_root = keccak^255(seed); releasekeccak^(255−k)(seed)after chunkk.
New PoolError variants: BadPreimage, ChainExhausted. Both are permanent, so per ADR 005 § Mirror obligation each needs a VoucherRejectReason counterpart and a retry-semantics row — both already in the ADR. voucher_reject_reason matches exhaustively with no wildcard, so this fails to compile until wired.
Rate floor (rate.rs) — a node MUST check chunk_price >= delivery_floor at accept time, zero tolerance, plus chunk_price >= its own advertised rate_per_mb. This is stricter than the contract's aggregate check, deliberately: on the unilateral-fallback path the claim is dominated by chain_index × chunk_price with a small anchor, so an under-priced chunk strands the whole chain unredeemable — unrecoverable once the payer stops responding.
Tests worth having
claimedmonotonicity across a voucher→preimage→voucher sequence- preimage at the wrong index, and a preimage for another lane's root, both rejected
- root reuse across two
LaneKeys rejected - seeds for two lanes differing only in
providerare independent - chain exhaustion at 255 →
ChainExhausted, and rollover accepted when the new anchor folds in255 × chunk_price - typehash string parity with the Solidity constant
Blocked on #1692 merging. Pairs with #1693 (contracts).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity