Skip to content

Raise error on PSBTv0 missing PSBT_GLOBAL_UNSIGNED_TX - #149

Open
KY-U wants to merge 1 commit into
diybitcoinhardware:masterfrom
KY-U:2027-08-fix-psbtv0
Open

Raise error on PSBTv0 missing PSBT_GLOBAL_UNSIGNED_TX#149
KY-U wants to merge 1 commit into
diybitcoinhardware:masterfrom
KY-U:2027-08-fix-psbtv0

Conversation

@KY-U

@KY-U KY-U commented Aug 6, 2026

Copy link
Copy Markdown

PSBTv0 requires the field PSBT_GLOBAL_UNSIGNED_TX (0x00). However, the current parsing logic does not outright reject a PSBTv0 omiting that field. The resulting object's tx property then returns an empty default transaction (version=2, locktime=0, inputs=0 and outputs=0).

This PR raises an error when a PSBTv0 is missing the required PSBT_GLOBAL_UNSIGNED_TX field.

@KY-U
KY-U requested review from miketlk and odudex as code owners August 6, 2026 00:25
Copilot AI lite review requested due to automatic review settings August 6, 2026 00:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request tightens PSBT parsing to reject PSBTv0 payloads that omit the required PSBT_GLOBAL_UNSIGNED_TX (0x00) field, preventing callers from accidentally working with a synthesized empty default transaction.

Changes:

  • Add a validation in PSBT.read_from() to raise PSBTError when parsing a PSBTv0 that has no global unsigned transaction.
  • Add a regression test vector for a minimal PSBTv0 missing the unsigned transaction field.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/embit/psbt.py Adds a guard to error out when a PSBTv0 is missing PSBT_GLOBAL_UNSIGNED_TX.
tests/tests/test_psbt.py Adds an invalid vector exercising the missing-unsigned-tx case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/embit/psbt.py Outdated
Comment on lines 802 to 805
if tx is None and version is None:
raise PSBTError("Missing unsigned transaction in PSBTv0")
if tx and version == 2:
raise PSBTError("Global TX field is not allowed in PSBTv2")

@KY-U KY-U Aug 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included both the implicit and explicit v0 on the version check: version in (None, 0). However, I'm not sure whether treating every non-v2 version on the v0 validation is conceptually correct. I think it makes sense that an explicit v0 should follow the rule, while other values should probably be rejected as unsupported rather than fall on the same v0 rule.

I could add an extra case to explicitly fail on non-supported versions:

if version not in (None, 0, 2):
    raise PSBTError("Unsupported PSBT version")

Copilot AI review requested due to automatic review settings August 6, 2026 00:38
@KY-U
KY-U force-pushed the 2027-08-fix-psbtv0 branch from 4b210f0 to 90b5820 Compare August 6, 2026 00:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants