网络安全创业公司Comae Technologies开发了首个以太坊反编译器。该工具名为Porosity,能够把智能合约恢复为源代码,帮助开发人员更容易地识别智能合约中的漏洞,增强其安全性。并且,Porosity正在与摩根大通的Quorum区块链整合,将发挥更大的作用。
以太坊虚拟机(EVM)现在似乎拥有了其第一个把智能合约恢复为源代码的反编译器。
网络安全创业公司Comae Technologies的创始人于7月27日在拉斯维加斯的DefCon黑客大会上宣布,开源的EVM反编译器的目标是更容易地识别以太坊智能合约中的漏洞。
一连串的以太坊被黑事件证明了编写安全智能合约的代码是很困难的,名为Porosity的反编译器承诺可以使开发人员将难以理解的EVM字节码恢复到原始状态。
Porosity开发者兼Comae创始人Matt Suiche告诉CoinDesk:
“我编写反编译器要解决的初始问题是使人们能够拥有实际的源代码,而无需通过逆向工程访问它们。”
Comae还在27日宣布,Porosity已经与摩根大通为企业级解决方案创建的开源Quorum区块链整合,现在已经出现在该银行的Github页面上。
摩根大通的一些工程师也帮助测试了Porosity与Quorum的整合,它们预计将被打包在一起,以帮助运行实时的智能合约安全检查。该组合会创造性地直接与以太坊的Geth相结合。私有网络的安全性和修补流程将与正式治理模型相结合。
摩根大通的区块链领导Amber Baldet向CoinDesk阐述了她所理解的该技术的意义:
“Porosity是第一个通过以太坊虚拟机字节码生成可读的Solidity智能合约的反编译器。”
需要逆向工程师
虽然Suiche表示他在区块链领域还是新手,但这位将自己之前的创业公司卖给VMware的连续企业家在开发反编译器上却胸有成竹。
Suiche作为一名逆向工程师,熟悉如何从产品着手并将其最基本的部分剥离出来。
所以在二月份,当他开始深入研究智能合约时,他几乎是在研究中偶然地开发出了反编译器。
在Porosity被推出的这个月内,为CoinDash、Parity和Veritaseum撰写的以太坊智能合约全部被黑,Suiche认为自己所从事的逆向工程师这一职位的需求将增加。
他说:“以太坊的安全社区会不断壮大,我们将会看到越来越多的逆向工程师。”
反编译业务
实际上,推动反编译器使用的商业动机还有很多,不仅仅是确保资金安全。
按照客户软件供应商兼网络安全咨询公司ITBS LLC首席执行官Alex Rass的说法,由于智能合约实施之后其脆弱性时常暴露出来,EVM反编译器可以让投资者放心。
据Rass说,反编译器在大多数“主要”编程语言中是常见的,其部分原因在于它们有助于确保投资者的投资转化成了产品。
Rass说:
“有了反编译器,人们就可以生成合同的二进制代码,并向投资者提供他们购买的产品。”
EVM反编译软件Porosity的使用-mac
首先给出 porosity 的 GitHub 地址: here
本文也是根据这个网址进行学习。
1. 创建和约
可以使用自己写的合约,也可以在etherscan 上面找一些合约, 给出例子如下:
//vulnerable.sol
pragma solidity ^0.4.4;
contract SendBalance {
mapping ( address => uint ) userBalances;
function SendBalance(){
}
function getBalance (address u) constant returns ( uint ){
return userBalances [u];
}
function addToBalance () payable{
userBalances[msg.sender] += msg.value ;
}
function withdrawBalance (){
if (!(msg.sender.call.gas(0x1111).value (
userBalances [msg . sender])())) { throw ; }
userBalances [msg.sender ] = 0;
}
}
2. 下载porosity 并编译
下载之后,在终端进入porosity/porosity/porosity目录
然后输入:make //编译
你会看到生成了porosity(exec)
3. 使用porosity
a. 在porosity下创建文件夹 solidity-example (自己取得名字随意创),并将合约放在该目录下面。
b. 创建decompile.sh
#!/bin/bash
solc --abi -o output vulnerable.sol
solc --bin -o output vulnerable.sol
solc --bin-runtime -o output vulnerable.sol
abi=$(< output/SendBalance.abi)
echo "This is abi variable: "
echo $abi
bin=$(< output/SendBalance.bin)
echo ""
echo "This is bin variable: "
echo $bin
binRuntime=$(< output/SendBalance.bin-runtime)
echo ""
echo "This is binruntime variable: "
echo $binRuntime
echo ""
echo "Firstly listing functions: "
#注意路径,指向的是前面编译之后生成的porosity文件
../porosity/porosity/porosity --code $bin --abi $abi --list --verbose 0
echo "Now performing decompilation: "
../porosity/porosity/porosity --code $bin --abi $abi --decompile --verbose 0
c. 授权decompile.sh (只有第一次需要)
输入:chmod 777 decompile.sh
d.运行decompile.sh
输入:./decompile.sh
e. 结果,类似于
Porosity v0.1 (https://www.comae.io)
Matt Suiche, Comae Technologies <support@comae.io>
The Ethereum bytecode commandline decompiler.
Decompiles the given Ethereum input bytecode and outputs the Solidity code.
Attempting to parse ABI definition...
Success.
[+] Hash: 0x0A19B14A (trade) (1 references)
[+] Hash: 0x0B927666 (order) (1 references)
[+] Hash: 0x19774D43 (orderFills) (1 references)
[+] Hash: 0x278B8C0E (cancelOrder) (1 references)
[+] Hash: 0x2E1A7D4D (withdraw) (1 references)
[+] Hash: 0x338B5DEA (depositToken) (1 references)
[+] Hash: 0x46BE96C3 (amountFilled) (1 references)
[+] Hash: 0x508493BC (tokens) (1 references)
[+] Hash: 0x54D03B5C (changeFeeMake) (1 references)
[+] Hash: 0x57786394 (feeMake) (1 references)
[+] Hash: 0x5E1D7AE4 (changeFeeRebate) (1 references)
[+] Hash: 0x65E17C9D (feeAccount) (1 references)
[+] Hash: 0x6C86888B (testTrade) (1 references)
[+] Hash: 0x71FFCB16 (changeFeeAccount) (1 references)
[+] Hash: 0x731C2F81 (feeRebate) (1 references)
[+] Hash: 0x8823A9C0 (changeFeeTake) (1 references)
[+] Hash: 0x8F283970 (changeAdmin) (1 references)
[+] Hash: 0x9E281A98 (withdrawToken) (1 references)
[+] Hash: 0xBB5F4629 (orders) (1 references)
[+] Hash: 0xC281309E (feeTake) (1 references)
[+] Hash: 0xD0E30DB0 (deposit) (1 references)
[+] Hash: 0xE8F6BC2E (changeAccountLevelsAddr) (1 references)
[+] Hash: 0xF3412942 (accountLevelsAddr) (1 references)
[+] Hash: 0xF7888AEC (balanceOf) (1 references)
[+] Hash: 0xF851A440 (admin) (1 references)
[+] Hash: 0xFB6E155F (availableVolume) (1 references)
网友评论