Repository navigation
feat(payments): narrow wire voucher amount/bytes_delivered to u64 (#1705) - #1708
Merged
Merged
Conversation
…#1705) The wire Voucher and WatermarkBundle carried amount and bytes_delivered as [u8;32] uint256, but the contract stores both as uint64 (Lane/LaneVoucher), so 24 of every 32 bytes were always zero. Carry them as u64 (postcard varints them); the EIP-712 payload stays uint256, reconstructed by zero-extending the wire u64. The send side narrows fallibly — a value above the on-chain uint64 cap is unredeemable and refused, never truncated. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR narrows the on-the-wire payment voucher and watermark fields (amount, bytes_delivered) from fixed-width [u8; 32] big-endian uint256 encodings to u64, aligning the wire format with the on-chain PaymentPool storage types (uint64) while keeping the EIP-712 signed payload unchanged (receiver reconstructs uint256 via zero-extension).
Changes:
- Updated
decdn_protocol::client::{Voucher, WatermarkBundle}wire fields tou64and adjusted docs + wire-format stability tests accordingly. - Updated node/client codepaths to widen
u64 → U256on receipt/verify and to refuse narrowing when attempting to send a voucher whose internalU256exceedsu64::MAX(newWireVoucherError::ValueExceedsWireWidth). - Updated client-pull ledger reseeding and a set of node/client integration tests to match the new wire types and error behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/client.rs | Narrows wire Voucher/WatermarkBundle fields to u64, updates docs, and updates postcard wire-stability expectations. |
| crates/protocol/tests/snapshots/public_api__public_api.snap | Regenerates public API snapshot reflecting the type narrowing. |
| crates/incentive/src/client_bridge.rs | Implements infallible widen (u64 → U256) and fallible narrow (U256 → u64) with a dedicated refusal error. |
| crates/node/src/handlers/client/voucher.rs | Switches wire parsing to U256::from(u64) and ensures watermark bundles are only produced when values fit u64. |
| crates/node/src/handlers/client/wire.rs | Updates audit receipt recording to accept u64 wire amounts and widen to U256 for receipt payloads. |
| crates/client-pull/src/lib.rs | Handles fallible narrowing when sending vouchers; updates watermark reconstruction and related tests. |
| crates/client-pull/src/ledger.rs | Updates wallet-less reseed decoding to use u64 bundle totals widened to U256. |
| crates/node/tests/* | Updates tests to accommodate signed_to_wire_voucher now returning Result and the new u64 wire fields. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…conflicts-406dfa # Conflicts: # crates/node/src/handlers/client/voucher.rs # crates/node/tests/client_loopback.rs
This was referenced Aug 17, 2026
Coverage reportTotal: 80.23% (was 80.63%, ▼ 0.40%) — 56891/70909 lines
History
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1705. Follow-up to #1699.
The wire
VoucherandWatermarkBundlecarriedamountandbytes_deliveredas[u8;32]big-endianuint256, but the contract stores both asuint64(PaymentPool.solLane { uint64 amount; uint64 bytesDelivered }andLaneVoucher { uint64 cumulative; uint64 bytesDelivered }), so 24 of every 32 bytes were always zero. This narrows the wire fields tou64.What changed
Voucher { amount: u64, bytes_delivered: u64 }andWatermarkBundle { amount: u64, bytes_delivered: u64 }(were[u8;32]). postcard varint-encodesu64, so typical vouchers shrink from 64 fixed bytes (amount+bytes) to a couple of varint bytes.u64toU256— exact, so the signature still recovers the signer.signed_to_wire_vouchernow returnsResult; a value above the on-chainuint64cap is unredeemable and refused withWireVoucherError::ValueExceedsWireWidth, neveras u64/saturated.uint256; this is a wire-only change.Scope
SignedVoucher,LaneState,Cumulative,PoolLedger) stayU256; only the wire boundary narrows.buyer_pool_tableStoredLane,channel_storeStoredLaneState) deliberately stay[u8;32]— not the wire.Tests
u64range; a> u64::MAXamount is covered by a newValueExceedsWireWidthrefusal test.watermark_bundle_for_rejectreturnsNone(not a truncated bundle) on an over-u64watermark.cargo denypasses.🤖 Generated with Claude Code