1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-22 08:08:11 +00:00

Auth&Auth: explain differerence between MAST and Merklized Alt Script Trees

Inspired by a comment from Roasbeef about how we shouldn't described
MAST because that's not what taproot implements.
This commit is contained in:
David A. Harding 2023-08-09 15:48:06 -10:00
parent 89b548d5b5
commit 114d7bf25a
5 changed files with 68 additions and 0 deletions

View File

@ -1732,6 +1732,39 @@ significant downsides of MAST for Bitcoin and there were two solid
proposals for it, BIP114 and BIP116, before an improved approach was
discovered, which we'll see in <<taproot>>.
.MAST versus MAST
****
The earliest idea for what we now know as _MAST_ in Bitcoin was
_Merklized Abstract Syntax Trees_. In an Absract Syntax Tree (AST),
every condition in a script creates a new branch, as show in <<ast>>.
[[ast]]
.An Abstract Syntax Tree (AST) for a script
image::../images/ast.dot.png["An Abstract Syntax Tree (AST) for a script"]
ASTs are widely used by programs that parse and optimize code for other
programs, such as compilers. A merklized AST would commit to every part
of a program and so enable the features described in the section about
<<mast>>, but it would require revealing at least one 32-byte digest for
every separate part of the program, which would not be very space
efficient on the blockchain for most programs.
What most people in most cases call _MAST_ in Bitcoin today is
_Merklized Alternative Script Trees_, a backronym coined by developer
Anthony Towns. An alternative script tree is a a set of scripts, each
one of them complete by itself, where only one can be selected--making
them alternatives for each other, as shown in <<alt_script>>.
[[alt_script]]
.An alternative script tree
image::../images/alt_script.dot.png["An alternative script tree"]
Alternative script trees only require revealing one 32-byte digest for
each level of depth between the spender's chosen script and the root of
the tree. For most scripts, this is a much more efficient use of space
in the blockchain.
****
[[pay_to_contract]]
=== Pay to Contract (P2C)

12
images/alt_script.dot Normal file
View File

@ -0,0 +1,12 @@
digraph AST {
node [shape=box];
// Main Script
script [label="Script"];
op1 [ label = "<pubKey1> OP_CHECKSIG" ]
op2 [ label = "<pubKey2> OP_CHECKSIG" ]
// Script Structure
script -> {op1, op2};
}

BIN
images/alt_script.dot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

23
images/ast.dot Normal file
View File

@ -0,0 +1,23 @@
digraph AST {
node [shape=box];
// Main Script
script [label="Script"];
op_if [label="OP_IF"];
pubKey1 [label="<pubKey1>"];
op_checksig1 [label="OP_CHECKSIG"];
op_else [label="OP_ELSE"];
pubKey2 [label="<pubKey2>"];
op_checksig2 [label="OP_CHECKSIG"];
op_endif [label="OP_ENDIF"];
// Script Structure
script -> op_if;
op_if -> pubKey1;
op_if -> op_checksig1;
script -> op_else;
op_else -> pubKey2;
op_else -> op_checksig2;
script -> op_endif;
}

BIN
images/ast.dot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB