Skip to content

fix(bond): reject malformed pay-bond-invoice payloads (empty invoice, zero amount) #477

Description

@grunch

Problem

classify_take_reply (rust/src/mostro/pending.rs) accepts a malformed pay-bond-invoice reply as a successful take:

  • A PaymentRequest payload with an empty invoice is returned as TakeAccepted with bond: Some(BondRequest { invoice: "" , .. }).
  • The bond amount falls back to 0 (.unwrap_or(0)) when both amount and the SmallOrder amount are absent, zero or negative — u64::try_from only rejects negatives, so 0 also passes.

Those values flow through bond_requested into BondInfo and get persisted on the trade row, parking the trade at WaitingTakerBond with a bond the user cannot pay.

Expected

Only a non-empty bolt11 invoice with a positive bond amount yields TakeAccepted with WaitingTakerBond. Anything else is Rejected { reason: "InvalidBondInvoice" }, the same marker already used for a non-PaymentRequest payload.

Tasks

  • Reject an empty invoice in the Action::PayBondInvoice branch.
  • Drop the unwrap_or(0) fallback; require the resolved amount to be > 0.
  • Unit tests: empty invoice, amount absent, amount zero, amount negative (both the amount field and the SmallOrder fallback).
  • Check whether the maker-side bond path (add-bond-invoice / order creation) has the same fallback.

Context

Flagged by CodeRabbit on #407 (#407 (review)) as an outside-diff finding. The code predates #407 (it landed with the taker bond work, see #208), so it was split out rather than blocking that PR. See docs/ANTI_ABUSE_BOND.md §6.1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions