Silent Payments: Sending (take 2)

bitcoin/bitcoin: PR #35302

4 minor findings · 14 suggestions

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

Findings

Link

[minor] · Coin selection can reject a fundable silent payment

A silent-payment send can fail with No silent payment eligible inputs were found. even when the wallet has enough funds and an available contributing input.

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

Details and suggested fix

Non-contributing inputs such as P2WSH remain valid funding candidates, but selection does not require a contributing input. In test_preset_ineligible_input, changing add_inputs to True still leaves the sufficient 10 BTC P2WSH preset as the entire selection for the 5 BTC payment, despite the wallet's other eligible coin. Automatic selection likewise accepts monetary solutions before considering mixed output types. Derivation then fails, and CreateTransaction returns without retrying. When an actual silent-payment output will be created, require a contributing input, for example by retrying with an eligible coin forced in and recalculating fees and weight. Keep the derivation check as a safety net and preserve the working case where a silent-payment change address produces no change output. Explicitly selecting an eligible input through send is a workaround; wallets containing only contributing coins are unaffected.


Link

[minor] · Rejected silent-payment requests leave selected inputs locked

With lock_unspents=true, successfully funded but unsupported silent-payment requests return an error after locking inputs, leaving them unavailable to automatic selection until explicitly unlocked or the wallet restarts.

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

Details and suggested fix

send funds before rejecting psbt=true or add_to_wallet=false. fundrawtransaction and walletcreatefundedpsbt also reject silent-payment change addresses only after funding. Successful funding keeps the reserved change destination and optionally locks inputs, but these exceptions do not undo those effects. The new incomplete-signing error similarly follows locking in send and sendall. Reject known unsupported modes after parsing recipients and change options but before funding, as sendall already does for PSBT and wallet-insertion options. For incomplete signing, roll back newly acquired locks or defer them until completion succeeds. Add rejection tests that inspect listlockunspent.


Link

[minor] · Restoring a pre-send backup loses silent-payment fee-bump safety

Restoring a pre-send backup can let an input-adding fee bump retain a silent-payment script that BIP352 scanning cannot find; practical manual recovery has not been established.

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

Details and suggested fix

If the original transaction remains unconfirmed, the restored wallet can rediscover it from the mempool through its owned inputs, but rediscovery restores neither the flag nor the recipient instructions. bumpfee consequently treats the output as ordinary P2TR. With no descendants and a spare confirmed coin, bumping a no-change send can add an input while preserving the old script, so scanning the replacement derives a different shared secret. Bumps that retain the input set are unaffected. At minimum, document this recovery limitation and the need to retain a post-send backup containing the recipient data before relying on automatic fee bumping. A blanket restriction on input-adding bumps to foreign P2TR outputs would also restrict ordinary taproot payments, so that mitigation needs an explicit policy choice.


Link

[minor] · Existing-transaction commits skip silent-payment recipient persistence

An existing txid can abort ABORT_ON_FAILED_ASSUME builds or lose newly attached recipient data after reload; no ordinary single-wallet production occurrence was confirmed.

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

Details and suggested fix

AddToWallet runs this callback for an existing txid too, but that path calls WriteTxMetadata, not WriteFullTx, which writes sprecipients. A no-change send retried with the same explicit inputs, locktime and fees can reproduce the txid because selected wallet TXOs are not rejected as already spent. That violates Assume(new_tx); the release-build retry is harmless when its recipient record already exists. The persistence problem instead occurs when the entry lacks that record, for example if an overlapping wallet broadcasts the identical transaction between funding and commit. The callback then persists the marker without the recipients, and a later reload makes fee bumping fail closed. Handle existing entries by writing missing recipient data before persisting the marker rather than assuming insertion.


Optional improvements

Link

[suggestion] · RPC help omits the silent-payment sending restrictions

The RPCs now accept silent-payment addresses, but their help still describes PSBT and non-wallet output modes unconditionally and does not explain the new destination-dependent restrictions.

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

Details and suggested fix

send still advertises “Always return a PSBT” and returning a serialized transaction for add_to_wallet=false, although silent payments reject both modes. Sending also requires local private keys, no external signer, an unlocked wallet and complete signing. Qualify the destination, change_address, psbt and add_to_wallet help, and explain which sending and funding RPCs support silent payments. Add a release note covering these restrictions, sendall's refusal to leave filtered coins behind, and the downgrade marker used to prevent older releases from fee bumping these transactions.


Link

[suggestion] · Dummy-output sizing is separated from its first consumers

The series introduces GetDummyTxOut two commits before its first consumers, separating the P2TR size and dust assumption from the behavior that depends on it.

Location: src/wallet/spend.cpp:1053 at 1b5d2c8712c7 (commit) (commit).

Details and suggested fix

Move the definition and spend.h declaration from 1b5d2c8712c721cbf258ee09a25ec46e7e2e070e into 4d88dc9d367f3fc14d35e7fb2a009ca54a011c6e. The former adds the helper while recipient size and dust checks still require static scripts; the latter introduces its first size, dust and change-prototype uses. The intervening 8d9b4562cedfeaa2493b5e217a986949ec198ef6 only adds input filtering, and the feebumper consumer arrives later in 51e03c73b220998a703d7d86bd50fb3d482fbed4. This lets reviewers validate the stand-in's sizing contract together with its consumers without changing the final tree.


Link

[suggestion] · Qt bump tests miss the silent-payment-specific branches

The Qt tests do not exercise silent-payment bump unlocking, unsigned-PSBT suppression, or forwarding recipient metadata when committing the replacement.

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

Details and suggested fix

The existing bump fixture uses ordinary PKHash sends, so it cannot detect regressions in these WalletModel branches; RPC functional tests do not drive them either. Add a backend-created silent-payment transaction in an encrypted wallet with PSBT controls enabled. Drive the bump action through unlock and confirmation cancellation, then acceptance. Check that “Create Unsigned” is unavailable and that the committed replacement retains enough recipient data to be bumped again.


Link

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

When sendall selects no inputs for a silent-payment target, it reports a wallet eligibility error instead of the existing insufficient-funds error.

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

Details and suggested fix

CreateSilentPaymentsOutputs sees the empty key set before sendall reaches its effective-value check. An empty wallet, or confirmation filters excluding every coin, therefore produces -4 “No silent payment eligible inputs were found.” This suggests an input-type problem rather than absent funds. Check for an empty rawTx.vin before derivation and return the existing insufficient-funds error. Keep the eligibility error for a nonempty set whose inputs cannot contribute a key.


Link

[suggestion] · Multi-recipient tests do not bind amounts to derived outputs

The new tests can miss swapped recipient amounts; the silent-payment sendall cases also rely on a pre-existing helper that accepts amount matches without matching the destination.

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

Details and suggested fix

Swapping the 3 BTC and 4 BTC assignments in test_multiple_sp_recipients leaves both scanned-output counts unchanged. In sendall_and_spend, assert_tx_has_output evaluates as (address_match and value is None) or value_match, so swapping the fixed and remainder amounts also passes, as can substituting an arbitrary same-value taproot output. Map each scanned output key to its vout using "5120" + output and assert that recipient's expected value. Use a generated silent-payment recipient with known keys in wallet_sendall.py so its remainder output can be identified by scanning.


Link

[suggestion] · The filtered-coin sweep refusal lacks regression coverage

No test exercises sendall's refusal when silent-payment filtering would leave an otherwise spendable coin behind.

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

Details and suggested fix

The existing P2WSH and NUMS cases are permitted funding inputs, so they do not exercise skipped_silent_payments_ineligible. Fund a wallet with an ordinary eligible coin and a confirmed tr(<public internal key>,pk(<private leaf key>)) coin. The latter is script-path spendable but lacks the output-key private key required here. Assert that automatic sendall refuses the sweep, selecting only the eligible coin with inputs succeeds and scans correctly, and ordinary silent-payment funding never selects the filtered coin. This distinguishes the sweep contract from the direct CheckSilentPaymentsInput assertions.


Link

[suggestion] · The oversized sweep test rebuilds an unchanged fixture

The second target adds another 1600 UTXOs even though the first oversized sweep spent none, unnecessarily doubling the silent-payment pass's input workload.

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

Details and suggested fix

Move the keypool refill, 1600-output sendmany and block generation above the target loop. The first sendall fails at the size check before locking or spending any coin, so both targets can reuse that oversized set. This preserves both assertions while avoiding another large funding transaction and key derivation for a 3200-input silent-payment construction.


Link

[suggestion] · The ancestor-funding assertions repeat only ordinary recipients

Both passes of sendall_does_ancestor_aware_funding construct ordinary-address payments, so the silent-payment parameter adds no coverage of its ancestor-fee assertions.

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

Details and suggested fix

Neither construction uses self.remainder_target; both pay a fresh def_wallet address with add_to_wallet=False. The second pass therefore repeats the parent funding and two constructions without exercising silent-payment ancestor-aware funding. Use @for_each_target(allow_sp=False) for this test. Keep the cleanup needed to confirm and unlock its pending coins.


Link

[suggestion] · The test scanner accepts transactions receivers must skip

The Python test scanner can report a silent payment in a transaction spending a future witness version, although BIP352 receivers skip the entire transaction.

Location: test/functional/test_framework/bip352.py:58 (head).

Details and suggested fix

get_input_pubkey returns None for a native v2+ witness program, and scan simply filters it out while continuing with any eligible keys. This differs from GetSilentPaymentsPrevoutsSummary and would not expose a regression in the sender's future-witness filter. Add the transaction-level rejection before key aggregation and a unit case mixing an eligible input with a v2 input.


Link

[suggestion] · Silent-payment bump refusal guards lack negative tests

The reload test covers valid recipient metadata, but neither missing recipients nor recipients that fail to reproduce the transaction's outputs are tested.

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

Details and suggested fix

The marker and sprecipients are separate records, and an unreadable recipient record is only a noncritical load error. Add one case with the marker retained but recipients absent, and another with valid but wrong destinations. A unit fixture constructing CWalletTx directly is sufficient. Assert the specific refusal and unchanged mempool state. Without these guards, an input-adding bump could preserve unrecognized silent-payment scripts as ordinary P2TR outputs.


Link

[suggestion] · Silent-payment sending tests omit rawtr input keys

The new sending tests do not exercise the branch that must use a rawtr output's private key without applying a TapTweak.

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

Details and suggested fix

The covered tr(...) inputs take the internal-key tweak path, whereas rawtr(...) requires ComputeKeyPair(nullptr). A missing rawtr branch would reject usable funding, and an accidental tweak would derive an output the recipient cannot find. Fund a rawtr(<priv>) coin, select it explicitly in a silent-payment sendall, and verify the output with scan_tx.


Link

[suggestion] · The input-type fixture spends its named type only once

In test_eligible_input_types, only sendtoaddress spends the P2PKH or P2SH-P2WPKH funding coin; the later RPCs spend P2WPKH change.

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

Details and suggested fix

create_funded_wallet supplies one coin, and do_send calls sendtoaddress, sendmany, send and sendall sequentially without new funding. Both non-taproot fixtures use a wpkh internal descriptor, so the later calls no longer exercise the named input type, including sendall's separate construction path. Use a fresh funded wallet per RPC and assert the selected prevout script types.


Link

[suggestion] · Wallet change tests miss a two-output scan under one scan key

The wallet tests do not independently verify numbering and bump reconstruction while both a recipient and silent-payment change remain under the same scan key.

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

Details and suggested fix

Change is appended after recipients for derivation, but test_rbf_sp_change_dropped first scans only after dropping one shared-scan-key output. The bump's original-script matching checks the node against its own derivation. Use the same silent-payment address as both recipient and change_address, allowing the label-free Python scanner to find both consecutive outputs. Assert n=2, reload, force a bump that adds an input, and scan the replacement again.


Link

[suggestion] · Failed replacement-metadata writes can erase needed recipients

If a replacement-metadata write fails but recipient erasure succeeds, the stored transaction retains its silent-payment marker without the data needed to bump it after reload.

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

Details and suggested fix

MarkReplaced sets success=false after WriteTxMetadata fails but still erases sprecipients. This defeats the ordering promised by the comment: the stored transaction can remain unreplaced and flagged, while reload loses its recipients and later fee bumping fails closed. Erase the record only when that transaction's metadata write succeeds. Apply the same condition separately to each malleated variant; a leftover recipient record is harmless.


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

Silent payments trade receiver-side scanning work for reusable payment instructions without address reuse, sender–receiver interaction, or notification transactions. Avoiding notifications also avoids their additional cost, recognizable footprint, and potential linkage between payments.

This explains why the head's PaymentDestination distinguishes payment instructions from a fixed scriptPubKey. It also explains deriving ordinary-looking taproot outputs only after selecting inputs: reusing the published silent-payment address must not mean reusing the on-chain destination.

Source 1

