Skip to content

fix(node): clamp a presented capability to the signer's on-chain registration - #2266

Merged
alpergundogdu merged 2 commits into
mainfrom
fix/2265-clamp-capability-onchain
Oct 1, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
fix/2265-clamp-capability-onchain

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #2265.

Problem

On-chain registration is write-once per (pool, signer). A node held the cap and expiry of the capability the client presented, not the registered terms. A pool owner could register signer S with a small capability A, then present a wider capability B for S at another node. That node served under B's terms, and every voucher past A's cap redeemed to 0.

The new e2e test reproduces it on unmodified main (first commit):

the node accepted 161 µUSDC of vouchers under capability B, past the delegate's
registered cap of 40 µUSDC; the chain pays 40 µUSDC and the remaining 121 µUSDC redeems to 0

Fix

  • Admission. The admit path already read getAuthorization for cap − spent headroom (fix(node): confirm signer cap headroom on-chain before admitting a serve #1958) but dropped the registered terms. The PoolView method is now signer_authorization, returning Unregistered or Registered { cap, expiry, spent }. Admission refuses a registered signer whose registration has expired, as well as one whose cap − spent can't cover a floor. The refusal reason is still SignerCapExhausted, so the wire is unchanged.
  • Clamp. For a registered signer, the live lane holds min(presented, registered) for cap and expiry and records registered_until. The lane is recorded to the store under the per-lane lock (LaneState::clamp_to_registration, ClientHandler::clamp_lane_to_registration). This applies to new lanes and to existing lanes on their next stream. The voucher path then refuses past the registered cap (SpendingCapExhausted) or expiry (CapabilityExpired), and the mid-stream signer re-check reads the clamped held_cap.
  • No extra RPC and no new cache. The terms come from the read admission already makes. Registered cap/expiry are write-once and persist on the lane. Only spent goes stale, and the existing 1-minute TTL covers that.
  • On-disk format. Unchanged. The clamped terms live in the existing cap/expiry/registered_until fields.
  • Redemption. After a landed redeemMany that carried CapabilityRegs, the node reads getAuthorizations once for those lanes and persists the chain's registered expiry, not the attached reg.expiry. If that read fails, nothing is persisted. The next sweep re-attaches the reg (an on-chain no-op) and reads again.
  • ADRs. ADR 003 covers the write-once registration under Capability delegation, the admission gate and clamp, held_cap in the mid-stream re-check, and a new residual. ADR 005 updates the client guidance for SpendingCapExhausted and CapabilityExpired: a registered signer needs a new key, not a fresh capability for the same key.

Needs a maintainer decision

  1. The issue's open decision is not decided here. If two capabilities are presented for a signer that is not yet registered, the first to land wins. A node holding the other capability can over-serve until its next stream admission for that signer, or until its own first redemption lands. The options are to accept this bounded window or to redeem early for a signer the node has not seen registered. This is documented as an open residual in ADR 003 § Pool solvency, Residuals.
  2. [your call] Step 3 corrects a watermark; it does not stop a loss. registered_until only gates whether the planner attaches a CapabilityReg, and that attach is a harmless no-op for an already-registered signer. The admission clamp is what stops the loss. Step 3 costs one eth_call per landed chunk that carried registrations. Keep it, or drop it as surface?

Tests

  • e2e cli_fetch_delegated::presented_capability_is_clamped_to_the_signers_registered_terms: registers A via a capability-only redeemMany, fetches with B, and asserts the node accepted no more than A's cap and that every accepted voucher redeems. Fails on main, passes here.
  • Unit tests: clamp_to_registration (lower terms, zero-expiry mapping), SignerAuthorization view and cache tests (including the expired registration), the handler live-lane clamp with store persistence, and the post-redeem expiry read (chain expiry wins; a failed read persists nothing).

🤖 Generated with Claude Code

alpergundogdu and others added 2 commits October 1, 2026 15:03
…stration (#2265)

On-chain registration is write-once per (pool, signer), so a voucher past
the registered cap or expiry redeems to nothing. Admission now keeps the
registered terms from its existing getAuthorization read, refuses an
expired registration, and clamps the lane to min(presented, registered).
After a landed registration the redeemer persists the chain's registered
expiry instead of the attached capability's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:24

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 9ffcd09 in the fix/2265-clamp-capab... branch remains at 87%, unchanged from commit f6de71c in the main branch.

Show a line coverage summary of the most impacted files.
File main f6de71c fix/2265-clamp-capab... 9ffcd09 +/-
crates/node/src...s/client/mod.rs 96% 95% -1%
crates/node/src...t_settlement.rs 83% 83% 0%
crates/node/src/dht/publish.rs 92% 92% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/incentive/src/lane.rs 95% 95% 0%
crates/node/src...gin/pull_leg.rs 90% 90% 0%
crates/node/src...ent/dispatch.rs 82% 82% 0%
crates/node/src/pool_view.rs 98% 98% 0%
crates/node/src...nt/serve_leg.rs 91% 92% +1%

@alpergundogdu
alpergundogdu merged commit 6e1f8b4 into main Oct 1, 2026
30 of 31 checks passed
@alpergundogdu
alpergundogdu deleted the fix/2265-clamp-capability-onchain branch October 1, 2026 16:19
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.

fix(node): clamp a presented capability to the signer's on-chain registration

2 participants