diff --git a/keccak-lys.yaml b/keccak-lys.yaml new file mode 100644 index 0000000..ca0e43d --- /dev/null +++ b/keccak-lys.yaml @@ -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" diff --git a/scripts/keccak-lys/.gitignore b/scripts/keccak-lys/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/scripts/keccak-lys/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/scripts/keccak-lys/Makefile b/scripts/keccak-lys/Makefile new file mode 100644 index 0000000..c7a56a7 --- /dev/null +++ b/scripts/keccak-lys/Makefile @@ -0,0 +1,2 @@ +all: + lys main.lys diff --git a/scripts/keccak-lys/README.md b/scripts/keccak-lys/README.md new file mode 100644 index 0000000..48a39ac --- /dev/null +++ b/scripts/keccak-lys/README.md @@ -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 diff --git a/scripts/keccak-lys/eth2.lys b/scripts/keccak-lys/eth2.lys new file mode 100644 index 0000000..f714f75 --- /dev/null +++ b/scripts/keccak-lys/eth2.lys @@ -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() diff --git a/scripts/keccak-lys/main.lys b/scripts/keccak-lys/main.lys new file mode 100644 index 0000000..3ead7cc --- /dev/null +++ b/scripts/keccak-lys/main.lys @@ -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) +}