Fix #2249: Use slice() instead of subarray() to preserve Buffer type#2320
Closed
R-Panic wants to merge 1 commit into
Closed
Fix #2249: Use slice() instead of subarray() to preserve Buffer type#2320R-Panic wants to merge 1 commit into
R-Panic wants to merge 1 commit into
Conversation
- Changed script.subarray(2, 34) to script.slice(2, 34) in getPrevoutTaprootKey - Changed signature.subarray(0, 64) to signature.slice(0, 64) in trimTaprootSig - Fixes spurious Buffer.equals() failures when comparing Taproot keys - Buffer.slice() returns Buffer while Buffer.subarray() returns Uint8Array view - Resolves compatibility issue between bip371.toXOnly() output and Uint8Array arguments Fixes bitcoinjs#2249
Member
|
We are migrating away from Buffer. The solution is not to move back to Buffer, it's to fix the BIP371 code to not use Buffer.equals(). |
Member
|
Oh, I see. The issue is from an old version. The current version no longer has the same issue. If it does, let me know. |
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.
Fixes #2249
Summary
Fixed Buffer type mismatch issue in PSBT Taproot handling where
Buffer.subarray()was returningUint8Arrayinstead ofBuffer, causingBuffer.equals()comparisons to fail even when byte content is identical.Changes
script.subarray(2, 34)toscript.slice(2, 34)ingetPrevoutTaprootKey()signature.subarray(0, 64)tosignature.slice(0, 64)intrimTaprootSig()Root Cause
Node.js
Buffer.subarray()returns aUint8Arrayview of the underlying buffer, whileBuffer.slice()returns a newBufferwith its own backing. The issue comment in #2249 explains:Impact
Buffer.equals()failures in BIP371 PSBT Taproot signature verificationTesting
Manual verification: The fix matches the exact solution provided by the issue reporter and addresses both occurrences identified in the codebase.