Skip to content

fix(node): refuse before serving when deposit can't cover the next interval #1516

Closed

Description

@alpergundogdu

Off-by-one fix. The seller signs a success StreamResponse and ships up to one voucher interval (~1 MB) before the per-voucher deposit ceiling can fire, so a channel that can't cover even the first interval still gets ~1 interval served.

  • Change: in the serve path before signing (crates/node/src/handlers/client/dispatch.rs:515-603, sign at :584, deliver at :589), compute next-interval cost = interval_bytes × rate_per_mb; if the cached channel deposit is below it, refuse rather than sign+serve.
  • Refusal signaling: prefer InsufficientDeposit
  • The per-voucher ceiling check (crates/incentive/src/channel.rs:401) stays as the mid-stream backstop.
  • Out of scope: interval size / rate logic.
  • Acceptance: a request against a channel that can't cover one interval serves zero bytes; a channel that covers ≥1 interval serves normally.

Activity

  1. added
    kind:bug
    prio:high
    rust
    kind:security
    on Jul 29, 2026
  2. github-actions commented on Jul 29, 2026

    @github-actions

    🎯 Triage report

    The seller-side dispatch path signs a StreamResponse and delivers up to one voucher interval (~1 MB) before the per-voucher ceiling in incentive/src/channel.rs:401 fires, meaning a channel whose deposit can't cover even the first interval still receives ~1 MB of service gratis. The fix is a pre-flight check in node/src/handlers/client/dispatch.rs (around line 515–584) that computes next_interval_cost = interval_bytes × rate_per_mb and refuses with InsufficientDeposit before signing if the cached deposit is below that threshold.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Off-by-one in deposit sufficiency check — economically exploitable correctness defect
    Labels bug, security, rust, high Economic exploit; underfunded channels get ~1 MB free; fix is pure Rust in node + incentive crates
    Coding agent Suitable Requirements are precise: add a pre-flight deposit check before signing at dispatch.rs:584, return InsufficientDeposit if deposit < interval_bytes × rate_per_mb. Scope is explicitly bounded (no changes to interval size/rate logic). Acceptance criteria stated.

    🔗 Similar issues

    💡 Notes and suggestions

    Key locations:

    • crates/node/src/handlers/client/dispatch.rs lines 515–603 — serve path; signing happens at ~584, delivery at ~589. The pre-flight check belongs here, before the sign.
    • crates/incentive/src/channel.rs:401 — existing per-voucher ceiling check; this stays as the mid-stream backstop.

    Implementation checklist:

    • Read channel.cached_deposit (or equivalent) at the start of the serve path.
    • Compute next_interval_cost = interval_bytes * rate_per_mb / 1_000_000 (confirm unit convention in the crate).
    • If cached_deposit < next_interval_cost, return InsufficientDeposit error before calling sign.
    • Ensure the refusal path does not sign or ship any bytes.
    • Add a unit test: channel with deposit = next_interval_cost - 1 must serve 0 bytes; channel with deposit = next_interval_cost must serve normally.

    Anti-panic note: The workspace denies unwrap_used/expect_used — use checked_mul or saturating_mul for the cost arithmetic, and handle the None branch.

    Acceptance criteria (from issue): a request against a channel that can't cover one interval serves zero bytes; a channel that covers ≥1 interval serves normally.

    Generated by Agentic Triage for #1516 · sonnet46 · 23.6 AIC · ⌖ 8.44 AIC · ⊞ 6.2K · ◷

    Add this agentic workflow to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on Jul 29, 2026
  4. added 2 commits that reference this issue on Jul 29, 2026
    841ddfe
    6a4c0cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:securityprio:highrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions