Skip to content

Guard coin selection against inputs that don't cover their fee - #2165

Merged
nullPointerEnjoyer merged 5 commits into
mintlayer:masterfrom
oliv3rdrt:guard_dust_inputs
Nov 19, 2026
Merged

nullPointerEnjoyer merged 5 commits into
mintlayer:masterfrom
oliv3rdrt:guard_dust_inputs

Conversation

@oliv3rdrt

@oliv3rdrt oliv3rdrt commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

OutputGroup::get_effective_value subtracts an input's fee from its value and panics via expect if the fee is larger. As nullPointerEnjoyer pointed out on #2094, nothing in the selector enforces that. Today the wallet builds its groups in utxo_output_groups_by_currency, which already drops coin inputs with value <= fee, so I don't think users can hit the panic right now. But select_coins depends on a filter in another module, so a new caller or a refactor could bring it back.

Fix

When fees are paid with the inputs' currency, select_coins now leaves out groups whose value doesn't exceed their fee before running any algorithm. It's the same rule the wallet already applies, so behaviour doesn't change, and it covers SRD, knapsack, BnB and preselected inputs. It also covers both pools in select_coins_preferring_confirmed from #2095, since that goes through select_coins. Inputs whose fee is paid with another currency (tokens) are left alone, since their fee doesn't reduce their value.

I kept the filter in utxo_output_groups_by_currency because it also feeds the input count used for the fee estimate.

Tests

  • test_select_coins_skips_inputs_not_covering_their_fee: a pool with one input worth less than its fee and one worth exactly its fee. Neither is selected with either algorithm. Panics without the fix.
  • test_select_coins_no_inputs_covering_their_fee: a pool with only such inputs returns NoUtxos instead of panicking. Panics without the fix.
  • test_select_coins_keeps_inputs_when_fee_paid_with_other_currency: checks the guard doesn't drop inputs when another currency pays the fee.

cargo test -p wallet --lib, cargo fmt --check and clippy with the CI flags pass locally.

get_effective_value expects an input's fee to be less than its value and
panics otherwise, but select_coins relied on its caller to filter such
inputs out. When fees are paid with the inputs' currency, select_coins now
leaves them out itself before running any algorithm.
- cross-reference comments on both filter sites (select_coins guard is
  authoritative; the caller keeps a copy only for the conservative
  input-count estimate)
- note the pre-existing silent omission of preselected dust inputs
- seed the fee-coverage test per the file convention (assertions are
  shuffle-independent)
@nullPointerEnjoyer
nullPointerEnjoyer merged commit cc4fb82 into mintlayer:master Nov 19, 2026
19 checks passed
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.

3 participants