Skip to content

Commit 25b9e58

Browse files
committed
added first take on chapter 19
1 parent e0ef9ab commit 25b9e58

4 files changed

Lines changed: 139 additions & 0 deletions

File tree

‎docs/19_0_Using_Tapscript.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Chapter 19: Using Tapscript
2+
3+
Schnorr is the enabler of the Taproot upgrade: it's what makes
4+
everything else possible. Sure, it has advantages of its own, such as
5+
the ability to aggregate FROST and MuSig2 multisigs, but its greatest
6+
power may be its support for combining keypaths and scriptpaths into a
7+
single address.
8+
9+
Doing so requires two additional elements, both of which are outlined
10+
in this chapter. First, it requires the ability to store multiple
11+
scripts in a Merkle Tree that can be represented by its root
12+
hash. Second, it requires a slight variant of Bitcoin Script designed
13+
to work with these Merkles Trees.
14+
15+
Both of these additions are covered in this chapter. Though Bitcoin
16+
Core doesn't currently show off either of these capabilities, they're
17+
embedded in one feature: Tapscript multisigs.
18+
19+
## Objectives for This Chapter
20+
21+
After working through this chapter, a developer will be able to:
22+
23+
* Create Taproot Multisigs
24+
* Sign for Taproot Multisigs
25+
26+
Supporting objectives include the ability to:
27+
28+
* Understand Merkle Trees
29+
* Understand the Differences of Tapscript
30+
* Understand the Varieties of Multisig
31+
32+
## Table of Contents
33+
34+
* [Section One: Understanding MAST](19_1_Understanding_MAST.md)
35+
* [Section Two: Designing Tapscripts](19_2_Designing_Tapscripts.md)
36+
* [Section Three: Creating a Taproot Multisig](19_3_Creating_a_Taproot_Multisig.md)

‎docs/19_1_Understanding_MAST.md‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# 19.1: Understanding MAST
2+
3+
MAST stands for Merkelized Abstract Syntax Tree, an idea first
4+
suggested in 2016 as [BIP
5+
114](https://github.com/bitcoin/bips/blob/master/bip-0114.mediawiki). Though
6+
that BIP has been Closed, it lives on in the Taproot Update.
7+
8+
## Understand the Merkle Tree
9+
10+
A Merkle Tree is also known as a hash tree. That's because it's a tree
11+
of hashes. Data is hashed to form the leaves at the bottom level of
12+
the tree. Then hashes are combined to form a node: usually a Merkle
13+
tree is a binary hash tree, which means that every pair of hashes are
14+
combined.
15+
16+
> 📖 **_What is a hash?_** A hash is the output of a hash
17+
function. It's a short, fixed length representation of a longer
18+
variable length input. Hash functions are designed to be collision
19+
resistant, which means that each hash uniquely represents each input,
20+
and one way, which means that you can derive a hash from the input,
21+
but you can't derive the input from the hash.
22+
23+
As you ascend in a hash tree, more hashes are combined, resulting in
24+
fewer and fewer nodes. Ultimately, you get root hash that represents
25+
all of the individual hashes of the tree, and so all of the individual
26+
data input into the tree. A hash tree is usually represented just by
27+
its root hash.
28+
29+
Individual leaves of a hash tree can be revealed without revealing the
30+
content as a whole: a user simply reveals the leaf and then each of
31+
the hashes that it contributes to, up to the root hash.
32+
33+
<center>
34+
<a href="19_1_Understanding_MAST.png">
35+
<img src="19_1_Understanding_MAST.png">
36+
</a>
37+
</center>
38+
39+
## Understand the MAST
40+
41+
MAST is a simple application of the Merkle Tree to Bitcoin Scripts:
42+
each leaf represents a Bitcoin Script (or rather, the slightly varied
43+
Tapscript) that can be used to unlock the funds at a Taproot address.
44+
45+
* If there is **no Script**, then the Taproot address is tweaked with
46+
an unspendable script path.
47+
* If there is a **Merkle Tree**, then the Taproot address is tweaked
48+
with the root hash of the tree.
49+
50+
To spend from a Taproot address using a key just requires a signature
51+
from the private key and the inclusion of the public key (just like
52+
with traditional P2PKH and P2WPKH addresses).
53+
54+
To spend from a script in the Merkle tree requires that the spender
55+
supply the script and the inputs that satisfy the script (just as with
56+
traditional P2SH and P2WSH addresses), but also the path in the Merkle
57+
Tree that runs from the leaf script being satisfied to the root hash
58+
that was encoded in the P2TR address.
59+
60+
(The term MAST is not used in BIP-341, but is referenced here for its
61+
historic inclusion.)
62+
63+
## Summary: Understanding MAST
64+
65+
Merkle Trees, or MASTs, are included in Taproot. They're a way to
66+
simply and efficiently support a whole collection of scripts, any of
67+
which can unlock an address, and which can be used as alternatives to
68+
typical key path spending.
69+
70+
> 🔥 ***What is the power of MAST?*** MAST is a way to record a whole
71+
collection of scripts as a single root hash that Taproot then applies
72+
as a tweak to a Taproot address. This methodology ensures that no one
73+
knows what the scripts or, or even that there are scripts, before
74+
they're actually used. So besides the versatility implicit in being
75+
able to unlock funds in a variety of ways, you also get the privacy of
76+
what those ways are.
77+
78+
## What's Next?
79+
80+
Continue "Using Tapscript" with [§19.2: Designing
81+
Tapscripts](19_2_Designing_Tapscripts.md).
82+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
flowchart TD
2+
3+
root["#ABCDEFGH"]:::root --> rootleft["#ABCD"]:::branch
4+
rootleft --> AB["#AB"]:::branch
5+
rootleft --> CD["#CD"]:::branch
6+
root --> rootright["#EFGH"]:::branch
7+
rootright --> EF["#EF"]:::branch
8+
rootright --> GH["#GH"]:::branch
9+
AB --> A["#A"]:::leaf
10+
AB --> B["#B"]:::leaf
11+
CD --> C["#C"]:::leaf
12+
CD --> D["#D"]:::leaf
13+
EF --> E["#E"]:::leaf
14+
EF --> F["#F"]:::leaf
15+
GH --> G["#G"]:::leaf
16+
GH --> H["#H"]:::leaf
17+
18+
classDef root stroke:#6E260E,stroke-width:4px;
19+
classDef branch stroke:#C4A484,stroke-width:4px;
20+
classDef leaf stroke:#0f0,stroke-width:4px;
21+
50.9 KB
Loading

0 commit comments

Comments
 (0)