想了很多 却不知从何说起,最后想想只有四个字,膜拜大佬。
一、前言叙述
最近,我通过一些相关文章的阅读发现了几个有趣的DAPP。而深入研究后我准备将分析过程记录下来,并分享给读者。本文包括一则蜜罐DAPP,该合约为一则答题类游戏,然而深入分析后发现,这款游戏不仅仅只简单的问答接口,然而对于了解以太坊的人是一个陷阱。所以我对其进行了复现、分析操作,并记录下来引以为戒。
二、合约分析与测试
1 蜜罐合约漏洞
我们首先根据代码来对合约进行分析。
//Question and answer honeypot.
pragma solidity ^0.4.20;
contract QUESTION
{
function Play(string _response)
external
payable
{
require(msg.sender == tx.origin);
if(responseHash == keccak256(_response) && msg.value>1 ether)
{
msg.sender.transfer(this.balance);
}
}
string public question;
address questionSender;
bytes32 responseHash;
function StartGame(string _question,string _response)
public
payable
{
if(responseHash==0x0)
{
responseHash = keccak256(_response);
question = _question;
questionSender = msg.sender;
}
}
function StopGame()
public
payable
{
require(msg.sender==questionSender);
msg.sender.transfer(this.balance);
}
function NewQuestion(string _question, bytes32 _responseHash)
public
payable
{
require(msg.sender==questionSender);
question = _question;
responseHash = _responseHash;
点击收藏 | 1
关注 | 3