Review report

bitcoin/bitcoin: PR #35302

5 minor findings · 8 suggestions

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

Findings

Link

[minor] · Different-txid variants lose silent-payments fee-bump metadata

A scriptSig-malleated SP transaction is stored without its SP classification, allowing a later input-changing fee bump to retain an output the recipient cannot discover.

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

Details and suggested fix

CommitTransaction sets m_rbf_needs_sp_outputs and m_sprecipients only on the committed txid. For a different-txid scriptSig variant, such as a P2PKH spend, SyncMalleatedTxMetadata copies neither field. The variant therefore receives neither a recipient record nor the serialized downgrade marker. If the variant is mined and its block is later disconnected, an owner-initiated bumpfee can pass the ordinary preconditions. It skips SP reconstruction and treats the output as a fixed P2TR destination. If the bump adds an input that changes the BIP352 derivation, the recipient can no longer discover that output. The variant also bypasses the SP-specific psbtbumpfee refusal. Synchronize both fields and persist the separate recipient record for each variant; updating the tuple alone is insufficient because WriteTxMetadata writes only the transaction record. Extend the clone/disconnect/bump fixture with an SP recipient and an added input. This requires a different-txid variant, produced by wallet re-signing or a miner including a third-party malleation, followed by disconnection and a user bump. No production occurrence was found.


Link

[minor] · bumpfee can send change to an OP_RETURN output

When the owner points original_change_index at an OP_RETURN, the new optional destination retains that script and can burn the replacement's remainder instead of generating wallet change.

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

Details and suggested fix

ExtractDestination preserves OP_RETURN, bare-multisig and nonstandard scripts in CNoDestination. Previously, CreateTransactionInternal treated that value as no custom change and generated a wallet address. The engaged optional<PaymentDestination> now makes the same raw script a custom change destination. Consequently, selecting an OP_RETURN with original_change_index can put the entire remainder, including surplus from added inputs, into an unspendable output. A small OP_RETURN can pass standardness with positive value, and its dust threshold is zero. The refactor also changes address-less outputs automatically recognized as change and removes the old no-recipient rejection for such destinations. Preserve the previous sentinel semantics by leaving destChange unset for CNoDestination, while retaining support for other destination alternatives, including PubKeyDestination and SP destinations. No caller pointing original_change_index at an OP_RETURN was found, so production impact is unknown.


Link

[minor] · The SP anchor fallback can exceed max_tx_weight

An automatically added eligible anchor can take the unchecked MANUAL selection path, allowing send to commit a transaction above the requested weight limit or the TRUC policy limit.

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

Details and suggested fix

SelectCoinsForSilentPayments checks only each anchor's own weight before adding it to the presets. If the enlarged preset set covers the target, SelectCoins returns its MANUAL result before the combined-weight check. This affects ineligible preset inputs that already cover the payment, and an anchor that alone covers the target but needs change whose weight was not reserved. Final construction checks only MAX_STANDARD_TX_WEIGHT. Thus a smaller max_tx_weight can be exceeded; with version=3, exceeding TRUC_MAX_WEIGHT causes mempool rejection even though send commits the transaction and returns its txid. The unchecked explicit-preset path predates this PR, but automatically adding the anchor introduces a new way to reach it. Check the total candidate transaction weight, including existing presets and change, before accepting an anchor result; otherwise try the next anchor or return the weight error. No current caller combining these options was found, so production frequency is unknown.


Link

[minor] · The SP anchor fallback bypasses grouping and selection filters

Presetting one eligible coin outside GroupOutputs can split an avoid-partial-spends group and admit an anchor excluded by normal confirmation filters.

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

Details and suggested fix

