Skip to content

feat: enforce a minimum output value in created transactions (discussion first) #394

Backlog

Description

@emma31-dev

Summary

create_tx, create_sp_tx, and create_dns_tx currently accept any recipient amount and rely on bdk_wallet's dust check at build time. That gives two gaps:

  1. There is no way to enforce a higher minimum output than the relay dust threshold, e.g. 1,000 sats, to avoid creating uneconomical UTXOs.
  2. The error surfaced for a too-small output is not useful: bdk_wallet returns CreateTxError::OutputBelowDustLimit(index), whose Display is Output below the dust limit: {index}. The number is the output index, not the amount or the required threshold, and it does not identify which recipient failed.

For silent-payment and DNS-derived outputs the amount is not written as a plain address:amount pair, so accidentally creating a dust-level output is easy and hard to diagnose.

Current behaviour

  • bdk_wallet's TxBuilder checks recipients against Script::minimal_non_dust() when allow_dust is false, which is the default. So below-dust explicit recipients are already rejected at build time.
  • Script::minimal_non_dust() uses Bitcoin Core's default -dustrelayfee of 3 sat/vB. A node configured differently may accept or reject different outputs.
  • bdk-cli parses amounts in parse_recipient, parse_sp_code_value_pairs, and parse_dns_recipient but does not validate the value against dust or any configured minimum.
  • --send_all drains to a single output; change below dust is folded into the fee by bdk_wallet.

Proposal (for discussion)

  1. Validate every explicit recipient amount at the CLI boundary, before building, using the recipient script's minimal_non_dust() (OP_RETURN exempt).
  2. Allow a configurable floor above dust, for example:
    • --min-output-sats <SATOSHIS> on the create commands, and/or
    • min_output_sats per wallet in config.toml.
      Effective minimum = max(dust for that script, configured floor). Default remains the dust threshold.
  3. Apply the same check to DNS and silent-payment derived outputs, using the P2TR dust threshold.
  4. Return an error that names the recipient (address, silent payment code, or DNS name), the amount, the required minimum, and where the minimum came from (dust vs configured floor).
  5. Decide --send_all behaviour when the drained amount is below the minimum: reject, or allow with a warning.
  6. Decide whether bump_fee and payjoin need the same guard.

Open questions

  • Does a configurable minimum belong in bdk-cli, in bdk_wallet, or both? Dust is already a wallet concern, but a higher floor is an application/UX choice.
  • Should the floor apply to change outputs too? Applying it there could silently push change into fees, which may surprise users.
  • Should outputs above dust but below the floor be a hard error or a warning?
  • Flag/config naming and units (--min-output-sats vs --min-output, sats vs BTC).
  • Should an explicit opt-out exist for deliberate dust outputs (e.g. for testing or dust attacks)?

Discussion first

This is a discussion issue, not a ready-to-implement task. Please don't pick it up immediately or open a PR until the scope and API are agreed, especially whether this belongs in bdk-cli, bdk_wallet, or both. I'd rather settle the design here first.

References

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

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions