Glossary

Taproot Leaf Version

Learn what Taproot leaf versions are and how they enable future Bitcoin script upgrades.

Key Takeaways

  • A Taproot leaf version is a byte in the control block that tells nodes which script validation rules apply to a given Tapscript leaf. Currently only leaf version 0xC0 is defined, selecting BIP 342 Tapscript rules.
  • Unknown leaf versions are treated as automatically valid (anyone can spend), which lets future soft forks assign new script languages to unused versions without changing the Taproot output structure.
  • This design mirrors the witness version upgrade mechanism from SegWit but operates at a finer granularity: individual leaves within a single Taproot output can each carry their own version.

What Is a Taproot Leaf Version?

A Taproot leaf version is a version tag embedded in the control block of a Taproot script-path spend. When someone spends a Taproot output using a script rather than a key-path signature, they reveal a control block alongside the script. The first byte of that control block encodes two pieces of information: the leaf version (upper 7 bits) and the output key's y-coordinate parity (lowest bit). The leaf version tells validating nodes which set of script rules to apply when executing the revealed script.

As defined in BIP 341, the leaf version is extracted by masking the first control byte with 0xFE (ignoring the parity bit). This yields an even number between 0x00 and 0xFE, giving Bitcoin up to 128 possible leaf versions for future script languages. Today only one is assigned: leaf version 0xC0, which activates BIP 342 Tapscript validation rules.

The leaf version is a critical part of Taproot's forward-compatibility design. Rather than defining a single script language that must be changed through disruptive upgrades, Taproot reserves an entire version space so that new scripting capabilities can be introduced incrementally through soft forks.

How It Works

To understand leaf versions, it helps to see where they appear in the lifecycle of a Taproot script-path spend.

Control Block Structure

When spending via a script path, the witness stack includes the script itself plus a control block. The control block has a fixed structure:

Control block layout:
  Byte 0:      [leaf_version | output_key_parity]
  Bytes 1-32:  Internal public key (32 bytes, x-only)
  Bytes 33+:   Merkle proof hashes (0 to 128 hashes, 32 bytes each)

Total size: 33 + 32m bytes, where m = number of proof hashes

The first byte packs two values together. The leaf version occupies the upper 7 bits (extracted with c[0] & 0xFE), while the lowest bit carries the parity of the output key's y-coordinate. This compact encoding means the version and parity share a single byte without ambiguity.

Tapleaf Hash Commitment

The leaf version is not just metadata: it is cryptographically committed to in the TapTree via the tapleaf hash. This hash is computed as:

tapleaf_hash = tagged_hash("TapLeaf", leaf_version || compact_size(script_len) || script)

Because the leaf version is included in the hash, a script committed under version 0xC0 cannot be replayed under a different version. The Merkle root, and ultimately the Taproot output key, commits to the exact version of every leaf in the tree. This prevents cross-version attacks where someone tries to execute a script under different validation rules than the output creator intended.

Validation Flow

When a node validates a Taproot script-path spend, it follows these steps:

  1. Extract the control block from the witness stack and verify its length is 33 + 32m for some integer m between 0 and 128
  2. Parse the first byte: compute the leaf version as c[0] & 0xFE and the parity bit as c[0] & 0x01
  3. Compute the tapleaf hash using the leaf version and the revealed script
  4. Walk the Merkle proof to reconstruct the root and verify it matches the tweaked output key
  5. If the leaf version is 0xC0, apply BIP 342 Tapscript rules to execute the script
  6. If the leaf version is anything else, the spend is valid with no further checks

Step 6 is the key to the upgrade mechanism. Since nodes treat unknown leaf versions as automatically valid, a future soft fork can tighten those rules by adding validation logic for a new version. Existing nodes continue to accept the spend, while upgraded nodes enforce the new rules.

Comparison with SegWit Witness Versions

Taproot leaf versions serve a similar purpose to SegWit witness versions, but they operate at a different level. Witness versions define which top-level spending rules apply to an entire output: version 0 selects P2WPKH/P2WSH rules, version 1 selects Taproot rules, and versions 2 through 16 are reserved for future upgrades.

Leaf versions work within a single Taproot output. A TapTree can contain many leaves, and each leaf can theoretically carry a different version. This means a single output could offer spending paths under multiple script languages, each governed by its own validation rules.

PropertyWitness VersionLeaf Version
ScopeEntire outputIndividual TapTree leaf
Defined inBIP 141 (SegWit)BIP 341 (Taproot)
Range0 to 16 (17 versions)Even values 0x00 to 0xFE (128 versions)
Currently assignedv0 (SegWit), v1 (Taproot)0xC0 (Tapscript)
Unknown versionsAnyone can spendAnyone can spend

Both mechanisms share the same soft-fork compatibility pattern: unknown versions succeed by default, and a new soft fork restricts valid spending conditions. The leaf version simply offers more granularity and a much larger version space.

Why It Matters

Leaf versions are central to Bitcoin's long-term script programmability roadmap. Several active proposals would benefit from or require a new leaf version:

  • A new leaf version could introduce an entirely new scripting language with different opcode semantics, stack limits, or arithmetic capabilities, without any risk to existing Tapscript spends
  • Proposals for post-quantum signature schemes could be deployed under a dedicated leaf version, allowing quantum-resistant spending paths alongside traditional Schnorr-based paths in the same output
  • Future covenant-style opcodes like OP_CAT or CTV could be introduced either through OP_SUCCESS redefinition within Tapscript (leaf version 0xC0) or through a new leaf version with a modified script language

For layer-2 protocols like the Lightning Network and Spark, leaf versions provide assurance that future script capabilities can be adopted without requiring changes to the Taproot output format itself. A wallet can construct a TapTree today that includes leaves reserved for future versions, ready to be activated when a soft fork defines their rules.

OP_SUCCESS within Tapscript

Leaf versions are not the only upgrade path within Taproot. Inside leaf version 0xC0 (Tapscript), BIP 342 also defines OP_SUCCESS opcodes: specific opcode numbers (80, 98, 126 through 129, 131 through 134, and others) that cause immediate script validation success when encountered. Like unknown leaf versions, these act as placeholders that future soft forks can restrict.

The distinction is important: OP_SUCCESS lets you add new opcodes to the existing Tapscript language, while new leaf versions let you define entirely new scripting languages. Together, they give Taproot two complementary upgrade dimensions.

Use Cases

New Signature Algorithms

A new leaf version could define a script language that validates signatures under a different cryptographic scheme. For example, a hash-based signature algorithm resistant to quantum computing could be deployed as leaf version 0xC2. Wallets could then construct outputs with both a standard 0xC0 Tapscript path and a 0xC2 quantum-safe path, using whichever is appropriate.

Extended Script Capabilities

Current Tapscript inherits several limitations from Bitcoin's original scripting model, including element size limits and arithmetic constraints. A new leaf version could lift these restrictions for specific use cases without affecting the security properties of the existing language. Discussions on the Bitcoin development mailing list have explored a "Tapscript v2" concept under leaf version 0xC2 with modified stack and element size limits.

Cross-Version TapTrees

Because each leaf in a TapTree carries its own version, a single output can combine leaves from different script languages. A multisig spending condition under standard Tapscript could coexist with a covenant enforcement path under a future version, all within one compact P2TR output.

Risks and Considerations

Anyone-Can-Spend Semantics

The fact that unknown leaf versions are treated as valid means that if a wallet accidentally commits a script under an unassigned leaf version, anyone who can produce the Merkle proof can spend the output. Wallet software must ensure it only creates leaves with version 0xC0 (the only currently valid version). Using any other version before a soft fork activates it would make funds immediately spendable by anyone.

Soft Fork Coordination

Introducing a new leaf version requires network-wide consensus, just like any other soft fork. While the technical mechanism is ready, the social and political process of activating new rules remains complex. The large version space (128 possible values) reduces pressure but does not eliminate the coordination challenge.

Backward Compatibility Nuances

When a new leaf version is activated, non-upgraded nodes will continue to accept spends under that version without enforcing the new rules. This is by design (it is how soft forks work), but it means that the network's security for the new version depends on a majority of miners running upgraded software. During the transition period, SPV clients and non-upgraded nodes cannot fully validate spends under the new version.

Version Space Management

With 128 possible leaf versions, the version space is large but finite. Each allocation is permanent, as there is no mechanism to reclaim a version once assigned. Protocol designers must consider whether a new leaf version is truly necessary or whether the same goals can be achieved through OP_SUCCESS redefinition within existing Tapscript.

This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.