Repository navigation
feat(incentive): stream slash-sig, BindNodeId verify, wire-voucher bridge (#317) [2/3] - #732
Conversation
There was a problem hiding this comment.
Pull request overview
Adds the off-chain cryptography/translation layer needed by the upcoming cdn/client/v1 handler/requester: EIP-712 signing/verification for stream slashing evidence, verification of ephemeral client NodeId↔EOA bindings, and a bridge between protocol “wire” vouchers and the incentive channel/voucher types.
Changes:
- Introduce
StreamSlashData(EIP-712 typed data) forStreamResponseBodyslash_sigsigning/recovery/verification with canonical digest and tamper-guard tests. - Add
BindNodeIdEIP-712 verification (verify_binding) for ephemeral client bindings under theCapacityBonddomain. - Add
client_bridgehelpers to convert between wire vouchers andSignedVoucher, plus an exhaustiveChannelError → VoucherRejectReasonmapping (with transientStoresignaled as retry).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/incentive/src/stream_sig.rs | New EIP-712 struct + signing/recovery/verification for StreamResponse slash_sig, with strong digest/type-hash tests. |
| crates/incentive/src/bind_sig.rs | New EIP-712 domain + verification helper for BindNodeId ephemeral bindings. |
| crates/incentive/src/client_bridge.rs | New conversion layer between protocol wire vouchers and incentive SignedVoucher, plus rejection mapping/retry signal. |
| crates/incentive/src/lib.rs | Exposes the new modules and re-exports their public API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces three new modules to the incentive crate: bind_sig for ephemeral client binding verification, client_bridge to bridge wire vouchers with the state machine, and stream_sig for EIP-712 stream response signatures. The review feedback highlights two important improvements: importing Signature from alloy::primitives in bind_sig.rs for consistency, and changing voucher_reject_reason from a const fn to a regular pub fn in client_bridge.rs to avoid potential compilation issues when matching on types with non-trivial destructors like std::io::Error.
Introduce `crates/protocol/src/client.rs` with the `ClientMessage` enum and
all `cdn/client/v1` payload types per ADR 005 §`cdn/client/v1` and ADR 014 §1:
- `StreamRequest` (frozen base fields only) plus `StreamRequestExt` for
voucher-interval negotiation and the ephemeral client NodeId↔Ethereum
binding. The ext is carried as separate trailing bytes via the ADR 005
two-phase deserialization pattern (`encode_stream_request` /
`parse_stream_request_ext`) — keeping the base frozen so a future ext field
stays Tier-1 backward-compatible (old senders emit fewer trailing bytes; new
optional fields are appended and old receivers skip them).
- `StreamResponse` (signed `StreamResponseBody` + unsigned `error` /
`voucher_interval_mb` + 65-byte `slash_sig`)
- `ChunkData`, `Voucher` (wire `{signature, amount, nonce}` with u256 fields as
big-endian bytes — the leaf crate has no `U256`), `VoucherAck`, `StreamEnd`
- `StreamError` / `VoucherRejectReason` (frozen variant order, mirroring
`decdn_incentive::ChannelError` ∪ `VoucherError`)
`StreamResponse::validate()` and `ProbeResponse::validate()` both reject
`rate_per_mb == 0` on receive (#252) via a shared `MessageValidationError::
RateIsZero`; the rate-decode hook is shared (`pub(crate)`). Validation error
text is response-type-neutral so it reads correctly for both probe and stream
responses. Adds constants (`CHUNK_SIZE`, `MB_BYTES`, voucher-interval bounds,
`VOUCHER_SIG_LEN`) and a full test suite: per-variant discriminant pins,
roundtrips, fixed-byte wire-stability, two-phase ext (incl. forward-compat),
validation, and a full framing-stack roundtrip.
Leaf crate only — no behavior. Handler (node) and voucher logic (incentive)
follow in stacked PRs.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ae7472c to
db01cbb
Compare
de4a504 to
5454a3a
Compare
… seam Address PR review findings on the cdn/client/v1 wire types: several real invariants lived only in doc comments. Convert them into enforced checks on MessageValidationError-returning validate() methods. - Enforce voucher_interval_mb ∈ 1..=MAX_VOUCHER_INTERVAL_MB on both StreamResponse and the new StreamRequestExt::validate, closing the unbounded unvouchered-byte window (and interval * MB_BYTES u64 overflow). - Add StreamResponse ok/error consistency rules (ok=true ⇒ no error; ok=false ⇒ exactly one delivery-side error; never mid-stream-only VoucherRejected) via StreamErrorWithOk / MissingStreamError / VoucherRejectedInResponse. - Group StreamRequestExt.ethereum_address + binding_signature into Option<ClientBinding> so a half-populated binding is unrepresentable, add BINDING_SIG_LEN + ClientBinding::validate length check. - Add ClientMessage::validate dispatcher as the single decode-then-validate seam, and StreamError::is_delivery_side/is_mid_stream to express the error-domain split in code. - Fix docs: drop the non-existent decdn_incentive::StreamSlashData references (3 sites) for an analogous-to-ProbeSlashData forward note; relabel MAX_VOUCHER_INTERVAL_MB as the hardcoded ceiling, not governable. - Tests (+18): malformed ext remainder rejection, interval bounds, decode roundtrip in variant-order loops, empty ChunkData, non-zero byte_offset, ok/error consistency, ClientBinding, dispatcher, domain-split accessors. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…idge (#317) Adds the off-chain crypto/conversion layer the `cdn/client/v1` handler and requester need (#317), all mirroring the existing `probe_sig`/`voucher` patterns: - `stream_sig.rs` — `StreamSlashData`, the EIP-712 signed view of a `StreamResponse` (`{hash, ok, ratePerMb, totalBytes, channelId, timestampUs, redirect}`) over the shared `SlashJudge` domain (ADR 014 §1). Includes a `from_response_body` helper (`redirect: Option<NodeId>` → `bytes32(0)`/bytes) and an independent EIP-712 digest reconstruction test, plus type-hash and per-field tamper guards. - `bind_sig.rs` — `verify_binding` for the ephemeral client `BindNodeId(nodeId, nonce=0)` binding (ADR 003 §Off-Chain Ephemeral Binding), EOA `ecrecover` against the `CapacityBond` domain. ERC-1271 (ADR 024) deferred. - `client_bridge.rs` — `wire_voucher_to_signed` / `signed_to_wire_voucher` (reconstructing `channel_id`/`token`/`bytes_delivered` from stream context, u256 as big-endian bytes) and `voucher_reject_reason`, an exhaustive `ChannelError` → `VoucherRejectReason` map (no wildcard, so a new variant fails to compile) with `Store(_)` → `RetrySignal` (transient, never a wire rejection — #527). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
5454a3a to
0e243d3
Compare
Coverage reportTotal: 89.83% (was 89.66%, ▲ +0.16%) — 23172/25796 lines
History
|
alpergundogdu
left a comment
There was a problem hiding this comment.
Review — ADR consistency (PR 732, reviewed together with #733)
Reviewed the full stack (this branch still carries #731's two protocol commits since #731 isn't merged to main yet, so the diff vs main includes client.rs/message.rs — I read them as context but focused findings on the parts this PR owns plus the incentive layer).
Overall the crypto/conversion layer is faithful to the ADRs. Things I verified as consistent:
StreamResponseEIP-712 struct (stream_sig.rs) is byte-for-byte the type string in ADR 014 §EIP-712 Type Definitions (StreamResponse(bytes32 hash,bool ok,uint64 ratePerMb,uint64 totalBytes,bytes32 channelId,uint64 timestampUs,bytes32 redirect)), and theredirect: None → bytes32(0)mapping matches ADR 014 §1. The independent canonical-digest test is a nice drift guard.BindNodeId(bytes32 nodeId,uint64 nonce)withnonce = 0over theCapacityBonddomain matches ADR 003 §Off-Chain Ephemeral Binding + §Binding Message Format; EOA-only with ERC-1271 deferred is exactly ADR 024 §Off-Chain ERC-1271 Verification.VoucherRejectReasonvariant order and the frozenClientMessage/StreamErrordiscriminants match the enums in ADR 005 §VoucherRejected semantics and the freezing rules in ADR 013 §Protocol Enums.- Zero-rate (#252) + mandatory 65-byte
slash_sigvalidation match ADR 014 §1 / ADR 005 §Rate bounds.
Finding 1 (moderate) — ADR 005 §Voucher wire format is missing bytesDelivered
client_bridge.rs (and the client.rs Voucher doc) reconstruct the full typed data as {channelId, amount, nonce, bytesDelivered, token} and cite ADR 005 §Voucher wire format. But ADR 005 actually says:
The EIP-712 signed data covers the full structure from ADR 003:
{channelId, amount, nonce, token}. … the rest are derived from stream context —channel_idis inStreamRequestandtokenis fixed at channel open.
That field list (and the "derived = channel_id + token" prose) omits bytesDelivered. The canonical type in ADR 003 §324 / §598 (VOUCHER_TYPEHASH = "Voucher(bytes32 channelId,uint256 amount,uint256 nonce,uint256 bytesDelivered,address token)") includes it, and the implementation correctly follows ADR 003. So the code is right; ADR 005 §Voucher wire format is stale and should be corrected to list the 5-field structure and note bytesDelivered as a third stream-context-derived field. As written, the section the PR cites contradicts what the PR implements.
Finding 2 (minor) — voucher_reject_reason signature/mirror drift vs ADR 005 §Mirror obligation
ADR 005 §Mirror obligation specifies the conversion as fn voucher_reject_reason(&ChannelError) -> VoucherRejectReason and describes the mirror as "ChannelError ∪ VoucherError minus the Signature wrapper." The implementation is fn voucher_reject_reason(&ChannelError) -> Result<VoucherRejectReason, RetrySignal> and additionally excludes the transient ChannelError::Store variant (mapped to RetrySignal, not a reject reason). This is a reasonable design — and the no-wildcard exhaustive match obligation is honored — but the ADR's stated return type and the "minus the Signature wrapper" wording (which should also say "and the transient Store variant", returning a Result) are now out of date. Worth a one-line ADR 005 update so the spec matches the compile-enforced shape.
The Store → RetrySignal decision is the protocol-layer half of a larger divergence from ADR 003 §Off-chain voucher state persistence — see my detailed note on #733, where the handler resolves it by tearing down the stream rather than sending the in-band transient wire rejection ADR 003 §332 calls for. These two should be reconciled together (either a transient VoucherRejectReason lands here, or ADR 003 §332 is updated).
None of these block merge of the stack; they're ADR-vs-code reconciliations (Finding 1 is the one most worth fixing, since the cited section directly contradicts the implementation).
Generated by Claude Code
…with code (#317) ADR-vs-code reconciliations from Alper's #732 review; the code is canonical, the prose was stale. - ADR 005 §Voucher wire format listed the typed data as the 4-field {channelId, amount, nonce, token}, omitting bytesDelivered. Corrected to the 5-field VOUCHER_TYPEHASH (ADR 003 §598) and noted bytesDelivered as a third stream-context-derived field (node's per-channel counter). - ADR 003 §904 had the inverse error — it claimed bytesDelivered is transmitted on the wire. The protocol Voucher struct carries only {signature, amount, nonce}; corrected to mark bytesDelivered derived. - ADR 005 §Mirror obligation: return type updated to Result<VoucherRejectReason, RetrySignal>, excluded the transient ChannelError::Store variant, and flagged the handler-side wire surfacing of transient store failures as an open reconciliation with ADR 003 §Off-chain voucher state persistence (deferred to #733). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Stacked PR 2 of 3 for #317 — base
feat/317-client-protocol-types(#731). Review/merge after [1/3]. Followed by [3/3] node handler+requester.What
The off-chain crypto/conversion layer the
cdn/client/v1handler and requester need, all mirroring the existingprobe_sig/voucherpatterns:stream_sig.rs—StreamSlashData, the EIP-712 signed view of aStreamResponse({hash, ok, ratePerMb, totalBytes, channelId, timestampUs, redirect}) over the sharedSlashJudgedomain (ADR 014 §1). Includesfrom_response_body(redirect: Option<NodeId>→bytes32(0)/bytes), an independent EIP-712 digest reconstruction test, type-hash, and per-field tamper guards.bind_sig.rs—verify_bindingfor the ephemeral clientBindNodeId(nodeId, nonce=0)binding (ADR 003 §Off-Chain Ephemeral Binding), EOAecrecoveragainst theCapacityBonddomain. ERC-1271 (ADR 024) deferred.client_bridge.rs—wire_voucher_to_signed/signed_to_wire_voucher(reconstructingchannel_id/token/bytes_deliveredfrom stream context) andvoucher_reject_reason, an exhaustiveChannelError → VoucherRejectReasonmap (no wildcard, so a new variant fails to compile) withStore(_) → RetrySignal(transient, never a wire rejection — incentive: no replay-protection window enforced on incoming voucher nonces, allowing a client to resubmit a previously accepted voucher after a node restart and receive a second byte-delivery for the same payment #527).Tests
Full mirror of the
probe_sigsuite forstream_sig,bind_siground-trip/tamper, andclient_bridgeroundtrip + exhaustiveness.cargo nextest run -p decdn-incentivegreen; clippy/doc clean.🤖 Generated with Claude Code