Silent Payments: Sending (take 2)

bitcoin/bitcoin: PR #35302

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 2 minor findings · 14 suggestions

Earlier concerns neither republished nor resolved: 1 major finding · 2 minor findings · 2 suggestions. See the Run archive for their assessments.

Findings

Link

[major] · Restored wallets can bump silent payments without recomputing their outputs

Restoring a backup taken before an unconfirmed silent payment loses its payment instructions, allowing bumpfee to add inputs while retaining scripts that the recipient's normal scan cannot find.

Location: src/wallet/feebumper.cpp:272 (head).

Details and suggested fix

Loading the backup requests mempool transactions and adds the payment through AddToWalletIfInvolvingMe with no metadata callback. The recovered transaction has an empty m_sprecipients and a false RBFNeedsSilentPayments(), so both the missing-recipient guard and output reconstruction are skipped. If its change cannot cover the higher fee and another confirmed coin is available, bumpfee can add a contributing input while preserving the original Taproot payment script. That changes the derivation, so the recipient does not find the replacement through normal scanning. Keeping exactly the original input set is harmless; recovery using the original inputs supplied out of band may still be possible.

Prevent input-changing bumps that preserve scripts when the recovered transaction's payment instructions are unknown. This also restricts ordinary recovered Taproot transactions because their scripts cannot identify silent payments. Add a regression test that restores a pre-send backup and forces a bump to add an input.


Link

[minor] · Coin selection can omit every shared-secret-eligible input

A silent payments send can fail with No silent payment eligible inputs were found. even when the wallet has a spendable eligible coin that could be added.

Location: src/wallet/spend.cpp:1459 (head).

Details and suggested fix

For example, preselect a 10 BTC P2WSH coin for a 5 BTC silent payment with add_inputs=true, while the wallet also holds an eligible P2WPKH coin. SelectCoins returns the preset set immediately because it covers the monetary target. P2WSH passes the funding-input checks but contributes no key, so CreateSilentPaymentsOutputs rejects the selection and the error returns without a retry. Automatic selection likewise has no contributing-input constraint. Keep the fail-closed derivation check, but make selection or a retry include an eligible coin whenever an actual silent payments output is needed and other inputs are allowed. The existing preset-ineligible test uses add_inputs=false and does not cover this case.


Link

[minor] · Rejected silent payments requests leave funding inputs locked

With lock_unspents=true, unsupported silent payments requests can return an error after funding has locked their selected coins.

Location: src/wallet/rpc/spend.cpp:1364 (head).

Details and suggested fix

send calls FundTransaction before rejecting psbt=true or add_to_wallet=false. Similarly, fundrawtransaction and walletcreatefundedpsbt reject a silent payments change address only after funding. When funding succeeds, its lockUnspents branch has already called LockCoin(..., persist=false) for every input, and these error paths do not undo those locks. A corrected automatic-selection retry can then report insufficient funds until the user unlocks the coins with lockunspent or reloads the wallet. Validate these combinations after parsing the recipients and change destination but before funding, and assert that rejected requests leave listlockunspent unchanged.


Optional improvements

Link

[suggestion] · The downgrade sentinel also changes reporting and coin selection

Older software interpreting the sentinel as replaced_by_txid reports a nonexistent replacement, including for confirmed payments, and excludes unconfirmed change from default coin selection.

Location: src/wallet/transaction.h:304 (head).

Details and suggested fix

Serialize writes the sentinel until the transaction is genuinely replaced; confirmation does not clear it. Software with the base behavior loads it as a real m_replaced_by_txid, always exposes it through transaction RPCs, and marks unconfirmed outputs unsafe in AvailableCoins. These effects go beyond the intended bumpfee and psbtbumpfee refusal. Document them in the compatibility comment and release notes, and extend the downgrade test to check reporting and change safety. This preserves the guard rather than removing it on confirmation and weakening protection after a reorg.


Link

[suggestion] · The validateaddress help omits its silent payments result shape

validateaddress now returns isvalid=true for silent payments addresses without scriptPubKey or witness details, but its help does not explain their absence.

Location: src/rpc/output_script.cpp:82 (head).

Details and suggested fix

The silent payments branch returns only isvalid and the normalized address. The help still describes scriptPubKey as the output script generated by the address, without explaining that a valid silent payments address has no fixed script. Document this exception so clients do not infer script availability from isvalid=true. Add a release note describing the result shape and the newly supported address arguments in send, sendmany, sendtoaddress, sendall, bumpfee outputs, and send's change_address.


Link

[suggestion] · A failed replacement-metadata write can still erase recipient data

If WriteTxMetadata fails and the following erase succeeds, the stored transaction retains its silent payments sentinel but loses its recipients.

Location: src/wallet/wallet.cpp:1021 (head).

Details and suggested fix

