-
-
[原创]合约安全分析识别ICO骗局
-
发表于: 2019-4-22 10:24 20630
-
ICO是一种依赖于区块链技术的新型融资方式,具有很多传统融资所不具备的优点,成功的ICO项目往往会给投资者带来高收益。但是,其中也不乏一些打着ICO的名义来诈骗的项目,这些项目会让投资者血本无归。本文从智能合约分析的角度来区别哪些项目是相对靠谱的,哪些项目是有较大安全风险的。
ICO是一种以初始产生数字加密货币作为投资回报的一种筹措资金的方式,类似于IPO(Initial Public Offering),IPO是通过一个可信的第三方(证券交易所)作为中介来筹措资金,ICO就是通过区块链技术作为可信担保来筹措资金。ICO具有降低融资门槛,流动性强,可全球性融资等优势。他可以让项目在最开始的阶段就直接面对投资者,若项目就有吸引力,那么可快速吸引全球投资者投资,免去了IPO种种繁琐手续和资质审核。
Ethereum(以太坊):ICO时募集3万余个比特币曾创下纪录。将智能合约理念推进到极致的区块链项目,让全世界重新认识区块链公有链的项目。
TheDAO:通过智能合约众筹了1.5亿美元的以太币,但由于合约中存在重入漏洞导致筹集的以太币被黑客窃取
我们在审计以太坊智能合约时,发现有有些合约是具有ICO功能的。合约创建者编写合约接收投资者投资的以太币,然后返回给投资者一些自己发行的代币。当众筹成功后,合约创建者提取筹到的以太币作为项目的资金。若项目成功,投资者获得项目方的高额回馈。比如,Ethereum 众筹项目,当时众筹时eth作价2-3元转给投资者,若投资者一直持有eth,现在已经涨到1000多块。
但是有好多众筹项目并没有成功,此时投资者手中的代币就一文不值了,投资就打了水漂;甚至有些众筹本身就是个骗局,项目方筹得款项后,就提现跑路了。关于ICO的详解参考下面的链接:https://www.zhihu.com/question/60363636
本文我们从智能合约角度来分析众筹合约的安全性,在我们看来,某些众筹合约在合约代码实现上就像极了一个骗局,根本不值得投资。
我们先看一下,以太坊官方推荐的一个众筹合约的合约代码,链接如下:
https://www.ethereum.org/crowdsale
合约主要代码如下:
constructor(
address ifSuccessfulSendTo,
uint fundingGoalInEthers,
uint durationInMinutes,
uint etherCostOfEachToken,
address addressOfTokenUsedAsReward
) public {
beneficiary = ifSuccessfulSendTo;
fundingGoal = fundingGoalInEthers * 1 ether;
deadline = now + durationInMinutes * 1 minutes;
price = etherCostOfEachToken * 1 ether;
tokenReward = token(addressOfTokenUsedAsReward);
}
上面的构造函数显示了众筹合约的几个关键属性,beneficiary是众筹时项目方收取eth的地址,fundingGoal是所要众筹的eth的数量,deadline是众筹的截止日期,price是eth和众筹代币的价值关系,tokenReward是项目方的代币地址。
function () payable external {
require(!crowdsaleClosed);
uint amount = msg.value;
balanceOf[msg.sender] += amount;
amountRaised += amount;
tokenReward.transfer(msg.sender, amount / price);
emit FundTransfer(msg.sender, amount, true);
}
modifier afterDeadline() { if (now >= deadline) _; }
/**
* Check if goal was reached
*
* Checks if the goal or time limit has been reached and ends the campaign
*/
function checkGoalReached() public afterDeadline {
if (amountRaised >= fundingGoal){
fundingGoalReached = true;
emit GoalReached(beneficiary, amountRaised);
}
crowdsaleClosed = true;
}
/**
* Withdraw the funds
*
* Checks to see if goal or time limit has been reached, and if so, and the funding goal was reached,
* sends the entire amount to the beneficiary. If goal was not reached, each contributor can withdraw
* the amount they contributed.
*/
function safeWithdrawal() public afterDeadline {
if (!fundingGoalReached) {
uint amount = balanceOf[msg.sender];
balanceOf[msg.sender] = 0;
if (amount > 0) {
if (msg.sender.send(amount)) {
emit FundTransfer(msg.sender, amount, false);
} else {
balanceOf[msg.sender] = amount;
}
}
}
if (fundingGoalReached && beneficiary == msg.sender) {
if (msg.sender.send(amountRaised)) {
emit FundTransfer(beneficiary, amountRaised, false);
} else {
//If we fail to send the funds to beneficiary, unlock funders balance
fundingGoalReached = false;
}
}
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课