wallet: harden external signer psbt processing, revamp mock

bitcoin/bitcoin: PR #36114

1 major finding · 1 suggestion

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

Findings

Link

[major] · Existing finalized inputs make otherwise valid signer responses fail

With a signer that echoes existing finalized inputs, walletprocesspsbt now rejects mixed-participant PSBTs that previously succeeded; this failure was reproduced with the in-tree mock, not HWI.

Location: src/external_signer.cpp:170 (head).

Details and suggested fix

A participant's ordinary walletprocesspsbt call finalizes its inputs by default. If the external-signer wallet signs last, Core forwards those final fields alongside its own unsigned input. The mock's finalize=False prevents new finalization but leaves existing finals intact, so this response-wide guard returns EXTERNAL_SIGNER_FAILED before merging. The base accepted that response. A signer that strips existing final fields avoids the rejection, but preserving them should not require changing signer behavior: merging retains the request's populated final fields.

After checking that input counts match, reject only inputs finalized by the signer, using PSBTInputSigned(signer_psbtx->inputs[i]) && !PSBTInputSigned(psbtx.inputs[i]). Update doc/external-signer.md to allow unchanged, already-finalized inputs and add a test with a foreign input finalized before the signer call. The existing partially_finalized mode only tests finalization introduced by the signer.


Optional improvements

Link

[suggestion] · Sighash tests omit Taproot script-path signatures

The new sighash cases cannot detect removal of the m_tap_script_sigs scan because their Taproot fixtures only produce key-path signatures.

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

Details and suggested fix

Both the mock's exported watch-only descriptors and its imported private descriptors use key-only tr(...). Consequently, the bech32m hidden-sighash cases return PSBT_IN_TAP_KEY_SIG, leaving the separate script-path rejection branch untested. Add matching descriptors with a script leaf whose key the mock holds, force a script-path spend, and run sighash_none_hidden and sighash_single_hidden against it, plus a DEFAULT acceptance case. Removing the declaration ensures that rejection depends on inspecting the script-path signature itself.


Coverage details

Earlier concerns

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