BIP 0341
How can an output commit to several ways of spending?
A Taproot output is a single 32-byte key. Behind it can sit a whole tree of alternative scripts, and a spend reveals only the one it uses, along with a proof that it was there all along.
Many coins have more than one acceptable way to be spent: the owners all agree, or one of them waits out a timeout, or a backup key steps in. Older Bitcoin outputs either showed one condition or locked all of them behind a single script that had to be published in full when spent.12
BIP 341, assigned in 2020 and building on BIP 340, defines a SegWit version 1 output whose spending rules combine Schnorr signatures, Merkle trees and a trick called Taproot. The BIP records that it activated on mainnet at block 709632. Its authors set out to minimize how much an output reveals about its spending conditions, both when it is created and when it is spent.1345
Source details
This chapter is an independent explanation, not the proposals themselves. Preamble fields are shown as recorded in the pinned files, with author e-mail addresses omitted. Status is the proposal’s own field, 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
No script treevector 0 · key only
- internal key P
d6889cb0…0a961d - no script treeempty
- t = hashTapTweak(P ‖ nothing)
b86e7be8…9c6c70 - output key Q = P + t⋅G
53a1f6e4…dda343 - scriptPubKey · address
512053a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343bc1p2wsldez5mud2yam29q22wgfh9439spgduvct83k3pm50fcxa5dps59h4z5
Three-leaf treevector 5 · 3 scripts
- internal key P
e0dfe230…263e6f - Merkle root
ccbd66c6…1ce0e2 - t = hashTapTweak(P ‖ root)
b57bfa18…a786f4 - output key Q = P + t⋅G
91b64d53…783605 - scriptPubKey · address
512091b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605bc1pjxmy65eywgafs5tsunw95ruycpqcqnev6ynxp7jaasylcgtcxczs6n332e
Exact values
- vector 0 P
d6889cb081036e0faefa3a35157ad71086b123b2b144b649798b494c300a961d- root
none- t
b86e7be8f39bab32a6f2c0443abbc210f0edac0e2c53d501b36b64437d9c6c70- Q
53a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343
- vector 5 P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f- root
ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2- t
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4- Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
BIP 341 wallet-test-vectors.json, scriptPubKey[0] and scriptPubKey[5]. Every value matched the published one at build time.
Two keys, one output
Start with an ordinary public key, P, called the internal key. Hash it together with the root of a tree of scripts to get a number t, and add t⋅G to P. The result, Q = P + t⋅G, is the output key. Only Q’s x coordinate goes into the output, as a 32-byte witness program. BIP 341 calls the program q the taproot output key and p the internal key, and they are different numbers.6711
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.1213
Because t depends on the tree, Q commits to the whole tree without showing any of it. Anyone holding the secret key for P can still sign for Q: they add t to their secret key (negated first if P’s y coordinate is odd), and a key path spend is simply a BIP 340 signature with that tweaked key. When no scripts are wanted, the BIP still asks wallets to tweak, hashing P alone, as vector 0 does. The authors explain why: with some ways of sharing one key among several parties, an untweaked output would let one of them slip in a hidden script; MuSig’s aggregation does not have this problem.8914
A tree of scripts
Each alternative way to spend is a leaf: a script plus a one-byte leaf version. A leaf’s hash is a tagged hash, TapLeaf, of the version, the script’s length and the script. Pairs of hashes are joined by another tagged hash, TapBranch, all the way up to a single root. Before joining, the two children are sorted, smaller first, so a proof never needs to say which side a hash came from.61516
The tree can take any shape. BIP 341 suggests a balanced tree when every condition is equally likely, and a Huffman tree, with likely scripts near the top, when the odds are known. These suggestions sit in a section the BIP marks as wallet guidance, not consensus: every output is one internal key plus zero or more scripts, and satisfying any one of them is enough.1718
The figure below shows published vector 5: one internal key and three leaves, with leaf A one level below the root and leaves B and C one level deeper. Switch between the two spending paths, choose a leaf, and then hide everything the spend itself does not reveal.1019
A · Interactive
Static view: a script-path spend of Leaf B, with the whole tree shown as the wallet knows it. With JavaScript you can switch to the key path, choose another leaf, and hide everything the spend does not reveal.
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605Output key Q (x only). This is all the output itself shows.Q = P + t⋅G, t = hashTapTweak(p ‖ root)recomputed by the verifier
e0dfe2…3e6fin the witnessccbd66…e0e2recomputed by the verifier- TapBranch
ccbd66…e0e2recomputed by the verifier- Leaf A
<32-byte key> OP_CHECKSIG2645a0…9817only its hash revealed - TapBranch
ffe578…e553recomputed by the verifier- Leaf B
<32-byte key> OP_CHECKSIGba982a…de1cscript in the witness; hash recomputed - Leaf C
<32-byte key> OP_CHECKSIG9e3140…eaf6only its hash revealed
in the witnesshash onlyrecomputedknown to the wallet
Script-path witness for Leaf B
- script inputsWhatever the script needs; for this leaf, a signature for its key. The vectors publish none, so none is shown.
- script s · 34 bytes
202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac - control block c · 97 bytes = 33 + 32 × 2
c0e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817first byte 0xc0 = leaf version 0xc0 + parity bit 0; then the internal key P; then 2 sibling hashes
- Length 97 bytes = 33 + 32 × 2 ✓
- P = lift_x(c[1:33]) ✓
- leaf version v = c[0] & 0xfe = 0xc0
- k0 = hashTapLeaf(v ‖ size ‖ s) =
ba982a…de1c - k1 = hashTapBranch(e0 ‖ k0) =
ffe578…e553smaller hash first - k2 = hashTapBranch(e1 ‖ k1) =
ccbd66…e0e2smaller hash first - t = hashTapTweak(p ‖ k) =
b57bfa…86f4 - Q = P + t⋅G; y(Q) is even, matching the parity bit
- x(Q) = q ✓: the output committed to this script
The spend reveals that a script path exists, the internal key P, the leaf version and parity bit, this leaf’s script and its inputs, and its depth (2). The rest of the tree appears, if at all, only as sibling hashes. Running the script itself is BIP 342’s job and is not shown here.
Exact values (the wallet’s view)
- internal key P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f- Merkle root
ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2- tweak t
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4- output key Q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605(y even)- address
bc1pjxmy65eywgafs5tsunw95ruycpqcqnev6ynxp7jaasylcgtcxczs6n332e- Leaf A hash
2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817- Leaf B hash
ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c- Leaf C hash
9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6
Source: BIP 341 wallet-test-vectors.json, scriptPubKey[5] and keyPathSpending[0].inputSpending[3]. Hashes are byte arrays, first byte first. The tree’s shape is this vector’s; BIP 341 lets a wallet choose any binary tree.
B · Worked example
Spending published vector 5 through one of its deepest leaves: what the verifier rebuilds from the control block.
Reveal one script (leaf B) and hash it with its leaf version 0xc0 and length
- script
202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac- TapLeaf hash
ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c
Fold in sibling hash 1, smaller first
- sibling
9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6- TapBranch
ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553
Fold in sibling hash 2, smaller first
- sibling
2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817- TapBranch
ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2
Tweak the internal key with the root
- internal key P
e0dfe2300b0dd746a3f8674dfd4525623639042569d829c7f0eed9602d263e6f- t
b57bfa183d28eeb6ad688ddaabb265b4a41fbf68e5fed2c72c74de70d5a786f4
Q = P + t⋅G must equal the output key
- output key q
91b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605
It does, and y(Q) is even, matching the control block’s parity bit: the output committed to this script all along.
Source: BIP 341 wallet-test-vectors.json, scriptPubKey[5]; every value matched the vector at build time.
Two ways to spend
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, a field reserved for future extensions that users SHOULD NOT include until a soft fork defines it. One remaining element means a key path spend; two or more mean a script path spend.2122
The key path is a single signature that must be valid for the output key q. The signature names no leaf and reveals nothing about the tree, and the figure’s key-path view shows the published one: 64 bytes, with nothing else in the witness.192324
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.11151925
From those pieces the verifier rebuilds the commitment. It hashes the leaf, folds in each sibling hash in sorted order to reach a root, computes t from the internal key and that root, then Q = P + t⋅G. The spend is accepted only if Q’s x coordinate equals the output key and its y parity matches the control block’s bit. The authors keep that bit so the output key can be lifted to one exact point, which batch verification needs.1126
A proof for one leaf proves nothing for another. The tests behind this page take each published control block and try it with a different leaf’s script, with the parity bit flipped and against another vector’s output key: every attempt fails the comparison.1027
Passing the commitment check only unlocks the next step: the script must then run successfully, with the remaining witness elements as its starting stack. For leaf version 0xc0 those rules are BIP 342’s, the subject of the next chapter.28
Details: byte order and the published vectors
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.29
This page’s model reproduces every value the vectors publish: leaf hashes, roots, tweaks, output keys, scriptPubKeys and control blocks for all 7 trees, and the keys, tweaks, signature message, signature hash and signature for all 7 key-path inputs.10
What a spend gives away
Only the condition actually used is published. A key path spend shows a key and a signature and nothing else, so an observer cannot tell whether a script tree existed at all. The BIP calls this the ideal case. The authors argue it can be the usual one: assuming most outputs could be spent by everyone involved agreeing, Schnorr key aggregation lets several people control one key that looks like anyone else’s.203031
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.3233
A script path spend is more talkative. It reveals that a script path existed, that the key path was not used, the script itself, and the leaf’s depth, which hints at the shape of the tree and even at the wallet software that built it. Other leaves stay hidden, but their hashes may appear as siblings in the proof. Taproot narrows what a spend discloses; it does not make every spend anonymous, and the BIP adds that keys should never be reused, in any leaf.2034
What the signature covers
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.2435
Among several changes to the message, one stands out. Unless the signer opts out with ANYONECANPAY, it commits to the amount and scriptPubKey of every output being spent, not just its own. The authors give the reason: an offline signing device can no longer be lied to about the fee or about what it is spending. The message is at most 206 bytes; for the published input below it is 174.3637
Input 4 of 9 · hash_type 0x00 · SigMsg 174 bytes
- hash_type1 B
00which parts are signed; 0x00 means SIGHASH_DEFAULT - nVersion4 B
02000000from the transaction - nLockTime4 B
0065cd1dfrom the transaction - sha_prevouts32 B
e3b33bb4ef…9c4c3fevery input’s outpoint - sha_amounts32 B
58a6964a4f…e0fde6the amount of every output being spent - sha_scriptpubkeys32 B
23ad0f61ad…d52e21the scriptPubKey of every output being spent - sha_sequences32 B
18959c7221…3a957eevery input’s nSequence - sha_outputs32 B
a2e6dab7c1…eb4bc5every output this transaction creates - spend_type1 B
00key path, no annex - input_index4 B
04000000which input this signature is for
hashTapSighash(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
BIP 341 wallet-test-vectors.json, keyPathSpending[0], input 4. SigMsg, sighash and the published signature were checked at build time.
Evidence
Each numbered marker in the text points here, and the ↩ links lead back to every place that cites an entry. Quotes are verbatim from the BIP files at commit
3a10b5b, including their wiki markup; links open
the exact lines; the quoted text sits under each entry. Labels say what kind of statement each 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
-
↩ 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.
-
↩ 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]].
-
↩ 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 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 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 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 party could otherwise hide a script path, though MuSig's randomized aggregation does not have this issue.
BIP 341 L158 BIP 341 L159 BIP 341 L161
Quoted source text (3)
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.
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
-
↩ 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 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
-
↩ 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.
-
↩ 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 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.
-
↩ a b c 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 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 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.
-
↩ a b 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 c d 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 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.
-
↩ 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:
-
↩ 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 a key path spend the single witness element is a signature that must be valid for the output key q.
Quoted source text (1)
The single witness stack element is interpreted as the signature and must be valid (see the next section) for the public key ''q''
-
↩ a b 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 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
-
↩ 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 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.
-
↩ 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
-
↩ 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.
-
↩ 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.
-
↩ Rule The BIP says taproot outputs should never reuse keys, for privacy, including in every leaf.
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.
-
↩ 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>.
-
↩ a b 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
-
↩ 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