MarkReplaced records a failed WriteTxMetadata call but still executes EraseSpRecipients; the malleated-variant loop does the same. After reload, the old metadata can therefore indicate that reconstruction is required while its recipient record is gone, causing a later bump to fail with the missing-recipient error. This fails closed, but rescanning cannot reconstruct the payment instructions. Make each erase conditional on that transaction's metadata write succeeding, matching the adjacent comment's promised ordering.


Link

[suggestion] · Missing m_silent_payments aborts recipient handling

A silent payments recipient without m_silent_payments reaches an abort instead of an error, although no current caller producing this input was found.

Location: src/wallet/spend.cpp:1473 (head).

Details and suggested fix

CreateTransactionInternal returns an explicit error for a silent payments change destination without the flag. For a recipient in the same mode, output derivation is skipped and Assert(vecSend[i].dest.GetScript()) fails because silent payments destinations return std::nullopt. interfaces::Wallet::createTransaction forwards these arguments unchanged. Add an early recipient check matching the change check, so inconsistent arguments fail through the function's error result rather than terminating the process.


Link

[suggestion] · The recipient-data bump guards lack negative coverage

The existing reload test retains valid sprecipients, so it would not detect removal of either the missing-recipient or mismatched-recipient refusal.

Location: src/wallet/feebumper.cpp:273 (head).

Details and suggested fix

The flag is stored in transaction metadata, while the destinations occupy a separate sprecipients record. CreateRateBumpTransaction must refuse both a flagged transaction with no destinations and destinations whose recomputed scripts do not match its outputs. Add reload tests that delete the recipient record and replace it with valid but wrong destinations. Assert the respective errors and that the mempool remains unchanged.


Link

[suggestion] · The skipped-coin sendall refusal has no regression test

Existing tests do not exercise skipped_silent_payments_ineligible, so they would miss removal of the guard against silently leaving unusable coins behind.

Location: src/wallet/rpc/spend.cpp:1619 (head).

Details and suggested fix

sendall_sp_fails_on_no_eligible_inputs funds P2WSH, which passes CheckSilentPaymentsInput and fails later during derivation. Instead, also test a wallet holding an eligible P2WPKH coin and a spendable tr(<xonly pub>,pk(<priv>)) coin whose internal private key is unavailable. Assert that automatic sendall reports skipped coins, then select only the P2WPKH coin with inputs and check its payment with the scanner.


Link

[suggestion] · test_eligible_input_types spends each legacy input type only once

In this table, only sendtoaddress spends the P2PKH or P2SH-P2WPKH coin; sendmany, send, and sendall spend its P2WPKH change.

Location: test/functional/wallet_silentpayments_sending.py:265 (head).

Details and suggested fix

create_funded_wallet supplies one 25 BTC coin of the named type. For the P2PKH and P2SH-P2WPKH cases, the sole internal descriptor is wpkh, and do_send invokes the four RPCs sequentially without refunding the wallet. The later calls therefore do not exercise the advertised input type, including through sendall's separate input-collection path. Fund a fresh named-type coin before each RPC, or use separate wallets, and assert the selected prevout script types.


Link

[suggestion] · Shared-scan-key recipient and change outputs are not scanned together

No functional test independently scans two retained outputs sharing a scan key, including recipient-plus-change reconstruction after reload and fee bumping.

Location: src/wallet/spend.cpp:1454 (head).

Details and suggested fix

CreateTransactionInternal derives silent payments change after the recipients, and GetSilentPaymentsDestinations persists that sequence for later reconstruction. The per-scan-key output counter makes retaining both outputs an important case. test_rbf_sp_change_dropped scans only after one shared-scan-key output is removed. Add a send with a recipient and change_address sharing a scan key, assert that the scanner finds both outputs, then reload, force a bump that adds an input, and scan the replacement again.


Link

[suggestion] · The multi-recipient test does not check recipient amounts

Swapping the derived scripts between the 3 BTC and 4 BTC outputs would still satisfy the multi-recipient test's scanner assertions.

Location: test/functional/wallet_silentpayments_sending.py:377 (head).

Details and suggested fix

The builder associates each derived script with vecSend[i].nAmount by index, but assert_sp_outputs only checks that each recipient finds one output. Match each scanner-returned output key to the transaction output and assert the requested value for fixed-amount sends. Keep sendall separate because this helper supplies its recipients without fixed amounts.


Link

[suggestion] · Silent payments tests omit the rawtr key-retrieval branch

The silent payments tests would not detect removal or incorrect tweaking of the rawtr output-key contribution.

Location: src/wallet/scriptpubkeyman.cpp:1555 (head).

Details and suggested fix

GetPrivKeyForSilentPayments uses ComputeKeyPair(nullptr) when a held private key directly matches the Taproot output key. The new eligibility checks cover tr(...), and the sending fixtures do not import rawtr(...). Fund a rawtr(<priv>) coin, spend it alone through sendall with explicit inputs, and check the payment with the scanner. That verifies both key availability and use of the untweaked output-key secret.


Link

[suggestion] · Empty silent payments sweeps report an input-eligibility error

With no spendable inputs, sendall to a silent payments address reports -4 eligibility failure instead of the usual -6 insufficient-funds error.

Location: src/wallet/rpc/spend.cpp:1642 (head).

Details and suggested fix

An empty wallet, or minconf/maxconf filtering out every coin, leaves both rawTx.vin and sp_input_coins empty. CreateSilentPaymentsOutputs then returns its no-eligible-input error before sendall reaches the insufficient-funds check. The new test branches expect this result, but it suggests a script-type problem when there are simply no spendable coins. Return the existing insufficient-funds error for an empty input set before deriving outputs.


Link

[suggestion] · GUI fee-bump tests do not exercise silent payments handling

Qt tests do not cover WalletModel::bumpFee's early unlock, hidden PSBT option, or forwarding of silent payments recipients to commit.

Location: src/qt/walletmodel.cpp:458 (head).

Details and suggested fix

The existing GUI test bumps only PKHash sends. Removing the early unlock would make construction fail for a locked silent payments wallet, while dropping sp_recipients at commit would leave the replacement without instructions for its next bump. RPC tests bypass this GUI path. Add a silent payments transaction through the wallet API, lock an encrypted wallet, and exercise GUI bumping, PSBT-option suppression, and a subsequent bump of the replacement.


Link

[suggestion] · sendall_does_ancestor_aware_funding repeats the same regular-address case

The silent payments iteration repeats regular-address ancestor-funding assertions because neither checked call uses self.remainder_target.

Location: test/functional/wallet_sendall.py:474 (head).

Details and suggested fix

Both sendall calls pay a fresh def_wallet address with add_to_wallet=False, then compare their output values. Changing the decorator's target affects only the later cleanup sweep, not those assertions. Use @for_each_target(allow_sp=False) to avoid repeating the funding, transaction construction, and cleanup without adding silent payments ancestor-funding coverage.


Link

[suggestion] · The oversized-sweep test accumulates another batch for each target

The silent payments iteration unnecessarily funds another 1,600 coins and processes about 3,200 inputs; the runtime cost has not been measured.

Location: test/functional/wallet_sendall.py:597 (head).

Details and suggested fix

The first sendall fails the weight check before locking or committing, so its 1,600 coins remain available. Funding another batch inside the loop makes the silent payments iteration collect both batches and retrieve their eligible keys before reaching the same rejection. Refill the keypool, fund, and mine once before the target loop, then check both rejections against the same 1,600-coin set.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Eligibility for shared-secret derivation is distinct from eligibility to fund the transaction. The earlier sending discussion explicitly allows otherwise ineligible inputs, such as P2PK, provided at least one silent-payment-eligible input is present.

The sender paths must distinguish inputs that contribute private keys to the shared secret from inputs that merely contribute value. This explains why CreateSilentPaymentsOutputs skips some selected coins but fails when no contributing keys remain; it does not require every funding input to contribute.

Source 1

Taproot contribution must not depend simply on whether the final witness uses the key path or script path. Otherwise a malicious CoinJoin participant could participate in derivation using its output key, then publish a script-path version that causes the receiver to omit that contribution and miss the payment.

This is the adversarial reason not to interpret all script-path-capable Taproot coins as noncontributing. The pinned receiver uses the Taproot output key even for script-path spends, except for the recognizable NUMS-H case. Sender key retrieval correspondingly needs the output-key secret contribution, rather than an arbitrary script-leaf key.

Source 1 · Source 2 · Source 3

Recognizable NUMS-H is a deliberate exception: revealing H as the Taproot internal key lets the receiver unambiguously omit that script-path input. The historical tradeoff is that recognizable H reveals that key-path spending was unavailable, unlike a randomized unspendable internal key.

The NUMS exclusion is not a blanket exclusion of Taproot scripts. It permits script-only coins to fund a silent payment without requiring an unavailable output-key secret. The sender and receiver must agree on this specific exception.

Source 1 · Source 2 · Source 3

Taproot secrets must be normalized to the even-Y public-key representative before aggregation. BIP352 explains that an x-only key corresponds to two private scalars, while receivers assume even Y when summing public keys.

Sender derivation and replacement derivation must use the same tweaked Taproot output-key contribution and parity convention as scanning. Possession of a signing key alone is not enough unless it produces the matching ECDH contribution.

Source 1

The smallest lexicographically serialized outpoint supplies a deterministic uniqueness nonce without making outputs depend on input order. The BIP also cites memory-constrained signing devices as a reason to use one outpoint rather than retain the whole transaction. Committing the aggregate public key in the input hash prevents a sender from algebraically choosing a later key to force address reuse.

CreateSilentPaymentsOutputs chooses the minimum over all selected funding outpoints, not just the inputs whose keys contribute to the shared secret. The historical specification says the minimum is taken over outpoints used in the transaction. Reordering unchanged inputs should not change derivation, but adding an input can change the minimum and/or aggregate key, making output recomputation necessary.

Source 1 · Source 2 · Source 3

Silent payments are not inherently incompatible with PSBTs or distributed key ownership. BIP375 specifies ECDH shares and optional DLEQ proofs so entities lacking some input secrets can verify derivation; the BIP352 discussion likewise describes combining shared-secret contributions from aggregated keys.

The rejection of PSBT and external-signer workflows in these wallet paths is an implementation safety boundary, not a BIP352 protocol prohibition. Its rationale must include preserving recipient instructions and controlling final input-dependent derivation, rather than asserting that silent payments can only ever be constructed by one holder of all private keys.

Source 1 · Source 2 · Source 3

Older-wallet metadata compatibility has two relevant hazards: unknown transaction metadata can be lost when a record is rewritten, and the pinned base now rejects unknown string-map entries. The metadata refactor retained the existing serialized format while moving recognized values into explicit members; its discussion specifically identified downgrade/re-upgrade rewriting as a preservation concern.

A new transaction string-map flag is not automatically downgrade-compatible. Reusing the recognized replaced_by_txid field avoids introducing an unknown key, while keeping recipient instructions outside the transaction record separates them from ordinary transaction-metadata rewrites.

Source 1 · Source 2 · Source 3

Ralph's inferences

The pinned eligibility rules preserve sender/receiver agreement: compressed-key P2PKH, P2WPKH, P2SH-P2WPKH, and eligible Taproot output keys contribute; uncompressed P2PKH and other script types do not. At least one contribution is required. Future witness versions are a transaction-level exclusion in the pinned receiver, rather than merely another noncontributing input.

Coin filtering and manually selected-input checks serve different purposes: permit noncontributing funding coins where possible, require access to every contributing secret in this implementation, and avoid funding a transaction that the receiver skips altogether. The receiver also parses malleated P2PKH scriptSigs for the matching public key instead of requiring the standard template.

Source 1

Recipient derivation order is meaningful, but it is not a requirement to globally sort transaction outputs. BIP352 groups destinations by scan key and uses successive output counters; the pinned interface carries recipient indices through derivation. Consequently, recipient persistence must retain the sequence used to derive outputs, including the relative order of destinations sharing a scan key.

GetSilentPaymentsDestinations records recipients followed by an actually present silent-payment change destination. Fee bumping first rederives the original scripts from that sequence and matches them to transaction outputs. This preserves the original recipient-to-script association despite change insertion or output placement; a replacement can then derive a new sequence for its surviving recipients.

Source 1 · Source 2

Commit-time persistence makes the original payment instructions available before a later replacement can reinterpret derived scripts as ordinary Taproot destinations. This is necessary because adding inputs may change the shared secret or input hash while the original scripts do not reveal the original silent-payment addresses.

The pinned database writes recipient data before the flagged transaction, tolerating an orphan recipient record rather than intentionally storing a flagged transaction without its instructions. Fee bumping refuses missing or mismatching recipient data. Requiring wallet commitment, rather than returning an externally finalized transaction or PSBT, keeps later wallet recognition tied to those instructions; BIP375 demonstrates that relaxing this boundary requires additional workflow support, not merely accepting a PSBT.

Source 1 · Source 2

The sentinel uses an existing fail-closed replacement rule as a downgrade guard. Older software treats the recognized, txid-shaped replaced_by_txid value as an already-bumped transaction and refuses both replacement paths using that precondition. New software instead recognizes the sentinel as a need-to-rederive flag, without presenting it internally as a real replacement.

This permits downgrade loading without an unknown metadata key and preserves the guard through recognized-field serialization. On upgrade, the flag and separately persisted recipient data allow derivation-aware replacement again. Once genuinely replaced, the real replacement txid supersedes the sentinel; the old transaction no longer needs recipient instructions. This explains the mechanism, rather than proving safety for every possible older release or database operation.

Malleated variants need the same replacement guard and recipient instructions because changing a scriptSig can change the transaction id without changing the funding outpoints or intended silent-payment outputs. Guarding only the originally committed txid would not preserve that logical payment identity.

The base already synchronizes replacement metadata between malleated variants using the oldest variant as the source. The head extends that mechanism to recipient data and the silent-payment flag, and marks every variant genuinely replaced before removing its now-unneeded recipient records. This complements BIP352’s requirement that receivers still recover keys from malleated P2PKH scriptSigs.

Source 1