码迷,mamicode.com
首页 > 其他好文 > 详细

EO bugs

时间:2019-03-27 12:45:24      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:fun   class   alter   add   nbsp   not   事件   ==   val   

定价两次-同一事件在确认前再次发生

pragma solidity ^0.4.18;

contract TransactionOrdering {
    uint256 price;
    address owner;
    
    event Purchase(address _buyer, uint256 _price);
    event PriceChange(address _owner, uint256 _price);
    
    modifier ownerOnly() {
        require(msg.sender == owner);
        _;
    }

    function TransactionOrdering() {
        // constructor
        owner = msg.sender;
        price = 100;
    }

    function buy() returns (uint256) {
        Purchase(msg.sender, price);
        return price;
    }

    function setPrice(uint256 _price) ownerOnly() {
        price = _price;
        PriceChange(owner, price);
    }
}

改价失败-同一事件再次发生前就完成了流程

contract IOU{ 
	// Approves the transfer of tokens 
	function approve(address _spender, uint256 _val) { 
		allowed[msg.sender][_spender] = _val; 
		return true; 
	} 
// Transfers tokens 
	function transferFrom(address _from, address _to, uint256 _val) { 
		require(
			allowed[_from][msg.sender] >= _val
			&& balances[_from] >= _val 
			&& _val > 0); 
		balances[_from] -= _val;
		balances[_to] += _val; 
		allowed [_from][msg.sender] -= _val;
		return true; 
	} 
}  

多人支付,总量不足-异步调用的问题,没能区别总成交量=目前已经完成的成交量+已经允许,但还没有callback的成交量,忽视了后面这一部分(Improper Check on Ether)

contract Casino{
    function bet() payable {
        // make sure we can pay out the player 
        if (address(this).balance < msg.value * 100 ) throw; 
            bytes32 oid = oraclize_query(...); // random 
            bets[oid] = msg.value; 
            players[oid] = msg.sender; 
    } 
    function __callback(bytes32 myid, string result) 
        onlyOraclize onlyIfNotProcessed(myid) { 
        if (parseInt(result) % 200 == 42)
            players[myid].send( bets[myid] * 100 ); 
    } 
} 

没有在异步调用时区别身份-异步调用的返回可能是打乱顺序的

contract CasinoAltered{
    function bet() payable {
        // make sure we can pay out the player 
        if (address(this).balance < msg.value * 100 ) throw; 
            bytes32 oid = oraclize_query(...); // random 
            bets[oid] = msg.value; 
            players[oid] = msg.sender; 
    } 
    function __callback(bytes32 myid, string result) 
        onlyOraclize onlyIfNotProcessed(myid) { 
        if (parseInt(result) % 200 == 42)
            players[myid].send( bets[bets.size() -1] * 100 ); 
    } 
} 

 

EO bugs

标签:fun   class   alter   add   nbsp   not   事件   ==   val   

原文地址:https://www.cnblogs.com/xuesu/p/10606546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!