Skip to content
BIP ATLAS

BIP 0341

How can an output commit to several ways of spending?

A coin can have several spending conditions. Taproot lets a spend reveal just the route it takes, while the unused alternatives stay hidden.

Imagine money that its owners can spend together, with a backup route if someone disappears: wait for a timeout, or use another key. Those alternatives are useful to the owners. An observer of the blockchain does not need to learn every one of them each time the money moves.12

Taproot puts a public key in the output. That key can also commit to a tree of alternative spending scripts. When the owners use the key, they supply a signature. When they use a script, they reveal that script and a proof that it belongs to the commitment. The unused scripts can stay private.3456

Source revision
bitcoin/bips @ 3a10b5b
Source checked
1 October 2026
Review state
Awaiting review
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 341: Taproot: SegWit version 1 spending rules

BIP
341
Layer
Consensus (soft fork)
Title
Taproot: SegWit version 1 spending rules
Authors
Pieter Wuille
Jonas Nick
Anthony Towns
Comments-Summary
No comments yet.
Comments-URI
https://github.com/bitcoin/bips/wiki/Comments:BIP-0341
Status
Deployed
Type
Specification
Assigned
2020-01-19
License
BSD-3-Clause
Requires
340

Pinned source · Reader view on bips.dev
SHA-256 463690d4c409587759c0ff6e8b8fc3a2bf6cb2cdda0c06ff193d317e0ed898ec
Git blob 0764e6cb762b6c17d3b3430af5532e0c63365993

Fig. A07.1 What reaches the blockchain

What reaches the blockchainThe output key Q 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605 is already public. A key-path spend supplies a 64-byte signature and reveals no internal key or script tree. A script-path spend of leaf B supplies the script inputs, the chosen script and a control block containing the internal key, leaf version and parity, and 2 sibling hashes. Its depth is 2; the other scripts are not revealed. Optional annexes are omitted from this illustration.KEY PATH SPENDQ 91b64d532472…OUTPUT KEY: ALREADY PUBLICADDED WHEN SPENTsignature · 64 BNo internal key.No script.No sign that a tree ever existed.SCRIPT TREE: UNKNOWNSCRIPT PATH SPENDQ 91b64d532472…OUTPUT KEY: ALREADY PUBLICADDED WHEN SPENTscript inputs (here a signature)<32-byte key> OP_CHECKSIGPROOF · internal key + 2 sibling hashesleaf version and parity includedDEPTH 2 · OTHER SCRIPTS UNSEEN
What reaches the blockchainThe output key Q 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605 is already public. A key-path spend supplies a 64-byte signature and reveals no internal key or script tree. A script-path spend of leaf B supplies the script inputs, the chosen script and a control block containing the internal key, leaf version and parity, and 2 sibling hashes. Its depth is 2; the other scripts are not revealed. Optional annexes are omitted from this illustration.KEY PATH SPENDQ 91b64d532472…OUTPUT KEY: ALREADY PUBLICADDED WHEN SPENTsignature · 64 BNo internal key.No script.No sign that a tree ever existed.SCRIPT TREE: UNKNOWNSCRIPT PATH SPENDQ 91b64d532472…OUTPUT KEY: ALREADY PUBLICADDED WHEN SPENTscript inputs (here a signature)<32-byte key> OP_CHECKSIGPROOF · internal key + 2 sibling hashesleaf version and parity includedDEPTH 2 · OTHER SCRIPTS UNSEEN
The output key and the revealed script proof
Output key Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
Revealed script
202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac
Control block for this script
c0e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817
The same output, spent two ways. A key-path spend reveals no script tree. A script-path spend reveals the chosen script and enough hashes to prove its place.567

Start with what an observer learns

The output key is already public before any spend happens. Using the key path adds a signature, with an optional annex discussed below. It does not publish the internal key or the script tree. From that spend alone, an observer cannot tell whether any alternative script existed.567

This also works with arrangements in which several people jointly control a key. BIP 341’s authors envisioned agreement between all participants as a common route, leaving more complicated conditions for exceptional cases. Key aggregation lets their cooperative signature look like another single-key signature.168

Taking the script path changes the disclosure. Now the script is public, along with a proof connecting it to the output. The proof reveals the script’s depth in the tree. It can include hashes of other branches, but a hash does not tell the observer what the hidden script says.269

Choose Script path and Only the proof in the tree below. Pick a different leaf and watch which script and hashes remain visible. Then choose Key path: the spend reveals no script tree at all.5691011

Fig. A07.2 Choose a path, then hide the rest

Static view: the script path for Leaf B, with the whole tree shown. With JavaScript you can switch to the key path, pick another leaf, and show only what the spend reveals.

One output, several ways to spendOutput key Q 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605, made from internal key P e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f tweaked by the Merkle root. The whole tree is drawn: Leaf A, <32-byte key> OP_CHECKSIG; Leaf B, <32-byte key> OP_CHECKSIG; Leaf C, <32-byte key> OP_CHECKSIG. Leaf B: the witness carries its script (34 bytes) and a 97-byte control block with 2 sibling hashes; the verifier recomputes 2 hashes up to the root, then the tweak, and checks Q.OUTPUT KEY Q91b64d53…P + t·GTAPTWEAKhashINTERNAL KEY Pe0dfe230…LEAF A<32-byte key> OP_CHECKSIGHASH IN PROOF · 2645a02e…LEAF B<32-byte key> OP_CHECKSIGIN THE WITNESSLEAF C<32-byte key> OP_CHECKSIGHASH IN PROOF · 9e31407b…RECOMPUTEDROOT · RECOMPUTEDLEFT AND RIGHT ARE THE WALLET'S LAYOUT; EACH PAIR IS HASHED IN SORTED ORDERWITNESS · SCRIPT PATH · LEAF Binputs: not in vectorscript 34 BP 32 Be0 32 Be1 32 BCONTROL BLOCK · 33 + 32 × 2 = 97 B
One output, several ways to spendOutput key Q 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605, made from internal key P e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f tweaked by the Merkle root. The whole tree is drawn: Leaf A, <32-byte key> OP_CHECKSIG; Leaf B, <32-byte key> OP_CHECKSIG; Leaf C, <32-byte key> OP_CHECKSIG. Leaf B: the witness carries its script (34 bytes) and a 97-byte control block with 2 sibling hashes; the verifier recomputes 2 hashes up to the root, then the tweak, and checks Q.OUTPUT KEY Q91b64d53…P + t·GTAPTWEAKhashINTERNAL KEY Pe0dfe230…LEAF A<32-bytekey> OP_CHECKSIGHASH 2645a02e…LEAF B<32-bytekey> OP_CHECKSIGIN THE WITNESSLEAF C<32-bytekey> OP_CHECKSIGHASH 9e31407b…RECOMPUTEDROOT · RECOMPUTEDEACH PAIR IS HASHED IN SORTED ORDERWITNESS · SCRIPT PATH · LEAF BinputsP 32 Be0 32 Be1 32 BCONTROL BLOCK · 33 + 32 × 2 = 97 B

Leaf B: the witness carries its script (34 bytes) and a 97-byte control block with 2 sibling hashes; the verifier recomputes 2 hashes up to the root, then the tweak, and checks Q.

Exact values for this view
Output key Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
Leaf B script
202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac
Control block
c0e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817
Internal key P (bytes 1–32 of the control block)
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f

BIP 341 wallet-test-vectors.json, scriptPubKey[5]. Every hash, tweak and control block was recomputed and checked at build time.

The wallet knows the whole tree. The blockchain receives only the material needed for the selected spending path.46910111213

How a branch can stand for a whole tree

Each alternative script is a leaf. Hash the leaf’s version and script, including its length, to give it a compact identifier. Hash pairs of identifiers together, then repeat until only a root remains. A change to a script changes the commitment calculated above it.24912

To prove that a leaf belongs to this tree, you do not need to supply all the other leaves. Supply a sibling hash at each level instead. Starting with the revealed script, the verifier can hash its way back to the root. A whole hidden subtree can be represented by its one root hash.2913

There is no mandatory tree shape. BIP 341 suggests a balanced tree when the alternatives are equally likely, or a Huffman tree that puts likely scripts nearer the top. Those are wallet-design suggestions. A shallower leaf needs fewer sibling hashes, so its proof takes less space.91415

Fig. A07.3 A deeper leaf needs a longer proof

Depth is proof sizeIn this published tree, Leaf A sits at depth 1 and needs a 65-byte control block (33 + 32 × 1); Leaf B sits at depth 2 and needs a 97-byte control block (33 + 32 × 2); Leaf C sits at depth 2 and needs a 97-byte control block (33 + 32 × 2). Each level adds one 32-byte hash. The tree's shape is one example, not a required layout.LEAF A65 B33 + 32 × 1LEAF B97 B33 + 32 × 2LEAF C97 B33 + 32 × 2CONTROL BLOCK UNDER EACH LEAF, TO SCALE
Each extra level contributes another 32-byte sibling hash.6914

The example has leaf A closer to the root than leaves B and C. Choosing A therefore produces a shorter control block. This is a tradeoff the wallet can make before the output is created; it cannot later move a leaf to a different depth without changing the commitment.4101314

Where the tree meets the key

So far we have a tree root and an ordinary public key. Taproot combines them. The ordinary key is called the internal key, P. A hash of P and the root produces a tweak, t. Adding t⋅G to P gives a new point, Q, whose x coordinate becomes the output’s 32-byte witness program.4131617

Fig. A07.4 The tree changes the output key

Internal key in, output key outVector 0: internal key P d6889cb081036e0faefa3a35157ad71086b123b2b144b649798b494c300a961d and no script tree go into the TapTweak hash, giving t = b86e7be8f39bab32a6f2c0443abbc210f0edac0e2c53d501b36b64437d9c6c70. The output key is Q = P + t·G = 53a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343, the 32-byte program of the output script 5120…. Vector 5: internal key P e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f and Merkle root ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2 go into the TapTweak hash, giving t = b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4. The output key is Q = P + t·G = 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605, the 32-byte program of the output script 5120….VECTOR 0 · KEY ONLYINTERNAL KEY Pd6889cb0…NO SCRIPT TREEHASHED: P ONLYTAPTWEAKhasht = b86e7be8…P + t·GOUTPUT KEY Q53a1f6e4…51 20 ‖ QOUTPUT SCRIPTVECTOR 5 · 3 SCRIPTSINTERNAL KEY Pe0dfe230…MERKLE ROOTccbd66c6…TAPTWEAKhasht = b57bfa18…P + t·GOUTPUT KEY Q91b64d53…51 20 ‖ QOUTPUT SCRIPT
Exact values
Vector 0: internal key P
d6889cb081036e0faefa3a35157ad71086b123b2b144b649798b494c300a961d
Merkle root
none
Tweak t
b86e7be8f39bab32a6f2c0443abbc210f0edac0e2c53d501b36b64437d9c6c70
Output key Q
53a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343
Address
bc1p2wsldez5mud2yam29q22wgfh9439spgduvct83k3pm50fcxa5dps59h4z5
Vector 5: internal key P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f
Merkle root
ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2
Tweak t
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4
Output key Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
Address
bc1pjxmy65eywgafs5tsunw95ruycpqcqnev6ynxp7jaasylcgtcxczs6n332e
The internal key becomes a different output key after tweaking. The lower example includes a script tree; the upper one has no scripts.411161819

The tree is now tied to the key on the blockchain, even though it was never published. A script-path verifier must reconstruct both the root and the tweaked output key. Producing a plausible-looking tree is not enough: the result must match the particular output being spent.413

The key path remains available because the corresponding private key can be tweaked too. After accounting for the internal point’s y parity, its holder adds the same tweak to the private key and can sign for Q. The public calculation and the signing calculation arrive at the same output key.20

Outputs without scripts, older nodes and key aggregation

A Taproot output is exactly that: a native SegWit output with version 1 and a 32-byte program. Version 1 outputs of other lengths, and version 1 programs wrapped in P2SH, are left unencumbered by these rules. Nodes that never upgraded treat every version 1 program as anyone-can-spend, so these rules are enforced by upgraded nodes.1721

When there are no scripts, BIP 341 recommends that wallets still tweak the internal key, hashing P alone. Its authors explain why. If the output key is an aggregate of several parties’ keys, a malicious party could add a script path the others do not notice, bypass the shared policy and steal the coin. MuSig aggregation avoids that particular problem because it already randomizes the internal key. The no-script example above follows the wallet recommendation.1819

Aggregation is not a matter of adding public keys together by hand: a plain sum is open to key cancellation and related attacks unless something like a proof of possession guards it. BIP 341 points to protocols such as MuSig and leaves their details out of scope, and recommends making the most likely single-key condition the internal key.2223

Check the proof, then run the script

A script-path witness carries the script’s inputs, the script, and a control block. The block supplies the internal key and the sibling hashes. It also records the leaf version and one bit of information about the output key’s y coordinate. These pieces let the verifier repeat the commitment calculation.91324

Fig. A07.5 What the two witnesses carry

Two witnessesKey path: the witness has one item, a 64-byte signature (the published key-path spend of this output). Script path for Leaf B: the script's own inputs (not published by the vector), then the 34-byte script, then the 97-byte control block. A verifier tells them apart by counting items after removing any annex, a last item starting with the byte 0x50; either kind of spend may carry one.KEY PATH · 1 ITEMsignature · 64 BSCRIPT PATH · LEAF Bscript inputs (not in the vector)script · 34 Bcontrol block · 97 BEITHER STACK MAY END WITH AN ANNEX (FIRST BYTE 0x50); IT IS SET ASIDE FIRST
Two witnessesKey path: the witness has one item, a 64-byte signature (the published key-path spend of this output). Script path for Leaf B: the script's own inputs (not published by the vector), then the 34-byte script, then the 97-byte control block. A verifier tells them apart by counting items after removing any annex, a last item starting with the byte 0x50; either kind of spend may carry one.KEY PATH · 1 ITEMsignature · 64 BSCRIPT PATH · LEAF Bscript inputs (not in the vector)script · 34 Bcontrol block · 97 BEITHER STACK MAY END WITH AN ANNEX (FIRST BYTE 0x50); IT IS SET ASIDE FIRST
After removing any annex, one item selects the key path. Two or more select the script path.79102425

First hash the revealed leaf. Join it to its sibling hash, and keep going up the proof. At each join the hashes are sorted before hashing, so the proof does not need left-or-right directions. Use the reconstructed root and internal key to calculate the tweak and output key.1213