A coin's ability to fund a transaction is distinct from its eligibility to contribute to the silent-payment shared secret. In the earlier sending implementation discussion, the author explicitly explained that P2PK inputs could be included provided at least one silent-payment-eligible input was present.

The head preserves this distinction in CheckSilentPaymentsInput and CreateSilentPaymentsOutputs: some inputs may fund the transaction without contributing a key, while output derivation fails if no contributing keys exist. The additional private-key checks ensure the sender can compute the same shared secret the recipient reconstructs from eligible input public keys.

Source 1 · Source 2 · Source 3

Taproot input treatment was designed against spend-path malleability. If receivers simply ignored every script-path spend, a collaborative participant could contribute a key-path ECDH share and then publish a script-path variant, changing the receiver's shared-secret calculation. The historical discussion therefore distinguished ordinary taproot output keys from the recognizable NUMS-H exception.

This explains the head's use of the private key corresponding to the taproot output key, including its tweak, rather than an arbitrary script-leaf signing key. It also explains why IsInputForSharedSecretDerivation excludes NUMS-H constructions rather than treating all taproot script-path-capable coins alike.

Source 1 · Source 2 · Source 3 · Source 4

Input-order independence was an explicit wallet-safety goal. The original BIP discussion explained that a wallet might reorder inputs during signing or RBF and overlook the need to regenerate the silent-payment output; a protocol-defined ordering avoids making mere permutation change the destination.

The pinned base and head use BIP352Comparator to select the smallest serialized outpoint rather than relying on transaction input order. This protection concerns reordering, not arbitrary changes to the input set; the head separately recomputes outputs when fee bumping adds inputs.

Source 1 · Source 2 · Source 3

Silent-payment construction does not fit the ordinary separation between transaction construction and signing. BIP375 states that outputs cannot be computed until all inputs have been added, and that ECDH-derived outputs supplied by a signer must be independently verifiable to avoid sending funds to an incorrect script. It proposes additional PSBT fields and responsibilities, including ECDH shares and DLEQ proofs.

This supplies historical context for the head's requirement for local private-key access and its refusal of external-signer and exported-PSBT sending paths. These are implementation-scope restrictions, not a claim that silent payments are inherently incompatible with PSBTs. BIP375 also explicitly separates silent-payment outputs from inputs spending future witness versions, matching the head's input filtering boundary.

Source 1

Compressed public keys were chosen over x-only address keys after implementation experience showed that tracking parity between sender and receiver, especially with labels, required repeated negations and additional scanning work. The author explicitly judged the extra address bytes worthwhile for simpler computation.

This explains the compressed scan and spend keys validated by SilentPaymentsDestination, and why parsing these addresses is not merely parsing an ordinary taproot address. It also provides context for preserving taproot key-pair parity correctly during shared-secret derivation.

Source 1 · Source 2 · Source 3

Ralph's inferences

The same indistinguishability that protects recipients creates a sender-side metadata requirement for replacement transactions: an existing taproot script alone does not identify the original silent-payment instructions needed to derive a replacement output for changed inputs.

At the base, fee bumping reconstructs recipients directly from existing output scripts and permits additional inputs. At the head, sprecipients preserves the original instructions, fee bumping matches recomputed scripts against the original transaction, and replacements carry updated recipient metadata. This connects the new persistence behavior to input-dependent derivation rather than treating it as ordinary address-book bookkeeping.

Source 1 · Source 2

Mandatory wallet insertion and downgrade refusal can be understood as protecting payment discoverability across transaction lifecycle boundaries, rather than as Bitcoin consensus requirements.

The head refuses psbt=true, add_to_wallet=false, and incomplete signing so that transactions created through these sending paths retain their silent-payment instructions. Its placeholder replaced_by_txid prevents older software from applying ordinary fee-bumping behavior without those semantics, while permitting wallet loading. The historical sources support the input-binding premise, but do not independently establish the exact marker or insertion policy.

Source 1 · Source 2

Filtering unusable coins has different consequences for ordinary funding and for a wallet sweep: quietly omitting a coin can be acceptable when selecting enough value for a payment, but conflicts with a sweep's expectation that eligible wallet funds are not unexpectedly left behind.

The head lets AvailableCoins filter coins that cannot participate safely in its silent-payment construction, but records that filtering occurred. sendall then refuses the automatic sweep and asks for explicit input selection. This appears to reconcile the existing sweep semantics with silent-payment key and scanning constraints; no independent historical discussion of this exact policy was retrieved.

Source 1 · Source 2