Repository navigation
Conversation
In ReadXPub, uint32Size * (numPathElements + 1) was evaluated in uint8 before converting to int, causing expectedSize to wrap around for extended keys with Depth() >= 63. Cast numPathElements to int before arithmetic and add a regression test.
In NewFromRawBytes, the duplicate check for PSBT_GLOBAL_XPUB compared x.ExtendedKey against keyData (from the earlier UnsignedTxType check, which is always nil) instead of keydata from the loop iteration. Compare against keydata and add a regression test.
In Extract, witCount was decoded as an unvalidated uint64 varint and passed directly to make(wire.TxWitness, witCount), allowing malformed FinalScriptWitness payloads to trigger a slice allocation panic. Reject witCount values exceeding witnessReader.Len() with ErrInvalidPsbtFormat and add a regression test.
TaprootScriptSpendSig.SortBefore combined XOnlyPubKey and LeafHash comparisons with && instead of lexicographical tie-breaking, returning false whenever two entries shared the same XOnlyPubKey. Break ties on XOnlyPubKey using LeafHash and add a regression test.
acxxcxx
force-pushed
the
fix/psbt-validation-sort
branch
from
November 19, 2026 02:04
0ba72d0 to
a469fa9
Compare
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.
Change Description
Fixes four edge-case bugs in
psbtdeserialization, sorting, and extraction:ReadXPub(psbt/bip32.go): castnumPathElements(uint8) tointbefore multiplying by
uint32Sizeto avoiduint8overflow for extendedkeys with
Depth() >= 63.NewFromRawBytes(psbt/psbt.go): comparex.ExtendedKeyagainstkeydatainstead of the shadowed
keyData(nil) so duplicate globalPSBT_GLOBAL_XPUBkeys are rejected per BIP-174.Extract(psbt/extractor.go): validatewitCount <= uint64(witnessReader.Len())before allocatingmake(wire.TxWitness, witCount)to prevent slice allocation panics onmalformed
FinalScriptWitnesspayloads.TaprootScriptSpendSig.SortBefore(psbt/taproot.go): compareXOnlyPubKeyand
LeafHashlexicographically rather than with&&so entries sharing thesame
XOnlyPubKeysatisfy strict weak ordering.psbt/bip32_test.go,psbt/psbt_test.go, andpsbt/sort_test.gowith both positive controls and error-path assertions forall four cases.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.