0

I asked a few questions within this one. They are all related to the leaf version, so I didn't find it necessary to split them into multiple separate questions as they can all be answered in 1/2 a sentence (at least I assume).

Thanks to all in advance.

  1. What is leaf version?
    • In BIP341 they say that leaf represents a logical AND between the first byte of the control block and 0xfe.
      • I quote: "Let v = c[0] & 0xfe and call it the leaf version"
    • Pieter Wuille said in his answer that only the top 7 bits of the first byte of the control block (11111110) represent leaf version while the first (bottom) bit (00000001) of the same byte is a sign.
      • I quote: "Its first byte stores the leaf version (#3) (top 7 bits) and the sign bit (#6) (bottom bit)."
    • In some answers/articles I also read that the leaf version represents entire first byte of the control block.
  2. What is the purpose of leaf version?
    • As I understand it, it is a way to indicate which type of script is used, i.e. that some special opcodes can be found within that script or that the existing ones have a different meaning, or that the content of that script has some totally new special meaning. Therefore, each leaf (script), has its version that defines the way in which we observe its content (something similar to the witness version in segWit). So, when we use a script from MAST, we must also specify its version in order to know how its content is treated (but also to correctly calculate the complete tree). Am I right?
  3. What is the leaf version value for using the normal (standard) Bitcoin scripts if its even possible to use them inside taproot? (with normal script I mean on scripts used in non-segwit outputs or in P2SH etc.)
  4. What are the all possible values for the leaf version?
    • BIP341[7] and Pieter Wuille gave some answers, but I still do not understand. I understand why it cannot be 0x50 (so as not to be confused with the annex) and why it can be only even value (because logical AND is done with 11111110), but it is not clear to me why there must be only those values listed there in the BIP341[7]/Pieter Wuille's answer.

1 Answer 1

1
  1. By the definition in BIP341, the leaf version is the first byte of the control block, after masking out its bottom bit. It is certainly not the entire first byte.

  2. Yes, exactly.

  3. Currently only one leaf version is defined, namely 0xc0, in BIP342. Using any other leaf version is non-standard, and has no associated semantics (meaning that any spend of it is valid, as long as it's properly revealed as described in BIP341). Thus wallets absolutely shouldn't use any other leaf versions (until more are defined, and their consensus rules deployed).

    • The leaf version can be any even byte value, except 0x50 (because that would make it conflict with the annex). So it's not illegal for wallets to construct transactions that use any leaf version but 0x50 (but see the previous point why they shouldn't).
    • It is advisable for future consensus changes to Bitcoin to pick leaf versions from that list in BIP341, because that permits certain kinds of contextless analysis: the ability to recognize what leaf version a transaction input uses without knowing the output. This ability may or may not turn out to be useful, but because adding leaf versions is probably very rare, it's unlikely to be burdensome to stick to this list. This is a suggestion for future protocol changes, but has no bearing on wallet software (before such changes happen).
4
  • 1) So the leaf version actually, as you said, represents just the top 7 bits of the first byte within control block since the content of that byte is masked with the 11111110 and by that the first (bottom) bit is not important. 3) Does it mean that we can make some script with the leaf version of, for example, 0xc4, create MAST with such a script and thereby make one of the paths of the three (MAST) as anyone-can-spend?
    – LeaBit
    Commented Nov 17, 2023 at 3:08
  • Right, if someone were to reveal the script path with leaf 0xc4, then the script and script inputs don't matter. Commented Nov 17, 2023 at 12:27
  • You also mentioned that the other leaf versions are "not-standard". Do you, by saying "non-standard", refer to the rules for "relaying" transactions or in this case "non-standard" has some other context? So transactions with leaf version other than 0xc0 (or sometimes 0xc1 if you look at the entire first byte within control block) won't be relayed, but will be consensus acceptable?
    – LeaBit
    Commented Nov 17, 2023 at 17:09
  • 1
    That's correct. BIP341 only controls the consensus rules, and according to those, any leaf version is fine. By the standard relay policy implemented in Bitcoin Core today, only leaf version 0xc0 is relayed. Commented Nov 17, 2023 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.