1. 引言
evm2 EVM平方: e=vm² (pronounced evm-squared; the = is silent), also spelled evm2, is an evm that runs inside evm。
开源代码见:
- https://github.com/hananbeer/evm2
当前使用 huff——为A low level assembly language for the EVM 汇编语言 实现了evm,使得可have a vm in evm:
- run_huff.sh
- test_huff.sh
同时,还有一些老接口:
- 1)编译:【其中evm为go-ethereum中的一个工具】
evm compile evm.easm
- 2)运行:使用
evm run
或如下脚本:./run.sh 0x
- 3)调试:
./disas.sh
将编译evm2,然后展示反汇编结果,有助于理解debug。
注意:代码中若无return
声明,将返回evm2的memory。
- 1)用例1:返回0x33 * 2:
./test.sh 60336002025952
"00..0066"
- 2)用例2:返回[0x00, 0x20, 0x40]:
./test.sh 595952595952595952
"..00..20..40"
- 3)用例3:mstore8 & mstore:
./test_huff.sh 6040595360205952
"40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020"
- 4)用例4:emit LOG0(abi.encode(uint256(-1), uint256(0))):【查看日志需运行
evm --debug
】
# classic evm:
evm --debug --json --code 600019595260406000a0 run
# and for evm2:
evm --debug --json --code `huffc evm.huff --bin-runtime` --input 600019595260406000a0 run
#### LOGS ####
LOG0: 0000000000000000000000007265636569766572 bn=0 txi=0
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
参考资料
[1] twitter evm-squared