Fig. A07.6 Walk the proof back to the output

  1. Rebuilding the commitment, step 1 of 6Control block of 97 bytes: one byte of leaf version and parity, the 32-byte internal key, and 2 32-byte sibling hashes.CONTROL BLOCK · 97 BPe0e1LEAF VERSION 0xc0 · PARITY BIT 0

    The control block is 97 bytes: 33 + 32 × 2, so the leaf sits 2 levels below the root.

  2. Rebuilding the commitment, step 2 of 6TapLeaf hash of leaf version 0xc0 and the script gives k0 = ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c.SCRIPT<32-byte key>OP_CHECKSIGTAPLEAFk0ba982a91…

    Hash the leaf version and script with TapLeaf: k0 = ba982a91…

  3. Rebuilding the commitment, step 3 of 6TapBranch of k = ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c and sibling e = 9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6, the smaller first, gives ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553.kba982a91…e0 (first)9e31407b…TAPBRANCHnextffe578e9…

    Branch 1: join k with the sibling e, e first (sorted), with TapBranch.

  4. Rebuilding the commitment, step 4 of 6TapBranch of k = ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553 and sibling e = 2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817, the smaller first, gives ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2.kffe578e9…e1 (first)2645a02e…TAPBRANCHnextccbd66c6…

    Branch 2: join k with the sibling e, e first (sorted), with TapBranch.

  5. Rebuilding the commitment, step 5 of 6TapTweak of the internal key P = e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f and the rebuilt root ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2 gives t = b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4.Prootccbd66c6…TAPTWEAKt = b57bfa18…

    Hash P and the rebuilt root with TapTweak: t = b57bfa18…

  6. Rebuilding the commitment, step 6 of 6P + t·G has x coordinate 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605, equal to the output key 91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605, and y parity 0, equal to the control block's parity bit. The commitment check passes.Q' = P + t·G91b64d53…=COMPAREOUTPUT KEY Q91b64d53…✓ MATCH · PARITY 0

    Q' = P + t·G has x = 91b64d53…, the output key, and y even (parity 0), matching the parity bit. The spend's commitment holds.

