WIP: RFC 1 : Abstract Syntax Tree-based output script locks
Compare changes
0001-ast-script-lock.md
0 → 100644
+ 144
− 0
To lower blocksize and transactions weights; or to allow more complex condtions, 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 be able to have multiple ways of spending an output, such as mutli-signatures or time locks. It means we must have *operators* which combines multiples conditions into one. One ways to store these functions are as *Abstract Syntax Tree*s : Each operator is a tree with its inputs as leaves. This leaves can be primitive values or other operators.
Some script may required in multiple places the same computed result. To avoid redudancies, we allow to provide a script with multiple ASTs. Each script is executed in order and only the output of the last is taken as the result. A script 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.
We define a hash (on 32 bytes) as `HASH(Branch) = 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 `BRANCH_HASH(Hash)` for which `HASH(BRANCH_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`.
\ No newline at end of file