|
| 1 | +<pre> |
| 2 | + BIP: 386 |
| 3 | + Layer: Applications |
| 4 | + Title: tr() Output Script Descriptors |
| 5 | + Author: Pieter Wuille < [email protected]> |
| 6 | + |
| 7 | + Comments-Summary: No comments yet. |
| 8 | + Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0386 |
| 9 | + Status: Draft |
| 10 | + Type: Informational |
| 11 | + Created: 2021-06-27 |
| 12 | + License: BSD-2-Clause |
| 13 | +</pre> |
| 14 | + |
| 15 | +==Abstract== |
| 16 | + |
| 17 | +This document specifies <tt>tr()</tt> output script descriptors. |
| 18 | +<tt>tr()</tt> descriptors take a key and optionally a tree of scripts and produces a P2TR output script. |
| 19 | + |
| 20 | +==Copyright== |
| 21 | + |
| 22 | +This BIP is licensed under the BSD 2-clause license. |
| 23 | + |
| 24 | +==Motivation== |
| 25 | + |
| 26 | +Taproot added one additional standard output script format: P2TR. |
| 27 | +These expressions allow specifying those formats as a descriptor. |
| 28 | + |
| 29 | +==Specification== |
| 30 | + |
| 31 | +A new script expression is defined: <tt>tr()</tt>. |
| 32 | +A new expression is defined: Tree Expressions |
| 33 | + |
| 34 | +===Tree Expression=== |
| 35 | + |
| 36 | +A Tree Expression (denoted <tt>TREE</tt>) is an expression which represents a tree of scripts. |
| 37 | +The way the tree is represented in an output script is dependent on the higher level expressions. |
| 38 | + |
| 39 | +A Tree Expression is: |
| 40 | +* Any Script Expression that is allowed at the level this Tree Expression is in. |
| 41 | +* A pair of Tree Expressions consisting of: |
| 42 | +** An open brace <tt>{</tt> |
| 43 | +** A Tree Expression |
| 44 | +** A comma <tt>,</tt> |
| 45 | +** A Tree Expression |
| 46 | +** A closing brace <tt>}</tt> |
| 47 | +
|
| 48 | +===<tt>tr()</tt>=== |
| 49 | + |
| 50 | +The <tt>tr(KEY)</tt> or <tt>tr(KEY, TREE)</tt> expression can only be used as a top level expression. |
| 51 | +All key expressions under any <tt>tr()</tt> expression must create x-only public keys. |
| 52 | + |
| 53 | +<tt>tr(KEY)</tt> takes a single key expression as an argument and produces a P2TR output script which does not have a script path. |
| 54 | +Each key produced by the key expression is used as the internal key of a P2TR output as specified by [[bip-0341.mediawiki#cite_ref-22-0|BIP 341]]. |
| 55 | +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. |
| 56 | +This can be achieved by computing the output key point as ''Q = P + int(hash<sub>TapTweak</sub>(bytes(P)))G''." |
| 57 | + |
| 58 | +<pre> |
| 59 | +internal_key: lift_x(KEY) |
| 60 | +32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key)))G |
| 61 | +scriptPubKey: OP_1 <32_byte_output_key> |
| 62 | +</pre> |
| 63 | + |
| 64 | +<tt>tr(KEY, TREE)</tt> 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. |
| 65 | +The keys produced by the first key expression are used as the internal key as specified by [[bip-0341.mediawiki#Constructing_and_spending_Taproot_outputs|BIP 341]]. |
| 66 | +The Tree expression becomes the Taproot script tree as described in BIP 341. |
| 67 | +A merkle root is computed from this tree and combined with the internal key to create the Taproot output key. |
| 68 | + |
| 69 | +<pre> |
| 70 | +internal_key: lift_x(KEY) |
| 71 | +merkle_root: HashTapBranch(TREE) |
| 72 | +32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key) || merkle_root))G |
| 73 | +scriptPubKey: OP_1 <32_byte_output_key> |
| 74 | +</pre> |
| 75 | + |
| 76 | +===Modified Key Expression=== |
| 77 | + |
| 78 | +Key Expressions within a <tt>tr()</tt> expression must only create x-only public keys. |
| 79 | +Uncompressed public keys are not allowed, but compressed public keys would be implicitly converted to x-only public keys. |
| 80 | +The keys derived from extended keys must be serialized as x-only public keys. |
| 81 | +An additional key expression is defined only for use within a <tt>tr()</tt> descriptor: |
| 82 | + |
| 83 | +* A 64 hex character string representing an x-only public key |
| 84 | +
|
| 85 | +==Test Vectors== |
| 86 | + |
| 87 | +TBD |
| 88 | + |
| 89 | +==Backwards Compatibility== |
| 90 | + |
| 91 | +<tt>tr()</tt> descriptors use the format and general operation specified in [[bip-0380.mediawiki|380]]. |
| 92 | +As these are a set of wholly new descriptors, they are not compatible with any implementation. |
| 93 | +However the scripts produced are standard scripts so existing software are likely to be familiar with them. |
| 94 | + |
| 95 | +Tree Expressions are largely incompatible with existing script expressions due to the restrictions in those expressions. |
| 96 | +As of 2021-06-27, the only allowed script expression that can be used in a tree expression is <tt>pk()</tt>. |
| 97 | +However there will be future BIPs that specify script expressions that can be used in tree expressions. |
| 98 | + |
| 99 | +==Reference Implementation== |
| 100 | + |
| 101 | +<tt>tr()</tt> descriptors have been implemented in Bitcoin Core since version 22.0. |
0 commit comments