Exact values, step by step
Control block (97 bytes)
c0e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817
k0 = TapLeaf hash
ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c
Branch 1: k, e0, result
ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c
9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6
ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553
Branch 2: k, e1, result
ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553
2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817
ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2
Internal key P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f
t = TapTweak hash
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4
x(Q') = output key
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
Parity
0 (y even)
Follow leaf B upward. Each sibling hash gets the verifier one step closer to the committed root.10121326

Both the x coordinate and the parity bit must match. A proof for another script cannot simply be borrowed: changing the script, the parity bit or the expected output breaks the comparison. The parity bit pins down the exact curve point, which the authors need for batch verification.132627

Even a correct proof does not make the spend valid on its own. It establishes that this script was committed to. The script must still execute successfully with the remaining witness items as its starting stack. Leaf version 0xc0 uses the Tapscript rules in BIP 342.28

Control-block lengths, annexes and byte order

A verifier decides which path is being used by counting witness elements. None at all fails. If the last of two or more elements begins with the byte 0x50, it is set aside as the annex. That field is reserved for future extensions, and users SHOULD NOT include it until a soft fork defines it. One remaining element means a key path spend; two or more mean a script path spend.2529

The script path carries more. The second-to-last element is the script, and the last is a control block of 33 + 32m bytes, where m runs from 0 to 128. Its first byte holds the leaf version, with the lowest bit recording whether Q has an even or odd y coordinate. The next 32 bytes are the internal key, followed by m sibling hashes, one per level. In vector 5 that makes 65 bytes for leaf A and 97 for B and C.9101324

The wallet vectors write every hash as a byte array, first byte first. That is the opposite of the familiar convention for transaction IDs, which are displayed reversed. This page follows the vectors.30

This page’s model reproduces every value the vectors publish. That covers leaf hashes, roots, tweaks, output keys, scriptPubKeys and control blocks for all 7 trees. It also covers the keys, tweaks, signature message, signature hash and signature for all 7 key-path inputs.11

The signature also commits to the payment

Hiding unused conditions is only part of BIP 341. The signature message changes too. Unless the signer selects ANYONECANPAY, it commits to the amount and scriptPubKey of every output being spent. This gives an offline signer a commitment to all the input amounts when it checks the fee.31

Fig. A07.7 The amounts travel into the signature

What a key-path signature signsThe signature message for input 4 of 9, hash_type 0x00, 174 bytes: hash_type (1 bytes), nVersion (4 bytes), nLockTime (4 bytes), sha_prevouts (32 bytes), sha_amounts (32 bytes), sha_scriptpubkeys (32 bytes), sha_sequences (32 bytes), sha_outputs (32 bytes), spend_type (1 bytes), input_index (4 bytes). sha_amounts and sha_scriptpubkeys commit to the amount and scriptPubKey of every output being spent. Its tagged hash, the sighash, is 4f900a0bae3f1446fd48490c2958b5a023228f01661cda3496a11da502a7f7ef.INPUT 4 OF 9 · HASH_TYPE 0x00 · 174 BYTES08162432sha_prevouts · 32 B…sha_amounts · 32 B…sha_scriptpubkeys · 32 B…sha_sequences · 32 B…sha_outputs · 32 B…hash_typenVersionnLockTimespend_typeinput_indexAMOUNT AND SCRIPTPUBKEY OF EVERY SPENT OUTPUThash_TapSighash(0x00 ‖ SigMsg) =4f900a0bae3f1446fd48490c2958b5a023228f01661cda3496a11da502a7f7ef
Exact values
hash_type
00
nVersion
02000000
nLockTime
0065cd1d
sha_prevouts
e3b33bb4ef3a52ad1fffb555c0d82828eb22737036eaeb02a235d82b909c4c3f
sha_amounts
58a6964a4f5f8f0b642ded0a8a553be7622a719da71d1f5befcefcdee8e0fde6
sha_scriptpubkeys
23ad0f61ad2bca5ba6a7693f50fce988e17c3780bf2b1e720cfbb38fbdd52e21
sha_sequences
18959c7221ab5ce9e26c3cd67b22c24f8baa54bac281d8e6b05e400e6c3a957e
sha_outputs
a2e6dab7c1f0dcd297c8d61647fd17d821541ea69c3cc37dcbad7f90d4eb4bc5
spend_type
00
input_index
04000000
The outlined fields commit to every spent output’s amount and scriptPubKey in this example.113132

The authors designed that change to prevent a signing device being misled about the fee or the outputs it is spending. It is a separate benefit from revealing fewer scripts: one concerns the transaction the owner authorizes, the other concerns what observers learn afterwards.631

Taproot still leaves clues. A script-path spend reveals its chosen condition and depth, and a distinctive tree can hint at the software that built it. Reusing keys creates other links; the BIP says keys should never be reused, and that covers every leaf committed to in the output, not only the one spent. The useful promise is narrower disclosure of spending conditions, not blanket anonymity.633

Signature encoding and source notes

A Taproot signature is a BIP 340 signature over a tagged hash, TapSighash, of a signature message. It is 64 bytes, or 65 with an explicit sighash byte; leaving the byte off means SIGHASH_DEFAULT, which signs the whole transaction like SIGHASH_ALL. Spelling out 0x00 as a 65th byte is invalid.3234

The signature message is at most 206 bytes; the illustrated input’s message is 174 bytes. BIP 341 was assigned in 2020 and records mainnet activation at block 709632. The figures use its published wallet vectors.11353637

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ a b Author’s rationale The authors aim to minimize how much information about an output's spending conditions is revealed on chain, when it is created or spent.

    Quoted source text (1)

    Specifically, it seeks to minimize how much information about the spendability conditions of a transaction output is revealed on chain at creation or spending time

    BIP 341, line 31
  2. ↩ a b c d Author’s rationale In the authors' design, Merkle branches let a spend reveal only the executed part of the script rather than every way it could have been executed.

    Quoted source text (1)

    let us only reveal the actually executed part of the script to the blockchain, as opposed to all possible ways a script can be executed.

    BIP 341, line 40
  3. ↩ Rule BIP 341 proposes a SegWit version 1 output type whose spending rules are based on Taproot, Schnorr signatures and Merkle branches.

    Quoted source text (1)

    This document proposes a new SegWit version 1 output type, with spending rules based on Taproot, Schnorr signatures, and Merkle branches.

    BIP 341, line 23
  4. ↩ a b c d e f g Rule Informally, the output is a point Q = P + hash(P||m)G for a public key P and the root m of a Merkle tree of (version, script) leaves; it is spent with a signature for Q, or by revealing P, the script and leaf version, inputs that satisfy the script, and a Merkle path proving Q committed to that leaf. All hashes are tagged.

    Quoted source text (2)

    ''Q'' is computed as ''P + hash(P||m)G'' for a public key ''P'', and the root ''m'' of a Merkle tree whose leaves consist of a version number and a script. These outputs can be spent directly by providing a signature for ''Q'', or indirectly by revealing ''P'', the script and leaf version, inputs that satisfy the script, and a Merkle path that proves ''Q'' committed to that leaf.

    BIP 341, line 48

    are tagged to guarantee domain separation.

    BIP 341, line 48
  5. ↩ a b c d Author’s rationale Taproot makes outputs spendable by a key or, optionally, a script, indistinguishable from each other; as long as the key path is used, it is not revealed whether a script path was permitted.

    Quoted source text (1)

    making all outputs spendable by either a key or (optionally) a script, and indistinguishable from each other. As long as the key-based spending path is used for spending, it is not revealed whether a script path was permitted as well

    BIP 341, line 41
  6. ↩ a b c d e f g h i j Author’s rationale In the BIP's Security section, only the satisfied condition is published. Key path spends prevent observers from learning the spending conditions; a script path spend leaks that a script path exists and that the key path was not used, and the leaf's depth leaks information about the tree and suggests which wallet software created the output.

    Quoted source text (3)

    only the satisfied spending condition has to be published.

    BIP 341, line 280

    Ideally, outputs are spent using the key path which prevents observers from learning the spending conditions of a coin.

    BIP 341, line 281

    A script path spend leaks that there is a script path and that the key path was not applicable - for example because the involved parties failed to reach agreement. Moreover, the depth of a script in the Merkle root leaks information including the minimum depth of the tree, which suggests specific wallet software that created the output and helps clustering.

    BIP 341, lines 284–285
  7. ↩ a b c Rule The output key q is the witness program already published in the spent output. After removing an optional annex, a key path witness has one element: a signature valid for q.

    Quoted source text (4)

    The single witness stack element is interpreted as the signature and must be valid (see the next section) for the public key ''q''

    BIP 341, line 65

    * Let ''q'' be the 32-byte array containing the witness program (the second push in the scriptPubKey) which represents a public key according to [[bip-0340.mediawiki#design|BIP340]].

    BIP 341, line 61

    this last element is called ''annex'' ''a''

    BIP 341, lines 63–64

    and is removed from the witness stack.

    BIP 341, line 63
  8. ↩ Author’s rationale The authors argue, assuming most applications involve outputs all parties could agree to spend, that most can use the key path because Schnorr signatures permit key aggregation: a key built from several participants' keys, which needs all of them to sign, and looks like a single-party key.

    Quoted source text (3)

    Taproot's advantages become apparent under the assumption that most applications involve outputs that could be spent by all parties agreeing.

    BIP 341, line 42

    This means that with taproot most applications can use the key-based spending path, which is both efficient and private.

    BIP 341, line 42

    a public key can be constructed from multiple participant public keys, and which requires cooperation between all participants to sign for. Such multi-party public keys and signatures are indistinguishable from their single-party equivalents.

    BIP 341, line 42
  9. ↩ a b c d e f g h i j Rule The control block holds the internal key p in bytes 1–32 and the leaf version in the first byte (c[0] & 0xfe); the leaf hash is hash_TapLeaf(v || compact_size(size of s) || s).

    Quoted source text (3)

    Let ''p = c[1:33]'' and let ''P = lift_x(int(p))''

    BIP 341, line 69

    Let ''v = c[0] & 0xfe'' and call it the ''leaf version''

    BIP 341, line 70

    Let ''k<sub>0</sub> = hash<sub>TapLeaf</sub>(v || compact_size(size of s) || s)''; also call it the ''tapleaf hash''.

    BIP 341, line 71
  10. ↩ a b c d e f Test vector In scriptPubKey vector 5, leaf A sits one level below the root and leaves B and C two levels down, so their control blocks are 65, 97 and 97 bytes; input 4 of the key-path vector spends this same output with a 64-byte SIGHASH_DEFAULT signature that verifies against its output key.

    Quoted source text (3)

    "internalPubkey": "e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f"

    BIP 341 (wallet-test-vectors.json), line 139

    "txinIndex": 4

    BIP 341 (wallet-test-vectors.json), lines 351–354

    "hashType": 0

    BIP 341 (wallet-test-vectors.json), line 354
  11. ↩ a b c d e f Test vector This site's model reproduces every published value in BIP 341's wallet vectors: for all 7 scriptPubKey vectors the leaf hashes, Merkle root, tweak, output key, scriptPubKey and control blocks, and for all 7 key-path inputs the internal key, tweak, tweaked secret key, SigMsg, sighash and witness signature; every control block passes the BIP's commitment check.

    Quoted source text (1)

    Test vectors for wallet operation (scriptPubKey computation, key path spending, control block construction) can be found [[bip-0341/wallet-test-vectors.json|here]].

    BIP 341, line 298
  12. ↩ a b c d Rule Each path step hashes the running hash k with the next control-block hash e using hash_TapBranch, putting the lexicographically smaller first; the authors sort so that spends need not reveal left/right directions.

    Quoted source text (3)

    If ''k<sub>j</sub> < e<sub>j</sub>'': ''k<sub>j+1</sub> = hash<sub>TapBranch</sub>(k<sub>j</sub> || e<sub>j</sub>)''

    BIP 341, lines 75–76

    If ''k<sub>j</sub> &ge; e<sub>j</sub>'': ''k<sub>j+1</sub> = hash<sub>TapBranch</sub>(e<sub>j</sub> || k<sub>j</sub>)''.

    BIP 341, line 76

    By doing so, it is not necessary to reveal the left/right directions along with the hashes in revealed Merkle branches.

    BIP 341, line 74
  13. ↩ a b c d e f g h i j Rule The verifier computes t = hash_TapTweak(p || k_m), fails if t is not below the curve order, computes Q = P + int(t)G, and fails unless q equals x(Q) and the control block's low bit equals the parity of Q's y coordinate.

    Quoted source text (2)

    Let ''t = hash<sub>TapTweak</sub>(p || k<sub>m</sub>)''.

    BIP 341, line 77

    Let ''Q = P + int(t)G''. ** If ''q &ne; x(Q)'' or ''c[0] & 1 &ne; y(Q) mod 2'', fail

    BIP 341, lines 79–80
  14. ↩ a b c Rule Scripts go in the leaves of a binary tree, which can be balanced if conditions are equally likely or built as a Huffman tree if their probabilities are known.

    Quoted source text (1)

    The remaining scripts should be organized into the leaves of a binary tree. This can be a balanced tree if each of the conditions these scripts correspond to are equally likely. If probabilities for each condition are known, consider constructing the tree as a Huffman tree.

    BIP 341, line 170
  15. ↩ Rule The construction and spending guidance is for wallets and is not consensus critical; every Taproot output combines one key condition (the internal key) with zero or more scripts in a tree, and satisfying any one suffices.

    Quoted source text (2)

    This section discusses how to construct and spend Taproot outputs. It only affects wallet software that chooses to implement receiving and spending, and is not consensus critical in any way.

    BIP 341, lines 148–149

    Conceptually, every Taproot output corresponds to a combination of a single public key condition (the internal key), and zero or more general conditions encoded in scripts organized in a tree. Satisfying any of these conditions is sufficient to spend the output.

    BIP 341, lines 151–152
  16. ↩ a b Rule The witness program q is called the taproot output key and p the taproot internal key.

    Quoted source text (1)

    ''q'' is referred to as ''taproot output key'' and ''p'' as ''taproot internal key''.

    BIP 341, line 83
  17. ↩ a b Rule A Taproot output is a native SegWit version 1 output with a 32-byte witness program; other version 1 outputs, including other lengths and P2SH-wrapped ones, remain unencumbered by these rules.

    Quoted source text (3)

    A Taproot output is a native SegWit output (see [[bip-0141.mediawiki|BIP141]]) with version number 1, and a 32-byte witness program.

    BIP 341, line 58

    Any other outputs, including version 1 outputs with lengths other than 32 bytes, or P2SH-wrapped version 1 outputs

    BIP 341, line 59

    remain unencumbered.

    BIP 341, line 59
  18. ↩ a b Rule If no script path is needed, the BIP says the output key should still commit to an unspendable script path, Q = P + int(hash_TapTweak(bytes(P)))G, instead of having none; the authors explain that with some key-aggregation schemes a malicious party could otherwise add a script path unnoticed, bypass the multiparty policy and steal the coin, though MuSig's randomized aggregation does not have this issue.

    Quoted source text (4)

    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(hash<sub>TapTweak</sub>(bytes(P)))G''.

    BIP 341, line 158

    If the taproot output key is an aggregate of keys, there is the possibility for a malicious party to add a script path without being noticed by the other parties.

    BIP 341, line 159

    This allows to bypass the multiparty policy and to steal the coin.

    BIP 341, line 160

    MuSig key aggregation does not have this issue because it already causes the internal key to be randomized.

    BIP 341, line 161
  19. ↩ a b Test vector Vector 0 has no script tree; its tweak hashes the internal key alone, as the BIP's no-script recommendation describes, and its output key still differs from the internal key.

    Quoted source text (1)

    "scriptTree": null

    BIP 341 (wallet-test-vectors.json), line 7
  20. ↩ Rule A key path spend is a BIP 340 signature made with the internal secret key tweaked by the same hash as the output key.

    Quoted source text (1)

    a [[bip-0340.mediawiki|BIP340]] signature on the signature hash as defined above, with the secret key tweaked by the same <code>h</code> as in the above snippet.

    BIP 341, line 250
  21. ↩ Rule Non-upgraded nodes treat every SegWit version 1 program as anyone-can-spend.

    Quoted source text (1)

    Non-upgraded nodes, however, will consider all SegWit version 1 witness programs as anyone-can-spend scripts.

    BIP 341, line 354
  22. ↩ Rule For several required signers the BIP points to aggregation techniques such as MuSig, whose details it leaves out of scope; it recommends making the most likely single-key condition the internal key.

    Quoted source text (2)

    When a single condition requires signatures with multiple keys, key aggregation techniques like MuSig can be used to combine them into a single key. The details are out of scope for this document

    BIP 341, line 156

    If one or more of the spending conditions consist of just a single key (after aggregation), the most likely one should be made the internal key.

    BIP 341, line 157
  23. ↩ Editorial inference Simply summing participants' keys is open to key cancellation and related attacks; the BIP's own example uses MSDL-pop, where a plain sum is made safe by proofs of possession, and points to MuSig, whose aggregation randomizes the key.

    Quoted source text (2)

    In order to prevent key cancellation and related attacks they use [https://eprint.iacr.org/2018/483.pdf MSDL-pop] instead of MuSig. The MSDL-pop protocol requires all parties to provide a proof of possession of their corresponding secret key and the aggregated key is just the sum of the individual keys.

    BIP 341, lines 164–165

    MuSig key aggregation does not have this issue because it already causes the internal key to be randomized.

    BIP 341, line 161
  24. ↩ a b c Rule In a script path spend the second-to-last element is the script s and the last is the control block c, which must be 33 + 32m bytes long for an integer m from 0 to 128.

    Quoted source text (1)

    ** Call the second-to-last stack element ''s'', the script. ** The last stack element is called the control block ''c'', and must have length ''33 + 32m'', for a value of ''m'' that is an integer between 0 and 128

    BIP 341, lines 67–68
  25. ↩ a b Rule A spend with no witness elements fails; after removing an annex, one remaining element means key path spending, two or more mean script path spending.

    Quoted source text (3)

    * Fail if the witness stack has 0 elements.

    BIP 341, line 62

    If there is exactly one element left in the witness stack, key path spending is used:

    BIP 341, line 64

    If there are at least two witness elements left, script path spending is used:

    BIP 341, line 66
  26. ↩ a b Author’s rationale The authors include the parity bit because lifting q to a unique point is needed for batch verification.

    Quoted source text (1)

    The parity of the Y coordinate is necessary to lift the X coordinate ''q'' to a unique point. While this is not strictly necessary for verifying the taproot commitment as described above, it is necessary to allow batch verification.

    BIP 341, line 80
  27. ↩ Test vector With vector 5's published control block for one leaf, the commitment check fails for any other leaf's script, for a flipped parity bit, and against another vector's output key.

    Quoted source text (1)

    If ''q &ne; x(Q)'' or ''c[0] & 1 &ne; y(Q) mod 2'', fail

    BIP 341, line 80
  28. ↩ Rule After the commitment check the script is executed under the rules for its leaf version, which BIP 342 specifies for leaf version 0xc0; script inputs are the remaining witness elements.

    Quoted source text (3)

    Execute the script, according to the applicable script rules

    BIP 341, line 81

    [[bip-0342.mediawiki|BIP342]] specifies validity rules that apply for leaf version 0xc0

    BIP 341, line 81

    using the witness stack elements excluding the script ''s'', the control block ''c'', and the annex ''a'' if present, as initial stack.

    BIP 341, line 81
  29. ↩ Rule If there are at least two witness elements and the last begins with 0x50, it is the annex, reserved for future extensions; until a soft fork defines it, users SHOULD NOT include one, or risk permanent fund loss.

    Quoted source text (4)

    If there are at least two witness elements, and the first byte of the last element is 0x50

    BIP 341, line 63

    this last element is called ''annex'' ''a''

    BIP 341, line 63

    The annex is a reserved space for future extensions

    BIP 341, line 63

    Until the meaning of this field is defined by another softfork, users SHOULD NOT include <code>annex</code> in transactions, or it may lead to PERMANENT FUND LOSS.

    BIP 341, line 63
  30. ↩ Rule In the wallet vectors, hex values are byte arrays written first byte first, unlike the reversed convention for txids.

    Quoted source text (1)

    In all cases, hexadecimal values represent byte arrays, not numbers. In particular, that means that provided hash values have the hex digits corresponding to the first bytes first.

    BIP 341, line 302
  31. ↩ a b c Rule Unless ANYONECANPAY is set, the signature message commits to the amounts and scriptPubKeys of all outputs the transaction spends; the authors say this stops lying to offline signers about the fee and about the outputs being spent.

    Quoted source text (4)

    If the <code>SIGHASH_ANYONECANPAY</code> flag is not set, the message commits to the amounts of ''all'' transaction inputs.

    BIP 341, line 133

    This eliminates the possibility to lie to offline signing devices about the fee of a transaction.

    BIP 341, line 133

    if the <code>SIGHASH_ANYONECANPAY</code> flag is not set, the message commits to the ''scriptPubKey''s of ''all'' outputs spent by the transaction.

    BIP 341, line 132

    This prevents lying to offline signing devices about output being spent

    BIP 341, line 132
  32. ↩ a b Rule A Taproot signature is a 64-byte BIP 340 signature, optionally followed by a sighash byte; without it, SIGHASH_DEFAULT (0x00), which signs the whole transaction like SIGHASH_ALL, is implied.

    Quoted source text (2)

    A Taproot signature is a 64-byte Schnorr signature, as defined in [[bip-0340.mediawiki|BIP340]], with the sighash byte appended in the usual Bitcoin fashion. This sighash byte is optional. If omitted, the resulting signatures are 64 bytes, and a SIGHASH_DEFAULT mode is implied.

    BIP 341, line 139

    We define a new ''hashtype'' <code>SIGHASH_DEFAULT</code> (value ''0x00'') which results in signing over the whole transaction just as for <code>SIGHASH_ALL</code>.

    BIP 341, line 93
  33. ↩ Rule The BIP says taproot outputs should never reuse keys, for privacy, and that this applies to every leaf committed to in the output, not only the leaf used to spend it.

    Quoted source text (1)

    Just like other existing output types, taproot outputs should never reuse keys, for privacy reasons. This does not only apply to the particular leaf that was used to spend an output but to all leaves committed to in the output.

    BIP 341, lines 288–289
  34. ↩ Rule A 64-byte key-path signature is checked with BIP 340 Verify against q and the message hash_TapSighash(0x00 || SigMsg(0x00, 0)); a 65-byte signature whose last byte is 0x00 is invalid.

    Quoted source text (2)

    If the ''sig'' is 64 bytes long, return ''Verify(q, hash<sub>TapSighash</sub>(0x00 || SigMsg(0x00, 0)), sig)''

    BIP 341, line 142

    If the ''sig'' is 65 bytes long, return ''sig[64] &ne; 0x00

    BIP 341, line 143
  35. ↩ Rule SigMsg is at most 206 bytes, not counting sub-hashes that can be cached across signatures.

    Quoted source text (1)

    The total length of ''SigMsg()'' is at most ''206'' bytes

    BIP 341, line 128
  36. ↩ History BIP 341 is a consensus soft-fork proposal assigned in 2020; its preamble records the status Deployed and that it requires BIP 340.

    Quoted source text (4)

    Layer: Consensus (soft fork)

    BIP 341, line 3

    Status: Deployed

    BIP 341, line 10

    Assigned: 2020-01-19

    BIP 341, line 12

    Requires: 340

    BIP 341, line 16
  37. ↩ History The BIP records that the deployment activated at height 709632 on Bitcoin mainnet, alongside BIP 342.

    Quoted source text (2)

    The deployment did activate at height 709632 on Bitcoin mainnet.

    BIP 341, line 347

    This BIP is deployed concurrently with [[bip-0342.mediawiki|BIP342]].

    BIP 341, line 312