Review report

bitcoin/bitcoin: PR #33112

Provider refusals

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

2 major findings · 3 minor findings · 3 suggestions

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

Findings

Link

[major] · Encryption replaces live signer managers and resets address issuance

Encrypting an existing nonblank signer wallet with private keys enabled can leave dangling manager pointers and persist next_index=0 when the signer returns the same descriptors.

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

Details and suggested fix

The newly allowed external_signer=true disable_private_keys=false wallet can reach encryptwallet. Encryption calls SetupWalletGeneration(), which fetches device descriptors again. When those descriptors match the existing ones, their descriptor-derived IDs also match. AddScriptPubKeyMan replaces the owning unique_ptr, but m_cached_spks retains the freed manager pointers. Subsequent IsMine and GetSolvingProvider calls dereference them, causing undefined behavior or a crash. CreateNew also writes each descriptor with a new creation time and next_index=0, allowing already-issued addresses to be issued again. Reloading rebuilds the pointer cache but does not restore the issuance history of unused addresses. For an ordinary hot wallet switched to external signing, this path instead makes device descriptors active in place of its local descriptors, despite the RPC reporting a new HD seed. Encryption of an existing signer wallet should not re-import its device descriptors.


Link

[major] · Missing signer leaves encryptwallet committed but unlocked

For a nonblank signer wallet with private keys, an unavailable signer makes encryptwallet report an error after committing encryption, while skipping the final relock and database rewrite.

Location: src/wallet/wallet.cpp:352 (base).

Details and suggested fix

EncryptWallet commits the encrypted keys and master key, unlocks the wallet, and then calls signer-dependent generation. With external_signer enabled, an unset -signer, disconnected device or enumeration failure can throw before the final Lock(), Rewrite() and status notification. This is reachable by enabling the flag on a populated hot wallet without configuring a signer, or by disconnecting the signer before encrypting a private-key-enabled signer wallet. The RPC returns an error although the supplied passphrase now encrypts the wallet, and a retry is rejected as already encrypted. The wallet remains unlocked without a relock timer until manually locked or reloaded. The skipped VACUUM is intended to purge plaintext key remnants; whether recoverable remnants remain in this SQLite configuration is unconfirmed. Keep signer-dependent work out of the post-commit encryption path and guarantee relocking and rewriting on failure.


Link

[minor] · Deferred GUI signing runs after the wallet relocks

Initially locked, encrypted external-signer wallets cannot use their hot keys in the GUI Send flow because the preparation unlock expires before PSBT signing.

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

Details and suggested fix

This change defers signing from prepareTransaction to signWithExternalSigner, but PrepareSendText owns the UnlockContext. That context relocks an initially locked wallet when preparation returns, before the confirmation dialog and subsequent fillPSBT(sign=true) call. Signing does not request another unlock, so GetKeys() cannot decrypt the local keys and the hot descriptor's manager falls through to the device. A hot-only spend can fail the device-fingerprint check, while a mixed spend can return an incomplete PSBT despite the user having entered the passphrase. An already-unlocked wallet avoids this. Hold an unlock context through the signing step, as the fee-bump flow does.


Link

[minor] · Unfinalized local signatures still trigger the external signer

With walletprocesspsbt finalize=false, a sufficiently signed hot-only input still triggers the external signer, whose failure prevents the RPC from returning the local signatures.

Location: src/wallet/external_signer_scriptpubkeyman.cpp:117 (head).

Details and suggested fix

Imported hot descriptors now receive an ExternalSignerScriptPubKeyMan. For walletprocesspsbt sign=true finalize=false, its base-class call signs a hot-only input locally, but SignPSBTInput deliberately leaves the final scripts empty. PSBTInputSigned checks only those final fields, so this loop treats the input as unfinished and calls the signer. An unavailable signer returns EXTERNAL_SIGNER_NOT_FOUND; a connected signer whose fingerprint matches no input returns EXTERNAL_SIGNER_FAILED. The RPC throws rather than returning the locally signed PSBT. Default finalize=true avoids this, and the new hot-key test covers only that path. Decide whether an external signature is still needed from per-input signature sufficiency, independently of whether finalization was requested.


Link

[minor] · Unimported input scripts bypass the external signer

The new ownership filter can make walletprocesspsbt silently omit a device signature when supplied UTXOs spend unimported scripts, even if their key origins identify the device.

Location: src/wallet/external_signer_scriptpubkeyman.cpp:115 (head).

Details and suggested fix

For a coordinator-supplied PSBT spending an unimported multisig script, every external-signer manager skips the input when its UTXO is present. Each manager then returns without contacting the device, and walletprocesspsbt returns an incomplete PSBT without a signer error. Previously, unfinished inputs reached the signer wrapper, which checks key-origin fingerprints rather than exact wallet script ownership. Importing the full spending descriptor works around the change. No checked-in test or current caller producing this unimported-script input was found, so production occurrence is unconfirmed. Use signer key-origin relevance and outstanding signatures to decide whether to invoke the device, rather than requiring the exact script to belong to a manager.


Optional improvements

Link

[suggestion] · Flag-triggered reload leaves transient state and partial outcomes undocumented

Changing external_signer discards transient wallet state, and a subsequent load failure would leave the flag applied and wallet unloaded without explaining that partial outcome.

Location: src/wallet/rpc/wallet.cpp:415 (head).

Details and suggested fix

setwalletflag persists the flag before fully unloading and reloading the wallet. This clears unlock status, non-persistent coin locks, including funding-RPC locks, and ongoing MuSig2 sessions' memory-only secret nonces. The help mentions a reload and concurrent clients, but not these consequences. Document the discarded state, especially signing-session invalidation. Also report explicitly on reload failure that the flag was applied and the wallet needs loadwallet: LoadWalletForRPC can throw after the old wallet has been deleted, with no rollback. Loading existing external descriptors does not contact the signer, so a disconnected device is not a trigger. No concrete loading failure after successful unload was identified, and its frequency is unconfirmed.


Link

[suggestion] · Blank watch-only signer wallets remain unavailable in the GUI

The dialog cannot select external signer, disabled private keys and blank together, although the RPC supports and tests that combination.

Location: src/qt/createwalletdialog.cpp:43 (head).

Details and suggested fix

createwallet external_signer=true blank=true defaults to disabled private keys, and the new test asserts that this wallet has neither a keypool nor descriptors. The dialog cannot create that state: selecting external signing checks disabled private keys, whose handler disables and clears blank; selecting blank instead clears and disables disabled private keys. Consequently, a blank signer wallet created through the GUI must allow private keys. Leave blank selectable together with disabled private keys for external-signer wallets, while retaining the existing ordinary-wallet behavior.


Link

[suggestion] · Hot-key coverage omits the external-signer roundtrip

The hot-only test cannot catch local signatures being discarded when a spend also needs a device signature.

Location: test/functional/wallet_signer.py:268 (head).

Details and suggested fix

test_hot_key selects one wpkh hot UTXO with add_inputs=False. Device managers skip it, and its own manager finalizes it locally, so the external signer is never called. The existing device-only tests do not cover the combination either. This matters because CWallet::FillPSBT visits managers in pointer order, and ExternalSigner::SignTransaction replaces the whole PSBT with the signer's response. Add a spend requiring both local and device signatures and assert completeness and mempool acceptance. The current mock returns a precomputed PSBT, so this needs a mock that merges its signature into the supplied PSBT, making the result depend on preserving the local signature.


Coverage details

Earlier concerns

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