EO bugs

Posted xuesu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EO bugs相关的知识,希望对你有一定的参考价值。

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

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的主要内容,如果未能解决你的问题,请参考以下文章

记录一些遇见的bug——调用增加方法报错line 1:43 no viable alternative at input ‘<EOF>‘ line 1:43 mismatched input ‘<EO

记录一些遇见的bug——调用增加方法报错line 1:43 no viable alternative at input ‘<EOF>‘ line 1:43 mismatched input ‘<EO

vscode代码片段建议bug

PHP 精度计算引发的灾难性Bug

小程序连续点击bug解决

oracle in 改为exists形式