Reject PSBT inputs that carry no utxo data - #966
Open
ruipereira1 wants to merge 2 commits into
Open
Conversation
The parser assumed the payload is always preceded by OP_PUSHDATA1 and sliced the scriptPubKey at a fixed offset of 3. That encoding is only required for payloads of 76-80 bytes; anything up to 75 bytes uses a single-byte direct push, which is what Bitcoin Core emits. For those the fixed offset drops the payload's first byte, so the OP_RETURN review screen shows the user data that differs from what they are about to sign. Read the push opcode instead of assuming its width, and slice to the declared length so trailing bytes are not included. The existing test vectors all encode OP_PUSHDATA1 explicitly, which is why this was not caught.
`_parse_inputs` sets `script_pubkey` from whichever utxo field the input has. An input with neither leaves the local variable bound to the previous iteration's value, so `_get_policy()` evaluates that input against a different input's scriptPubKey. On the first input it raises UnboundLocalError instead. Raise explicitly rather than reading a stale value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem or Issue being addressed
PSBTParser._parse_inputs()assignsscript_pubkeyfrom whichever utxo field an inputcarries:
An input with neither field leaves the local variable bound to the previous iteration's
value, so that input's policy is derived from a different input's script. On the first
input it raises
UnboundLocalErrorinstead — confirmed by the added test, which stripswitness_utxo/non_witness_utxofrom a single-input PSBT.Solution
An explicit
elsethat raises, rather than reading a stale value.This is defensive rather than a fix for an observed failure:
psbt.fee()later in_parse_outputs()would most likely raise first on such a PSBT. But silently reusing thelast loop value does not belong in the code that decides whether a transaction has mixed
inputs.
Additional Information
The error message is short because
Controller.handle_exceptionrenders it on the errorscreen.
Screenshots
No new or modified screens.
This pull request is categorized as a:
Checklist
I ran
pytestlocallyI included screenshots of any new or modified screens
I added or updated tests
I tested this PR hands-on on the following platform(s):
I have reviewed these notes: