Skip to content

Commit 734a859

Browse files
pinheadmzsipa
authored andcommitted
bip-taproot: example from diagram
1 parent 2c8feb1 commit 734a859

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

bip-taproot.mediawiki

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ def taproot_output_script(internal_pubkey, script_tree):
236236
237237
[[File:bip-taproot/tree.png|frame|This diagram shows the hashing structure to obtain the tweak from an internal key ''P'' and a Merkle tree consisting of 5 script leaves. ''A'', ''B'', ''C'' and ''E'' are ''TapLeaf'' hashes similar to ''D'' and ''AB'' is a ''TapBranch'' hash. Note that when ''CDE'' is computed ''E'' is hashed first because ''E'' is less than ''CD''.]]
238238
239+
To spend this output using script ''D'', the control block would contain the following data in this order:
240+
241+
<control byte with leaf version> <internal key p> <C> <E> <AB>
242+
243+
The TapTweak would then be computed as described in [[#script-validation-rules]] like so:
244+
245+
<source>
246+
D = tagged_hash("TapLeaf", bytes([leaf_version]) + ser_script(script))
247+
CD = tagged_hash("TapBranch", C + D)
248+
CDE = tagged_hash("TapBranch", E + CD)
249+
ABCDE = tagged_hash("TapBranch", AB + CDE)
250+
TapTweak = tagged_hash("TapTweak", p + ABCDE)
251+
</source>
252+
239253
'''Spending using the key path''' A Taproot output can be spent with the secret key corresponding to the <code>internal_pubkey</code>. To do so, a witness stack consists of a single element: a bip-schnorr signature on the signature hash as defined above, with the secret key tweaked by the same <code>h</code> as in the above snippet. See the code below:
240254
241255
<source lang="python">

0 commit comments

Comments
 (0)