Skip to content

feat(payments): narrow wire voucher amount/bytes_delivered to u64 (#1705) - #1708

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/issue-1705-u64-amount
Aug 18, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/issue-1705-u64-amount

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1705. Follow-up to #1699.

The wire Voucher and WatermarkBundle carried amount and bytes_delivered as [u8;32] big-endian uint256, but the contract stores both as uint64 (PaymentPool.sol Lane { uint64 amount; uint64 bytesDelivered } and LaneVoucher { uint64 cumulative; uint64 bytesDelivered }), so 24 of every 32 bytes were always zero. This narrows the wire fields to u64.

What changed

  • Wire: Voucher { amount: u64, bytes_delivered: u64 } and WatermarkBundle { amount: u64, bytes_delivered: u64 } (were [u8;32]). postcard varint-encodes u64, so typical vouchers shrink from 64 fixed bytes (amount+bytes) to a couple of varint bytes.
  • Receive widens (infallible): the node reconstructs the EIP-712 payload by zero-extending the wire u64 to U256 — exact, so the signature still recovers the signer.
  • Send narrows (fallible, never truncates): signed_to_wire_voucher now returns Result; a value above the on-chain uint64 cap is unredeemable and refused with WireVoucherError::ValueExceedsWireWidth, never as u64/saturated.
  • EIP-712 / contract unchanged: the signed payload stays uint256; this is a wire-only change.

Scope

  • Internal representations (SignedVoucher, LaneState, Cumulative, PoolLedger) stay U256; only the wire boundary narrows.
  • redb persistence tables (buyer_pool_table StoredLane, channel_store StoredLaneState) deliberately stay [u8;32] — not the wire.
  • Public-API snapshot regenerated (only the four fields' type changes).

Tests

  • Bridge round-trip proven lossless over the full u64 range; a > u64::MAX amount is covered by a new ValueExceedsWireWidth refusal test.
  • watermark_bundle_for_reject returns None (not a truncated bundle) on an over-u64 watermark.
  • Full workspace green: 2771/2771, clippy/fmt clean, e2e compile gate passes, public-API snapshot check passes, cargo deny passes.

🤖 Generated with Claude Code

…#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]>
Copilot AI lite review requested due to automatic review settings August 17, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to u64 and adjusted docs + wire-format stability tests accordingly.
  • Updated node/client codepaths to widen u64 → U256 on receipt/verify and to refuse narrowing when attempting to send a voucher whose internal U256 exceeds u64::MAX (new WireVoucherError::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
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.23% (was 80.63%, ▼ 0.40%) — 56891/70909 lines

File Coverage Lines Δ
crates/client-pull/src/ledger.rs 99.42% 345/347 ● 0.00%
crates/client-pull/src/lib.rs 88.95% 1449/1629 ▼ 0.25%
crates/incentive/src/client_bridge.rs 98.40% 185/188 ▼ 0.45%
crates/node/src/handlers/client/voucher.rs 87.75% 308/351 ▼ 1.14%
crates/node/src/handlers/client/wire.rs 97.64% 124/127 ● 0.00%
crates/protocol/src/client.rs 99.04% 721/728 ● 0.00%
History
Commit Total Δ vs base
781d846 (HEAD) 80.23% ▼ 0.40%

@alpergundogdu
alpergundogdu merged commit 281dd25 into main Aug 18, 2026
48 of 52 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1705-u64-amount branch August 18, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants