What are "leaf versions", when do you upgrade a version, how many versions are there and how do they differ from segwit versions?


SegWit introduced versioned witness programs. When satisfying a script to spend coins you need to provide a redeem script consisting of a version byte and a witness program. The version introduced with SegWit was version 0 (zero).

The Taproot proposal uses this SegWit versioning system by introducing spending rules for version 1. The witness program to satisfy a Taproot spend will be version 1.

The Taproot proposal also introduces a new versioning system in addition to SegWit versions called leaf versions. Each leaf of a Taproot tree will have its own leaf version. This is a version for spending rules from that particular leaf. The leaf version introduced with the Taproot proposal is version 0.

So in answer to your question there is just one leaf version with the Taproot proposal and a new SegWit version (to make two SegWit versions in total). The versions are there for future upgrades and as a user you do not need to upgrade anything like you might say upgrade the "version" of your Bitcoin Core software.

Remember that Taproot is still a proposal at this stage (July 2020) and so at the current time SegWit version 1 and leaf versions are not relevant to any transactions you might make on the Bitcoin network.

[darosior edit: There are 41 possible leaf versions (including version zero) for future upgrades as outlined in BIP-Taproot]

| improve this answer | |
  • Maybe worth mentioning that there are 41 possible leaf versions: github.com/bitcoin/bips/blob/master/… . – darosior Jul 20 at 11:13
  • Where do you get 41 from? The BIP refers to 32 leaf versions satisfying those constraints? – Michael Folkson Jul 20 at 11:23
  • 1
    There are 32 even leaf versions between 0xc0 and 0xfe, to which we add the 9 values 0x66, 0x7e, 0x80, 0x84, 0x96, 0x98, 0xba, 0xbc, 0xbe. – darosior Jul 20 at 11:32
  • Sorry I can't read ;) – Michael Folkson Jul 20 at 11:42

To add to Michael Folkson's answer, a question one may have is what the differences are between witness versions and leaf versions. Why do we need both?

  • Leaf versions are not revealed until an output is spent, and thus is not known in general to the payer (who is only given an address). For native witness outputs, the witness version is visible from the the BIP173 address.
  • Leaf versions do not need to be the same for every script branch. This means that if you have an output that can spent either using an old script, or in rare cases using a fancy new script that needs a new version, the fact that you're using this new version in the first place is not revealed to the network unless it actually needs to be used.
  • Leaf versions are cheaper, as they are only revealed in witness data (which is discounted by a factor 4 per BIP141). Witness versions are revealed in scriptPubKeys (or scriptSigs for P2SH wrapped ones).
  • The namespace of leaf versions is less restrictive (there are ~40 of them, while only 17 witness versions).
  • Leaf versions can be used to change script semantics, but are restricted to a Taproot structure. Witness versions can change anything, including the taproot structure.

In general, witness versions seem more appropriate for changes to the "structure" of spending conditions (taproot, graftroot, cross-input aggregation, ...), while leaf versions are more for changes to the execution rules of individual scripts.

See What are the different upgradeability features in the BIP-Taproot (BIP 341) proposal? for information on more extensibility features in taproot.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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