Skip to content

Commit

Permalink
Add keccak-lys example EE written in Lys
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jul 31, 2019
1 parent 245e659 commit 79349a6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
14 changes: 14 additions & 0 deletions keccak-lys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
beacon_state:
execution_scripts:
- scripts/keccak-lys/build/main.wasm
shard_pre_state:
exec_env_states:
- "0000000000000000000000000000000000000000000000000000000000000000"
shard_blocks:
- env: 0
data: ""
- env: 0
data: ""
shard_post_state:
exec_env_states:
- "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
1 change: 1 addition & 0 deletions scripts/keccak-lys/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
2 changes: 2 additions & 0 deletions scripts/keccak-lys/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
lys main.lys
19 changes: 19 additions & 0 deletions scripts/keccak-lys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# keccak-lys

Sample EE script written in [Lys].

## Build

Install Node.js and npm first. Then install the lys compiler:
```shell
npm i -g lys
```

Finally build the EE via:
```shell
lys main.lys
```

Or simply run `make`.

[Lys]: https://github.com/lys-lang/lys
11 changes: 11 additions & 0 deletions scripts/keccak-lys/eth2.lys
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[extern "env" "loadPreStateRoot"]
fun loadPreStateRoot(ptr: u32): void = panic()

#[extern "env" "eth2_blockDataSize"]
fun blockDataSize(): u32 = panic()

#[extern "env" "eth2_blockDataCopy"]
fun blockDataCopy(ptr: u32, offset: u32, len: u32): void = panic()

#[extern "env" "eth2_savePostStateRoot"]
fun savePostStateRoot(ptr: u32): void = panic()
16 changes: 16 additions & 0 deletions scripts/keccak-lys/main.lys
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import system::hash::keccak

import eth2

#[export]
fun main(): void = {
var len = blockDataSize()
var input = bytes(len)
blockDataCopy(input.ptr, 0 as u32, len)

var k = Keccak()
Keccak.update(k, input)
var ret = Keccak.digest(k)

savePostStateRoot(ret.ptr)
}

0 comments on commit 79349a6

Please sign in to comment.