以太坊字节码的高级分析的框架。 Ethir构建了以太坊字节码的完整而声音的CFG,并生成了程序的基于规则的表示(RBR)。这种高级表示可以应用现有的高级分析来推断EVM代码的属性。
下载包含固体编译器的静态可执行文件的文件夹源。
将其添加到路径中并测试安装它。
sudo cp source/solc* /usr/bin/
sudo chmod 755 /usr/bin/solc*
solc --version
solcv5 --version
solcv6 --version
如果您想安装最新版本:
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
文件夹源中提供了静态可执行文件。
将OT添加到路径上,并测试是否已安装。
sudo cp source/evm* /usr/bin/
sudo chmod 755 /usr/bin/evm*
evm --version
如果您想安装最新版本:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
下载源代码文件夹。
解压缩文件夹并安装。
unzip z3-z3-4.5.0.zip
cd z3-z3-4.5.0
python scripts/mk_make.py --python
cd build
make
sudo make install
使用pip install命令安装六个,请求Python库。
pip install six
pip install requests
以上命令可能会根据PIP版本失败。如果是这种情况,请运行以下命令而不是先前的命令。
python -m pip install six
python -m pip install requests
检查版本运行命令pip -V 。
要执行Ethir,请在文件夹Ethir中运行以下命令之一:
./oyente-ethir -s file_name.sol
./oyente-ethir -s file_name.evm -b
./oyente-ethir -s file_name.disasm -disasm
命令./oyente-ethir -h显示一个列表,其中包含Ethir的所有可用选项。一些最相关的是:
./oyente-ethir -s filename -cfg
./oyente-ethir -s filename -saco
./oyente-ethir -s filename -d
Ethir在执行过程中生成的所有文件都存储在DiRecrtory/TMP/Costabs/中。
安装Ethir后,假设我们要生成文件夹示例中可用的拆卸文件blockking.evm.disasm的RBR。首先,我们必须去Ethir目录并执行命令./oyente-ethir -s ../examples/blockking.evm.disasm -disasm 。
在执行过程中,Ethir创建了目录/TMP/Costabs/它存储与Blockking.evm.disasm文件相关的RBR的位置。如果检查此目录,我们会找到一个名为rbr.rbr的文件,其中包含RBR。如果我们使用任何通用编辑器(GEDIT,EMAC)打开文件,我们可以看到生成的RBR。以下是用于blockking.evm.disasm文件的RBR的滑冰。
block0(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(8), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), calldatasize, calldataload, gas, caller, callvalue, number, gasprice, balance)=>
s(0) = 96
s(1) = 64
l(0) = s(0)
s(0) = calldatasize
call(jump0(s(0),g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(8), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), calldatasize, calldataload, gas, caller, callvalue, number, gasprice, balance))
jump0(s(0), g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, calldatasize, caller, callvalue, gas, gasprice, number)=>
eq(s(0), 0)
call(block174(g(11), g(8), g(4), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), caller, callvalue, gas, gasprice, number))
jump0(s(0), g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, calldatasize, caller, callvalue, gas, gasprice, number)=>
neq(s(0), 0)
call(block11(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number))
block11(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number)=>
s(0) = 224
s(1) = 2
s(0) = s(1)^s(0)
s(1) = 0
s(1) = calldataload
s(0) = s(1)/s(0)
s(1) = 607252836
s(2) = s(0)
call(jump11(s(2),s(1),s(0),g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number))
如果我们执行命令./oyente-ethir -s ../examples/blockking.evm.disasm -disasm -eop而不是上述命令,则Ethir产生的RBR具有NOPS注释,EVM Bytecode在文本中交织在一起。以下是RBR的草图,该rbr具有用于blockking.evm.disasm的NOPS注释:
block0(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(8), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), calldatasize, calldataload, gas, caller, callvalue, number, gasprice, balance)=>
s(0) = 96
nop(PUSH1)
s(1) = 64
nop(PUSH1)
l(0) = s(0)
nop(MSTORE)
s(0) = calldatasize
nop(CALLDATASIZE)
call(jump0(s(0),g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(8), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), calldatasize, calldataload, gas, caller, callvalue, number, gasprice, balance))
nop(ISZERO)
nop(PUSH2)
nop(JUMPI)
jump0(s(0), g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, calldatasize, caller, callvalue, gas, gasprice, number)=>
eq(s(0), 0)
call(block174(g(11), g(8), g(4), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), caller, callvalue, gas, gasprice, number))
jump0(s(0), g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, calldatasize, caller, callvalue, gas, gasprice, number)=>
neq(s(0), 0)
call(block11(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number))
block11(g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number)=>
s(0) = 224
nop(PUSH1)
s(1) = 2
nop(PUSH1)
s(0) = s(1)^s(0)
nop(EXP)
s(1) = 0
nop(PUSH1)
s(1) = calldataload
nop(CALLDATALOAD)
s(0) = s(1)/s(0)
nop(DIV)
s(1) = 607252836
nop(PUSH4)
s(2) = s(0)
nop(DUP2)
call(jump11(s(2),s(1),s(0),g(11), g(10), g(9), g(8), g(7), g(6), g(5), g(4), g(3), g(2), g(1), g(0), l(7), l(6), l(5), l(4), l(3), l(2), l(1), l(0), balance, calldataload, caller, callvalue, gas, gasprice, number))
nop(EQ)
nop(PUSH2)
nop(JUMPI)
Ethir还允许我们存储所分析的文件的CFG。在这种情况下,我们必须执行命令./oyente-ethir -s ../examples/blockking.evm.disasm -disasm -cfg 。 Ethir将CFG存储在文件/tmp/costabs/Costabs/Costabs中的文件中。
请注意,文件可能包含多个智能合约。在这种情况下,Ethir每个合同RBR0.RBR,rbr1.rbr,... rbrn.rbr产生一个文件。
文件夹示例包含运行示例来测试该工具。既有固体,EVM和拆卸文件。
大多数示例,例如bloccking.evm.disasm,advertisement.sol,valialToken.sol或cryptophoenix.sol.sol是从区块链中获得的真实合同,而其他诸如loop1.sol和sum.sol等其他合同则是更容易理解分解过程的杂物示例。
SACO是并发对象的静态分析仪,可以推断出循环迭代次数的其他属性。请注意,这是推断智能合约的气体消耗的第一步。
SACO的内部表示与小句法翻译后Ethir产生的RBR的语法相匹配。因此,它可以证明某些示例包含的循环的终止,并为这些循环产生线性结合。以下是Saco推断出的一些循环范围,用于文件夹示例中包含的一些智能合约:
| 智能合约 | 边界 | 智能合约 | 边界 |
|---|---|---|---|
| 盖帽 | NAT(G8/10)*36+8934493 | 隐态 | NAT(G3)*228409344+4113285485 |
| loop1 | NAT(A)*25+234 | Eligma | NAT(_NUMBEROFRETURNS)*2628+134 |
| 彩票 | 159 | Blocksquareseriea | 286 |
| 飞地 | 268 | auctusether | 264 |
| 广告 | inf | 有效的语 | inf |
Saco侵入上表中显示的前四个智能合约的线性绑定。智能合约的界限阻碍和隐脚质取决于其一个字段的价值(分别为第八和第三个领域)。对于Smart Contracts Loop1和Eligma,获得的界限取决于其某些功能的参数(a和_numberofturns)。如果智能合约不包含任何循环,例如彩票,块秒,飞地或送礼,萨科会延伸一个恒定的结合。
请注意,由于SACO的精确限制(它没有比特操作和功能SHA3的模型),分析仪忘记了位变量的信息。由于这一因素,Saco无法推断出某些智能合约(例如有效的或广告)并返回INF的某些智能合约。
在整数过渡系统或Horn条款(例如,Aprove,T2,非常Max,Cofloco)等中间形式上工作的其他高级分析仪也可以很容易地适应Ethir生产的RBR翻译程序。
如果您在与SACO联合使用Ethir通过拉装或新问题联合使用Ethir。
您可以在此处尝试第一个原型。 Gastap注入每次交易中涉及的气体的上限。