MAST (Merkelized Alternative Script Trees)
Storing several spending conditions in a Merkle tree so only the one used is revealed.
Basically
MAST lets a Bitcoin output offer several spending conditions. You reveal only the condition you use when you spend.
Key Takeaways
- MAST organises multiple spending conditions in a Merkle tree. Only the condition you use is revealed on-chain, while all other branches remain completely hidden.
- MAST was activated as part of Taproot in November 2021 through BIP-341. It replaced the old model where every spending path had to be exposed at spend time, greatly improving privacy and efficiency.
- Complex contracts such as multisig with fallbacks, time-locked inheritance and conditional payments become practical without bloating transactions or leaking sensitive logic to observers.
What Is MAST?
MAST (Merkelized Alternative Script Trees) is a technique for encoding multiple spending conditions into a single Bitcoin output using a Merkle tree. Each spending condition becomes a leaf in the tree, and the tree's root is committed to the output. When you spend, you reveal only the specific condition you are executing and a compact Merkle proof that it belongs to the tree, while every other condition stays hidden.
The concept was first described by Russell O'Connor in 2013 and formalised in a 2014 MIT paper by Jeremy Rubin, Manali Naik and Nitya Subramanian under the original name "Merklized Abstract Syntax Trees". Anthony Towns later renamed it "Merkelized Alternative Script Trees". The new name reflects the actual implementation, which organises alternative Bitcoin Script branches rather than compiling scripts into abstract syntax trees.
Several standalone proposals attempted to bring MAST to Bitcoin, including BIP-114 by Johnson Lau in 2016 and BIP-116/117 by Mark Friedenbach in 2017, but none were activated independently. The MAST concept was instead incorporated into the Taproot upgrade, which activated at block height 709,632 on November 14, 2021.
How It Works
MAST in Taproot combines two spending paths into a single output. You use a key path for cooperative spending or a script path that draws on the Merkle tree of alternative conditions.
Building the Script Tree
You write each spending condition as a Bitcoin Script. Each script becomes a leaf node in a binary Merkle tree.
The Merkle root is then used to tweak an internal public key P, producing the output key Q = P + t*G, where t is derived from hashTapTweak(P // merkle_root). This uses the linearity of Schnorr signatures: tweaking both public and private keys by the same value preserves their validity as a key pair.
Key Path Spend (Cooperative)
All parties produce a single Schnorr signature against the tweaked output key when they agree. You reveal no scripts, Merkle proofs or details about the tree. The transaction looks identical to any ordinary single-key P2TR spend and costs approximately 57.5 vbytes per input.
Taproot's central insight, credited to Gregory Maxwell, is that most multi-party contracts have an "everyone agrees" outcome that should be optimised for. MAST provides the fallback complexity without penalising the common case.
Script Path Spend (Non-cooperative)
You use a script path spend when the cooperative path is unavailable. You reveal only the relevant leaf.
Validators reconstruct the Merkle root from the leaf hash and the provided path, verify that it matches the output's tweak and then execute the script. The control block is 33 + 32m bytes, where m is the path depth from 0 to 128.
Huffman Optimization
Spending conditions expected to be used more frequently should sit closer to the root, resulting in shorter Merkle paths and smaller witness data. This Huffman-style optimisation ensures that the most likely spending paths are also the cheapest to execute on-chain.
MAST vs. Legacy Script
Complex spending conditions used P2SH or P2WSH outputs before MAST. These outputs required you to reveal the entire script at spend time.
The Bitcoin address types research article provides a detailed walkthrough of these output types. It covers both P2SH and P2WSH.
Complex Multisig with Fallbacks
A business treasury controlled by three partners provides an example. MAST enables a tiered spending policy for this treasury.
Legacy P2WSH would expose all three fallback branches whenever any one was used. MAST reveals nothing about Leaves B or C when you use Leaf A.
Time-Locked Alternatives
MAST pairs naturally with timelocks. You can use them to create progressive fallback conditions.
Inheritance planning is a natural extension. Family members can set up an output requiring all signers initially, with progressively relaxed requirements as time passes. For example, after 6 months only N-1 signers are needed, after 12 months N-2, and eventually a single heir with legal assistance.
Conditional Payments and HTLCs
Hash time-locked contracts used in Lightning and atomic swaps naturally map to a two-leaf MAST tree, with one leaf for the hash-lock payment clause and another for the time-lock refund clause. PTLCs, the next-generation replacement using adaptor signatures, further leverage Taproot's Schnorr foundation alongside MAST.
Policy-Driven Spending with Miniscript
Miniscript compiles human-readable spending policies into optimised Bitcoin Scripts. MAST and Miniscript together compile complex policies into efficient script trees, with each condition as a separate leaf and automatic optimisation for the most likely spending path. The Miniscript spending policies research article explains more about how spending policies compose.
Why It Matters
MAST makes Bitcoin smart contracts practical at scale. Before Taproot, a contract with 10 spending conditions required revealing all 10 at spend time, leaking the contract's full logic and creating large transactions. MAST lets the same contract reveal only 1 condition plus a 4-hash Merkle proof, regardless of total complexity.
The privacy implications are significant: observers cannot determine what alternative conditions existed, how many parties were involved or what fallback logic was available. A transaction using the cooperative key path is indistinguishable from an ordinary single-key spend.
Layer 2 protocols like the Lightning Network and Spark benefit directly. Channel outputs can encode complex state transitions, penalty mechanisms and cooperative close paths in a MAST tree, keeping the cooperative case cheap and private while retaining the security of on-chain enforcement when needed.
Complexity in Script Design
An optimal MAST tree requires careful consideration of which conditions are most likely and how to arrange them for minimal proof size. Poorly structured trees waste witness space. Tools like Miniscript and output descriptors help automate this, but the design space is still more complex than legacy scripts.
Recovery and Backup
A MAST output is only spendable if you retain the full tree structure, including all leaf scripts and the internal key. Losing any branch means losing the ability to reconstruct the Merkle root, potentially making verification of alternative spending paths impossible. Your wallet backup strategy must account for the full descriptor including all tree branches, not just the key path.
Maximum Tree Depth
BIP-341 limits the Merkle path to 128 levels, theoretically allowing 2^128 leaf scripts. Trees beyond a few dozen leaves are rare in practice. The depth limit exists because scripts at deeper levels would have an execution probability below Bitcoin's security bound of 1 in 2^128, making them effectively unreachable.
Adoption and Tooling
Taproot activated in November 2021, but wallet and application support for script-path spends, the MAST functionality, has developed more slowly than key-path support. Developers building MAST-based contracts need libraries that support Tapscript construction, BIP-342 script validation and proper tree commitment.
This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.