Skip to content

feat(psbt): reject dust recipients unless allow_dust is set - #650

Open
LakshyaBagani wants to merge 2 commits into
bitcoindevkit:masterfrom
LakshyaBagani:issue-632
Open

LakshyaBagani wants to merge 2 commits into
bitcoindevkit:masterfrom
LakshyaBagani:issue-632

Conversation

@LakshyaBagani

Copy link
Copy Markdown

Description

Part of #632. This covers the allow_dust parity item.

TxBuilder rejects a recipient whose amount is below the dust limit unless TxBuilder::allow_dust is set. Wallet::create_psbt and Wallet::replace_by_fee did not check recipient amounts at all, so they built non-standard transactions with dust or zero-value outputs and returned no error.

This pull request adds PsbtParams::allow_dust and a CreatePsbtError::OutputBelowDustLimit(index) variant. Both entry points now check the recipients before coin selection with the same rule as TxBuilder: an amount below Script::minimal_non_dust for its script is rejected, and OP_RETURN outputs have a dust limit of zero. The allow_dust setting carries over through replace_txs.

Notes to the reviewers

  • This changes the default behaviour of the unstable create_psbt and replace_by_fee APIs. A recipient below the dust limit now returns an error unless allow_dust(true) is set.
  • The check lives in PsbtParams::check_recipients in bdk_wallet. Implement builder interface for SelectorParams. bdk-tx#41 plans a validating builder for SelectorParams that would also reject dust recipients, and I am happy to move the check there if you prefer.
  • CreatePsbtError is #[non_exhaustive], so adding the variant does not break the type.
  • The create_psbt documentation example sent Amount::ZERO, which the new check rejects, so it now sends 50 000 satoshis. The AllOutputsBelowDust documentation now says it only happens in a sweep with no recipients, because recipients are never dropped.
  • The fee_absolute parity item is not part of this pull request.
  • I checked this locally with toolchain 1.96.0: RUSTFLAGS="--cfg bdk_wallet_unstable" cargo test --workspace --all-features, the stable feature test suite, cargo clippy and cargo doc with -D warnings on both the stable and unstable surfaces, the no_std checks, and cargo fmt --all --check.

Changelog notice

  • Wallet::create_psbt and Wallet::replace_by_fee now return CreatePsbtError::OutputBelowDustLimit when a recipient's amount is below the dust limit. Use the new PsbtParams::allow_dust to allow it.

Before submitting

`TxBuilder` rejects a recipient whose amount is below the dust limit
with `CreateTxError::OutputBelowDustLimit`, unless
`TxBuilder::allow_dust` is set. `create_psbt` and `replace_by_fee`
never checked recipient amounts, so they built non-standard
transactions with dust or zero-value outputs and returned no error.

Add `PsbtParams::allow_dust` and a
`CreatePsbtError::OutputBelowDustLimit(index)` variant. Both entry
points now call `PsbtParams::check_recipients` before coin selection.
It rejects an amount below the dust limit of its script, which is
zero for `OP_RETURN` outputs. `allow_dust` carries over through
`replace_txs`.

This changes the default behaviour of the unstable `create_psbt` and
`replace_by_fee` APIs. The `create_psbt` doc example sent
`Amount::ZERO`, so it now sends 50 000 sats. The `AllOutputsBelowDust`
doc now says it only happens in a sweep with no recipients.

Part of bitcoindevkit#632.
Check that `create_psbt` accepts an amount equal to the dust limit and
rejects one sat less, reporting the index of that recipient. A
zero-value recipient is rejected by default and kept with
`allow_dust`, and a zero-value `OP_RETURN` output needs no
`allow_dust`. `replace_by_fee` applies the same rule, and `allow_dust`
set before `replace_txs` carries over to the replacement.

Part of bitcoindevkit#632.
@LakshyaBagani
LakshyaBagani requested a review from a team as a code owner November 12, 2026 11:40
@LakshyaBagani

Copy link
Copy Markdown
Author

@reez @oleonardolima This pull request covers the allow_dust item from #632. Could you review it when you have time? I am happy to move the check into bdk-tx if bitcoindevkit/bdk-tx#41 is the preferred place for it.

This branch has not been deployed

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant