Fix PSBT serialization: remove stray 0x00 when there are no inputs or no outputs (bip174 patch)#2338
Open
jstortoise wants to merge 1 commit into
Open
Fix PSBT serialization: remove stray 0x00 when there are no inputs or no outputs (bip174 patch)#2338jstortoise wants to merge 1 commit into
jstortoise wants to merge 1 commit into
Conversation
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.
Summary
PSBTs built with empty input lists and/or empty output lists were serialized with one extra
0x00byte per empty side. That came frombip174’skeyValsOrEmptyToBuffer, which treated “no maps” as a single zero-length map delimiter. That does not match a strict BIP-174-style layout and can break interoperability with parsers in other stacks that expect the canonical byte length.What we changed
patch-packagepatch onbip174@3.0.0so that when there are no input maps or no output maps, we append nothing instead of[Uint8Array.from([0])].postinstalltopatch-packageso a cleannpm installreapplies the patch.test/fixtures/psbt.jsonfor theaddInput/ “should be equal” case so the expected base64 matches the corrected serialization.Testing
npx mocha 'test/*.ts'.Follow-up
bip174releases a version with this fix, we should bump the dependency, deletepatches/bip174+3.0.0.patch, and removepostinstall/patch-packageif no other patches remain.