|
| 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 | + |
0 commit comments