Skip to content

feat(payments): delegated voucherSigner + voucher-less close - #1478

Merged
alpergundogdu merged 26 commits into
mainfrom
claude/pr-1476-implementation-97c262
Jul 28, 2026
Merged

alpergundogdu merged 26 commits into
mainfrom
claude/pr-1476-implementation-97c262

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Implements all four parts of #1476.

1 — openChannel(address provider, uint256 deposit, address voucherSigner)

Splits the funder role from the signer role.

  • ch.client stays the funder: puts up the deposit, receives the refund, owns the channelId nonce sequence, and is the subject of the ADR-011 blacklist gates.
  • ch.voucherSigner is what all four settlement paths (withdraw, closeChannel, disputeChannel, cooperativeClose) verify EIP-712 voucher signatures against.
  • address(0) resolves to msg.sender — today's self-signing behaviour is unchanged, and every buyer-side caller in-tree passes zero.
  • No setVoucherSigner, stated explicitly in NatSpec rather than implied. A mutable signer would let a funder retroactively void a voucher a provider had already earned.
  • channelId derivation is unchanged — still keccak256(client, provider, nonce), not keyed on the signer, so the funder keeps nonce control and can predict IDs.
  • cooperativeClose is callable by the pinned signer.

One deviation from the issue, approved before implementation

The issue asks for voucherSigner to be indexed on ChannelOpened. It cannot be: the event already carried channelId, client and provider indexed, which is the EVM maximum of three. It ships unindexed, which satisfies the issue's stated rationale (the node builds channel state from the event with no extra getChannel RPC) and breaks no existing filter — nothing in the tree filters logs by signer. The consequence is documented in ADR 003: signer-side enumeration is not eth_getLogs-filterable.

A second correction, found during implementation: the issue describes cooperativeClose's residual authority as a compromised hot key being able to force settlement at the watermark. Verified against the code, that was already true before this change — both signatures are checked regardless of msg.sender, and the provider holds both by construction, so widening the caller set only changes who pays gas. The NatSpec and ADR say that rather than the stronger claim.

2 & 3 — voucher-less close

closeChannel lost the ch.claimedNonce == 0 conjunct, and closeChannelWithoutVoucher(bytes32) was added as a thin alias over the same shared _initiateClose path, callable by client or provider.

Neither advances the watermark. settleChannel computes what it pays from claimed* netted against withdrawn*, so a voucher-less close settles at the already-validated watermark and can never settle below it; the counterparty keeps its full disputeChannel ratchet-up right for the dispute window. A voucher is required only to raise the watermark. This removes up to 90 days of capital lock-in when a voucher is lost or withheld.

The new function copies closeChannel's actual modifier list — external nonReentrant, without whenNotPaused, since exit paths deliberately stay open under pause. Adding the pause guard would have made the alias strictly weaker than the call it aliases.

4 — node-side keying

ChannelState gained voucher_signer, hydrated from ChannelOpened and persisted to redb as a trailing postcard segment gated on schema version 3; v1/v2 records decode to voucher_signer = client, matching the on-chain zero default. apply_voucher verifies against it.

The trap the issue names — handled explicitly. Five serve-path sites read state.client. Two are signer semantics and moved; three are ADR-011 funder compliance and deliberately did not:

site semantics action
dispatch.rs origin-blacklist gate funder stays client
dispatch.rs binding gate signer → voucher_signer
fill.rs pull_authorized signer for spend, funder for compliance → voucher_signer for ownership; blacklist keyed on funder
window.rs in-flight takedown re-check funder stays client
delivery.rs in-flight takedown re-check funder stays client

The three unmoved sites carry do-not-move comments naming the concrete attack (a blacklisted funder pinning a clean throwaway signer). Two compliance regression tests cover it, and the window.rs gate is mutation-proven: re-keying it to voucher_signer makes window_pull_through_funder_blacklisted_mid_stream_cuts_off_a_delegated_delivery fail.

Both blacklist paths key on the funder — see the follow-ups section below.

Interface freeze

  • openChannel — deliberate re-freeze (breaking selector change).
  • closeChannelWithoutVoucher — additive baseline entry.

Both ABI changes plus the ChannelOpened topic0 change and the getChannel tuple change are recorded under ### Changed (BREAKING) in CHANGELOG.md.

Not in scope

No CLI flag or config key for choosing a delegate signer — the publisher-pays UX is follow-up work. The duplicated PaymentChannelOpen binding in crates/e2e is kept (with a note), and the ADR 024 operator-side Safe hole is untouched.

Verification

cargo build --workspace                                    clean
cargo clippy --workspace --all-targets -- -D warnings      clean
cargo fmt -- --check                                       clean
cargo nextest run --workspace                              2586 passed, 0 failed

forge fmt --check                                          clean
FOUNDRY_PROFILE=ci forge build --sizes --deny warnings     no warnings
forge test                                                 766 passed, 0 failed, 12 skipped
forge snapshot --check                                     clean
pre-commit run --all-files                                 pass*

* the sole pre-commit failure is markdownlint on .github/workflows/issue-triage.md, which this branch does not touch — pre-existing.

slither is not installed on this machine, so that gate is CI-only for this branch; aderyn ran with no new High findings on the touched surface. The anvil-e2e suites are compile-checked only.

Review follow-ups — all folded in

The three items originally listed here as follow-ups are now part of this PR.

On-disk schema gated on a version, not a byte width. The voucher-signer redb segment was untagged and fixed-width, so presence was detected by leftover.len() >= 20 — a fail-open where any record carrying ≥20 bytes of unknown trailer would be silently read as a signer, moving the signature verification target. Flagged independently by review and by Copilot. SUPPORTED_SCHEMA_VERSION is now 3: v1/v2 records never inspect the segment and default voucher_signer = client (correct — channels predating this contract change are self-signing by construction), v3 records treat it as mandatory so absence is genuine corruption. The regression test is mutation-proven. Consequence, documented in CHANGELOG.md: a node that writes a v3 record and is then rolled back to an older binary aborts startup with UnsupportedSchema. That is this codebase's deliberate fail-closed posture, and there are no production channels on disk yet.

Blacklist subject aligned on the funder, both paths. pull_authorized's early return predated the role split — it used to be a funder check and had silently become a signer check. Per ADR 011 the funding address is the compliance subject, so it is removed and both paths now key on the funder. Behaviour is identical today (signer == funder on every channel); the future divergence is asserted by a test rather than left to omission.

closeChannelWithoutVoucher wired — and it caught a latent bug. The premise that the node settlement sweep was the zero-voucher caller was wrong: both node paths are guarded on holding a signed voucher. The real zero branch is the CLI's submit_close, which re-signs even an all-zero watermark — and that non-empty signature skips the contract's zeroVoucher short-circuit (signature.length == 0 is one of its conjuncts). So once a delegate is pinned, the funder's own signature would not recover to voucherSigner and decdn channel close would revert. That branch now calls closeChannelWithoutVoucher.

One residual is recorded in a comment rather than fixed: BuyerChannelState carries no voucher_signer, so the CLI uses "do we hold a watermark" as a proxy for "do we hold a key this channel accepts". A funder-run CLI holding a non-zero watermark it did not sign would still take the reverting branch. Unreachable until a delegation CLI surface exists.

Closes #1476

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Channels can pin a separate voucherSigner at open (self-signing remains the default when unset).
    • Added closeChannelWithoutVoucher for voucher-less closure.
    • Channel listings now include a SIGNER column.
  • Bug Fixes
    • Voucher-less closure now works “at any watermark” while preserving settlement state.
    • Delegate voucher signer authorization and funder-based compliance checks are now enforced correctly.
  • Documentation
    • Updated payment/protocol/security and runbook guidance to match the pinned signer model and new closure semantics.
  • Breaking Changes
    • Contract ABI and event payloads changed to include voucherSigner, and the CLI output format shifts accordingly.
    • Channel on-disk state schema bumped (v3); older binaries can’t read it.

alpergundogdu and others added 22 commits July 27, 2026 12:32
Split the funder role from the voucher-signing role on PaymentChannel.
`ch.client` stays the funder and refund destination; a new immutable
`ch.voucherSigner`, pinned at open (address(0) means msg.sender), is what
all four settlement paths recover voucher signatures against. There is no
setter — a mutable signer would let a funder retroactively void a voucher
a provider had already earned.

Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the `claimedNonce == 0` conjunct from `closeChannel`s zero-voucher
branch and add `closeChannelWithoutVoucher(bytes32)`, a thin alias over the
same close path. Neither advances a watermark, so the counterparty keeps its
full `disputeChannel` ratchet-up right for the dispute window; a voucher is
now required only to raise the watermark, not to close.

Also folds in five doc/test cleanups from the delegated-signer review: the
cooperativeClose residual-authority note now states the provider waiver is
also required, records that the pinned signer is deliberately not a party to
the other lifecycle entry points, warns against passing the counterparty as
voucherSigner, renames ChannelOpenedSig to CHANNEL_OPENED_SIG, and asserts
the delegate cannot topUp.

Co-Authored-By: Claude Opus 5 <[email protected]>
…loseChannelWithoutVoucher tests

The `cooperativeClose` @dev clause claimed topUp and withdraw "remain
client/provider-only" for both parties, but topUp is client-only and
withdraw is provider-only; only the two close functions accept either
party. Reworded to say so explicitly.

Also closes three test gaps flagged in Task 2's review:
- test_closeChannelWithoutVoucher_disputeStillRatchets now warps past
  the dispute deadline and settles, proving the ratcheted watermark
  actually routes the delta, not just that it moved.
- Added revertsWhenAlreadyClosing and revertsAfterExpiry negative
  guards for closeChannelWithoutVoucher's own
  _requireOpenAndUnexpired check, since it is a distinct entry point
  whose guard could otherwise be dropped with no test failing.
- Pinned ChannelCloseInitiated's emitted arguments in
  test_closeChannelWithoutVoucher_byProvider via expectEmit, since
  _initiateClose now has two callers.

Co-Authored-By: Claude Opus 5 <[email protected]>
openChannel gained a pinned voucherSigner param (extra SSTORE + calldata
word) and closeChannelWithoutVoucher is a new entry point; both changed
gas costs and the ABI. Regenerated via
`FOUNDRY_PROFILE=ci forge snapshot --snap .gas-snapshot` after landing
the four carry-over test/doc fixes from Task 2's review so the snapshot
does not go stale again immediately.

Co-Authored-By: Claude Opus 5 <[email protected]>
`PaymentChannel` now splits the funder (`client`) from the address whose
EIP-712 signature authorizes vouchers (`voucherSigner`), pinned at
`openChannel` and immutable thereafter. Mirror that split off-chain:
`ChannelState` gains `voucher_signer` and `apply_voucher` recovers against
it instead of `client`, matching the four on-chain settlement paths.

`client` keeps its meaning as the funder and stays the subject of the
ADR-011 blacklist gates — moving those onto the signer would let a
blacklisted funder serve behind a throwaway key.

The production `sol!` binding picks up the third `openChannel` argument,
the trailing unindexed `ChannelOpened.voucherSigner`, the new
`Channel.voucherSigner` struct member, and `closeChannelWithoutVoucher`.
Persistence of the field (task 5), the serve-path gates (task 6), and
hydration from the event (task 7) are follow-ups; the persistence decoder
and `apply_channel_opened` pass the funder as the signer for now.

Co-Authored-By: Claude Opus 5 <[email protected]>
The redb seller record gains a fourth trailing postcard segment, a bare
`[u8; 20]` holding the channel's pinned voucher signer, appended after the
cooperative-close flag. `SUPPORTED_SCHEMA_VERSION` stays at 2: this is
additive, and records written before delegated signers existed have no such
segment and hydrate with `voucher_signer = client` — the on-chain default
`openChannel` applies when `voucherSigner` is passed as zero.

Presence is tested by width (postcard writes a byte array as raw bytes with
no length prefix), so a shorter future trailer is never misread as an
address. Removes the task-4 decoder placeholder that passed `client` for
both legs.

Also, in decdn-incentive: correct `hydrate`'s round-trip-coverage claim now
that the decoder really does persist the two addresses separately, reflow an
orphaned doc line, and drop a duplicated channel-id literal from the two
delegation tests in favour of the fixture's own id.

Co-Authored-By: Claude Opus 5 <[email protected]>
The channel_store.rs comment overstated what the length-gated decode of the
untagged, fixed-width voucher_signer segment actually guarantees: any >= 20
byte remainder at that position decodes as an address, so it's an ordering
invariant (append after it) not a misread-proofing mechanism. Document that
invariant once at decode_record and cross-reference it at the record write
site and the StoredChannelState doc; annotate the now-unreachable Corrupt
branch as a deliberate guard. Also de-triplicate the three tests' hand-encoded
fixture bytes into one encode_pre_signer helper, strengthen the
self-referential client-vs-signer test assertion, and flag the 20-byte trap
in the trailing-junk regression test.

No behavioural change: same bytes written and decoded.

Co-Authored-By: Claude Opus 5 <[email protected]>
The binding gate in dispatch.rs and the pull-through gate in fill.rs ask a
signer question: only the channel's pinned voucher_signer can produce a
voucher the channel accepts, so it is the only identity that can authorize
paid delivery or an upstream spend. Both now compare against
state.voucher_signer.

The three ADR-011 takedown gates (the dispatch origin-blacklist gate, and
the in-flight re-checks in window.rs and delivery.rs) stay keyed on
state.client, the funder, and say so explicitly: a blacklisted funder can
pin a clean throwaway key as its signer, so moving them would silently
stop enforcing takedowns. pull_authorized now checks BOTH — signer for
ownership, funder for compliance.

Also replaces the line-number cross-references added to channel_store.rs
with symbol references.

Co-Authored-By: Claude Opus 5 <[email protected]>
The watcher discarded the events voucherSigner and registered the funder
as both client and signer, so a delegated channel rejected every voucher
it was opened to accept. Split the field mapping into a pure
opened_channel_state kernel and hydrate the pinned signer from the event
(already resolved on-chain, so no client-side defaulting).

Co-Authored-By: Claude Opus 5 <[email protected]>
Both inline sol! blocks still declared the pre-delegation signature. They
compiled fine and would only have misencoded against the deployed
contract at runtime. Every buyer-side call now passes Address::ZERO,
which the contract resolves to msg.sender — todays exact behaviour.

Co-Authored-By: Claude Opus 5 <[email protected]>
Additive #[serde(default)] DTO field plus a SIGNER column in
"decdn node channels"; a pre-delegation server omits it and renders "?"
rather than echoing the funder.

Co-Authored-By: Claude Opus 5 <[email protected]>
…down

One test crosses the whole seam — delegate-signed vouchers accepted, the
stream completing, funder and signer staying distinct. The other
blacklists the funder mid-stream on a channel with a clean delegate
signer; it fails if the per-MB re-check is re-keyed onto the signer
(verified by mutating delivery.rs).

Co-Authored-By: Claude Opus 5 <[email protected]>
Also reflow a channel_store trailing-segment paragraph that a rewrap left
with a two-word orphan line.

Co-Authored-By: Claude Opus 5 <[email protected]>
…hrough path

The delegated mid-stream takedown test in `client_loopback.rs` reaches only
`delivery.rs`: its harness wires no `pull_through_origin`, and
`serve_via_window_pull_through` is entered only when that provider is `Some`.
So `window.rs`'s per-interval funder re-check was guarded by a comment and
nothing else — re-keying it onto `voucher_signer` left the suite green.

Adds a window-path sibling built on the existing node A/B pull-through
fixture: the leaf's channel is funded by one address and signed by a distinct,
never-blacklisted delegate; the funder goes on the deny-set only once the
window loop is demonstrably running (its pause counter has ticked). Mutating
`window.rs` to read `state.voucher_signer` now fails the test with the 12 MiB
delivery completing.

`build_node_b_with_leaves` grows a per-leaf voucher-signer leg and an optional
content deny-set; every existing caller keeps the undelegated, deny-nothing
default.

Co-Authored-By: Claude Opus 5 <[email protected]>
…omment

`buyer_channel.rs` carried `TODO(task 7): plumb a configurable delegate
signer` for a task that deliberately declined that work — the delegate-signer
surface needs a publisher-pays UX, not an extra argument. Says so instead.

`payment_settlement.rs` repeated "Only channels where this node is the
provider concern us." above a `let … else` that delegates exactly that
decision to `opened_channel_state`, which already carries it. Keeps the copy
in the kernel.

Co-Authored-By: Claude Opus 5 <[email protected]>
The column is operator-visible and output-breaking: the table is ~15
characters wider and positions after COUNTERPARTY shift, so positional
parsers need updating. Its value equals COUNTERPARTY for every channel opened
today, since a zero voucherSigner resolves on-chain to msg.sender.

Co-Authored-By: Claude Opus 5 <[email protected]>
…fication claims

State that the ephemeral client binding gates channel use rather than
supplying voucher attribution, in ADR 003 and ADR 012, matching ADR 005
and the dispatch gate. Restate the voucher-less-close safety premise
against the claimed/withdrawn pair actually read at settlement. Correct
the Channel slot-packing byte count. Collapse the PaymentChannel
signature-verification table to the shape that exists.

Co-Authored-By: Claude Opus 5 <[email protected]>
… close

openChannel's selector, ChannelOpened's topic0, and the getChannel tuple
layout all changed with the pinned voucherSigner; none were logged. Add the
BREAKING entry with the ABI sub-bullet, plus the additive
closeChannelWithoutVoucher entry point and the relaxed zero-voucher close.

Co-Authored-By: Claude Opus 5 <[email protected]>
… close note

_verifyVoucher still declared `address client` though all four call sites pass
ch.voucherSigner — the innermost spot where funder and signer could transpose
silently. Parameter names are not part of the selector; no behaviour change.

The cooperativeClose @dev overstated the pinned signer's residual authority:
both signatures are verified independently of msg.sender, so the provider —
which holds the vouchers and signs its own waiver — could already submit the
identical call. Widening the party check only moves who pays the gas.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 27, 2026 14:04
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: f0129530-575b-4d74-addc-250e8e71e41c

📥 Commits

Reviewing files that changed from the base of the PR and between ca2a6f4 and f189625.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • crates/cli/src/commands/channel.rs
  • crates/incentive/src/payment_channel.rs
  • crates/node/src/buyer_channel.rs
  • crates/node/src/channel_store.rs
  • crates/node/src/handlers/client/fill.rs
  • crates/node/tests/anvil_settlement_e2e.rs
  • crates/node/tests/client_loopback.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/incentive/src/payment_channel.rs
  • crates/node/src/handlers/client/fill.rs
  • CHANGELOG.md

Walkthrough

Payment channels now separate the funder from a pinned voucher signer. Contract settlement, Rust state, persistence, node authorization, admin APIs, CLI output, ABI bindings, documentation, and tests are updated for delegated voucher signing and voucher-less closure.

Changes

Voucher signer delegation

Layer / File(s) Summary
Contract signer authority and close paths
contracts/src/PaymentChannel.sol, contracts/test/PaymentChannel.t.sol, contracts/test/InterfaceFreeze.t.sol
openChannel accepts and emits voucherSigner; lifecycle voucher checks use the pinned signer; delegated cooperative close and voucher-less close paths are supported and tested.
Rust channel model and ABI propagation
crates/incentive/..., crates/e2e/..., crates/client-pull/..., crates/node/src/payment_settlement.rs
Rust channel state, ABI bindings, buyer calls, and settlement event handling carry voucher_signer, defaulting zero-address opens to self-signing.
Persistent signer state and compatibility
crates/node/src/channel_store.rs, crates/incentive/src/store.rs
Persistent records append and decode a signer segment; legacy records default the signer to the funder.
Node authorization and funder compliance
crates/node/src/handlers/client/*, crates/node/tests/client_loopback.rs, crates/node/tests/node_origin_pull.rs
Connection and pull-through authorization use voucher_signer, while blacklist and takedown checks remain keyed to the funder.
Admin wire and CLI signer output
crates/common/src/admin.rs, crates/node/src/admin.rs, crates/cli/src/commands/node.rs, crates/cli/tests/admin_peers.rs
Channel snapshots expose an optional signer and decdn node channels renders it in a new SIGNER column, using ? when omitted.
Integration fixtures and documentation
contracts/.gas-snapshot, crates/node/tests/*, CHANGELOG.md, adr/*
Call sites, fixtures, gas snapshots, ADRs, glossary entries, and changelog entries reflect the updated ABI, signer roles, close semantics, and output format.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Funder
  participant PaymentChannel
  participant VoucherSigner
  participant Provider
  Funder->>PaymentChannel: openChannel(provider, deposit, voucherSigner)
  PaymentChannel-->>Provider: ChannelOpened with voucherSigner
  VoucherSigner->>PaymentChannel: sign voucher
  Provider->>PaymentChannel: withdraw or close
  PaymentChannel-->>Funder: settle using funder/refund role
Loading

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.57% (2422/2704 lines)
▲ +0.03pp vs base (89.54% → 89.57%)
Run: 30283946771

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

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

Implements the delegated voucherSigner + voucher-less close work from #1476 across the Solidity PaymentChannel contract, Rust bindings/runtime, CLI/admin surfaces, and ADR documentation to keep funder-vs-signer semantics consistent end-to-end.

Changes:

  • Extends PaymentChannel.openChannel to pin an immutable voucherSigner (defaulting to msg.sender) and updates all settlement-path signature verification to recover against it.
  • Adds a voucher-less close flow by removing the claimedNonce == 0 restriction and introducing closeChannelWithoutVoucher(bytes32) as an explicit alias over the same close-at-watermark path.
  • Splits node-side channel state into client (funder) vs voucher_signer (signer), persists it to redb, updates serve gates accordingly, and expands tests/admin/CLI/docs to reflect the new roles.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/tests/origin_range_pull.rs Updates ChannelState::new construction for new funder/signer arguments.
crates/node/tests/node_to_node_pull_through.rs Updates test fixtures for funder vs signer fields.
crates/node/tests/node_origin_pull.rs Updates leaf channel fixtures, adds compliance regression test for mid-stream funder takedown with delegated signer.
crates/node/tests/client_loopback.rs Adds delegated-signer fixtures and coverage for binding/pull-through authorization and funder-deny compliance.
crates/node/tests/channel_state_store.rs Updates store tests for new ChannelState shape.
crates/node/tests/anvil_settlement_e2e.rs Updates on-chain buyer binding for new openChannel signature (self-signing via Address::ZERO).
crates/node/src/payment_settlement.rs Hydrates ChannelOpened into ChannelState including voucherSigner, with unit tests to prevent transposition.
crates/node/src/handlers/client/window.rs Documents/anchors that in-flight takedown checks stay keyed on funder (state.client).
crates/node/src/handlers/client/mod.rs Updates internal test state construction for new ChannelState signature.
crates/node/src/handlers/client/fill.rs Re-keys pull-through spend authorization to voucher_signer while preserving funder-deny backstop.
crates/node/src/handlers/client/dispatch.rs Keeps origin-deny gate keyed on funder; re-keys binding authorization to voucher_signer.
crates/node/src/handlers/client/delivery.rs Documents/anchors that in-flight takedown checks stay keyed on funder (state.client).
crates/node/src/channel_store.rs Persists/decodes voucher_signer as an additive trailing segment with tests for legacy decode and delegated round-trip.
crates/node/src/admin.rs Exposes voucher_signer on the admin channel snapshot surface.
crates/incentive/src/store.rs Updates incentive-store tests to the new ChannelState::hydrate ordering.
crates/incentive/src/payment_channel.rs Updates Rust sol! bindings: Channel tuple, openChannel signature, ChannelOpened event, and new close entrypoint.
crates/incentive/src/channel.rs Adds voucher_signer to ChannelState and verifies vouchers against it (plus new delegated-signer tests).
crates/e2e/src/client.rs Updates e2e buyer openChannel call to pass Address::ZERO.
crates/e2e/src/bindings.rs Updates duplicated buyer-side PaymentChannelOpen binding to new openChannel signature and documents duplication.
crates/common/src/admin.rs Extends ChannelSnapshot DTO with voucher_signer and preserves backward compatibility via #[serde(default)].
crates/client-pull/src/buyer_channel.rs Updates buyer open path to pass zero voucherSigner (self-signing default).
crates/cli/tests/admin_peers.rs Updates CLI admin test to assert voucher_signer is surfaced and distinct when delegated.
crates/cli/src/commands/node.rs Adds SIGNER column and legacy “unknown” rendering for missing voucher_signer.
contracts/test/PaymentChannel.t.sol Adds coverage for delegated signer behavior and voucher-less close/alias semantics.
contracts/test/InterfaceFreeze.t.sol Re-freezes openChannel selector and adds new selector for closeChannelWithoutVoucher.
contracts/test/E2EProtocol.t.sol Updates protocol e2e to the new openChannel signature.
contracts/src/PaymentChannel.sol Implements pinned voucherSigner, voucher-less close-at-watermark, and adds closeChannelWithoutVoucher.
contracts/.gas-snapshot Updates gas snapshot for new/changed contract paths.
CHANGELOG.md Records breaking ABI/event/tuple changes and the additive close entrypoint.
adr/glossary.md Updates glossary definitions for channel roles and voucher signer semantics.
adr/appendix-operator-key-rotation.md Updates operational guidance to account for pinned voucherSigner and voucher-less close.
adr/appendix-fraud-detection.md Updates stale-close detector semantics for voucher-less closes and signer recovery target.
adr/024-account-abstraction.md Updates account-abstraction ADR to reflect voucherSigner as the verification target and Safe-as-funder viability.
adr/016-contract-interactions.md Updates interface-surface wording and function signature reference.
adr/012-client.md Updates client key-role discussion and binding semantics keyed on pinned signer.
adr/005-protocol.md Updates binding description and WrongSigner semantics to reference pinned voucherSigner.
adr/003-payments.md Updates canonical payments ADR for role split, voucher-less close, cooperative close caller set, and verification target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/channel_store.rs Resolved
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.18% (was 81.10%, ▲ +0.08%) — 52667/64873 lines

File Coverage Lines Δ
crates/cli/src/commands/channel.rs 55.98% 426/761 ▲ +0.68%
crates/cli/src/commands/node.rs 84.26% 1065/1264 ▲ +0.46%
crates/client-pull/src/buyer_channel.rs 46.61% 103/221 ▲ +0.73%
crates/common/src/admin.rs 96.46% 191/198 ▲ +0.09%
crates/e2e/src/client.rs 0.00% 0/363 ● 0.00%
crates/incentive/src/channel.rs 96.34% 447/464 ▲ +0.18%
crates/incentive/src/store.rs 90.86% 169/186 ▲ +0.10%
crates/node/src/admin.rs 95.93% 1201/1252 ▲ +0.01%
crates/node/src/buyer_channel.rs 57.43% 1133/1973 ● 0.00%
crates/node/src/channel_store.rs 89.57% 1323/1477 ▲ +0.29%
crates/node/src/handlers/client/delivery.rs 94.44% 68/72 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 86.19% 231/268 ● 0.00%
crates/node/src/handlers/client/fill.rs 60.99% 111/182 ▲ +0.99%
crates/node/src/handlers/client/mod.rs 89.44% 644/720 ▲ +0.03%
crates/node/src/handlers/client/window.rs 84.91% 225/265 ▲ +1.13%
crates/node/src/payment_settlement.rs 58.36% 1012/1734 ▲ +1.80%
History
Commit Total Δ vs base
ca2a6f4 81.17% ▲ +0.06%
f189625 (HEAD) 81.18% ▲ +0.08%

…width

The pinned `voucher_signer` shipped as an untagged, fixed-width trailing
postcard segment whose presence was detected by `leftover.len() >= 20`.
That fails open: any record carrying >= 20 bytes of unknown trailer at
that position — a future additive segment, padding, a partial write — is
read as an address, moving the voucher signature-recovery target and
making the node verify against a key the chain will reject.

Bump `SUPPORTED_SCHEMA_VERSION` to 3 and read the segment only when
`schema_version >= 3`. v1/v2 records never wrote it, so their trailer is
left alone and `voucher_signer` hydrates from `client` — correct by
construction, since those channels predate the funder/signer split and
are self-signing. On v3 the segment is mandatory: `record` always emits
it, so absence or truncation is corruption and surfaces as
`StoreError::Corrupt` instead of silently defaulting.

Rollback is not supported: an older binary reading a v3 record raises
`UnsupportedSchema`, and the seller table is fail-closed, so startup
aborts. No production channels exist on disk yet.

Co-Authored-By: Claude Opus 5 <[email protected]>
alpergundogdu and others added 3 commits July 27, 2026 16:53
`pull_authorized` carried two ADR 011 origin-blacklist checks: an early
return on the *bound* address and a later one on `state.client`. The early
return predates the funder/signer split — the bound address was necessarily
the funder then, so it was a funder check that silently became a signer
check when `voucher_signer` was pinned separately.

ADR 011 makes the funding address the compliance subject: a takedown
sanctions the money, not whichever throwaway key signs the vouchers. Drop
the early return and keep the funder check, so this gate and the origin
gate in `dispatch.rs` agree on the subject.

Behaviour-preserving today (`voucher_signer == client` on every channel
that exists — no delegate surface has shipped). The unknown-channel case is
unaffected: the `None` arm below the lookup still returns `false`.

Co-Authored-By: Claude Opus 5 <[email protected]>
…lWithoutVoucher

No production path closed with the zero-voucher form of `closeChannel`: the
seller `send_close` and the buyer `close_unilateral` are both guarded on
holding a signed voucher, so they always present a real one. The one caller
that could reach an empty claim is the CLI `channel close`/`clean`, which
re-signs the persisted watermark unconditionally — including the all-zero
watermark of a channel opened but never drawn.

That branch is now `closeChannelWithoutVoucher`. It is not just cheaper:
`closeChannel` treats a signature of any length as a voucher to verify, so a
zero-amount voucher is still checked against the channel's pinned
`voucherSigner` — and once a channel can name a delegate, the funder's own
signature does not recover to it and the close reverts. The voucher-less
entry point is exactly the escape hatch for that case.

Both functions take `nonReentrant` only (neither is `whenNotPaused`, so exit
paths stay open under pause), gate on `_requireOpenAndUnexpired`, and admit
client or provider — so the switch preserves the caller set and the revert
conditions. Behaviour today is unchanged: with signer == funder on every
channel, both forms reach `_initiateClose` at the same watermark.

The anvil settlement e2e's three zero-voucher setup calls move over too, and
the binding declaration records why the node's own paths never use it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Precision-only fixes, no behaviour change:
- buyer_channel.rs: close_unilateral comment said the contract checks
  sig against `channel.client`; it checks `ch.voucherSigner`. Node
  self-signs today so its key is that signer.
- cli/channel.rs: submit_close's send-failure message named
  closeChannel even on the closeChannelWithoutVoucher branch; made
  neutral for both.
- cli/channel.rs: documented the residual gap in has_claim_watermark
  as a proxy for "holds an accepted key", unreachable today with no
  delegation CLI surface.
- channel_store.rs: CHANNEL_TABLE doc no longer implies additive-only
  segments on `_v1`; states the actual rule (table name tracks
  key/value shape, schema_version gates segment presence, a mandatory
  segment is reader-breaking and bumps SUPPORTED_SCHEMA_VERSION).
- channel_store.rs: kept the `<= SUPPORTED_SCHEMA_VERSION` conjunct in
  decode_record's voucher-signer branch (confirmed via
  future_schema_version_refuses_to_load failing under nextest when
  dropped) and documented why it is not dead: it defers rejection of
  an unknown future segment layout to into_state's clean
  UnsupportedSchema instead of a confusing Corrupt.

Co-Authored-By: Claude Opus 5 <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in f189625 (schema gate in bac6d96).

You and an internal reviewer landed on this independently, so rather than defer it I took the version-gate option you suggested: SUPPORTED_SCHEMA_VERSION is now 3, and the signer segment is read iff schema_version >= 3. Width is no longer part of the presence test, so unknown trailing bytes can't be misread as an address.

  • v1/v2 records — the trailer is never inspected; voucher_signer defaults to client. That default is correct by construction rather than by luck: any channel opened before this contract change is self-signing, because the old openChannel had no voucherSigner parameter.
  • v3 records — the segment is mandatory. Absence or truncation is now genuine corruption (StoreError::Corrupt) instead of a silent default.
  • v4+ — still refused by into_state with UnsupportedSchema.

The regression test is mutation-proven: v2_record_with_long_trailing_junk_does_not_hydrate_signer writes a v2 record with 24 bytes of 0xDE junk, and it fails against the old width gate (hydrating 0xdede…de as the signer) and passes with the version gate.

I went with the gate over a self-describing Option<[u8;20]> / TrailerV3 because the restructure would still need the version bump to tell an old tail from a new one — it's the gate plus a layout change, not an alternative to it.

One consequence worth flagging, since it's a real behavioural change and not free: a node that writes a v3 record and is then rolled back to an older binary will abort startup with UnsupportedSchema (the seller table is deliberately fail-closed, unlike the buyer table which logs and skips). That's recorded in CHANGELOG.md with the remedy. Acceptable here because there are no production channels on disk yet — which is also the argument for doing this now rather than after the testnet deploy.

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.

PaymentChannel: delegated voucherSigner + voucher-less close

2 participants