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 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
Fig. A07.1 What reaches the blockchain
The output key and the revealed script proof
- Output key Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605- Revealed script
202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac- Control block for this script
c0e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817
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.
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.
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
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
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 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
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
The control block is 97 bytes: 33 + 32 × 2, so the leaf sits 2 levels below the root.
Hash the leaf version and script with TapLeaf: k0 = ba982a91…
Branch 1: join k with the sibling e, e first (sorted), with TapBranch.
Branch 2: join k with the sibling e, e first (sorted), with TapBranch.
Hash P and the rebuilt root with TapTweak: t = b57bfa18…
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
ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553- Branch 2: k, e1, result
ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e5532645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2- Internal key P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f- t = TapTweak hash
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4- x(Q') = output key
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605- Parity
- 0 (y even)
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
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 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.
-
↩ 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
-
↩ 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.
-
↩ 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.
-
↩ 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.
are tagged to guarantee domain separation.
-
↩ 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
-
↩ 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.
BIP 341 L280 BIP 341 L281 BIP 341 L284–285
Quoted source text (3)
only the satisfied spending condition has to be published.
Ideally, outputs are spent using the key path which prevents observers from learning the spending conditions of a coin.
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.
-
↩ 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.
BIP 341 L65 BIP 341 L61 BIP 341 L63–64 BIP 341 L63
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''
* 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]].
this last element is called ''annex'' ''a''
and is removed from the witness stack.
-
↩ 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.
BIP 341 L42 BIP 341 L42 BIP 341 L42
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.
This means that with taproot most applications can use the key-based spending path, which is both efficient and private.
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.
-
↩ 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).
BIP 341 L69 BIP 341 L70 BIP 341 L71
Quoted source text (3)
Let ''p = c[1:33]'' and let ''P = lift_x(int(p))''
Let ''v = c[0] & 0xfe'' and call it the ''leaf version''
Let ''k<sub>0</sub> = hash<sub>TapLeaf</sub>(v || compact_size(size of s) || s)''; also call it the ''tapleaf hash''.
-
↩ 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.
BIP 341 (wallet-test-vectors.json) L139 BIP 341 (wallet-test-vectors.json) L351–354 BIP 341 (wallet-test-vectors.json) L354
Quoted source text (3)
"internalPubkey": "e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f"
"txinIndex": 4
"hashType": 0
-
↩ 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]].
-
↩ 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.
BIP 341 L75–76 BIP 341 L76 BIP 341 L74
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>)''
If ''k<sub>j</sub> ≥ e<sub>j</sub>'': ''k<sub>j+1</sub> = hash<sub>TapBranch</sub>(e<sub>j</sub> || k<sub>j</sub>)''.
By doing so, it is not necessary to reveal the left/right directions along with the hashes in revealed Merkle branches.
-
↩ 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>)''.
Let ''Q = P + int(t)G''. ** If ''q ≠ x(Q)'' or ''c[0] & 1 ≠ y(Q) mod 2'', fail
-
↩ 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.
-
↩ 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.
BIP 341 L148–149 BIP 341 L151–152
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.
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.
-
↩ 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''.
-
↩ 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.
BIP 341 L58 BIP 341 L59 BIP 341 L59
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.
Any other outputs, including version 1 outputs with lengths other than 32 bytes, or P2SH-wrapped version 1 outputs
remain unencumbered.
-
↩ 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.
BIP 341 L158 BIP 341 L159 BIP 341 L160 BIP 341 L161
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''.
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.
This allows to bypass the multiparty policy and to steal the coin.
MuSig key aggregation does not have this issue because it already causes the internal key to be randomized.
-
↩ 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.
BIP 341 (wallet-test-vectors.json) L7
Quoted source text (1)
"scriptTree": null
-
↩ 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.
-
↩ 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.
-
↩ 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
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.
-
↩ 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.
MuSig key aggregation does not have this issue because it already causes the internal key to be randomized.
-
↩ 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
-
↩ 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.
BIP 341 L62 BIP 341 L64 BIP 341 L66
Quoted source text (3)
* Fail if the witness stack has 0 elements.
If there is exactly one element left in the witness stack, key path spending is used:
If there are at least two witness elements left, script path spending is used:
-
↩ 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.
-
↩ 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 ≠ x(Q)'' or ''c[0] & 1 ≠ y(Q) mod 2'', fail
-
↩ 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.
BIP 341 L81 BIP 341 L81 BIP 341 L81
Quoted source text (3)
Execute the script, according to the applicable script rules
[[bip-0342.mediawiki|BIP342]] specifies validity rules that apply for leaf version 0xc0
using the witness stack elements excluding the script ''s'', the control block ''c'', and the annex ''a'' if present, as initial stack.
-
↩ 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.
BIP 341 L63 BIP 341 L63 BIP 341 L63 BIP 341 L63
Quoted source text (4)
If there are at least two witness elements, and the first byte of the last element is 0x50
this last element is called ''annex'' ''a''
The annex is a reserved space for future extensions
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.
-
↩ 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.
-
↩ 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.
BIP 341 L133 BIP 341 L133 BIP 341 L132 BIP 341 L132
Quoted source text (4)
If the <code>SIGHASH_ANYONECANPAY</code> flag is not set, the message commits to the amounts of ''all'' transaction inputs.
This eliminates the possibility to lie to offline signing devices about the fee of a transaction.
if the <code>SIGHASH_ANYONECANPAY</code> flag is not set, the message commits to the ''scriptPubKey''s of ''all'' outputs spent by the transaction.
This prevents lying to offline signing devices about output being spent
-
↩ 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.
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>.
-
↩ 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.
-
↩ 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)''
If the ''sig'' is 65 bytes long, return ''sig[64] ≠ 0x00
-
↩ 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
-
↩ History BIP 341 is a consensus soft-fork proposal assigned in 2020; its preamble records the status Deployed and that it requires BIP 340.
BIP 341 L3 BIP 341 L10 BIP 341 L12 BIP 341 L16
Quoted source text (4)
Layer: Consensus (soft fork)
Status: Deployed
Assigned: 2020-01-19
Requires: 340
-
↩ 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.
This BIP is deployed concurrently with [[bip-0342.mediawiki|BIP342]].