Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where comparison-specific test macros should replace generic comparisons:
2026-12-01 18:09:13 |
|
cc @bigspider and other hardware wallet folks, any other hardware wallet shenanigans we should check against (perhaps in a followup)? |
This comment was marked as resolved.
This comment was marked as resolved.
…nd revamp mock # Conflicts: # test/functional/wallet_signer.py
bitcoin#33112 tests walletdisplayaddress for an imported external-signer descriptor using the same xpub as a wallet exercised earlier in wallet_signer.py. bitcoin#36114 then revamps the shared external signer mock used by the test. With #127, the imported descriptor's known HD keys are filled immediately, so its first address is recognized as used and the wallet advances to the next index, which the mock intentionally maps to wrong_address for a separate error case. Let the test configure the address echoed by the mock so it remains independent of the derived index while preserving the mismatched-address coverage.
79fb761 to
0567fa6
Compare
jeanpablojp
left a comment
There was a problem hiding this comment.
Concept ACK
I made the new mock return a finalized response and FindUnsafeSighashType doesn't catch it. The fields it reads are the ones PSBTInput::Serialize writes only when the input isn't finalized, and BIP 174 has a finalizer clear them, so the signatures arrive in final_script_sig and final_script_witness alone.
With SIGHASH_NONE the send comes back complete, both signatures in the transaction end in 0x02, and testmempoolaccept allows it.
The commit message says the change rejects a response containing signatures made with an unsafe sighash type, and a finalized one does. The different-transaction check still rejects a finalized response that changes an output.
Is skipping the finalized case deliberate, or worth covering?
| } | ||
|
|
||
| if (!psbtx.Merge(*signer_psbtx)) { | ||
| error = "Signer returned a PSBT for a different transaction"; |
There was a problem hiding this comment.
nit: Merge only returns false for two reasons, GetUniqueID and the version comparison, since neither PSBTInput::Merge nor PSBTOutput::Merge has a failure path.
I returned the same transaction as a v0 PSBT and send failed with this message. GetUniqueID is what stops it, since it zeroes nSequence only from version 2 on, and before this commit that response was accepted.
Worth a separate message, or does the signer have to return the version it was given?
There was a problem hiding this comment.
I added a constraint that the version must match.
| self.log.info('The signer must not use unsafe sighash types') | ||
| # The first mode declares the sighash type in the PSBT, the second | ||
| # leaves it out, so only the signatures themselves reveal it | ||
| for mode in ["sighash_none", "sighash_none_hidden"]: |
There was a problem hiding this comment.
nit: this transaction has an ECDSA and a taproot input, and FindUnsafeSighashType collects from both before it scans, so either signature alone triggers the rejection. Disabling the m_tap_key_sig collection leaves wallet_signer.py green, and disabling the partial_sigs one does too. Only removing both makes sighash_none_hidden fail.
A single-input transaction of each type would make each branch carry its own case. Worth adding?
0567fa6 to
50270c0
Compare
|
Rebased after #36076 and addressed @jeanpablojp's feedback.
It now rejects finalized PSBTs, which avoids complicating I simplified test setup by using Also enforced IWYU. |
…nd revamp mock # Conflicts: # test/functional/wallet_signer.py
bitcoin#33112 tests walletdisplayaddress for an imported external-signer descriptor using the same xpub as a wallet exercised earlier in wallet_signer.py. bitcoin#36114 then revamps the shared external signer mock used by the test. With #127, the imported descriptor's known HD keys are filled immediately, so its first address is recognized as used and the wallet advances to the next index, which the mock intentionally maps to wrong_address for a separate error case. Let the test configure the address echoed by the mock so it remains independent of the derived index while preserving the mismatched-address coverage.
…nd revamp mock # Conflicts: # test/functional/wallet_signer.py
bitcoin#33112 tests walletdisplayaddress for an imported external-signer descriptor using the same xpub as a wallet exercised earlier in wallet_signer.py. bitcoin#36114 then revamps the shared external signer mock used by the test. With #127, the imported descriptor's known HD keys are filled immediately, so its first address is recognized as used and the wallet advances to the next index, which the mock intentionally maps to wrong_address for a separate error case. Let the test configure the address echoed by the mock so it remains independent of the derived index while preserving the mismatched-address coverage.
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
|
Concept ACK Built on macOS arm64 and tested an edge case around PSBTv2 input sequences in In If a caller passes a v2 PSBT with an omitted
Would it make sense to snapshot (Disclosure per AI policy: used an LLM while auditing |
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of the R42 series, which builds only at its final commit. Refs bitcoin-core#1122
Check that the transaction returned by an external signer has exactly the reviewed terms; signing may only add signatures. Refuse a substituted transaction. These are the app-side checks; the full fix needs bitcoin/bitcoin#36114 in Core. Part of a series that builds only at its final commit. Refs bitcoin-core#1122
The external signer mock previously replayed a PSBT that the test prepared in advance. This makes it difficult to test more complicated scenarios like a misbehaving wallet and (MuSig2) multisig. Instead, give the mock its own descriptor wallet. The test provides a dedicated node for this wallet and keeps it offline, so the mock can't cheat by e.g. inspecting the UTXO set. The mock creates the wallet on first use and signs with walletprocesspsbt. wallet_signer.py now funds all four descriptor types and spends them in a single transaction, exercising every signing code path.
Co-authored-by: brunoerg <[email protected]>
Reject a signer response with a different PSBT version and report the expected and returned versions. Document the requirement and test a v0 response to a v2 request.
Return the txid of the unsigned transaction. Unlike GetUniqueID(), it commits to PSBTv2 input sequences. Also document GetUniqueID().
Previously the PSBT returned by the external signer replaced the original wholesale, trusting the signer not to modify the transaction. Merge it instead, and reject the response if it describes a different transaction or if merging would change the unsigned transaction. This also supports signers that strip fields they don't need from their response. Test a stripped response, and signers that change an output amount or script, remove an output, or add a PSBT v2 input sequence that the original omits. A signer that changes an existing sequence or corrupts a signature must leave the original transaction unchanged and the PSBT incomplete. Test ECDSA and Schnorr signatures independently. Suggested in: bitcoin#36114 (comment) and bitcoin#36114 (comment) Co-authored-by: brunoerg <[email protected]>
Require signer responses to keep signatures in non-final fields and leave finalization to Bitcoin Core. Document the requirement in the signer API. Test final scriptSig and witness fields independently, including responses that finalize only one input.
A signature with SIGHASH_NONE or SIGHASH_SINGLE doesn't commit to all outputs, letting anyone alter them after signing. Reject a PSBT from an external signer that declares such a sighash type or contains signatures made with one. SIGHASH_ANYONECANPAY is still accepted: it only permits adding inputs, which does not affect us. The mock signer produces real signatures for these scenarios by letting its wallet sign with the requested sighash type, optionally hiding the declared sighash type field so that only the signatures themselves reveal it. Co-authored-by: brunoerg <[email protected]>
aee9e7a to
70f1357
Compare
|
@johnny9 that's quite a lot of back-pings :-) Added a check based on @enessubass's feedback: #36114 (comment) I ended up adding a |
|
ACK 70f1357
(AI policy disclosure: used an LLM to help script the local regtest checks; reviewed the commits directly.) |

The current external signer functional test mock can only echo a prepared PSBT. This gets in the way of testing more complicated scenarios, i.e. misbehaving signers and (MuSig2) multisig.
GetUnsignedTxid(): unlikeGetUniqueID(), this commits to PSBTv2 input sequences, which BIP 370 lets Updaters and Combiners change.The remaining commits prepare the test helpers and enforce IWYU for
src/external_signer.cpp.This PR absorbs the scenarios from #35358, but is better able to test them thanks to the new mock signer implementation.
This PR does not intend to fully harden against a malicious external signer, and can't protect against a malicious HWI (equivalent) process running as the same user.