Bitcoin Book of BIPs

BIP 386

Abstract

This document specifies tr() output script descriptors. tr() descriptors take a key and optionally a tree of scripts and produces a P2TR output script.

This BIP is licensed under the BSD 2-clause license.

Motivation

Taproot added one additional standard output script format: P2TR. These expressions allow specifying those formats as a descriptor.

Specification

A new script expression is defined: tr(). A new expression is defined: Tree Expressions

Tree Expression

A Tree Expression (denoted TREE) is an expression which represents a tree of scripts. The way the tree is represented in an output script is dependent on the higher level expressions.

A Tree Expression is:

tr()

The tr(KEY) or tr(KEY, TREE) expression can only be used as a top level expression. All key expressions under any tr() expression must create x-only public keys.

tr(KEY) takes a single key expression as an argument and produces a P2TR output script which does not have a script path. Each key produced by the key expression is used as the internal key of a P2TR output as specified by BIP 341. Specifically, “If the spending conditions do not require a script path, the output key should commit to an unspendable script path instead of having no script path. This can be achieved by computing the output key point as Q = P + int(hashTapTweak(bytes(P)))G.”

internal_key:       lift_x(KEY)
32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key)))G
scriptPubKey:       OP_1 <32_byte_output_key>

tr(KEY, TREE) takes a key expression as the first argument, and a tree expression as the second argument and produces a P2TR output script which has a script path. The keys produced by the first key expression are used as the internal key as specified by BIP 341. The Tree expression becomes the Taproot script tree as described in BIP 341. A merkle root is computed from this tree and combined with the internal key to create the Taproot output key.

internal_key:       lift_x(KEY)
merkle_root:        HashTapBranch(TREE)
32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key) || merkle_root))G
scriptPubKey:       OP_1 <32_byte_output_key>

Modified Key Expression

Key Expressions within a tr() expression must only create x-only public keys. Uncompressed public keys are not allowed, but compressed public keys would be implicitly converted to x-only public keys. The keys derived from extended keys must be serialized as x-only public keys. An additional key expression is defined only for use within a tr() descriptor:

Test Vectors

Valid descriptors followed by the scripts they produce. Descriptors involving derived child keys will have the 0th, 1st, and 2nd scripts listed.

Invalid Descriptors

Backwards Compatibility

tr() descriptors use the format and general operation specified in 380. As these are a set of wholly new descriptors, they are not compatible with any implementation. However the scripts produced are standard scripts so existing software are likely to be familiar with them.

Tree Expressions are largely incompatible with existing script expressions due to the restrictions in those expressions. Of the script expressions that existed when this BIP was written, only pk() can be used in a tree expression. Script expressions specified since then that can be used in a tree expression are the Miniscript expressions of 379, which include a pkh() fragment, and the multi_a() and sortedmulti_a() expressions of 387.

Reference Implementation

tr() descriptors have been implemented in Bitcoin Core since version 22.0.

  BIP: 387
  Layer: Applications
  Title: Tapscript Multisig Output Script Descriptors
  Authors: Pieter Wuille <pieter@wuille.net>
           Ava Chow <me@achow101.com>
  Status: Deployed
  Type: Specification
  Assigned: 2024-04-17
  License: BSD-2-Clause
  Requires: 380