Skip to content

feat(incentive): PayWord chain in voucher, lane state, and seed derivation #1694

Closed as not planned

Description

@yigitdot

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 Rust Voucher (:90-104) each gain chain_root: B256 and chunk_price: U256. The type string derived by sol! must match PaymentPool.VOUCHER_TYPEHASH exactly — worth a test that pins the string.
  • Domain and Capability are unchanged.

crates/incentive/src/lane.rs

  • LaneState tracks the chain alongside the anchor: the lane's chain_root, the highest accepted index, and the deepest preimage held. Redemption presents the best proof, so the deepest preimage must survive alongside last_amount.
  • stage_voucher monotonicity moves from amount to claimed = amount + chain_index × chunk_price. A fresh voucher must not reduce claimed below the position the chain already proved.
  • New stage_preimage: verify keccak^k(preimage) == chain_root at the claimed index, advance the index by one and claimed by exactly one chunk_price.
  • Root is one-shot per lane. Reject a chain_root already 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), so provider is 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); release keccak^(255−k)(seed) after chunk k.

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

  • claimed monotonicity 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 provider are independent
  • chain exhaustion at 255 → ChainExhausted, and rollover accepted when the new anchor folds in 255 × chunk_price
  • typehash string parity with the Solidity constant

Blocked on #1692 merging. Pairs with #1693 (contracts).

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions