Skip to content

Silent Payments: Sending (take 2) - #35302

Open
Eunovo wants to merge 16 commits into
bitcoin:masterfrom
Eunovo:implement-bip352-sending
Open

Eunovo wants to merge 16 commits into
bitcoin:masterfrom
Eunovo:implement-bip352-sending

Conversation

@Eunovo

@Eunovo Eunovo commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR is part of integrating silent payments into Bitcoin Core. It is the second iteration of #28201. Status and tracking for the project is managed in #28536

Prerequisite PRs:

Sending

Silent Payments logic
Key things to note in this PR:

  • PaymentDestination is added to contain CTxDestination or SilentPaymentsDestination
  • coin selection logic for silent payments requires at least one shared secret derivation-eligible coin to be present in the result set
  • recipient silent payments destinations are now persisted to the wallet to make it possible to RBF
  • silent payment txs created on the latest wallet software then loaded into older software are not replaceable
  • any operation that produces a silent payments tx that is not safe to fee bump later is blocked; this includes operations that create psbts and send with add_to_wallet=False

@DrahtBot

DrahtBot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK rkrux, w0xlt, rustaceanrob, polespinasa, davidgumberg
Stale ACK Yudis-bit, fametrano

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37017 (wallet: Use util::Result for fee bumping methods by rustaceanrob)
  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36978 (rpc: require a hex string for OP_RETURN data by l0rinc)
  • #36976 (rpc: Use OBJ_NAMED_PARAMS in estimatesmartfee by maflcko)
  • #36962 (wallet/feebumper: reject an original_change_index output without a destination by Eunovo)
  • #36946 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
  • #36897 (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101)
  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36823 (wallet, migration: Skip legacy wallet records rather than erasing them, and drop unused record erase functions by achow101)
  • #36167 (build: Enable -Wunused by fanquake)
  • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
  • #35444 (wallet: make descriptor SPKM mutex non-recursive by w0xlt)
  • #34872 (wallet: fix mixed-input transaction accounting in history RPCs by w0xlt)
  • #34698 (wallet: handle MiniMiner bump fee calculation failures by shuv-amp)
  • #34405 (wallet: skip APS when no partial spend exists by 8144225309)
  • #32857 (wallet: allow skipping script paths by Sjors)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
  • #27260 (Enhanced error messages for invalid network prefix during address parsing. by portlandhodl)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • src/wallet/spend.cpp: CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, new_coin_control, false)

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/wallet_sendall.py: assert 0 < self.wallet.getbalances()["mine"]["trusted"] → Prefer assert_greater_than(self.wallet.getbalances()["mine"]["trusted"], 0).

2026-12-03 14:42:53

@rkrux

rkrux commented May 20, 2026

Copy link
Copy Markdown
Contributor

Concept ACK 03c835d

Comment thread src/wallet/scriptpubkeyman.cpp Resolved
Comment thread src/wallet/scriptpubkeyman.cpp Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved
Comment thread src/wallet/rpc/spend.cpp Resolved
@Eunovo

Eunovo commented May 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@theStack I'll attend to your reviews when I rebase on #35301

@DrahtBot

DrahtBot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/27090770600/job/79953877713
LLM reason (✨ experimental): (empty)

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@Eunovo

Eunovo commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

I reverted the decision to make CCoinCointrol::destChange an std::optional, because it creates 2 values (instead of just 1 on master) that CreateTransactionInternal interprets as no custom change:

  • std::nullopt and
  • CNoDestination
    By setting destChange to PaymentDestination(CNoDestination()) by default, CreateTransactionInternal only checks that case and decides whether to generate a change address.

I also slightly adjusted the PaymentDestination API to reduce the code required by users of the API.

@rustaceanrob

Copy link
Copy Markdown
Member

Haven't done a full re-review, but is cbc9a4a something we should address in a separate PR? This behavior is a mistake on the user behalf I would imagine, but having the CNoDestination get replaced with something else seems bad for meta protocols. I can imagine a transaction that attempts to commit to a proof in an OP_RETURN and when trying to fee bump, the OP_RETURN gets replaced by something else. Raising an error seems like the right thing to do regardless of what happens here?

@Eunovo

Eunovo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Reply to #35302 (comment), opened #36962 with the first 2 commits.

@Eunovo

Eunovo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on master now that #36835 is merged.

Eunovo and others added 16 commits December 3, 2026 15:20
Return the bump transaction and its fees in a `BumpTransaction` struct,
or the error result and messages in a `BumpError`, instead of through
output parameters.
Such an output, like an OP_RETURN, was silently dropped from the
bumped transaction and change sent to a new address.
A silent payments address has no fixed scriptPubKey: it is derived from
the inputs of the paying transaction, so it does not fit in
CTxDestination.

Add `PaymentDestination`, which holds either a CTxDestination or a
`bip352::SilentPaymentsDestination` and can be parsed from either kind
of address. Use it in `validateaddress`, so it accepts silent payments
addresses.

Co-authored-by: rustaceanrob <[email protected]>
Change `CRecipient::dest` and `CCoinControl::destChange` to hold a
`PaymentDestination`, in preparation for sending to silent payments
addresses. As before, a `CNoDestination` change destination means a
change address is generated. No behavior change.

Co-authored-by: rustaceanrob <[email protected]>
…dpsbt

Both rpcs parse the outputs into recipients for `FundTransaction`, but
also passed them to `ConstructTransaction`, which parsed them again
only for the resulting outputs to be cleared.

Make the outputs of `ConstructTransaction` optional and pass none from
both rpcs. In `walletcreatefundedpsbt`, the sequence/replaceable check
now runs before the outputs are parsed.
Make `ParseOutputs` return `PaymentDestination`s and take an
`allow_silent_payments` option, which every caller leaves off for now.
Use the parsed outputs in `sendall`, which adds them once the inputs are
known, and in `bumpfee`, whose `CreateRateBumpTransaction` now takes
destinations instead of `CTxOut`s.

No behavior change.
Add a silent payments flag to `CCoinControl`, which
`MaybeEnableSilentPayments` sets when paying to a silent payments
address. Such a transaction must be added to the wallet when it is
created, since its outputs are derived from the private keys of its
inputs: `send` refuses `psbt=true`, `add_to_wallet=false` and incomplete
signing for it.

Add `GetDummyTxOut`, to size an output before its script is known, and
`GetSilentPaymentsDestinations`.

No behavior change, since silent payments addresses are still rejected.
When funding a silent payments transaction, skip coins that cannot be
spent in it: outputs of an unknown witness version, which BIP352
receivers skip, and inputs eligible for the shared secret whose private
key the wallet does not have, such as external inputs, since the outputs
are derived from it. Add `GetPrivKeyForSilentPayments` to get the
(tweaked, for taproot) private key of an input. `AvailableCoins` caches
the key check per set of ScriptPubKeyMans, since every script of a
descriptor is derived from the same keys.

Co-authored-by: josibake <[email protected]>
Add `CreateSilentPaymentsOutputs`, which sums the private keys of the
eligible selected inputs and derives the taproot outputs of the silent
payments destinations. Fail if no selected input is eligible, or if the
key of an eligible input is missing, instead of creating outputs the
recipient cannot find.

`CreateTransactionInternal` uses these outputs for silent payments
recipients, and for a silent payments change destination. Until the
inputs are selected, `GetDummyTxOut` stands in a P2TR output for size
and dust estimation, and taproot change is preferred.

Co-authored-by: josibake <[email protected]>
Fee bumping a silent payments tx by adding inputs needs its original
recipients to recompute its outputs. Store them in the wallet database
(`sprecipients`) when the tx is committed, keep them in sync with
malleated variants, and drop them once the tx is replaced.

Stop older releases from bumping such a tx by writing a placeholder tag
as its `replaced_by_txid`, which also flags it as a silent payments tx
on load.
Use the recorded recipients in `bumpfee` to recompute the silent
payments outputs. Refuse to bump a silent payments tx whose recipients
are missing.

Allow sp addresses in the `outputs` of `bumpfee`. `psbtbumpfee` refuses
to bump silent payments txs, since a PSBT is not added to the wallet.
Accept silent payments addresses in `send`, `sendmany` and
`sendtoaddress`. Paying to one requires an unlocked wallet with private
keys and no external signer, since the outputs are derived from the
private keys of the inputs.

Co-authored-by: josibake <[email protected]>
Accept silent payments addresses in the recipients of `sendall`, and
derive their outputs from the inputs. As with `send`, refuse
`psbt=true`, `add_to_wallet=false` and incomplete signing for them.

Since `sendall` is meant to leave no coin behind, fail if any coin
would be skipped because it cannot be spent in a silent payments
transaction, and let the user pick the coins with `inputs` instead.
The coins picked with `inputs` are checked the same way as those of
`send`.
Accept a silent payments address as the `change_address` of `send`. Its
output is derived from the inputs like those of the recipients, and it
is recorded with them.

`fundrawtransaction` and `walletcreatefundedpsbt` refuse it, since
their transactions are not added to the wallet.
Older releases do not know the recipients of a silent payments tx, so
they must refuse to bump it, which would invalidate its silent payments
outputs. Check that they do, and that master can still bump it after
upgrading again.
Test sending to silent payments addresses with `sendtoaddress`,
`sendmany`, `send` and `sendall`, and check with
`scantxforsilentpayments` that the recipients find their outputs.

Cover eligible input types, coin selection with eligible and
ineligible inputs, wallets and inputs that cannot send silent payments,
transactions that must be added to the wallet, fee bumping, and reorgs.
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.