Skip to content

feat(payments): narrow wire voucher amount (and bytes_delivered) to u64 #1705

Closed

Description

@alpergundogdu

Follow-up to #1699.

Motivation

The wire Voucher carries amount and bytes_delivered as [u8; 32] big-endian uint256 (crates/protocol/src/client.rs), but the on-chain contract already stores and settles both as uint64 — the wire is 24 bytes wider than the value it can ever represent.

  • The lane watermark: struct Lane { uint64 amount; uint64 bytesDelivered; } (PaymentPool.sol:163). Its comment: "Both fields are watermarks that only ever advance toward a presented uint64 cumulative… bytesDelivered tops out at 18.4 exabytes on a single lane."
  • The redeemed voucher: struct LaneVoucher { … uint64 cumulative; uint64 bytesDelivered; … } (PaymentPool.sol:424), and settlement advances the watermark with uint64 bytesDelta / w.bytesDelivered += bytesPaid (PaymentPool.sol:760-767).
  • Money is uint64 too: deposit/totalRedeemed/cap/spent are uint64 (PaymentPool.sol:139-157), and spendingCap ≤ deposit, so any voucher whose amount exceeds u64::MAX is unredeemable and already rejected by the cap check.

So narrowing the wire fields to u64 is not merely fitting an economic ceiling — it aligns the wire to the contract's actual storage type. The only place these fields are uint256 is the EIP-712 typehash string (PaymentPool.sol:97); _verifyVoucher ABI-encodes the uint64 values into those uint256 slots purely as the signed field's ABI width (PaymentPool.sol:792).

Proposed change (wire only — no contract change)

Change the wire fields from [u8; 32] to u64:

  • protocol::client::Voucher { amount: u64, bytes_delivered: u64 }
  • protocol::client::WatermarkBundle { amount: u64, bytes_delivered: u64 }

postcard varint-encodes u64, so typical vouchers shrink from 64 fixed bytes (amount+bytes) to a couple of varint bytes each. The EIP-712 signed payload stays uint256 (the contract typehash is unchanged): the node zero-extends the wire u64 back to U256 to reconstruct and verify the signature — lossless, because the on-chain type is already uint64. This mirrors exactly how #1699 already treats bytes_delivered.

Scope

  • Wire break, pre-launch: change every side in one PR, delete the old shape, no shim (same discipline as feat(payments): self-describing vouchers to enable concurrent same-lane settlement #1699).
  • Touch points: the Voucher/WatermarkBundle structs + their validate/doc comments; the client_bridge encode/decode (signed_to_wire_voucher / wire_voucher_to_signed — widen u64 → U256); the node verify path; the client sender; the WatermarkBundle reseed path; the public-api-test snapshot (crates/protocol/tests/snapshots/public_api__public_api.snap).
  • Internal decdn-incentive accounting can stay U256 (alloy) or narrow to u64 — decide during design; the only hard requirement is that signature reconstruction produces the exact uint256 the client signed.
  • Update the Voucher wire doc: its current caveat that "truncating to u64 would break pools whose totals exceed u64::MAX" is moot — the contract's own watermark is uint64, so totals cannot exceed it.

Out of scope (separate decision)

Narrowing the EIP-712 / contract amount/bytesDelivered typehash fields from uint256 to uint64 would change the signed-domain hash and the deployed contract surface. Since the contract's Lane/LaneVoucher already store both as uint64, only the typehash string is out of step — aligning it is defensible, but it is a signature-format + redeploy change, so it belongs in its own issue if pursued.

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

Metadata

Metadata

Assignees

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