Since TaprootBuilder has assertions for the depth and leaf versions, the PSBT decoder should check these values before calling TaprootBuilder::Add so that the assertions are not triggered on malformed taproot trees.
Fixes #22558 (comment)
Since TaprootBuilder has assertions for the depth and leaf versions, the PSBT decoder should check these values before calling TaprootBuilder::Add so that the assertions are not triggered on malformed taproot trees.
Fixes #22558 (comment)
Since TaprootBuilder has assertions for the depth and leaf versions, the
PSBT decoder should check these values before calling
TaprootBuilder::Add so that the assertions are not triggered on
malformed taproot trees.
utACK 76fb300b63c5c0d01d768510ec69d894820432fa
Maybe reject 0x50
too as that’s reserved for the annex.
Maybe reject
0x50
too as that’s reserved for the annex.
I don’t think the annex byte has any effect on the leaf version. AFAICT, a future leaf version could b 0x50
too and it wouldn’t conflict with the annex.
From BIP341:
What constraints are there on the leaf version? First, the leaf version cannot be odd as c[0] & 0xfe will always be even, and cannot be 0x50 as that would result in ambiguity with the annex. In addition, in order to support some forms of static analysis that rely on being able to identify script spends without access to the output being spent, it is recommended to avoid using any leaf versions that would conflict with a valid first byte of either a valid P2WPKH pubkey or a valid P2WSH script (that is, both v and v | 1 should be an undefined, invalid or disabled opcode or an opcode that is not valid as the first opcode). The values that comply to this rule are the 32 even values between 0xc0 and 0xfe and also 0x66, 0x7e, 0x80, 0x84, 0x96, 0x98, 0xba, 0xbc, 0xbe. Note also that this constraint implies that leaf versions should be shared amongst different witness versions, as knowing the witness version requires access to the output being spent.
I guess it’s in theory possible to use 0x50 as leaf version, but it would be only be usable in spends that also have an annex.
If we want to add direct PSBT support for annexes later, presumably in the form of additional keytype
’s, it may save us some headache if we disallow 0x50
as a leaf version here. The downside is that if in some far future we end up having to introduce leaf version 0x50, we (or the AI programmer) have to remember to remove the throw
.
https://github.com/bitcoin/bips/blob/master/bip-0371.mediawiki
@achow101 The leaf version is the first byte of the last witness stack element in a P2TR script path spend, after skipping over the annex field if present, which would follow the control block.
So while there is no actual consensus rule against leaf version 0x50, constructing a spend for it would imply the spend must have an annex as well, because otherwise the control block would be interpreted as an annex.
For this reason, the BIP does state that leaf version cannot be 0x50.