Skip to content

[Bug] Coin Selection Fails Due to Insufficient Fee Accounting in Balance Check #692

@NeoZ666

Description

@NeoZ666

Summary

The coin_select function incorrectly determines whether regular or swap UTXOs can cover a transaction by only checking if the target amount is available, without accounting for estimated transaction fees. This causes coin selection to fail even when sufficient total balance exists.

Problem Description

Root Cause

The can_use_regular and can_use_swap boolean flags were computed using only the target amount:

// (Thi is Buggy) behavior)
let can_use_regular = target_sats <= regular_total;
let can_use_swap = target_sats <= swap_total;

This creates an edge case where:

  1. can_use_regular is flagged as true (e.g., 29,000 <= 29,296)
  2. The function attempts coin selection with regular UTXOs
  3. Coin selection fails because target + estimated_fee > regular_total (e.g., 29,000 + 324 = 29,324 > 29,296 becomes false after coinselect's overshoot)
  4. The function returns an error instead of falling back to swap UTXOs

FUrthermore

The rust-coinselect library can overshoot the fee estimate by a few satoshis above the estimated_fee + target range, making this issue more pronounced when:

  • The target amount is small
  • Regular UTXO balance is just barely above the target
  • Swap UTXO balance has sufficient funds to cover target + fees + overshoot

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