Skip to content

Commit 79349a6

Browse files
committed
Add keccak-lys example EE written in Lys
1 parent 245e659 commit 79349a6

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

keccak-lys.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
beacon_state:
2+
execution_scripts:
3+
- scripts/keccak-lys/build/main.wasm
4+
shard_pre_state:
5+
exec_env_states:
6+
- "0000000000000000000000000000000000000000000000000000000000000000"
7+
shard_blocks:
8+
- env: 0
9+
data: ""
10+
- env: 0
11+
data: ""
12+
shard_post_state:
13+
exec_env_states:
14+
- "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"

scripts/keccak-lys/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

scripts/keccak-lys/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
lys main.lys

scripts/keccak-lys/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# keccak-lys
2+
3+
Sample EE script written in [Lys].
4+
5+
## Build
6+
7+
Install Node.js and npm first. Then install the lys compiler:
8+
```shell
9+
npm i -g lys
10+
```
11+
12+
Finally build the EE via:
13+
```shell
14+
lys main.lys
15+
```
16+
17+
Or simply run `make`.
18+
19+
[Lys]: https://github.com/lys-lang/lys

scripts/keccak-lys/eth2.lys

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[extern "env" "loadPreStateRoot"]
2+
fun loadPreStateRoot(ptr: u32): void = panic()
3+
4+
#[extern "env" "eth2_blockDataSize"]
5+
fun blockDataSize(): u32 = panic()
6+
7+
#[extern "env" "eth2_blockDataCopy"]
8+
fun blockDataCopy(ptr: u32, offset: u32, len: u32): void = panic()
9+
10+
#[extern "env" "eth2_savePostStateRoot"]
11+
fun savePostStateRoot(ptr: u32): void = panic()

scripts/keccak-lys/main.lys

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import system::hash::keccak
2+
3+
import eth2
4+
5+
#[export]
6+
fun main(): void = {
7+
var len = blockDataSize()
8+
var input = bytes(len)
9+
blockDataCopy(input.ptr, 0 as u32, len)
10+
11+
var k = Keccak()
12+
Keccak.update(k, input)
13+
var ret = Keccak.digest(k)
14+
15+
savePostStateRoot(ret.ptr)
16+
}

0 commit comments

Comments
 (0)