Review report

bitcoin/bitcoin: PR #35302

5 minor findings · 11 suggestions

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

Findings

Link

[minor] · Malleated SP transactions lose their fee-bump metadata

A different-txid scriptSig variant lacks the SP flag and recipients, so an input-adding bump after block disconnection can retain an output the recipient's BIP352 scan cannot find.

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

Details and suggested fix

For a P2PKH-funded SP send, a re-signed or third-party-malleated scriptSig can produce a different txid without changing the payment's input outpoints or outputs. When a block introduces that variant, SyncMalleatedTxMetadata copies descriptive and replacement metadata but neither new SP field. The variant consequently skips both the missing-recipient guard and output reconstruction. If its block is disconnected and the user bumps the variant with an added input, the wallet preserves the old SP script even though the BIP352 input context changed. It also omits the compatibility tag used to prevent older software from bumping SP transactions. Copy both SP fields during metadata synchronization and persist the recipients for each variant; WriteTxMetadata alone does not write that record. Extend the clone test with an SP recipient, reload, and an input-adding bump. No production occurrence of this sequence was identified.


Link

[minor] · Restored SP sends can be bumped as static taproot payments

Restoring a pre-send backup can relearn a pending SP payment without its metadata, allowing an input-adding bump to preserve a script the recipient's scan no longer finds.

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

Details and suggested fix

A pre-send backup contains neither the SP flag nor sprecipients. The same applies to a wallet independently populated from the sending descriptors. Mempool replay recognizes the outgoing transaction but adds it without construction metadata. bumpfee then skips this guard and SP reconstruction, treats the output as a fixed P2TR destination, and permits additional confirmed inputs. Requiring add-to-wallet at creation does not protect this recovery path. Define and test the recovery contract before relying on that requirement. One conservative option is to refuse input-changing bumps of unflagged transactions with non-wallet P2TR outputs unless the user supplies outputs; this also restricts ordinary taproot payments because scripts do not reveal SP provenance. Add a backup-before-send restore test and document any remaining limitation in the RPC help or release notes. No production occurrence was identified.


Link

[minor] · An OP_RETURN change index can burn the bump's remainder

Pointing original_change_index at an OP_RETURN now sends the replacement's remainder there instead of generating wallet change as before.

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

Details and suggested fix

ExtractDestination returns CNoDestination{script} for OP_RETURN, bare multisig, and nonstandard scripts. The fee bumper now wraps that result in an engaged PaymentDestination optional, which CreateTransactionInternal treats as custom change. If the user designates an OP_RETURN as original_change_index, any resulting change, including surplus from added inputs, uses that unspendable script. Its zero dust threshold does not reject the output. Previously, CNoDestination selected the fresh-change-address path. Preserve that distinction when assigning destChange, while retaining PubKeyDestination and SP destinations, and add an OP_RETURN bump regression test. No current caller pointing original_change_index at an OP_RETURN was identified, so production impact is unconfirmed.


Link

[minor] · SP anchor fallback splits avoid-partial-spends groups

Presetting one eligible anchor outside GroupOutputs can spend a single UTXO of a reused address despite avoid-partial-spends.

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

Details and suggested fix

When the initial selection contains only BIP352-ineligible inputs, the fallback removes one eligible coin from available_coins and adds it to the presets. If those presets cover the target, selection returns before grouping; otherwise, grouping sees only the remaining coins and the singleton anchor is merged afterward. Neither path requires spending its same-script siblings. This also affects the APS retry in CreateTransaction. In an avoid_reuse wallet, spending the anchor additionally makes its remaining siblings unavailable as used-address coins. Choose anchors from the filtered output groups and preset the whole group when APS is enabled, respecting OUTPUT_GROUP_MAX_ENTRIES. Add a mixed-input test with multiple eligible coins at one address and APS enabled. Reaching this fallback requires an initial selection with only ineligible inputs, such as imported P2WSH coins; no production wallet with this trigger was identified.


Link

[minor] · SP send ignores requested input reservations

Concurrent SP send calls can select the same inputs even with lock_unspents=true, because funding silently disables that reservation before signing and commit.

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

Details and suggested fix

The funding helper forces lockUnspents off for SP transactions, but send releases cs_wallet after funding and commits only later in FinishTransaction. Another RPC can select the same coin during that interval. Both transactions can be signed and reported as complete, because signing does not recheck spent state and commit only logs a mempool rejection; a sufficiently higher-fee transaction may instead replace the first. This requires concurrent spends from the same wallet. Default lock_unspents=false sends already have this race, and sendall avoids this window by holding its wallet lock through completion. Preserve the requested reservations through commit and use scoped cleanup for newly acquired locks when signing or completion fails.


Optional improvements

Link

[suggestion] · SP anchor retries scale with the eligible coin count

The fallback can rerun automatic coin selection once per eligible UTXO while holding cs_wallet.

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

Details and suggested fix

If the first selection has no eligible input, this loop tries each qualifying eligible coin until one succeeds. Every failed combination can trigger another grouping and automatic-selection pass, including when the selected coins exceed the combined weight limit. The candidate count is the only attempt bound. Measure a large mixed wallet near the weight limit, then either justify that bound or introduce a documented retry budget. A budget can miss fundable selections, and weight-only pruning is not automatically equivalent: the new test deliberately requires a lighter anchor to succeed after a heavier one fails. No runtime measurement was made.


Link

[suggestion] · Unsupported SP options are rejected after funding

fundrawtransaction and walletcreatefundedpsbt check unsupported SP change addresses only after private-key checks and transaction funding.

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

Details and suggested fix

The parsed SP change address reaches MaybeEnableSilentPayments before either RPC rejects it. Watch-only and external-signer wallets therefore receive a private-key error, locked wallets receive a passphrase error, and unlocked wallets can perform coin selection and output derivation before the unsupported-change error. Validate this restriction after parsing the destination but before enabling or funding SP. Apply the same ordering to send with psbt=true or add_to_wallet=false, which currently rejects after successful construction has already kept any reserved automatic change destination. This is an error-ordering and unnecessary-work issue.


Link

[suggestion] · SP output assertions omit recipient amounts

The functional helper checks discovery counts only, so exchanging the amounts received by two SP recipients would leave those assertions passing.

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 checks only that each recipient finds one output. A regression in the script-to-recipient index pairing could exchange those payments without changing either count. Map each scanned output key back to its vout and assert the expected value, including after an input-adding fee bump. For sendall, compare against the computed remainder shares rather than the fixed-send amounts.


Link

[suggestion] · SP fee-bump refusal paths lack negative tests

The reload tests preserve valid recipient data and do not exercise the missing-recipient or output-mismatch guards.

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

Details and suggested fix

The flag and sprecipients are stored separately, and an unreadable recipients record produces a noncritical load error. Neither a retained flag with missing recipients nor valid recipient data that reproduces the wrong scripts is exercised by the new tests. These guards prevent an input-changing bump from retaining stale SP scripts. Add reload cases that delete the record and replace it with valid but wrong recipient data. Assert the specific bumpfee error and an unchanged mempool in each case.


Link

[suggestion] · sendall's skipped-coin refusal has no coverage

The P2WSH-only test fails for lack of a shared-secret input, not because AvailableCoins skipped a coin that cannot be spent in an SP transaction.

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

Details and suggested fix

Without explicit inputs, sendall refuses an SP sweep if input filtering would leave coins behind. The current no-eligible-input test does not reach that branch because P2WSH coins are allowed in the transaction. Fund a wallet with an eligible P2WPKH coin and a tr(<xonly pub>,pk(<priv>)) coin whose internal private key is unavailable. Assert the skipped-coin error and that neither coin was spent. Then select only the eligible coin through inputs, verify its SP output with scan_tx, and check that the excluded coin remains unspent.


Link

[suggestion] · Independent SP scanner accepts future-witness spends

The Python test oracle continues scanning a transaction with a future-witness input, while BIP352 and the production receiver skip the whole transaction.

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

Details and suggested fix

get_input_pubkey returns no key for a native future-witness input, but scan merely drops that contribution and derives outputs from the other eligible inputs. It can therefore report an otherwise matching payment that the production receiver ignores. Before aggregating keys, return no matches if any native prevout is a witness program with version greater than 1. Add a unit case containing an eligible input, a v2 input, and an otherwise matching output. Do not reject every unrecognized script, since those do not all make a transaction ineligible.


Link

[suggestion] · GUI SP fee-bump branches lack coverage

The Qt bump tests do not exercise the new early SP unlock, recipient forwarding, or unsigned-export suppression.

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

Details and suggested fix

The MiniGUI fixture bumps only ordinary PKHash payments. It cannot detect removal of the early unlock, which SP output reconstruction needs before the later signing unlock, or loss of sp_recipients through the wallet interface. Extend it with an SP transaction created through the wallet API. Bump from a locked encrypted wallet with PSBT controls enabled, checking unlock and confirmation cancellation, restored lock state, absence of unsigned export, and preservation of the replacement's recipients.


Link

[suggestion] · Input-type fixtures change type after the first RPC

After sendtoaddress consumes the named P2PKH or P2SH-P2WPKH coin, the remaining RPCs in do_send spend P2WPKH change instead.

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

Details and suggested fix

Each named input-type test funds one coin, then do_send calls sendtoaddress, sendmany, send, and sendall on that wallet in sequence. The only internal descriptor is wpkh, so the first call replaces the named coin with P2WPKH change. In particular, these tests never exercise the separate sendall construction path with P2PKH or P2SH-P2WPKH inputs. Fund a fresh confirmed coin of the requested type before each RPC and assert the selected prevout script types.


Link

[suggestion] · Retained same-scan-key outputs lack lifecycle coverage

No end-to-end test independently discovers two retained outputs for one scan key through reload and an input-adding fee bump.

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

Details and suggested fix

SP change is deliberately derived after recipients, and the persisted destination order must reproduce that numbering. test_rbf_sp_change_dropped constructs a shared-scan-key pair but independently scans only after one member is dropped; the other multi-recipient tests use distinct scan keys. Add a send using the same SP destination as both recipient and change_address. Assert that the scanner finds both outputs, then reload and force an added input during fee bumping and repeat the assertion. The existing no-label scanner supports this case.


Link

[suggestion] · Ancestor-funding test repeats without exercising SP funding

The second target iteration repeats the same ancestor-funding comparison without making either tested transaction pay an SP destination.

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

Details and suggested fix

sendall_does_ancestor_aware_funding now runs for both remainder targets, but both sendall calls under its assertion still pay self.def_wallet.getnewaddress() with add_to_wallet=False. Only cleanup uses the selected remainder target. Use @for_each_target(allow_sp=False) to retain the existing comparison without repeating the parent sends, constructions, and mining. Genuine SP ancestor-funding coverage would need SP recipients and a fixture compatible with mandatory wallet commit.


Link

[suggestion] · Oversized-UTXO setup is duplicated for each target

The test funds another 1,600 outputs for the SP iteration even though the first rejected sweep leaves its oversized coin set intact.

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

Details and suggested fix

sendall rejects at the weight check before signing or commit, so the first iteration does not consume its 1,600 coins. Funding inside the loop adds another 1,600 for the SP target, which also derives SP outputs before reaching the size rejection. Move keypool refill, funding, and mining before the loop, then assert both target rejections against the same oversized set. This preserves the intended coverage without accumulating a second fixture.


Coverage details

Earlier concerns

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