When the first selection contains no BIP352-eligible input, the fallback removes one eligible COutput, presets it, and selects again. Its same-script siblings are grouped without it, or grouping is skipped entirely if the presets cover the target. This defeats APS enabled by -avoidpartialspends, avoid_reuse, or the APS retry. For example, a confirmed 5 BTC P2WSH coin plus two 1 BTC P2WPKH coins at one address can fund a 4 BTC payment by spending the P2WSH coin and only one P2WPKH anchor. In an avoid_reuse wallet, the remaining sibling then becomes a used-address coin excluded by default. Presetting also bypasses normal confirmation tiers: with include_unsafe=true and -spendzeroconfchange=0, an unconfirmed eligible coin can become an anchor despite being excluded from ordinary selection. Choose anchors from normally filtered groups and, when APS is enabled, preset the whole group subject to OUTPUT_GROUP_MAX_ENTRIES. The loop can also run a full selection per eligible coin, so consider bounding attempts. The new selector fixtures disable APS and generate fresh eligible addresses. No production wallet UTXO set demonstrating these triggers was found.


Link

[minor] · SP send ignores the requested input reservation

Concurrent send calls can select the same inputs between funding and commit even when the owner explicitly sets lock_unspents=true.

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

Details and suggested fix

The SP condition forces lockUnspents off during funding, but send releases cs_wallet before FinishTransaction signs and commits. Another RPC thread can select the same coins in that interval. Two calls can therefore construct conflicting, fully signed transactions and both return complete=true with a txid. CommitTransaction only logs a broadcast rejection; a sufficiently higher-fee second transaction may instead replace the first. Default sends with lock_unspents=false already have this exposure, but callers requesting reservation previously avoided it. Honor the reservation during funding and release newly acquired locks with scoped cleanup if completion fails, rather than removing the protection. sendall does not have this gap because it holds cs_wallet through completion.


Optional improvements

Link

[suggestion] · Recovered SP transactions lack a safe fee-bump contract

Restoring a backup taken before an SP send loses its classification and recipients, so a later derivation-changing bump can preserve a script the recipient cannot discover.

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

Details and suggested fix

An unconfirmed SP transaction relearned after restoring a pre-send backup, or loading the same descriptors elsewhere, enters through AddToWalletIfInvolvingMe without the CommitTransaction metadata callback. Both SP fields retain their defaults. The missing-recipient guard requires the flag, so bumpfee treats the output as fixed taproot and permits additional inputs. If those inputs change the BIP352 derivation, scanning no longer finds the payment. Creation-time recording does not cover this recovery transition. Define a recovery rule, such as requiring explicit replacement outputs before permitting an input-changing bump when provenance is unknown. This also restricts ordinary recovered taproot payments, since their scripts do not reveal whether they were SP payments. If that restriction is not adopted, document the unsafe recovered-SP workflow in bumpfee help and release notes. Add a backup-before-send restore test to pin down the chosen behavior.


Link

[suggestion] · RPC help omits silent-payments restrictions and result semantics

The help advertises workflows that SP transactions reject and does not explain why a valid SP address has no scriptPubKey.

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

Details and suggested fix

send and sendall still document psbt and add_to_wallet without explaining that SP transactions must be fully signed and recorded immediately. Their SP construction also requires an unlocked wallet with private keys and no external signer. Document those prerequisites, the current SP handling of lock_unspents, the psbtbumpfee refusal, and the SP change-address exclusions in fundrawtransaction and walletcreatefundedpsbt. validateaddress now returns isvalid=true and iswitness=false for SP addresses but omits scriptPubKey, because no static script exists. Its help should explain that case so clients do not assume every valid address supplies a script. Add a release note for these API changes; no PR-specific note is included.


Link

[suggestion] · SP discovery assertions do not check recipient amounts

The multiple-recipient test would accept swapped SP scripts because each recipient would still discover one output despite receiving the wrong amount.

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

Details and suggested fix

test_multiple_sp_recipients requests 3 BTC and 4 BTC for different scan keys, but assert_sp_outputs checks only the number of discovered keys. A regression pairing sp_outputs[i] with the wrong vecSend[i].nAmount preserves both counts and the transaction's total value. Map each discovered key back to its vout and compare the value with the expected payment. For sendall, calculate the expected remainder split instead of reusing the fixed amounts, since do_send intentionally supplies only addresses to that RPC.


Link

[suggestion] · SP fee-bump rejection paths lack regression coverage

The tests preserve intact recipient metadata, so they do not exercise rejection when a flagged transaction's recipient record is missing or does not reproduce its outputs.

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

Details and suggested fix

The successful reload and downgrade tests do not depend on either fail-closed guard in CreateRateBumpTransaction. The marker and recipient record are stored separately, and an unreadable recipient record produces a noncritical load error. Add two reload cases: delete the record to exercise the missing-data error, and replace it with valid but incorrect recipient data to exercise the output-mismatch error. Assert the specific bumpfee rejection and an unchanged mempool in each case. These fixtures would protect against accepting an input-adding bump that retains stale SP scripts.


Link

[suggestion] · sendall's skipped-SP-coin rejection is untested

The P2WSH-only test does not cover the guard that prevents an SP sweep from silently leaving otherwise spendable coins behind.

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

Details and suggested fix

sendall without explicit inputs rejects a sweep when AvailableCoins filtered any coin as unusable in an SP transaction. The P2WSH-only case instead fails because no input contributes a shared-secret key; P2WSH itself is allowed. Fund one eligible P2WPKH coin and one tr(<xonly pub>,pk(<priv>)) coin whose output-key private key is unavailable. Assert the skipped-coin error and that nothing was spent. Then select only the P2WPKH coin through inputs and verify the resulting output with scan_tx. This isolates the sweep guard from the existing no-eligible-input check.


Link

[suggestion] · Unsupported SP requests consume construction work and change indexes

send checks incompatible PSBT and recording options after funding, so a request that must fail can still derive SP outputs and consume an automatic change index.

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

Details and suggested fix

FundTransaction performs coin selection, private-key lookup and SP output derivation before send rejects psbt=true or add_to_wallet=false. Successful construction calls reservedest.KeepDestination(), so rejecting the RPC afterward does not return an automatically reserved change index. fundrawtransaction and walletcreatefundedpsbt also reject SP change addresses only after derivation, although their custom destination avoids reserving an automatic index. Determine SP use from the parsed recipients and change address, then reject unsupported combinations before funding. This preserves supported workflows while avoiding wasted derivation and skipped indexes.


Link

[suggestion] · The rawtr SP key-lookup branch has no test

Existing SP fixtures exercise tweaked tr keys, not the direct output-key path, so they do not protect against removing or incorrectly tweaking rawtr handling.

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

Details and suggested fix

GetPrivKeyForSilentPayments returns an untweaked keypair when a wallet key already equals the taproot output key. The SP unit and functional tests use tr(...), while the BIP352 vectors receive prepared keypairs rather than exercising this wallet lookup. Add a funded rawtr(<priv>) coin, select it explicitly in sendall, and verify the resulting payment with scan_tx. That case would depend on this branch and distinguish the direct output key from an incorrectly applied taproot tweak.


Link

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

The Qt tests leave SP-specific early unlocking, recipient forwarding and unsigned-export suppression untested.

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

Details and suggested fix

WalletModel::bumpFee must unlock before constructing an SP replacement, then forward sp_recipients through creation and commit while suppressing the PSBT option. Existing GUI bumps use PKHash recipients, so they do not exercise those branches; RPC tests bypass them entirely. Extend the MiniGUI fixture with an SP transaction created through the wallet API, funded by an SP-eligible coin and committed with recipient metadata. Bump it from a locked encrypted wallet, check the early unlock and absence of unsigned export, and verify that recipient metadata survives the replacement. The later signing-time unlock would not catch loss of the earlier unlock because SP output reconstruction happens first.


Coverage details

Earlier concerns

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