This is an ekt
implementation of the EIP-4788
system contract. It is 100 bytes once assembled.
To setup a dev environment capable of assembling, analyzing, and executing the
repository's assembly you will need to install foundry
and
etk
. This can be accomplished by running:
$ curl -L https://foundry.paradigm.xyz | bash
$ cargo install --features cli etk-asm etk-dasm
To assemble src/main.etk
you will need to invoke eas
:
$ eas src/main.etk
3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500
It's also possible to remove the etk
preproccessing by doing a roundtrip --
first assembling the program, then disassembling the program:
$ disease --code 0x$(eas src/main.etk)
0: caller
1: push20 0xfffffffffffffffffffffffffffffffffffffffe
16: eq
17: push1 0x44
19: jumpi
1a: push1 0x20
1c: calldatasize
1d: eq
1e: push1 0x24
20: jumpi
21: push0
22: push0
23: revert
24: jumpdest
25: push3 0x018000
29: push0
2a: calldataload
2b: mod
2c: dup1
2d: sload
2e: push0
2f: calldataload
30: eq
31: push1 0x37
33: jumpi
34: push0
35: push0
36: revert
37: jumpdest
38: push3 0x018000
3c: add
3d: sload
3e: push0
3f: mstore
40: push1 0x20
42: push0
43: return
44: jumpdest
45: push3 0x018000
49: timestamp
4a: mod
4b: timestamp
4c: dup2
4d: sstore
4e: push0
4f: calldataload
50: swap1
51: push3 0x018000
55: add
56: sstore
57: stop
There are several tools to generate a control-flow graph. We'll demostrate
evm-cfg
here:
evm-cfg $(eas src/main.etk) | dot -Tpng -o cfg.png
note: you will also need graphviz
installed to use the dot
utility.
The tests can be executed using the builder-wrapper
script with the same
arguments as forge:
$ ./build-wrapper test
[โ ] Compiling...
No files changed, compilation skipped
Running 2 tests for test/Contract.t.sol:ContractTest
[PASS] testRead() (gas: 18514)
[PASS] testUpdate() (gas: 53953)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 3.35ms
Ran 1 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests)
A step-by-step debugger can be brought up using ./build-wrapper test --debug {test name}
.