fix: use correct leafVersion in control block byte for non-default version leaves#2103
Open
jasonandjay wants to merge 1 commit intobitcoin:masterfrom
Open
fix: use correct leafVersion in control block byte for non-default version leaves#2103jasonandjay wants to merge 1 commit intobitcoin:masterfrom
jasonandjay wants to merge 1 commit intobitcoin:masterfrom
Conversation
…rsion leaves The P2MR control block's first byte encodes both the leaf version and parity bit: controlBlock[0] = (leafVersion & 0xfe) | parityBit. For the leaf with leafVersion 250 (0xFA), the correct first byte is 0xFB (with parity bit 1), not 0xC1 (which corresponds to leafVersion 192). Fix p2mr_different_version_leaves scriptPathControlBlocks[1] first byte from c1 to fb.
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
Fix the first byte of
scriptPathControlBlocks[1]in thep2mr_different_version_leavestest vector. The control block incorrectly uses
0xC1(leafVersion 192) instead of0xFB(leafVersion 250) for a leaf explicitly declared with
"leafVersion": 250.Problem
The P2MR control block's first byte encodes both the leaf version and parity bit:
For P2MR, the parity bit is always 1. So:
0xC10xFBThe test vector defines two leaves:
{ "id": 0, "leafVersion": 192, "script": "...OP_CHECKSIG" } { "id": 1, "leafVersion": 250, "script": "06424950333431" }But the current control block for leaf1 starts with
0xC1:This is incorrect because a verifier would extract
leafVersion = 0xC1 & 0xFE = 0xC0 = 192from this byte, then compute
tapleafHash(script, version=192)which produces acompletely different hash than the correct
tapleafHash(script, version=250), makingit impossible to reconstruct the correct Merkle root.
Fix
Change the first byte from
0xC1to0xFB:Verification:
Changes
p2mr_different_version_leaves: changescriptPathControlBlocks[1]first byte fromc1tofb