Raise error on PSBTv0 missing PSBT_GLOBAL_UNSIGNED_TX - #149
Conversation
There was a problem hiding this comment.
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 raisePSBTErrorwhen 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.
| 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") |
There was a problem hiding this comment.
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")4b210f0 to
90b5820
Compare
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=0andoutputs=0).This PR raises an error when a PSBTv0 is missing the required
PSBT_GLOBAL_UNSIGNED_TXfield.