Repository navigation
Description
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 presenteduint64cumulative…bytesDeliveredtops 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 withuint64 bytesDelta/w.bytesDelivered += bytesPaid(PaymentPool.sol:760-767). - Money is
uint64too:deposit/totalRedeemed/cap/spentareuint64(PaymentPool.sol:139-157), andspendingCap ≤ deposit, so any voucher whoseamountexceedsu64::MAXis 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/WatermarkBundlestructs + theirvalidate/doc comments; theclient_bridgeencode/decode (signed_to_wire_voucher/wire_voucher_to_signed— widenu64 → U256); the node verify path; the client sender; theWatermarkBundlereseed path; thepublic-api-testsnapshot (crates/protocol/tests/snapshots/public_api__public_api.snap). - Internal
decdn-incentiveaccounting can stayU256(alloy) or narrow tou64— decide during design; the only hard requirement is that signature reconstruction produces the exactuint256the client signed. - Update the
Voucherwire doc: its current caveat that "truncating tou64would break pools whose totals exceedu64::MAX" is moot — the contract's own watermark isuint64, 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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
feat(payments): narrow wire voucher amount/bytes_delivered to u64 (#1705