WIP: RFC 1 : Abstract Syntax Tree-based output script locks
Compare changes
+ 482
− 0
To lower blocksize and transactions weights, or to allow more complex conditions; it could be preferable to use a more simple binary format which need little or no parsing, close to memory and that can be converted back to text format. It can also allow to add new features without hard-forking the protocol.
We want to have multiple ways of spending an output, such as multi-signatures or time locks. It means we must have *operators* which combines conditions into one. One way to store these functions are as *Abstract Syntax Trees* : Each operator is a tree with its inputs as leaves. This leaves can be primitive values or other operators.
Some parts of a script may required in multiple places the same computed result. To avoid redudancies, we allow to provide an script with multiple ASTs. Each AST is executed in order and only the output of the last one is taken as the result. An AST can use the result of an above script with an `INCLUDE` operator. With this structure it's not possible to have recursion or cycles which avoid infinite loops and Turing-Completeness. All ASTs are grouped into a single structure (an **AST group** or a **script**).
We define an AST hash (on 32 bytes) as `HASH(AST) = SHA256(OperatorCode + HASH(Child0) + HASH(Child1) + ...)`. Since we want to use provide only the hash of a branch while keeping the script valid, we defined an operator `AST_HASH(Hash)` for which `HASH(AST_HASH(Hash)) = Hash`. To allow only hashes of unused branches, this operator will return an `Undefined` value and should be used with aggregators such as `OR` or `SUM`.
In this exemple merkelized scripts allow to hide each public keys needed to spend the output, and `PKHash1` is never sent on the blockchain. Also, it's impossible to know what was the content of the branch, so it could have been any test of any complexity and nobody will never now it by looking at the blockchain.
\ No newline at end of file