mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
wallet: select FillPSBT SigningProvider via GetUTXO #35747
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35747
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-fillpsbt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
A PSBT input can carry both a
non_witness_utxoand awitness_utxo.GetUTXOprefers a verifiednon_witness_utxoand does not fall back towitness_utxowhen thenon_witness_utxois present but unusable.Previously,
FillPSBTselected theSigningProviderfrom thewitness_utxowhenever it was set. When the two disagreed,FillPSBTloaded keys for thewitness_utxoscript whileSignPSBTInputsigned thenon_witness_utxospend. This could lead to an incomplete input even though the wallet owns the appropriatenon_witness_utxoscript.Fix
Route
FillPSBTthroughGetUTXOso it sharesSignPSBTInput's prefer/reject rule.Behavior change
FillPSBTnow usesGetUTXOfor script selection, so an input whosenon_witness_utxois present but unusable (out-of-range or txid-mismatched) returnsMISSING_INPUTSinstead of first selecting a script fromwitness_utxo.SignPSBTInputrejects the same input withMISSING_INPUTS, andFillPSBTalready propagates any non-INCOMPLETEerror for the remainingScriptPubKeyMans and inputs. The change is that the failure is detected at script selection rather than after a mistaken key lookup.Well-formed PSBTs are unaffected, since
witness_utxoandnon_witness_utxoresolve to the same script. Txid handling is also tightened in the selection path. A txid-mismatchednon_witness_utxois now rejected byGetUTXOrather than used for script selection when nowitness_utxois present.Testing
fillpsbt_signs_despite_conflicting_witness_utxocovers the regression.psbt2_getutxopins theGetUTXOprefer/reject rules the fix relies on.Follow-up
SignPSBTInput,PSBTInputSignedAndVerified, anddecodepsbtfee totaling still reimplementGetUTXO's logic and risk the same divergence. Refactoring them is left for a follow-up.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
🚧 At least one of the CI tasks failed.
Task
tidy: https://github.com/bitcoin/bitcoin/actions/runs/29695490423/job/88215409202LLM reason (✨ experimental): CI failed because
clang-tidyreported abugprone-argument-commenterror (commented argument name mismatch inwallet/test/psbt_wallet_tests.cpp), treated as warnings-as-errors.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Why do I feel as if these checks are enough? Is there any motivation for someone intending to disagree
non_witness_utxoandwitness_utxo? Any risk involved? I have explored some possible paths and saw that at no particular point can this be internal.Hi vicjuma, thanks for your review!
For
SignPSBTInputthey are butFillPSBTwasn't using that same rule for key selection though, which is the gap this PR closes.IIUC, a malicious or otherwise buggy PSBT coordinator could add a faulty witness_utxo to an honest peer's already-existing non_witness_utxo. That would cause FillPSBT to choose the faulty witness_utxo for key selection instead of the desired non_witness_utxo, so signing could fail even though we owned the right input.
As I see it, the risk with the old FillPSBT behavior is just that signing fails or stays incomplete. We'd never sign the wrong utxo.
That's my understanding as well. I think this only corrects the external/mutated PSBT case.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
Resolved merge conflicts and rebased off master.
Earlier concerns neither republished nor resolved: 1 minor finding. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · Legacy signing retains a conflicting
witness_utxothat can discard verified dataConflicting
witness_utxodata can still make legacy inputs incomplete after signing, a pre-existing limitation that survives this fix; no current producer of such PSBTs was identified.Location:
src/wallet/scriptpubkeyman.cpp:1406(head).🔵 Suggestion · The conflicting-UTXO test omits update-only metadata filling
The new test checks signing completion but does not cover the changed provider selection for update-only
FillPSBTcalls.Location:
src/wallet/scriptpubkeyman.cpp:1413(head).Reviewed:
41272c98d033· Review report · Previous reportspermalink
ACK
7aed7f8d17Reproduced on master first:
fillpsbt_signs_despite_conflicting_witness_utxofails there and passes with the fix. Reverting just thescriptpubkeyman.cppchange brings the failure back. Full unit and functional suites pass.Routing
FillPSBTthroughGetUTXOmatchesSignPSBTInput's selection, so when thewitness_utxodisagrees with thenon_witness_utxo, the wallet no longer loads keys for the wrong script. Nice fix, thanks.🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
I agree with the approach taken. Before, If
witness_utxoandnon_witness_utxo. had conflicting scripts,FillPSBTcould select a signing providerdifferent than
SignPSBTInput(sinc ethe first one is looking atwitness_utxoand the second one atnon_witness_utxo) leaving the input as incomplete despite having the needed key. With this fix,FillPSBTwill useGetUTXOsharing the same logic asSignPSBTInputand avoiding any disagreements.I left some comments on the tests to try to make them more strong.
I think to imporve the test we could create the witness_utxo with a diferent script to see if this script is kept. Sth like this:
You could also check if it is the same output to avoid doing extra checks:
Same as before:
We could an extra check to ensure that the
witness_utxois now the same asnon_witness_utxo@nervana21 can you rebase here?
Done.
Done.
In the behavior under test, after
FillPSBT, we still expectwitness_utxoandnon_witness_utxoto disagree. The function does not make them equal.Instead we test that the
FillPSBTcall selects the correct utxo type.Nice catch here, but I think
SignPSBTInputside-effect behavior is out of scope. For now, will leave tests of that behavior as a follow up and focus onFillPSBT.Thanks for reviewing!
Updates:
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/46673188214/job/142733738530LLM reason (✨ experimental): intermittent_network: Dependency installation failed because Ubuntu package repositories repeatedly returned 503s and connection errors, leaving required packages unavailable.
Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.
A functional or integration test failure may be intermittent or unrelated to this pull request.
If no dedicated issue thread exists, create a new one to track it.
Leave a comment here, if you need help tracking down a confusing failure.