{"number":386,"title":"tr() Output Script Descriptors","authors":["Pieter Wuille","Ava Chow"],"status":"Deployed","type":"Specification","layer":"Applications","created":"2021-06-27","license":"BSD-2-Clause","requires":[380],"replaces":[],"replacedBy":[],"discussion":[],"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.","eli5":"Defines the descriptor function for Taproot outputs, combining a main key with an optional tree of alternative spending conditions. This gives wallets a standard way to describe, back up and recover Taproot wallets.","categories":["transactions"],"filename":"bip-0386.mediawiki","githubUrl":"https://github.com/bitcoin/bips/blob/master/bip-0386.mediawiki","format":"mediawiki","readingMinutes":3,"inbound":2,"revisions":14,"impact":65,"core":false,"references":[341,379,387],"lastModified":"2026-09-17","html":"<h2 id=\"abstract\">Abstract</h2>\n<p>This document specifies <code>tr()</code> output script descriptors. <code>tr()</code> descriptors take a key and optionally a tree of scripts and produces a P2TR output script.</p>\n<h2 id=\"copyright\">Copyright</h2>\n<p>This BIP is licensed under the BSD 2-clause license.</p>\n<h2 id=\"motivation\">Motivation</h2>\n<p>Taproot added one additional standard output script format: P2TR. These expressions allow specifying those formats as a descriptor.</p>\n<h2 id=\"specification\">Specification</h2>\n<p>A new script expression is defined: <code>tr()</code>. A new expression is defined: Tree Expressions</p>\n<h3 id=\"tree-expression\">Tree Expression</h3>\n<p>A Tree Expression (denoted <code>TREE</code>) 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.</p>\n<p>A Tree Expression is:</p>\n<ul><li>\nAny Script Expression that is allowed at the level this Tree Expression is in.\n</li></ul>\n<ul><li>\nA pair of Tree Expressions consisting of:\n<ul><li>\nAn open brace <code>{</code>\n</li></ul>\n<ul><li>\nA Tree Expression\n</li></ul>\n<ul><li>\nA comma <code>,</code>\n</li></ul>\n<ul><li>\nA Tree Expression\n</li></ul>\n<ul><li>\nA closing brace <code>}</code>\n</li></ul>\n</li></ul>\n<h3 id=\"tr\"><code>tr()</code></h3>\n<p>The <code>tr(KEY)</code> or <code>tr(KEY, TREE)</code> expression can only be used as a top level expression. All key expressions under any <code>tr()</code> expression must create x-only public keys.</p>\n<p><code>tr(KEY)</code> 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 <a href=\"/bip/341#cite-ref-22-0\">BIP 341</a>. 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 <em>Q = P + int(hash<sub>TapTweak</sub>(bytes(P)))G</em>.\"</p>\n<pre><code>internal_key:       lift_x(KEY)\n32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key)))G\nscriptPubKey:       OP_1 &lt;32_byte_output_key&gt;</code></pre>\n<p><code>tr(KEY, TREE)</code> 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 <a href=\"/bip/341#constructing-and-spending-taproot-outputs\">BIP 341</a>. 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.</p>\n<pre><code>internal_key:       lift_x(KEY)\nmerkle_root:        HashTapBranch(TREE)\n32_byte_output_key: internal_key + int(HashTapTweak(bytes(internal_key) || merkle_root))G\nscriptPubKey:       OP_1 &lt;32_byte_output_key&gt;</code></pre>\n<h3 id=\"modified-key-expression\">Modified Key Expression</h3>\n<p>Key Expressions within a <code>tr()</code> 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 <code>tr()</code> descriptor:</p>\n<ul><li>\nA 64 hex character string representing an x-only public key\n</li></ul>\n<h2 id=\"test-vectors\">Test Vectors</h2>\n<p>Valid descriptors followed by the scripts they produce. Descriptors involving derived child keys will have the 0th, 1st, and 2nd scripts listed.</p>\n<ul><li>\n<code>tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)</code>\n<ul><li>\n<code>512077aab6e066f8a7419c5ab714c12c67d25007ed55a43cadcacb4d7a970a093f11</code>\n</li></ul>\n</li><li>\n<code>tr(L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1)</code>\n<ul><li>\n<code>512077aab6e066f8a7419c5ab714c12c67d25007ed55a43cadcacb4d7a970a093f11</code>\n</li></ul>\n</li><li>\n<code>tr(xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc/0/*,pk(xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc/1/*))</code>\n<ul><li>\n<code>512078bc707124daa551b65af74de2ec128b7525e10f374dc67b64e00ce0ab8b3e12</code>\n</li></ul>\n<ul><li>\n<code>512001f0a02a17808c20134b78faab80ef93ffba82261ccef0a2314f5d62b6438f11</code>\n</li></ul>\n<ul><li>\n<code>512021024954fcec88237a9386fce80ef2ced5f1e91b422b26c59ccfc174c8d1ad25</code>\n</li></ul>\n</li><li>\n<code>tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,pk(669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0))</code>\n<ul><li>\n<code>512017cf18db381d836d8923b1bdb246cfcd818da1a9f0e6e7907f187f0b2f937754</code>\n</li></ul>\n</li><li>\n<code>tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,{pk(xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334/0),{{pk(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL),pk(02df12b7035bdac8e3bab862a3a83d06ea6b17b6753d52edecba9be46f5d09e076)},pk(L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1)}})</code>\n<ul><li>\n<code>512071fff39599a7b78bc02623cbe814efebf1a404f5d8ad34ea80f213bd8943f574</code>\n</li></ul>\n</li><li>\n<code>tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,pkh(L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1))</code>\n</li></ul>\n<p>Invalid Descriptors</p>\n<ul><li>\nUncompressed private key: <code>tr(5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss)</code>\n</li></ul>\n<ul><li>\nUncompressed public key: <code>tr(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)</code>\n</li></ul>\n<ul><li>\n<code>tr()</code> nested in <code>wsh</code>: <code>wsh(tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))</code>\n</li></ul>\n<ul><li>\n<code>tr()</code> nested in <code>sh</code>: <code>sh(tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))</code>\n</li></ul>\n<h2 id=\"backwards-compatibility\">Backwards Compatibility</h2>\n<p><code>tr()</code> descriptors use the format and general operation specified in <a href=\"/bip/380\">380</a>. 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.</p>\n<p>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 <code>pk()</code> 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 <a href=\"/bip/379\">379</a>, which include a <code>pkh()</code> fragment, and the <code>multi_a()</code> and <code>sortedmulti_a()</code> expressions of <a href=\"/bip/387\">387</a>.</p>\n<h2 id=\"reference-implementation\">Reference Implementation</h2>\n<p><code>tr()</code> descriptors have been implemented in Bitcoin Core since version 22.0.</p>","toc":[{"id":"abstract","title":"Abstract","level":2},{"id":"copyright","title":"Copyright","level":2},{"id":"motivation","title":"Motivation","level":2},{"id":"specification","title":"Specification","level":2},{"id":"tree-expression","title":"Tree Expression","level":3},{"id":"tr","title":"tr()","level":3},{"id":"modified-key-expression","title":"Modified Key Expression","level":3},{"id":"test-vectors","title":"Test Vectors","level":2},{"id":"backwards-compatibility","title":"Backwards Compatibility","level":2},{"id":"reference-implementation","title":"Reference Implementation","level":2}],"history":{"totalCommits":14,"firstCommit":"2021-06-29T16:33:02-04:00","lastUpdated":"2026-09-17T15:04:12+02:00","events":[{"sha":"9d735fb36fdd6a5860febe7e84680aa220baad23","date":"2026-09-17T15:04:12+02:00","author":"Daniela Brozzoni","message":"bip386: Update to Specification type","url":"https://github.com/bitcoin/bips/commit/9d735fb36fdd6a5860febe7e84680aa220baad23","kind":"edit"},{"sha":"d7854890ac7299863b1652868f2f6206dba44b4c","date":"2026-08-06T09:37:33+02:00","author":"Oli","message":"bip386: update stale sentence","url":"https://github.com/bitcoin/bips/commit/d7854890ac7299863b1652868f2f6206dba44b4c","kind":"edit"},{"sha":"83c04884a14f0e308f533012406ab6c24d4a53ee","date":"2026-08-06T09:27:58+02:00","author":"Oli","message":"bip386: remove stray space","url":"https://github.com/bitcoin/bips/commit/83c04884a14f0e308f533012406ab6c24d4a53ee","kind":"edit"},{"sha":"b3a069464a8879dd858c392a788c9d19a9f7a075","date":"2026-02-27T14:12:41-08:00","author":"Murch","message":"Fix other broken anchors","url":"https://github.com/bitcoin/bips/commit/b3a069464a8879dd858c392a788c9d19a9f7a075","kind":"edit"},{"sha":"24e96e870fffaa257b465ce1f0370c14aac588e8","date":"2025-10-08T14:59:36-07:00","author":"Murch","message":"process: Created ↦ Assigned","url":"https://github.com/bitcoin/bips/commit/24e96e870fffaa257b465ce1f0370c14aac588e8","kind":"edit"},{"sha":"5207ef92a52d0b8902895b0dbb40823a4d698ec9","date":"2025-04-11T20:08:17-07:00","author":"Murch","message":"process: Author ↦ Authors","url":"https://github.com/bitcoin/bips/commit/5207ef92a52d0b8902895b0dbb40823a4d698ec9","kind":"edit"},{"sha":"59730dec4fb641a41589aa1b91d3c452f13e0e36","date":"2025-04-11T20:05:13-07:00","author":"Murch","message":"process: Remove Comments-URI and -Summary","url":"https://github.com/bitcoin/bips/commit/59730dec4fb641a41589aa1b91d3c452f13e0e36","kind":"edit"},{"sha":"5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","date":"2025-04-11T18:08:44-07:00","author":"Murch","message":"process: Final/Active ↦ Deployed","url":"https://github.com/bitcoin/bips/commit/5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","kind":"status"},{"sha":"bc66fdb1664781eacfa23c9077f268eb918103e2","date":"2025-06-18T14:56:02-07:00","author":"Ava Chow","message":"descriptors: Require BIP 380","url":"https://github.com/bitcoin/bips/commit/bc66fdb1664781eacfa23c9077f268eb918103e2","kind":"edit"},{"sha":"d71428ade56ad9a90e18d643eefefefb6088fbd7","date":"2024-07-10T19:02:19-04:00","author":"Ava Chow","message":"380-387: Mark basic descriptor BIPs as final","url":"https://github.com/bitcoin/bips/commit/d71428ade56ad9a90e18d643eefefefb6088fbd7","kind":"status"},{"sha":"7acfe207e0e78ee6fc6053789cc90ac848dcfeb2","date":"2024-07-06T21:49:37+09:00","author":"azuchi","message":"BIP-0386: Fix uncompressed private key test vector","url":"https://github.com/bitcoin/bips/commit/7acfe207e0e78ee6fc6053789cc90ac848dcfeb2","kind":"edit"},{"sha":"a28b021b9933cb6b035cbb94fc1a15c30da3f6fd","date":"2023-12-13T11:12:08-05:00","author":"Ava Chow","message":"Update contact info for achow101","url":"https://github.com/bitcoin/bips/commit/a28b021b9933cb6b035cbb94fc1a15c30da3f6fd","kind":"edit"},{"sha":"bb562aa8e9c438e653668b08e5c16b7e71abc832","date":"2023-06-29T16:15:14-04:00","author":"Andrew Chow","message":"descriptors: add test vectors","url":"https://github.com/bitcoin/bips/commit/bb562aa8e9c438e653668b08e5c16b7e71abc832","kind":"edit"},{"sha":"761ef12782dc02af48b3e3b5a5238faeec6870fe","date":"2021-06-29T16:33:02-04:00","author":"Andrew Chow","message":"Specify BIP 386: Taproot descriptors","url":"https://github.com/bitcoin/bips/commit/761ef12782dc02af48b3e3b5a5238faeec6870fe","kind":"edit"}]}}