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 ConflictsNo conflicts as of last run. |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
| if (!input.witness_utxo.IsNull()) { | ||
| script = input.witness_utxo.scriptPubKey; | ||
| } else if (input.non_witness_utxo) { | ||
| if (input.prev_out >= input.non_witness_utxo->vout.size()) { |
There was a problem hiding this comment.
Why do I feel as if these checks are enough? Is there any motivation for someone intending to disagree non_witness_utxo and witness_utxo? Any risk involved? I have explored some possible paths and saw that at no particular point can this be internal.
There was a problem hiding this comment.
Hi vicjuma, thanks for your review!
Why do I feel as if these checks are enough?
For SignPSBTInput they are but FillPSBT wasn't using that same rule for key selection though, which is the gap this PR closes.
Is there any motivation for someone intending to disagree non_witness_utxo and witness_utxo?
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.
Any risk involved?
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.
I have explored some possible paths and saw that at no particular point can this be internal.
That's my understanding as well. I think this only corrects the external/mutated PSBT case.
0a13744 to
2c361ed
Compare
2c361ed to
7aed7f8
Compare
|
Resolved merge conflicts and rebased off master. |
|
ACK 7aed7f8 Reproduced on master first: Routing |
Bicaru20
left a comment
There was a problem hiding this comment.
Concept ACK
I agree with the approach taken. Before, If witness_utxo and non_witness_utxo. had conflicting scripts, FillPSBT could select a signing provider
different than SignPSBTInput (sinc ethe first one is looking at witness_utxo and the second one at non_witness_utxo) leaving the input as incomplete despite having the needed key. With this fix, FillPSBT will use GetUTXO sharing the same logic as SignPSBTInput and avoiding any disagreements.
I left some comments on the tests to try to make them more strong.
|
@nervana21 can you rebase here? |
Document and test prefer-non_witness, reject OOB/txid mismatch, and no witness fallthrough when fields disagree, before migrating callers.
Document that FillPSBT selects SigningProvider from witness_utxo even when a verified non_witness_utxo disagrees, before aligning it with GetUTXO.
7aed7f8 to
c4c2bf5
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Match SignPSBTInput by preferring a verified non_witness_utxo and rejecting a bad non_witness_utxo instead of falling back to a witness_utxo.
c4c2bf5 to
41272c9
Compare

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.