Skip to content
Snippets Groups Projects
Commit 8909b0dd authored by nanocryk's avatar nanocryk
Browse files

First list of system functions

parent 3a19831c
Branches
No related tags found
1 merge request!6WIP: RFC 5 : New Scalable Blockchain Protocol
......@@ -319,7 +319,7 @@ used as an *instance script* to lock funds :
use compute_aef
keys = [<key0> <key1> <key2>]
message = compute_aef fetch_token
check_sig a = sig_verify message (fetch_tx_storage (fetch_param a)) (keys a)
check_sig a = verify_sig message (fetch_store (fetch_param a)) (keys a)
final = and (for 0..(len keys) check_sig)
```
......@@ -365,6 +365,11 @@ thus uncontroled infinite loops. In our example `message` must be declared befor
results before giving it to `compute_aef`, `filter_tokens` would have been declared before the
`use` statement, since `compute_aef` will use it.
> Writing a function as a library is only usefull if its compiled code is larger than 32 bytes. If
> smaller providing the hash will take more place than the function itself. Its size should be
> a bit more than 32 bytes and used by multiple scripts to compensate the additionnal data of
> the subscript.
> TODO Explanation for `(fetch_tx_storage (fetch_param a))`
#### Compilation
......@@ -420,8 +425,10 @@ grp2
-- function 3 check_sig
grp4
sys[sig_verify]
sys[verify_sig]
usr2
grp2
sys[fetch_store]
grp2
sys[fetch_param]
par0 -- use parameter a/0
......@@ -446,6 +453,44 @@ grp 2
#### System functions list
| Code (hex) | Name | Parameters | Description
|:----:|:------------------|:------------------------|:-------
| | | | **Primitives**
| `00` | `true` | | Represents a "true" value.
| `01` | `false` | | Represents a "false" value.
| | | |
| | | | **Basic operations**
| `10` | `len` | `fun` | Counts `i` from 0 to infinity, and return the index of the first `nil` value for `fun i`.
| `11` | `for` | `indexes` `fun` | For each `index` in `indexes`, calls `fun index`.
| | | |
| `20` | `sum` | `fun` | Return the sum of each value returned by `fun i` with `i` growing from 0 to infinity until `fun i` returns `nil`.
| `21` | `mul` | `fun` | Return the product of each value returned by `fun i` with `i` growing from 0 to infinity until `fun i` returns `nil`.
| | | |
| `30` | `or` | `fun` | Return the binary OR of each value returned by `fun i` with `i` growing from 0 to infinity until `fun i` returns `nil`.
| `31` | `and` | `fun` | Return the binary AND of each value returned by `fun i` with `i` growing from 0 to infinity until `fun i` returns `nil`.
| | | |
| `40` | `not` | `value` | Return the binary NOT of `value`.
| `41` | `=` | `a` `b` | Return `true` if `a = b`, `false` otherwise.
| `42` | `!=` | `a` `b` | Return `true` if `a != b`, `false` otherwise.
| `43` | `>` | `a` `b` | Return `true` if `a > b`, `false` otherwise.
| `44` | `<` | `a` `b` | Return `true` if `a < b`, `false` otherwise.
| `45` | `>=` | `a` `b` | Return `true` if `a >= b`, `false` otherwise.
| `46` | `<=` | `a` `b` | Return `true` if `a <= b`, `false` otherwise.
| | | |
| | | | **Data fetching**
| `50` | `fetch_token` | `index` | Returns the token at this index. The token data is stored in an array in a format described below.
| `51` | `fetch_param` | `index` | Returns the script param at this index.
| `52` | `fetch_store` | `index` | Returns the transaction storage at this index.
| | | |
| | | | **Cryptography**
| `60` | `hash` | `algorithm` `message` | Returns the hash of `message` with given algorithm. *An unknown hashing algorithm make the whole script returns true, allowing new hashing algorithms via soft-forks.*
| `61` | `verify_sig` | `message` `sig` `key` | Verify if `sig` is valid for the `message` and public `key`. *If `sig` and `key` "cryptographic system codes" are equal but undefined, the function returns true to allow new cryptographic systems via soft-forks.*
> Any undeclared system function makes the script valid without executing it, allowing addition of
> new system functions via soft-forks.
> TODO Token array format
#### Some functions of a "standard library"
#### Execution
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment