diff --git a/benchmark2/integer overflow/21.sol b/benchmark2/integer overflow/21.sol new file mode 100644 index 0000000000000000000000000000000000000000..69e54c7b6aace9722ae65e4f93b8675d4174ad79 --- /dev/null +++ b/benchmark2/integer overflow/21.sol @@ -0,0 +1,137 @@ +pragma solidity ^0.4.24; + + +library SafeMath { + function mul(uint256 a, uint256 b) pure internal returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) pure internal returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) pure internal returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) pure internal returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + + function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract WPAYCoin is StandardToken { + + string public constant name = "WPAYCoin"; + string public constant symbol = "WPY"; + uint8 public constant decimals = 6; + + uint256 public constant INITIAL_SUPPLY = 600000000 * (10 ** uint256(decimals)); + + + function WPAYCoin() public { + totalSupply = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/22.sol b/benchmark2/integer overflow/22.sol new file mode 100644 index 0000000000000000000000000000000000000000..f06909502b508e861490d92427c34dd34a8f4da2 --- /dev/null +++ b/benchmark2/integer overflow/22.sol @@ -0,0 +1,418 @@ +pragma solidity ^0.4.24; + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address _who) public view returns (uint256); + function transfer(address _to, uint256 _value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + + + + if (_a == 0) { + return 0; + } + + c = _a * _b; + assert(c / _a == _b); + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + return _a / _b; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_b <= _a); + return _a - _b; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + c = _a + _b; + assert(c >= _a); + return c; + } +} + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) internal balances; + + uint256 internal totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + +contract ERC20 is ERC20Basic { + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + function approve(address _spender, uint256 _value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract XinCoin is StandardToken { + address public admin; + string public name = "XinCoin"; + string public symbol = "XC"; + uint8 public decimals = 8; + uint256 public INITIAL_SUPPLY = 100000000000000000; + + mapping (address => bool) public frozenAccount; + mapping (address => uint256) public frozenTimestamp; + + event Approval(address indexed owner, address indexed spender, uint256 value); + event Transfer(address indexed from, address indexed to, uint256 value); + event Burn(address indexed from, uint256 value); + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + admin = msg.sender; + balances[msg.sender] = INITIAL_SUPPLY; + } + + function() public payable { + require(msg.value > 0); + } + + function changeAdmin( + address _newAdmin + ) + public returns (bool) { + require(msg.sender == admin); + require(_newAdmin != address(0)); + balances[_newAdmin] = balances[_newAdmin].add(balances[admin]); + balances[admin] = 0; + admin = _newAdmin; + return true; + } + + function generateToken( + address _target, + uint256 _amount + ) + public returns (bool) { + require(msg.sender == admin); + require(_target != address(0)); + balances[_target] = balances[_target].add(_amount); + totalSupply_ = totalSupply_.add(_amount); + INITIAL_SUPPLY = totalSupply_; + return true; + } + + function withdraw ( + uint256 _amount + ) + public returns (bool) { + require(msg.sender == admin); + msg.sender.transfer(_amount); + return true; + } + + function freeze( + address _target, + bool _freeze + ) + public returns (bool) { + require(msg.sender == admin); + require(_target != address(0)); + frozenAccount[_target] = _freeze; + return true; + } + + function freezeWithTimestamp( + address _target, + uint256 _timestamp + ) + public returns (bool) { + require(msg.sender == admin); + require(_target != address(0)); + frozenTimestamp[_target] = _timestamp; + return true; + } + + function multiFreeze( + address[] _targets, + bool[] _freezes + ) + public returns (bool) { + require(msg.sender == admin); + require(_targets.length == _freezes.length); + uint256 len = _targets.length; + require(len > 0); + for (uint256 i = 0; i < len; i = i.add(1)) { + address _target = _targets[i]; + require(_target != address(0)); + bool _freeze = _freezes[i]; + frozenAccount[_target] = _freeze; + } + return true; + } + + function multiFreezeWithTimestamp( + address[] _targets, + uint256[] _timestamps + ) + public returns (bool) { + require(msg.sender == admin); + require(_targets.length == _timestamps.length); + uint256 len = _targets.length; + require(len > 0); + for (uint256 i = 0; i < len; i = i.add(1)) { + address _target = _targets[i]; + require(_target != address(0)); + uint256 _timestamp = _timestamps[i]; + frozenTimestamp[_target] = _timestamp; + } + return true; + } + + function multiTransfer( + address[] _tos, + uint256[] _values + ) + public returns (bool) { + require(!frozenAccount[msg.sender]); + require(now > frozenTimestamp[msg.sender]); + require(_tos.length == _values.length); + uint256 len = _tos.length; + require(len > 0); + uint256 amount = 0; + for (uint256 i = 0; i < len; i = i.add(1)) { + amount = amount.add(_values[i]); + } + require(amount <= balances[msg.sender]); + for (uint256 j = 0; j < len; j = j.add(1)) { + address _to = _tos[j]; + require(_to != address(0)); + balances[_to] = balances[_to].add(_values[j]); + balances[msg.sender] = balances[msg.sender].sub(_values[j]); + emit Transfer(msg.sender, _to, _values[j]); + } + return true; + } + + function transfer( + address _to, + uint256 _value + ) + public returns (bool) { + require(!frozenAccount[msg.sender]); + require(now > frozenTimestamp[msg.sender]); + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + + emit Transfer(msg.sender, _to, _value); + return true; + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public returns (bool) + { + require(!frozenAccount[_from]); + require(now > frozenTimestamp[msg.sender]); + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + + emit Transfer(_from, _to, _value); + return true; + } + + function approve( + address _spender, + uint256 _value + ) + public returns (bool) { + require(_value <= balances[_spender]); + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function burn(uint256 _value) + public returns (bool) { + require(_value <= balances[msg.sender]); + balances[msg.sender] = balances[msg.sender].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + INITIAL_SUPPLY = totalSupply_; + emit Burn(msg.sender, _value); + return true; + } + + function getFrozenTimestamp( + address _target + ) + public view returns (uint256) { + require(_target != address(0)); + return frozenTimestamp[_target]; + } + + function getFrozenAccount( + address _target + ) + public view returns (bool) { + require(_target != address(0)); + return frozenAccount[_target]; + } + + function getBalance(address _owner) + public view returns (uint256) { + return balances[_owner]; + } + + function setName ( + string _value + ) + public returns (bool) { + require(msg.sender == admin); + name = _value; + return true; + } + + function setSymbol ( + string _value + ) + public returns (bool) { + require(msg.sender == admin); + symbol = _value; + return true; + } + + function kill() + public { + require(msg.sender == admin); + selfdestruct(admin); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/225.sol b/benchmark2/integer overflow/225.sol new file mode 100644 index 0000000000000000000000000000000000000000..12a0caebeba058026777f1d992e6199072c4d8c8 --- /dev/null +++ b/benchmark2/integer overflow/225.sol @@ -0,0 +1,183 @@ +pragma solidity ^0.4.24; + +library SafeMath { + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + if (_a == 0) { + return 0; + } + + uint256 c = _a * _b; + require(c / _a == _b); + + return c; + } + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b > 0); + uint256 c = _a / _b; + + + return c; + } + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b <= _a); + uint256 c = _a - _b; + + return c; + } + + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + require(c >= _a); + + return c; + } + + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} + +contract ERC20 { + function totalSupply() public view returns (uint256); + function balanceOf(address _who) public view returns (uint256); + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transfer(address _to, uint256 _value) public returns (bool); + function approve(address _spender, uint256 _value) + public returns (bool); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); + + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +contract StandardToken is ERC20 { + using SafeMath for uint256; + + mapping (address => uint256) private balances; + + mapping (address => mapping (address => uint256)) private allowed; + + uint256 private totalSupply_; + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function _mint(address _account, uint256 _amount) internal { + require(_account != 0); + totalSupply_ = totalSupply_.add(_amount); + balances[_account] = balances[_account].add(_amount); + emit Transfer(address(0), _account, _amount); + } + + function _burn(address _account, uint256 _amount) internal { + require(_account != 0); + require(_amount <= balances[_account]); + + totalSupply_ = totalSupply_.sub(_amount); + balances[_account] = balances[_account].sub(_amount); + emit Transfer(_account, address(0), _amount); + } + + function _burnFrom(address _account, uint256 _amount) internal { + require(_amount <= allowed[_account][msg.sender]); + allowed[_account][msg.sender] = allowed[_account][msg.sender].sub(_amount); + _burn(_account, _amount); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/241.sol b/benchmark2/integer overflow/241.sol new file mode 100644 index 0000000000000000000000000000000000000000..7de6bf2cac5e33e1356f8c7782d67c0f4f95105c --- /dev/null +++ b/benchmark2/integer overflow/241.sol @@ -0,0 +1,287 @@ +pragma solidity ^0.4.19; + +library SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a / b; + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + +contract ForeignToken { + function balanceOf(address _owner) constant public returns (uint256); + function transfer(address _to, uint256 _value) public returns (bool); +} + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +interface Token { + function distr(address _to, uint256 _value) public returns (bool); + function totalSupply() constant public returns (uint256 supply); + function balanceOf(address _owner) constant public returns (uint256 balance); +} + +contract BEN is ERC20 { + + using SafeMath for uint256; + address owner = msg.sender; + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; + mapping (address => bool) public blacklist; + + string public constant name = "BENetwork"; + string public constant symbol = "BEN"; + uint public constant decimals = 8; + + uint256 public totalSupply = 100000000e8; + uint256 public totalDistributed = 10000000e8; + uint256 public totalRemaining = totalSupply.sub(totalDistributed); + uint256 public value; + + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + event Distr(address indexed to, uint256 amount); + event DistrFinished(); + + event Burn(address indexed burner, uint256 value); + + bool public distributionFinished = false; + + modifier canDistr() { + require(!distributionFinished); + _; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + modifier onlyWhitelist() { + require(blacklist[msg.sender] == false); + _; + } + + function BEN () public { + owner = msg.sender; + value = 400e8; + distr(owner, totalDistributed); + } + + function transferOwnership(address newOwner) onlyOwner public { + if (newOwner != address(0)) { + owner = newOwner; + } + } + + function enableWhitelist(address[] addresses) onlyOwner public { + for (uint i = 0; i < addresses.length; i++) { + blacklist[addresses[i]] = false; + } + } + + function disableWhitelist(address[] addresses) onlyOwner public { + for (uint i = 0; i < addresses.length; i++) { + blacklist[addresses[i]] = true; + } + } + + function finishDistribution() onlyOwner canDistr public returns (bool) { + distributionFinished = true; + DistrFinished(); + return true; + } + + function distr(address _to, uint256 _amount) canDistr private returns (bool) { + totalDistributed = totalDistributed.add(_amount); + totalRemaining = totalRemaining.sub(_amount); + balances[_to] = balances[_to].add(_amount); + Distr(_to, _amount); + Transfer(address(0), _to, _amount); + return true; + + if (totalDistributed >= totalSupply) { + distributionFinished = true; + } + } + + function airdrop(address[] addresses) onlyOwner canDistr public { + + require(addresses.length <= 255); + require(value <= totalRemaining); + + for (uint i = 0; i < addresses.length; i++) { + require(value <= totalRemaining); + distr(addresses[i], value); + } + + if (totalDistributed >= totalSupply) { + distributionFinished = true; + } + } + + function distribution(address[] addresses, uint256 amount) onlyOwner canDistr public { + + require(addresses.length <= 255); + require(amount <= totalRemaining); + + for (uint i = 0; i < addresses.length; i++) { + require(amount <= totalRemaining); + distr(addresses[i], amount); + } + + if (totalDistributed >= totalSupply) { + distributionFinished = true; + } + } + + function distributeAmounts(address[] addresses, uint256[] amounts) onlyOwner canDistr public { + + require(addresses.length <= 255); + require(addresses.length == amounts.length); + + for (uint8 i = 0; i < addresses.length; i++) { + require(amounts[i] <= totalRemaining); + distr(addresses[i], amounts[i]); + + if (totalDistributed >= totalSupply) { + distributionFinished = true; + } + } + } + + function () external payable { + getTokens(); + } + + function getTokens() payable canDistr onlyWhitelist public { + + if (value > totalRemaining) { + value = totalRemaining; + } + + require(value <= totalRemaining); + + address investor = msg.sender; + uint256 toGive = value; + + distr(investor, toGive); + + if (toGive > 0) { + blacklist[investor] = true; + } + + if (totalDistributed >= totalSupply) { + distributionFinished = true; + } + + value = value.div(100000).mul(99999); + } + + function balanceOf(address _owner) constant public returns (uint256) { + return balances[_owner]; + } + + // mitigates the ERC20 short address attack + modifier onlyPayloadSize(uint size) { + assert(msg.data.length >= size + 4); + _; + } + + function transfer(address _to, uint256 _amount) onlyPayloadSize(2 * 32) public returns (bool success) { + + require(_to != address(0)); + require(_amount <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_amount); + balances[_to] = balances[_to].add(_amount); + Transfer(msg.sender, _to, _amount); + return true; + } + + function transferFrom(address _from, address _to, uint256 _amount) onlyPayloadSize(3 * 32) public returns (bool success) { + + require(_to != address(0)); + require(_amount <= balances[_from]); + require(_amount <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_amount); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount); + balances[_to] = balances[_to].add(_amount); + Transfer(_from, _to, _amount); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool success) { + // mitigates the ERC20 spend/approval race condition + if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; } + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) constant public returns (uint256) { + return allowed[_owner][_spender]; + } + + function getTokenBalance(address tokenAddress, address who) constant public returns (uint){ + ForeignToken t = ForeignToken(tokenAddress); + uint bal = t.balanceOf(who); + return bal; + } + + function withdraw() onlyOwner public { + uint256 etherBalance = this.balance; + owner.transfer(etherBalance); + } + + function burn(uint256 _value) onlyOwner public { + require(_value <= balances[msg.sender]); + // no need to require value <= totalSupply, since that would imply the + // sender's balance is greater than the totalSupply, which *should* be an assertion failure + + address burner = msg.sender; + balances[burner] = balances[burner].sub(_value); + totalSupply = totalSupply.sub(_value); + totalDistributed = totalDistributed.sub(_value); + Burn(burner, _value); + } + + function withdrawForeignTokens(address _tokenContract) onlyOwner public returns (bool) { + ForeignToken token = ForeignToken(_tokenContract); + uint256 amount = token.balanceOf(address(this)); + return token.transfer(owner, amount); + } + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/253.sol b/benchmark2/integer overflow/253.sol new file mode 100644 index 0000000000000000000000000000000000000000..56f263351fee540d73ced4ea27be269764dc1ec7 --- /dev/null +++ b/benchmark2/integer overflow/253.sol @@ -0,0 +1,317 @@ +pragma solidity ^0.4.24; + +contract SafeMath { + function safeMul(uint a, uint b) internal returns (uint) { + uint c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeSub(uint a, uint b) internal returns (uint) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint a, uint b) internal returns (uint) { + uint c = a + b; + assert(c>=a && c>=b); + return c; + } + + function assert(bool assertion) internal { + if (!assertion) throw; + } +} + +contract AccessControl is SafeMath{ + + + event ContractUpgrade(address newContract); + + + address public ceoAddress; + address public cfoAddress; + address public cooAddress; + + address newContractAddress; + + uint public tip_total = 0; + uint public tip_rate = 20000000000000000; + + + bool public paused = false; + + + modifier onlyCEO() { + require(msg.sender == ceoAddress); + _; + } + + + modifier onlyCFO() { + require(msg.sender == cfoAddress); + _; + } + + + modifier onlyCOO() { + require(msg.sender == cooAddress); + _; + } + + modifier onlyCLevel() { + require( + msg.sender == cooAddress || + msg.sender == ceoAddress || + msg.sender == cfoAddress + ); + _; + } + + function () public payable{ + tip_total = safeAdd(tip_total, msg.value); + } + + + + function amountWithTip(uint amount) internal returns(uint){ + uint tip = safeMul(amount, tip_rate) / (1 ether); + tip_total = safeAdd(tip_total, tip); + return safeSub(amount, tip); + } + + + function withdrawTip(uint amount) external onlyCFO { + require(amount > 0 && amount <= tip_total); + require(msg.sender.send(amount)); + tip_total = tip_total - amount; + } + + + function setNewAddress(address newContract) external onlyCEO whenPaused { + newContractAddress = newContract; + emit ContractUpgrade(newContract); + } + + + + function setCEO(address _newCEO) external onlyCEO { + require(_newCEO != address(0)); + + ceoAddress = _newCEO; + } + + + + function setCFO(address _newCFO) external onlyCEO { + require(_newCFO != address(0)); + + cfoAddress = _newCFO; + } + + + + function setCOO(address _newCOO) external onlyCEO { + require(_newCOO != address(0)); + + cooAddress = _newCOO; + } + + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused { + require(paused); + _; + } + + + + function pause() external onlyCLevel whenNotPaused { + paused = true; + } + + + + + + + function unpause() public onlyCEO whenPaused { + + paused = false; + } +} + + +contract RpsGame is SafeMath , AccessControl{ + + + uint8 constant public NONE = 0; + uint8 constant public ROCK = 10; + uint8 constant public PAPER = 20; + uint8 constant public SCISSORS = 30; + uint8 constant public DEALERWIN = 201; + uint8 constant public PLAYERWIN = 102; + uint8 constant public DRAW = 101; + + + event CreateGame(uint gameid, address dealer, uint amount); + event JoinGame(uint gameid, address player, uint amount); + event Reveal(uint gameid, address player, uint8 choice); + event CloseGame(uint gameid,address dealer,address player, uint8 result); + + + struct Game { + uint expireTime; + address dealer; + uint dealerValue; + bytes32 dealerHash; + uint8 dealerChoice; + address player; + uint8 playerChoice; + uint playerValue; + uint8 result; + bool closed; + } + + + mapping (uint => mapping(uint => uint8)) public payoff; + mapping (uint => Game) public games; + mapping (address => uint[]) public gameidsOf; + + + uint public maxgame = 0; + uint public expireTimeLimit = 30 minutes; + + + function RpsGame() { + payoff[ROCK][ROCK] = DRAW; + payoff[ROCK][PAPER] = PLAYERWIN; + payoff[ROCK][SCISSORS] = DEALERWIN; + payoff[PAPER][ROCK] = DEALERWIN; + payoff[PAPER][PAPER] = DRAW; + payoff[PAPER][SCISSORS] = PLAYERWIN; + payoff[SCISSORS][ROCK] = PLAYERWIN; + payoff[SCISSORS][PAPER] = DEALERWIN; + payoff[SCISSORS][SCISSORS] = DRAW; + payoff[NONE][NONE] = DRAW; + payoff[ROCK][NONE] = DEALERWIN; + payoff[PAPER][NONE] = DEALERWIN; + payoff[SCISSORS][NONE] = DEALERWIN; + payoff[NONE][ROCK] = PLAYERWIN; + payoff[NONE][PAPER] = PLAYERWIN; + payoff[NONE][SCISSORS] = PLAYERWIN; + + ceoAddress = msg.sender; + cooAddress = msg.sender; + cfoAddress = msg.sender; + } + + + function createGame(bytes32 dealerHash, address player) public payable whenNotPaused returns (uint){ + require(dealerHash != 0x0); + + maxgame += 1; + Game storage game = games[maxgame]; + game.dealer = msg.sender; + game.player = player; + game.dealerHash = dealerHash; + game.dealerChoice = NONE; + game.dealerValue = msg.value; + game.expireTime = expireTimeLimit + now; + + gameidsOf[msg.sender].push(maxgame); + + emit CreateGame(maxgame, game.dealer, game.dealerValue); + + return maxgame; + } + + + function joinGame(uint gameid, uint8 choice) public payable whenNotPaused returns (uint){ + Game storage game = games[gameid]; + + require(msg.value == game.dealerValue && game.dealer != address(0) && game.dealer != msg.sender && game.playerChoice==NONE); + require(game.player == address(0) || game.player == msg.sender); + require(!game.closed); + require(now < game.expireTime); + require(checkChoice(choice)); + + game.player = msg.sender; + game.playerChoice = choice; + game.playerValue = msg.value; + game.expireTime = expireTimeLimit + now; + + gameidsOf[msg.sender].push(gameid); + + emit JoinGame(gameid, game.player, game.playerValue); + + return gameid; + } + + + function reveal(uint gameid, uint8 choice, bytes32 randomSecret) public returns (bool) { + Game storage game = games[gameid]; + bytes32 proof = getProof(msg.sender, choice, randomSecret); + + require(!game.closed); + require(now < game.expireTime); + require(game.dealerHash != 0x0); + require(checkChoice(choice)); + require(checkChoice(game.playerChoice)); + require(game.dealer == msg.sender && proof == game.dealerHash ); + + game.dealerChoice = choice; + + Reveal(gameid, msg.sender, choice); + + close(gameid); + + return true; + } + + + function close(uint gameid) public returns(bool) { + Game storage game = games[gameid]; + + require(!game.closed); + require(now > game.expireTime || (game.dealerChoice != NONE && game.playerChoice != NONE)); + + uint8 result = payoff[game.dealerChoice][game.playerChoice]; + + if(result == DEALERWIN){ + require(game.dealer.send(amountWithTip(safeAdd(game.dealerValue, game.playerValue)))); + }else if(result == PLAYERWIN){ + require(game.player.send(amountWithTip(safeAdd(game.dealerValue, game.playerValue)))); + }else if(result == DRAW){ + require(game.dealer.send(game.dealerValue) && game.player.send(game.playerValue)); + } + + game.closed = true; + game.result = result; + + emit CloseGame(gameid, game.dealer, game.player, result); + + return game.closed; + } + + + function getProof(address sender, uint8 choice, bytes32 randomSecret) public view returns (bytes32){ + return sha3(sender, choice, randomSecret); + } + + function gameCountOf(address owner) public view returns (uint){ + return gameidsOf[owner].length; + } + + function checkChoice(uint8 choice) public view returns (bool){ + return choice==ROCK||choice==PAPER||choice==SCISSORS; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/262.sol b/benchmark2/integer overflow/262.sol new file mode 100644 index 0000000000000000000000000000000000000000..516f90577acad75f1718258827e0c4b427792256 --- /dev/null +++ b/benchmark2/integer overflow/262.sol @@ -0,0 +1,223 @@ +pragma solidity ^0.4.18; + + + + + + + + + + + + + + + + + + + +contract SafeMath { + function safeAdd(uint a, uint b) public pure returns (uint c) { + c = a + b; + require(c >= a); + } + function safeSub(uint a, uint b) public pure returns (uint c) { + require(b <= a); + c = a - b; + } + function safeMul(uint a, uint b) public pure returns (uint c) { + c = a * b; + require(a == 0 || c / a == b); + } + function safeDiv(uint a, uint b) public pure returns (uint c) { + require(b > 0); + c = a / b; + } +} + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + +contract Owned { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Owned() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + + + + + + +contract GroovaToken is ERC20Interface, Owned, SafeMath { + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + constructor() public { + symbol = "GRV"; + name = "Groova Token"; + decimals = 0; + _totalSupply = 1000000; + balances[0x7f0f94823D1b0fc4D251A72e9375F2AfdA2faba3] = _totalSupply; + Transfer(address(0), 0x7f0f94823D1b0fc4D251A72e9375F2AfdA2faba3, _totalSupply); + } + + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public returns (bool success) { + balances[msg.sender] = safeSub(balances[msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + return true; + } + + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public returns (bool success) { + balances[from] = safeSub(balances[from], tokens); + allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/274.sol b/benchmark2/integer overflow/274.sol new file mode 100644 index 0000000000000000000000000000000000000000..98a248791a9cc5b0b79e33728681bf073e792db4 --- /dev/null +++ b/benchmark2/integer overflow/274.sol @@ -0,0 +1,109 @@ +pragma solidity ^0.4.16; + +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } + +contract Hacienda { + + string public name; + string public symbol; + uint8 public decimals = 18; + + uint256 public totalSupply; + + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + event Burn(address indexed from, uint256 value); + + + function TokenERC20( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) public { + totalSupply = initialSupply * 10 ** uint256(decimals); + balanceOf[msg.sender] = totalSupply; + name = tokenName; + symbol = tokenSymbol; + } + + + function _transfer(address _from, address _to, uint _value) internal { + + require(_to != 0x0); + + require(balanceOf[_from] >= _value); + + require(balanceOf[_to] + _value >= balanceOf[_to]); + + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + + balanceOf[_from] -= _value; + + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + _transfer(msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public + returns (bool success) { + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function approveAndCall(address _spender, uint256 _value, bytes _extraData) + public + returns (bool success) { + tokenRecipient spender = tokenRecipient(_spender); + if (approve(_spender, _value)) { + spender.receiveApproval(msg.sender, _value, this, _extraData); + return true; + } + } + + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + emit Burn(msg.sender, _value); + return true; + } + + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + emit Burn(_from, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/276.sol b/benchmark2/integer overflow/276.sol new file mode 100644 index 0000000000000000000000000000000000000000..86d50b68213cc0eca678684a185f754f1d5cbed7 --- /dev/null +++ b/benchmark2/integer overflow/276.sol @@ -0,0 +1,325 @@ +pragma solidity ^0.4.24; + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address _who) public view returns (uint256); + function transfer(address _to, uint256 _value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + + + + if (_a == 0) { + return 0; + } + + c = _a * _b; + assert(c / _a == _b); + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + return _a / _b; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_b <= _a); + return _a - _b; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + c = _a + _b; + assert(c >= _a); + return c; + } +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) internal balances; + + uint256 internal totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + function approve(address _spender, uint256 _value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + + +contract DetailedERC20 is ERC20 { + string public name; + string public symbol; + uint8 public decimals; + + constructor(string _name, string _symbol, uint8 _decimals) public { + name = _name; + symbol = _symbol; + decimals = _decimals; + } +} + + + + +contract BurnableToken is BasicToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + modifier hasMintPermission() { + require(msg.sender == owner); + _; + } + + + function mint( + address _to, + uint256 _amount + ) + public + hasMintPermission + canMint + returns (bool) + { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() public onlyOwner canMint returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + + +contract BSPCP is StandardToken, DetailedERC20, BurnableToken, MintableToken { + + constructor(string _name, string _symbol, uint8 _decimals) + DetailedERC20(_name, _symbol, _decimals) + public + { + + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/281.sol b/benchmark2/integer overflow/281.sol new file mode 100644 index 0000000000000000000000000000000000000000..f21b390cb59d6bd09d54d37bca69409eea711c46 --- /dev/null +++ b/benchmark2/integer overflow/281.sol @@ -0,0 +1,298 @@ +pragma solidity ^0.4.22; + + + +library SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + +contract Ownable { + address public owner; + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + if (newOwner != address(0)) { + owner = newOwner; + } + } +} + + + +contract Haltable is Ownable { + bool public halted; + + modifier inNormalState { + assert(!halted); + _; + } + + modifier inEmergencyState { + assert(halted); + _; + } + + + function halt() external onlyOwner inNormalState { + halted = true; + } + + + function resume() external onlyOwner inEmergencyState { + halted = false; + } + +} + + + +contract ERC20Basic { + uint256 public totalSupply; + + function balanceOf(address who) public constant returns (uint256); + + function transfer(address to, uint256 value) public returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + + function transferFrom(address from, address to, uint256 value) public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) public balances; + + + function transfer(address _to, uint256 _value) public returns (bool) { + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping(address => mapping(address => uint256)) public allowed; + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + uint256 _allowance; + _allowance = allowed[_from][msg.sender]; + + + + + balances[_to] = balances[_to].add(_value); + balances[_from] = balances[_from].sub(_value); + allowed[_from][msg.sender] = _allowance.sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + + + + + + require((_value == 0) || (allowed[msg.sender][_spender] == 0)); + + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + + +contract Burnable is StandardToken { + using SafeMath for uint; + + + event Burn(address indexed from, uint256 value); + + function burn(uint256 _value) public returns (bool success) { + require(balances[msg.sender] >= _value); + + balances[msg.sender] = balances[msg.sender].sub(_value); + + totalSupply = totalSupply.sub(_value); + + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balances[_from] >= _value); + + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + + totalSupply = totalSupply.sub(_value); + + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Burn(_from, _value); + return true; + } + + function transfer(address _to, uint _value) public returns (bool success) { + require(_to != 0x0); + + + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint _value) public returns (bool success) { + require(_to != 0x0); + + + return super.transferFrom(_from, _to, _value); + } +} + + + +contract Centive is Burnable, Ownable { + + string public name; + string public symbol; + uint8 public decimals = 18; + + + address public releaseAgent; + + + bool public released = false; + + + mapping(address => bool) public transferAgents; + + + modifier canTransfer(address _sender) { + require(transferAgents[_sender] || released); + _; + } + + + modifier inReleaseState(bool releaseState) { + require(releaseState == released); + _; + } + + + modifier onlyReleaseAgent() { + require(msg.sender == releaseAgent); + _; + } + + + constructor(uint256 initialSupply, string tokenName, string tokenSymbol) public { + totalSupply = initialSupply * 10 ** uint256(decimals); + + balances[msg.sender] = totalSupply; + + name = tokenName; + + symbol = tokenSymbol; + + } + + + function setReleaseAgent(address addr) external onlyOwner inReleaseState(false) { + + + releaseAgent = addr; + } + + function release() external onlyReleaseAgent inReleaseState(false) { + released = true; + } + + + function setTransferAgent(address addr, bool state) external onlyOwner inReleaseState(false) { + transferAgents[addr] = state; + } + + function transfer(address _to, uint _value) public canTransfer(msg.sender) returns (bool success) { + + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint _value) public canTransfer(_from) returns (bool success) { + + return super.transferFrom(_from, _to, _value); + } + + function burn(uint256 _value) public onlyOwner returns (bool success) { + return super.burn(_value); + } + + function burnFrom(address _from, uint256 _value) public onlyOwner returns (bool success) { + return super.burnFrom(_from, _value); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/286.sol b/benchmark2/integer overflow/286.sol new file mode 100644 index 0000000000000000000000000000000000000000..eaf6bd3fcc42f15fcea804ae39fa9d3a3ec6bcd5 --- /dev/null +++ b/benchmark2/integer overflow/286.sol @@ -0,0 +1,232 @@ +pragma solidity ^0.4.24; + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract LineageCode is StandardToken { + string public name = 'LineageCode'; + string public symbol = 'LIN'; + uint public decimals = 10; + uint public INITIAL_SUPPLY = 80 * 100000000 * (10 ** decimals); + address owner; + bool public released = false; + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + owner = msg.sender; + } + + function release() public { + require(owner == msg.sender); + require(!released); + released = true; + } + + function lock() public { + require(owner == msg.sender); + require(released); + released = false; + } + + function get_Release() view public returns (bool) { + return released; + } + + modifier onlyReleased() { + if (owner != msg.sender) + require(released); + _; + } + + function transfer(address to, uint256 value) public onlyReleased returns (bool) { + super.transfer(to, value); + } + + function allowance(address _owner, address _spender) public onlyReleased view returns (uint256) { + super.allowance(_owner, _spender); + } + + function transferFrom(address from, address to, uint256 value) public onlyReleased returns (bool) { + super.transferFrom(from, to, value); + } + + function approve(address spender, uint256 value) public onlyReleased returns (bool) { + super.approve(spender, value); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/291.sol b/benchmark2/integer overflow/291.sol new file mode 100644 index 0000000000000000000000000000000000000000..3e8c465758ee2f36127c037940e59a7b284b8a5d --- /dev/null +++ b/benchmark2/integer overflow/291.sol @@ -0,0 +1,213 @@ +pragma solidity ^0.4.20; + +contract SafeMath { + function safeMul(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b)public pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b)public pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b)public pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function _assert(bool assertion)public pure { + assert(!assertion); + } +} + + +contract ERC20Interface { + string public name; + string public symbol; + uint8 public decimals; + uint public totalSupply; + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) view returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + } + +contract ERC20 is ERC20Interface,SafeMath { + + + mapping(address => uint256) public balanceOf; + + + mapping(address => mapping(address => uint256)) allowed; + + constructor(string _name) public { + name = _name; + symbol = "REL"; + decimals = 18; + totalSupply = 10000000000000000000000000000; + balanceOf[msg.sender] = totalSupply; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(balanceOf[msg.sender] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] ,_value); + + + emit Transfer(msg.sender, _to, _value); + + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(allowed[_from][msg.sender] >= _value); + require(balanceOf[_from] >= _value); + require(balanceOf[_to] + _value >= balanceOf[_to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to],_value); + + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender], _value); + + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowed[msg.sender][_spender] = _value; + + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + +contract owned { + address public owner; + + constructor () public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnerShip(address newOwer) public onlyOwner { + owner = newOwer; + } + +} + +contract SelfDesctructionContract is owned { + + string public someValue; + modifier ownerRestricted { + require(owner == msg.sender); + _; + } + + function SelfDesctructionContract() { + owner = msg.sender; + } + + function setSomeValue(string value){ + someValue = value; + } + + function destroyContract() ownerRestricted { + selfdestruct(owner); + } +} + + + +contract AdvanceToken is ERC20, owned,SelfDesctructionContract{ + + mapping (address => bool) public frozenAccount; + + event FrozenFunds(address target, bool frozen); + event Burn(address target, uint amount); + + constructor (string _name) ERC20(_name) public { + + } + + function freezeAccount(address target, bool freeze) public onlyOwner { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + success = _transfer(msg.sender, _to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(allowed[_from][msg.sender] >= _value); + success = _transfer(_from, _to, _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value) ; + } + + function _transfer(address _from, address _to, uint256 _value) internal returns (bool) { + require(_to != address(0)); + require(!frozenAccount[_from]); + + require(balanceOf[_from] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; + + emit Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(allowed[_from][msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender], _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value); + + emit Burn(msg.sender, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/311.sol b/benchmark2/integer overflow/311.sol new file mode 100644 index 0000000000000000000000000000000000000000..121bcaadd3699b50ecde21e38099a789253402e2 --- /dev/null +++ b/benchmark2/integer overflow/311.sol @@ -0,0 +1,232 @@ +pragma solidity ^0.4.24; + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract LineageCode is StandardToken { + string public name = 'LinageCode'; + string public symbol = 'LIN'; + uint public decimals = 10; + uint public INITIAL_SUPPLY = 80 * 100000000 * (10 ** decimals); + address owner; + bool public released = false; + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + owner = msg.sender; + } + + function release() public { + require(owner == msg.sender); + require(!released); + released = true; + } + + function lock() public { + require(owner == msg.sender); + require(released); + released = false; + } + + function get_Release() view public returns (bool) { + return released; + } + + modifier onlyReleased() { + if (owner != msg.sender) + require(released); + _; + } + + function transfer(address to, uint256 value) public onlyReleased returns (bool) { + super.transfer(to, value); + } + + function allowance(address _owner, address _spender) public onlyReleased view returns (uint256) { + super.allowance(_owner, _spender); + } + + function transferFrom(address from, address to, uint256 value) public onlyReleased returns (bool) { + super.transferFrom(from, to, value); + } + + function approve(address spender, uint256 value) public onlyReleased returns (bool) { + super.approve(spender, value); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/333.sol b/benchmark2/integer overflow/333.sol new file mode 100644 index 0000000000000000000000000000000000000000..227176dd03c7f235d3268ca1101409d35602c6dc --- /dev/null +++ b/benchmark2/integer overflow/333.sol @@ -0,0 +1,219 @@ +pragma solidity ^0.4.18; + + + + + + + + + + + + + + + +contract SafeMath { + function safeAdd(uint a, uint b) public pure returns (uint c) { + c = a + b; + require(c >= a); + } + function safeSub(uint a, uint b) public pure returns (uint c) { + require(b <= a); + c = a - b; + } + function safeMul(uint a, uint b) public pure returns (uint c) { + c = a * b; + require(a == 0 || c / a == b); + } + function safeDiv(uint a, uint b) public pure returns (uint c) { + require(b > 0); + c = a / b; + } +} + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + +contract Owned { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Owned() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + + + + + + +contract CoinDisplayNetwork is ERC20Interface, Owned, SafeMath { + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + function CoinDisplayNetwork() public { + symbol = "CDN"; + name = "Coin Display Network"; + decimals = 18; + _totalSupply = 100000000000000000000000000; + balances[0xd76618b352D0bFC8014Fc44BF31Bd0F947331660] = _totalSupply; + Transfer(address(0), 0xd76618b352D0bFC8014Fc44BF31Bd0F947331660, _totalSupply); + } + + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public returns (bool success) { + balances[msg.sender] = safeSub(balances[msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + return true; + } + + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public returns (bool success) { + balances[from] = safeSub(balances[from], tokens); + allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/338.sol b/benchmark2/integer overflow/338.sol new file mode 100644 index 0000000000000000000000000000000000000000..f29243033ba6a7fe7e23ecbb2f3b84d9a064539f --- /dev/null +++ b/benchmark2/integer overflow/338.sol @@ -0,0 +1,316 @@ +pragma solidity ^0.4.24; + +contract SafeMath { + function safeMul(uint a, uint b) internal returns (uint) { + uint c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeSub(uint a, uint b) internal returns (uint) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint a, uint b) internal returns (uint) { + uint c = a + b; + assert(c>=a && c>=b); + return c; + } + + function assert(bool assertion) internal { + if (!assertion) throw; + } +} + +contract AccessControl is SafeMath{ + + + event ContractUpgrade(address newContract); + + + address public ceoAddress; + address public cfoAddress; + address public cooAddress; + + address newContractAddress; + + uint public tip_total = 0; + uint public tip_rate = 20000000000000000; + + + bool public paused = false; + + + modifier onlyCEO() { + require(msg.sender == ceoAddress); + _; + } + + + modifier onlyCFO() { + require(msg.sender == cfoAddress); + _; + } + + + modifier onlyCOO() { + require(msg.sender == cooAddress); + _; + } + + modifier onlyCLevel() { + require( + msg.sender == cooAddress || + msg.sender == ceoAddress || + msg.sender == cfoAddress + ); + _; + } + + function () public payable{ + tip_total = safeAdd(tip_total, msg.value); + } + + + + function amountWithTip(uint amount) internal returns(uint){ + uint tip = safeMul(amount, tip_rate) / (1 ether); + tip_total = safeAdd(tip_total, tip); + return safeSub(amount, tip); + } + + + function withdrawTip(uint amount) external onlyCFO { + require(amount > 0 && amount <= tip_total); + require(msg.sender.send(amount)); + tip_total = tip_total - amount; + } + + + function setNewAddress(address newContract) external onlyCEO whenPaused { + newContractAddress = newContract; + emit ContractUpgrade(newContract); + } + + + + function setCEO(address _newCEO) external onlyCEO { + require(_newCEO != address(0)); + + ceoAddress = _newCEO; + } + + + + function setCFO(address _newCFO) external onlyCEO { + require(_newCFO != address(0)); + + cfoAddress = _newCFO; + } + + + + function setCOO(address _newCOO) external onlyCEO { + require(_newCOO != address(0)); + + cooAddress = _newCOO; + } + + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused { + require(paused); + _; + } + + + + function pause() external onlyCLevel whenNotPaused { + paused = true; + } + + + + + + + function unpause() public onlyCEO whenPaused { + + paused = false; + } +} + + +contract RpsGame is SafeMath , AccessControl{ + + + uint8 constant public NONE = 0; + uint8 constant public ROCK = 10; + uint8 constant public PAPER = 20; + uint8 constant public SCISSORS = 30; + uint8 constant public DEALERWIN = 201; + uint8 constant public PLAYERWIN = 102; + uint8 constant public DRAW = 101; + + + event CreateGame(uint gameid, address dealer, uint amount); + event JoinGame(uint gameid, address player, uint amount); + event Reveal(uint gameid, address player, uint8 choice); + event CloseGame(uint gameid,address dealer,address player, uint8 result); + + + struct Game { + uint expireTime; + address dealer; + uint dealerValue; + bytes32 dealerHash; + uint8 dealerChoice; + address player; + uint8 playerChoice; + uint playerValue; + uint8 result; + bool closed; + } + + + mapping (uint => mapping(uint => uint8)) public payoff; + mapping (uint => Game) public games; + mapping (address => uint[]) public gameidsOf; + + + uint public maxgame = 0; + uint public expireTimeLimit = 30 minutes; + + + function RpsGame() { + payoff[ROCK][ROCK] = DRAW; + payoff[ROCK][PAPER] = PLAYERWIN; + payoff[ROCK][SCISSORS] = DEALERWIN; + payoff[PAPER][ROCK] = DEALERWIN; + payoff[PAPER][PAPER] = DRAW; + payoff[PAPER][SCISSORS] = PLAYERWIN; + payoff[SCISSORS][ROCK] = PLAYERWIN; + payoff[SCISSORS][PAPER] = DEALERWIN; + payoff[SCISSORS][SCISSORS] = DRAW; + payoff[NONE][NONE] = DRAW; + payoff[ROCK][NONE] = DEALERWIN; + payoff[PAPER][NONE] = DEALERWIN; + payoff[SCISSORS][NONE] = DEALERWIN; + payoff[NONE][ROCK] = PLAYERWIN; + payoff[NONE][PAPER] = PLAYERWIN; + payoff[NONE][SCISSORS] = PLAYERWIN; + + ceoAddress = msg.sender; + cooAddress = msg.sender; + cfoAddress = msg.sender; + } + + + function createGame(bytes32 dealerHash, address player) public payable whenNotPaused returns (uint){ + require(dealerHash != 0x0); + maxgame += 1; + Game storage game = games[maxgame]; + game.dealer = msg.sender; + game.player = player; + game.dealerHash = dealerHash; + game.dealerChoice = NONE; + game.dealerValue = msg.value; + game.expireTime = expireTimeLimit + now; + + gameidsOf[msg.sender].push(maxgame); + + emit CreateGame(maxgame, game.dealer, game.dealerValue); + + return maxgame; + } + + + function joinGame(uint gameid, uint8 choice) public payable whenNotPaused returns (uint){ + Game storage game = games[gameid]; + require(msg.value == game.dealerValue && game.dealer != address(0) && game.dealer != msg.sender && game.playerChoice==NONE); + require(game.player == address(0) || game.player == msg.sender); + require(!game.closed); + require(now < game.expireTime); + require(checkChoice(choice)); + + game.player = msg.sender; + game.playerChoice = choice; + game.playerValue = msg.value; + game.expireTime = expireTimeLimit + now; + + gameidsOf[msg.sender].push(gameid); + + emit JoinGame(gameid, game.player, game.playerValue); + + return gameid; + } + + + function reveal(uint gameid, uint8 choice, bytes32 randomSecret) public returns (bool) { + Game storage game = games[gameid]; + bytes32 proof = getProof(msg.sender, choice, randomSecret); + + require(!game.closed); + require(now < game.expireTime); + require(game.dealerHash != 0x0); + require(checkChoice(choice)); + require(checkChoice(game.playerChoice)); + require(game.dealer == msg.sender && proof == game.dealerHash ); + + game.dealerChoice = choice; + + Reveal(gameid, msg.sender, choice); + + close(gameid); + + return true; + } + + + function close(uint gameid) public returns(bool) { + Game storage game = games[gameid]; + require(!game.closed); + require(now > game.expireTime || (game.dealerChoice != NONE && game.playerChoice != NONE)); + + uint totalAmount = safeAdd(game.dealerValue, game.playerValue); + uint reward = amountWithTip(totalAmount); + uint8 result = payoff[game.dealerChoice][game.playerChoice]; + + if(result == DEALERWIN){ + require(game.dealer.send(reward)); + }else if(result == PLAYERWIN){ + require(game.player.send(reward)); + }else if(result == DRAW){ + require(game.dealer.send(game.dealerValue) && game.player.send(game.playerValue)); + } + + game.closed = true; + game.result = result; + + emit CloseGame(gameid, game.dealer, game.player, result); + + return game.closed; + } + + + function getProof(address sender, uint8 choice, bytes32 randomSecret) public view returns (bytes32){ + return sha3(sender, choice, randomSecret); + } + + function gameCountOf(address owner) public view returns (uint){ + return gameidsOf[owner].length; + } + + function checkChoice(uint8 choice) public view returns (bool){ + return choice==ROCK||choice==PAPER||choice==SCISSORS; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/339.sol b/benchmark2/integer overflow/339.sol new file mode 100644 index 0000000000000000000000000000000000000000..b7b711f74d06588735bdd49b5242037746ba7e80 --- /dev/null +++ b/benchmark2/integer overflow/339.sol @@ -0,0 +1,115 @@ +pragma solidity ^0.4.10; + + +contract SafeMath { + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + +} + + + +contract StandardToken is Token , SafeMath { + + bool public status = true; + modifier on() { + require(status == true); + _; + } + + function transfer(address _to, uint256 _value) on returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0 && _to != 0X0) { + balances[msg.sender] -= _value; + balances[_to] = safeAdd(balances[_to],_value); + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) on returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] = safeAdd(balances[_to],_value); + balances[_from] = safeSubtract(balances[_from],_value); + allowed[_from][msg.sender] = safeSubtract(allowed[_from][msg.sender],_value); + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) on constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) on returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) on constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + + + + +contract ExShellToken is StandardToken { + string public name = "ExShellToken"; + uint8 public decimals = 8; + string public symbol = "ET"; + bool private init =true; + function turnon() controller { + status = true; + } + function turnoff() controller { + status = false; + } + function ExShellToken() { + require(init==true); + totalSupply = 2000000000; + balances[0xa089a405b1df71a6155705fb2bce87df2a86a9e4] = totalSupply; + init = false; + } + address public controller1 =0xa089a405b1df71a6155705fb2bce87df2a86a9e4; + address public controller2 =0x5aa64423529e43a53c7ea037a07f94abc0c3a111; + + modifier controller () { + require(msg.sender == controller1||msg.sender == controller2); + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/355.sol b/benchmark2/integer overflow/355.sol new file mode 100644 index 0000000000000000000000000000000000000000..1cd31f4218e5cbf438cbdd878474f1bf6995c31d --- /dev/null +++ b/benchmark2/integer overflow/355.sol @@ -0,0 +1,198 @@ +pragma solidity ^0.4.24; + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract PeopleWaveToken is StandardToken { + string public constant name = "PeopleWave Token"; + string public constant symbol = "PPL"; + uint8 public constant decimals = 18; + uint public constant initialSupply = 1200000000000000000000000000; + + constructor() public { + totalSupply_ = initialSupply; + balances[msg.sender] = initialSupply; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/373.sol b/benchmark2/integer overflow/373.sol new file mode 100644 index 0000000000000000000000000000000000000000..0bcf8d3caf3cf73cb5cee2c17f379ad5dd3e69cc --- /dev/null +++ b/benchmark2/integer overflow/373.sol @@ -0,0 +1,414 @@ +pragma solidity ^0.4.24; + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + +contract ERC20 { + function totalSupply() public view returns (uint256); + + function balanceOf(address _who) public view returns (uint256); + + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transfer(address _to, uint256 _value) public returns (bool); + + function approve(address _spender, uint256 _value) + public returns (bool); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); + + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +contract StandardToken is ERC20 { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + mapping (address => mapping (address => uint256)) internal allowed; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() public onlyOwner whenNotPaused { + paused = true; + emit Pause(); + } + + + function unpause() public onlyOwner whenPaused { + paused = false; + emit Unpause(); + } +} + + + + +contract BurnableToken is StandardToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + + function burnFrom(address _from, uint256 _value) public { + require(_value <= allowed[_from][msg.sender]); + + + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + _burn(_from, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} + + + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + modifier hasMintPermission() { + require(msg.sender == owner); + _; + } + + + function mint( + address _to, + uint256 _amount + ) + public + hasMintPermission + canMint + returns (bool) + { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() public onlyOwner canMint returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + + + + if (_a == 0) { + return 0; + } + + c = _a * _b; + assert(c / _a == _b); + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + return _a / _b; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_b <= _a); + return _a - _b; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + c = _a + _b; + assert(c >= _a); + return c; + } +} + + +contract PausableToken is StandardToken, Pausable { + + function transfer( + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(_to, _value); + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(_from, _to, _value); + } + + function approve( + address _spender, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(_spender, _value); + } + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + + + + +contract SCAVOToken is StandardToken, MintableToken, PausableToken, BurnableToken { + + string public constant name = "SCAVO Token"; + string public constant symbol = "SCAVO"; + string public constant version = "1.1"; + uint8 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 200000000 * (10 ** uint256(decimals)); + + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + emit Transfer(address(0), msg.sender, INITIAL_SUPPLY); + } + + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/375.sol b/benchmark2/integer overflow/375.sol new file mode 100644 index 0000000000000000000000000000000000000000..0b95f5825a7b0e85215ffd5e284cb3b774cc8cc4 --- /dev/null +++ b/benchmark2/integer overflow/375.sol @@ -0,0 +1,366 @@ +pragma solidity ^0.4.18; + +/* +// -- +// -- +// -- +// ___ ___ ___ ___ ___ +// /\ \ /\__\ /\ \ /\__\ /\ \ +// /::\ \ /:/ _/_ /::\ \ /::L_L_ \:\ \ +// /\:\:\__\ /:/_/\__\ /::\:\__\ /:/L:\__\ /::\__\ +// \:\:\/__/ \:\/:/ / \/\::/ / \/_/:/ / /:/\/__/ +// \::/ / \::/ / \/__/ /:/ / \/__/ +// \/__/ \/__/ \/__/ +// -- +// -- +// -- +*/ + +// Contract must have an owner +contract Owned { + address public owner; + + constructor() public { + owner = msg.sender; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function setOwner(address _owner) onlyOwner public { + owner = _owner; + } +} + +// SafeMath methods +contract SafeMath { + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + assert(c >= _a); + return c; + } + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_a >= _b); + return _a - _b; + } + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a * _b; + assert(_a == 0 || c / _a == _b); + return c; + } +} + +// for safety methods +interface ERC20Token { + function transfer(address _to, uint256 _value) external returns (bool); + function balanceOf(address _addr) external view returns (uint256); + function decimals() external view returns (uint8); +} + +// the main ERC20-compliant contract +contract Token is SafeMath, Owned { + uint256 constant DAY_IN_SECONDS = 86400; + string public constant standard = "0.66"; + string public name = ""; + string public symbol = ""; + uint8 public decimals = 0; + uint256 public totalSupply = 0; + mapping (address => uint256) public balanceP; + mapping (address => mapping (address => uint256)) public allowance; + + mapping (address => uint256[]) public lockTime; + mapping (address => uint256[]) public lockValue; + mapping (address => uint256) public lockNum; + mapping (address => bool) public locker; + uint256 public later = 0; + uint256 public earlier = 0; + + // standard ERC20 events + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + // timelock-related events + event TransferLocked(address indexed _from, address indexed _to, uint256 _time, uint256 _value); + event TokenUnlocked(address indexed _address, uint256 _value); + + // safety method-related events + event WrongTokenEmptied(address indexed _token, address indexed _addr, uint256 _amount); + event WrongEtherEmptied(address indexed _addr, uint256 _amount); + + // constructor for the ERC20 Token + constructor(string _name, string _symbol, uint8 _decimals, uint256 _totalSupply) public { + require(bytes(_name).length > 0 && bytes(_symbol).length > 0); + + name = _name; + symbol = _symbol; + decimals = _decimals; + totalSupply = _totalSupply; + + balanceP[msg.sender] = _totalSupply; + + } + + modifier validAddress(address _address) { + require(_address != 0x0); + _; + } + + // owner may add or remove a locker address for the contract + function addLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = true; + } + + function removeLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = false; + } + + // fast-forward the timelocks for all accounts + function setUnlockEarlier(uint256 _earlier) public onlyOwner { + earlier = add(earlier, _earlier); + } + + // delay the timelocks for all accounts + function setUnlockLater(uint256 _later) public onlyOwner { + later = add(later, _later); + } + + // show unlocked balance of an account + function balanceUnlocked(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + // show timelocked balance of an account + function balanceLocked(address _address) public view returns (uint256 _balance) { + _balance = 0; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) < add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + // standard ERC20 balanceOf with timelock added + function balanceOf(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + // show timelocks in an account + function showTime(address _address) public view validAddress(_address) returns (uint256[] _time) { + uint i = 0; + uint256[] memory tempLockTime = new uint256[](lockNum[_address]); + while (i < lockNum[_address]) { + tempLockTime[i] = sub(add(lockTime[_address][i], later), earlier); + i++; + } + return tempLockTime; + } + + // show values locked in an account's timelocks + function showValue(address _address) public view validAddress(_address) returns (uint256[] _value) { + return lockValue[_address]; + } + + // Calculate and process the timelock states of an account + function calcUnlock(address _address) private { + uint256 i = 0; + uint256 j = 0; + uint256[] memory currentLockTime; + uint256[] memory currentLockValue; + uint256[] memory newLockTime = new uint256[](lockNum[_address]); + uint256[] memory newLockValue = new uint256[](lockNum[_address]); + currentLockTime = lockTime[_address]; + currentLockValue = lockValue[_address]; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(currentLockTime[i], later)) { + balanceP[_address] = add(balanceP[_address], currentLockValue[i]); + emit TokenUnlocked(_address, currentLockValue[i]); + } else { + newLockTime[j] = currentLockTime[i]; + newLockValue[j] = currentLockValue[i]; + j++; + } + i++; + } + uint256[] memory trimLockTime = new uint256[](j); + uint256[] memory trimLockValue = new uint256[](j); + i = 0; + while (i < j) { + trimLockTime[i] = newLockTime[i]; + trimLockValue[i] = newLockValue[i]; + i++; + } + lockTime[_address] = trimLockTime; + lockValue[_address] = trimLockValue; + lockNum[_address] = j; + } + + // standard ERC20 transfer + function transfer(address _to, uint256 _value) public validAddress(_to) returns (bool success) { + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + if (balanceP[msg.sender] >= _value && _value > 0) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + // transfer Token with timelocks + function transferLocked(address _to, uint256[] _time, uint256[] _value) public validAddress(_to) returns (bool success) { + require(_value.length == _time.length); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[msg.sender] >= totalValue && totalValue > 0) { + i = 0; + while (i < _time.length) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + // emit custom TransferLocked event + emit TransferLocked(msg.sender, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + // emit standard Transfer event for wallets + emit Transfer(msg.sender, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + // lockers set by owners may transfer Token with timelocks + function transferLockedFrom(address _from, address _to, uint256[] _time, uint256[] _value) public + validAddress(_from) validAddress(_to) returns (bool success) { + require(locker[msg.sender]); + require(_value.length == _time.length); + + if (lockNum[_from] > 0) calcUnlock(_from); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[_from] >= totalValue && totalValue > 0 && allowance[_from][msg.sender] >= totalValue) { + i = 0; + while (i < _time.length) { + balanceP[_from] = sub(balanceP[_from], _value[i]); + allowance[_from][msg.sender] = sub(allowance[_from][msg.sender], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + // emit custom TransferLocked event + emit TransferLocked(_from, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + // emit standard Transfer event for wallets + emit Transfer(_from, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + // standard ERC20 transferFrom + function transferFrom(address _from, address _to, uint256 _value) public validAddress(_from) validAddress(_to) returns (bool success) { + if (lockNum[_from] > 0) calcUnlock(_from); + if (balanceP[_from] >= _value && _value > 0 && allowance[_from][msg.sender] >= _value) { + allowance[_from][msg.sender] = sub(allowance[_from][msg.sender], _value); + balanceP[_from] = sub(balanceP[_from], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + // should only be called when first setting an allowance + function approve(address _spender, uint256 _value) public validAddress(_spender) returns (bool success) { + require(allowance[msg.sender][_spender] == 0); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + // increase or decrease allowance + function increaseApproval(address _spender, uint _value) public returns (bool) { + allowance[msg.sender][_spender] = add(allowance[msg.sender][_spender], _value); + emit Approval(msg.sender, _spender, allowance[msg.sender][_spender]); + return true; + } + + function decreaseApproval(address _spender, uint _value) public returns (bool) { + if(_value > allowance[msg.sender][_spender]) { + allowance[msg.sender][_spender] = 0; + } else { + allowance[msg.sender][_spender] = sub(allowance[msg.sender][_spender], _value); + } + emit Approval(msg.sender, _spender, allowance[msg.sender][_spender]); + return true; + } + + // safety methods + function () public payable { + revert(); + } + + function emptyWrongToken(address _addr) onlyOwner public { + ERC20Token wrongToken = ERC20Token(_addr); + uint256 amount = wrongToken.balanceOf(address(this)); + require(amount > 0); + require(wrongToken.transfer(msg.sender, amount)); + + emit WrongTokenEmptied(_addr, msg.sender, amount); + } + + // shouldn't happen, just in case + function emptyWrongEther() onlyOwner public { + uint256 amount = address(this).balance; + require(amount > 0); + msg.sender.transfer(amount); + + emit WrongEtherEmptied(msg.sender, amount); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/382.sol b/benchmark2/integer overflow/382.sol new file mode 100644 index 0000000000000000000000000000000000000000..47427afb8aa3f6ab226ee0d2ca9a824c594e6262 --- /dev/null +++ b/benchmark2/integer overflow/382.sol @@ -0,0 +1,222 @@ +pragma solidity ^0.4.20; + +contract SafeMath { + function safeMul(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b)public pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b)public pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b)public pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function _assert(bool assertion)public pure { + assert(!assertion); + } +} + + +contract ERC20Interface { + string public name; + string public symbol; + uint8 public decimals; + uint public totalSupply; + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) view returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + } + +contract ERC20 is ERC20Interface,SafeMath { + + + mapping(address => uint256) public balanceOf; + + + mapping(address => mapping(address => uint256)) allowed; + + constructor(string _name) public { + name = _name; + symbol = "IMTC"; + decimals = 4; + totalSupply = 3600000000000; + balanceOf[msg.sender] = totalSupply; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(balanceOf[msg.sender] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] ,_value); + + + emit Transfer(msg.sender, _to, _value); + + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(allowed[_from][msg.sender] >= _value); + require(balanceOf[_from] >= _value); + require(balanceOf[_to] + _value >= balanceOf[_to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to],_value); + + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender], _value); + + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowed[msg.sender][_spender] = _value; + + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + +contract owned { + address public owner; + + constructor () public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnerShip(address newOwer) public onlyOwner { + owner = newOwer; + } + +} + +contract SelfDesctructionContract is owned { + + string public someValue; + modifier ownerRestricted { + require(owner == msg.sender); + _; + } + + function SelfDesctructionContract() { + owner = msg.sender; + } + + function setSomeValue(string value){ + someValue = value; + } + + function destroyContract() ownerRestricted { + selfdestruct(owner); + } +} + + + +contract AdvanceToken is ERC20, owned,SelfDesctructionContract{ + + mapping (address => bool) public frozenAccount; + + event AddSupply(uint amount); + event FrozenFunds(address target, bool frozen); + event Burn(address target, uint amount); + + constructor (string _name) ERC20(_name) public { + + } + + function mine(address target, uint amount) public onlyOwner { + totalSupply =SafeMath.safeAdd(totalSupply,amount) ; + balanceOf[target] = SafeMath.safeAdd(balanceOf[target],amount); + + emit AddSupply(amount); + emit Transfer(0, target, amount); + } + + function freezeAccount(address target, bool freeze) public onlyOwner { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + success = _transfer(msg.sender, _to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(allowed[_from][msg.sender] >= _value); + success = _transfer(_from, _to, _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value) ; + } + + function _transfer(address _from, address _to, uint256 _value) internal returns (bool) { + require(_to != address(0)); + require(!frozenAccount[_from]); + + require(balanceOf[_from] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; + + emit Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(allowed[_from][msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender], _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value); + + emit Burn(msg.sender, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/39.sol b/benchmark2/integer overflow/39.sol new file mode 100644 index 0000000000000000000000000000000000000000..9a14358145a1b1539a11e9c353dca99c6826eccb --- /dev/null +++ b/benchmark2/integer overflow/39.sol @@ -0,0 +1 @@ +pragma solidity ^0.4.23;contract Ownable {address public owner;event OwnershipRenounced(address indexed previousOwner);event OwnershipTransferred(address indexed previousOwner,address indexed newOwner);constructor() public {owner = msg.sender;}modifier onlyOwner() {require(msg.sender == owner);_;}function transferOwnership(address newOwner) public onlyOwner {require(newOwner != address(0));emit OwnershipTransferred(owner, newOwner);owner = newOwner;}function renounceOwnership() public onlyOwner {emit OwnershipRenounced(owner);owner = address(0);}}library SafeMath {function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {if (a == 0) {return 0;}c = a * b;assert(c / a == b);return c;}function div(uint256 a, uint256 b) internal pure returns (uint256) {return a / b;}function sub(uint256 a, uint256 b) internal pure returns (uint256) {assert(b <= a);return a - b;}function add(uint256 a, uint256 b) internal pure returns (uint256 c) {c = a + b;assert(c >= a);return c;}}contract ERC20Basic {function totalSupply() public view returns (uint256);function balanceOf(address who) public view returns (uint256);function transfer(address to, uint256 value) public returns (bool);event Transfer(address indexed from, address indexed to, uint256 value);}contract ERC20 is ERC20Basic {function allowance(address owner, address spender) public view returns (uint256);function transferFrom(address from, address to, uint256 value) public returns(bool);function approve(address spender, uint256 value) public returns (bool);event Approval(address indexed owner, address indexed spender, uint256 value);}contract BasicToken is ERC20Basic {using SafeMath for uint256;mapping(address => uint256) balances;uint256 totalSupply_;function totalSupply() public view returns (uint256) {return totalSupply_;}function transfer(address _to, uint256 _value) public returns (bool) {require(_to != address(0));require(_value <= balances[msg.sender]);balances[msg.sender] = balances[msg.sender].sub(_value);balances[_to] = balances[_to].add(_value);emit Transfer(msg.sender, _to, _value);return true;}function balanceOf(address _owner) public view returns (uint256) {return balances[_owner];}}contract StandardToken is ERC20, BasicToken {mapping (address => mapping (address => uint256)) internal allowed;function transferFrom(address _from, address _to, uint256 _value) public returns(bool) {require(_to != address(0));require(_value <= balances[_from]);require(_value <= allowed[_from][msg.sender]);balances[_from] = balances[_from].sub(_value);balances[_to] = balances[_to].add(_value);allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);emit Transfer(_from, _to, _value);return true;}function approve(address _spender, uint256 _value) public returns (bool) {require((_value == 0 ) || (allowed[msg.sender][_spender] == 0));allowed[msg.sender][_spender] = _value;emit Approval(msg.sender, _spender, _value);return true;}function allowance(address _owner, address _spender) public view returns (uint256) {return allowed[_owner][_spender];}function increaseApproval(address _spender, uint _addedValue) public returns (bool){allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);return true;}function decreaseApproval(address _spender, uint _subtractedValue) public returns(bool) {uint oldValue = allowed[msg.sender][_spender];if (_subtractedValue > oldValue) {allowed[msg.sender][_spender] = 0;} else {allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);}emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);return true;}}contract TokenContract is StandardToken{string public constant name="SDKTOKEN";string public constant symbol="SDK"; uint8 public constant decimals=18;uint256 public constant INITIAL_SUPPLY=100000000000000000000;uint256 public constant MAX_SUPPLY = 100 * 10000 * 10000 * (10 **uint256(decimals));address public constant holder=0x968c9f1e66f40e2851de40e84e37d62566aab393;constructor() TokenContract() public {totalSupply_ = INITIAL_SUPPLY;balances[holder] = INITIAL_SUPPLY;emit Transfer(0x0, holder, INITIAL_SUPPLY);}function() payable public {revert();}} \ No newline at end of file diff --git a/benchmark2/integer overflow/394.sol b/benchmark2/integer overflow/394.sol new file mode 100644 index 0000000000000000000000000000000000000000..b7b711f74d06588735bdd49b5242037746ba7e80 --- /dev/null +++ b/benchmark2/integer overflow/394.sol @@ -0,0 +1,115 @@ +pragma solidity ^0.4.10; + + +contract SafeMath { + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + +} + + + +contract StandardToken is Token , SafeMath { + + bool public status = true; + modifier on() { + require(status == true); + _; + } + + function transfer(address _to, uint256 _value) on returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0 && _to != 0X0) { + balances[msg.sender] -= _value; + balances[_to] = safeAdd(balances[_to],_value); + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) on returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] = safeAdd(balances[_to],_value); + balances[_from] = safeSubtract(balances[_from],_value); + allowed[_from][msg.sender] = safeSubtract(allowed[_from][msg.sender],_value); + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) on constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) on returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) on constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + + + + +contract ExShellToken is StandardToken { + string public name = "ExShellToken"; + uint8 public decimals = 8; + string public symbol = "ET"; + bool private init =true; + function turnon() controller { + status = true; + } + function turnoff() controller { + status = false; + } + function ExShellToken() { + require(init==true); + totalSupply = 2000000000; + balances[0xa089a405b1df71a6155705fb2bce87df2a86a9e4] = totalSupply; + init = false; + } + address public controller1 =0xa089a405b1df71a6155705fb2bce87df2a86a9e4; + address public controller2 =0x5aa64423529e43a53c7ea037a07f94abc0c3a111; + + modifier controller () { + require(msg.sender == controller1||msg.sender == controller2); + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/423.sol b/benchmark2/integer overflow/423.sol new file mode 100644 index 0000000000000000000000000000000000000000..5b45145c13222066e8c6c95adcaf7334e47b85a5 --- /dev/null +++ b/benchmark2/integer overflow/423.sol @@ -0,0 +1,234 @@ +pragma solidity 0.4.16; + + +library SafeMath { + function mul(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal constant returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal constant returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value > 0 && _value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value > 0 && _value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } +} + + +contract Ownable { + address public owner; + + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + function Ownable() { + owner = msg.sender; + } + + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + + function transferOwnership(address newOwner) onlyOwner public { + require(newOwner != address(0)); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + Unpause(); + } +} + + + +contract PausableToken is StandardToken, Pausable { + mapping (address => bool) public frozenAccount; + event FrozenFunds(address target, bool frozen); + + function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { + require(!frozenAccount[msg.sender]); + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { + require(!frozenAccount[_from]); + return super.transferFrom(_from, _to, _value); + } + + function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { + + return super.approve(_spender, _value); + } + + function batchTransfer(address[] _receivers, uint256 _value) public whenNotPaused returns (bool) { + require(!frozenAccount[msg.sender]); + uint cnt = _receivers.length; + uint256 amount = uint256(cnt).mul(_value); + require(cnt > 0 && cnt <= 121); + require(_value > 0 && balances[msg.sender] >= amount); + + balances[msg.sender] = balances[msg.sender].sub(amount); + for (uint i = 0; i < cnt; i++) { + require (_receivers[i] != 0x0); + balances[_receivers[i]] = balances[_receivers[i]].add(_value); + Transfer(msg.sender, _receivers[i], _value); + } + return true; + } + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + FrozenFunds(target, freeze); + } + + function batchFreeze(address[] addresses, bool freeze) onlyOwner public { + for (uint i = 0; i < addresses.length; i++) { + frozenAccount[addresses[i]] = freeze; + FrozenFunds(addresses[i], freeze); + } + } +} + + +contract AdvancedToken is PausableToken { + + string public name = "Thailand Tourism Chain"; + string public symbol = "THTC"; + string public version = '3.0.0'; + uint8 public decimals = 18; + + + function AdvancedToken() { + totalSupply = 9 * 10000 * 10000 * (10**(uint256(decimals))); + balances[msg.sender] = totalSupply; + } + + function () external payable { + + revert(); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/440.sol b/benchmark2/integer overflow/440.sol new file mode 100644 index 0000000000000000000000000000000000000000..54fa15d0875789ed2a26c78cbb6705b16282d24b --- /dev/null +++ b/benchmark2/integer overflow/440.sol @@ -0,0 +1,106 @@ +pragma solidity 0.4.24; + +contract ERC20 { + function totalSupply() constant public returns (uint256 supply); + function balanceOf(address _owner) constant public returns (uint256 balance); + function transfer(address _to, uint256 _value) public returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); + function approve(address _spender, uint256 _value) public returns (bool success); + function allowance(address _owner, address _spender) constant public returns (uint256 remaining); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +library SafeMath { + function safeSub(uint a, uint b) internal pure returns (uint) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint a, uint b) internal pure returns (uint) { + uint c = a + b; + assert(c >= a); + return c; + } +} + +contract EmanateToken is ERC20 { + + using SafeMath for uint256; + + string public constant name = "Emanate (MN8) Token"; + string public constant symbol = "MN8"; + uint256 public constant decimals = 18; + uint256 public constant totalTokens = 208000000 * (10 ** decimals); + + mapping (address => uint256) public balances; + mapping (address => mapping (address => uint256)) public allowed; + + bool public locked = true; + bool public burningEnabled = false; + address public owner; + address public burnAddress; + + modifier unlocked (address _to) { + require( + owner == msg.sender || + locked == false || + allowance(owner, msg.sender) > 0 || + (_to == burnAddress && burningEnabled == true) + ); + _; + } + + constructor () public { + balances[msg.sender] = totalTokens; + owner = msg.sender; + } + + function totalSupply() public view returns (uint256) { + return totalTokens; + } + + + function transfer(address _to, uint _tokens) unlocked(_to) public returns (bool success) { + balances[msg.sender] = balances[msg.sender].safeSub(_tokens); + balances[_to] = balances[_to].safeAdd(_tokens); + emit Transfer(msg.sender, _to, _tokens); + return true; + } + + function transferFrom(address from, address _to, uint _tokens) unlocked(_to) public returns (bool success) { + balances[from] = balances[from].safeSub(_tokens); + allowed[from][msg.sender] = allowed[from][msg.sender].safeSub(_tokens); + balances[_to] = balances[_to].safeAdd(_tokens); + emit Transfer(from, _to, _tokens); + return true; + } + + function balanceOf(address _owner) constant public returns (uint256) { + return balances[_owner]; + } + + + function approve(address _spender, uint256 _value) unlocked(_spender) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) constant public returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + function setBurnAddress (address _burnAddress) public { + require(msg.sender == owner); + burningEnabled = true; + burnAddress = _burnAddress; + } + + function unlock () public { + require(msg.sender == owner); + locked = false; + owner = 0x0000000000000000000000000000000000000001; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/451.sol b/benchmark2/integer overflow/451.sol new file mode 100644 index 0000000000000000000000000000000000000000..d5b1fef59667c5bb4150a06fa1dfaefca5f91296 --- /dev/null +++ b/benchmark2/integer overflow/451.sol @@ -0,0 +1,115 @@ +pragma solidity ^0.4.10; + + +contract SafeMath { + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + +} + + + +contract StandardToken is Token , SafeMath { + + bool public status = true; + modifier on() { + require(status == true); + _; + } + + function transfer(address _to, uint256 _value) on returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0 && _to != 0X0) { + balances[msg.sender] -= _value; + balances[_to] = safeAdd(balances[_to],_value); + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) on returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] = safeAdd(balances[_to],_value); + balances[_from] = safeSubtract(balances[_from],_value); + allowed[_from][msg.sender] = safeSubtract(allowed[_from][msg.sender],_value); + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) on constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) on returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) on constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + + + + +contract HuobiPoolToken is StandardToken { + string public name = "HuobiPoolToken"; + uint8 public decimals = 8; + string public symbol = "HPT"; + bool private init =true; + function turnon() controller { + status = true; + } + function turnoff() controller { + status = false; + } + function HuobiPoolToken() { + require(init==true); + totalSupply = 100000000000; + balances[0x3567cafb8bf2a83bbea4e79f3591142fb4ebe86d] = totalSupply; + init = false; + } + address public controller1 =0x14de73a5602ee3769fb7a968daAFF23A4A6D4Bb5; + address public controller2 =0x3567cafb8bf2a83bbea4e79f3591142fb4ebe86d; + + modifier controller () { + require(msg.sender == controller1||msg.sender == controller2); + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/453.sol b/benchmark2/integer overflow/453.sol new file mode 100644 index 0000000000000000000000000000000000000000..b3f8e3352e2b475210879f8fe1a63d8b12282814 --- /dev/null +++ b/benchmark2/integer overflow/453.sol @@ -0,0 +1,152 @@ +pragma solidity ^0.4.17; + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract DAPL is StandardToken { + + string public name = "DAPL"; + + string public symbol = "DAPL"; + + uint8 public decimals = 8; + + uint public INITIAL_SUPPLY = 1000000000e8; + + constructor() public { + + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/462.sol b/benchmark2/integer overflow/462.sol new file mode 100644 index 0000000000000000000000000000000000000000..95f17fd629a099edcdf4654ac779810d49e0fee0 --- /dev/null +++ b/benchmark2/integer overflow/462.sol @@ -0,0 +1,398 @@ +pragma solidity ^0.4.24; + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + modifier hasMintPermission() { + require(msg.sender == owner); + _; + } + + + function mint( + address _to, + uint256 _amount + ) + hasMintPermission + canMint + public + returns (bool) + { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() onlyOwner canMint public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + + +contract ApprovalAndCallFallBack { + function receiveApproval(address _owner, uint256 _amount, address _token, bytes _data) public returns (bool); +} + + + +contract TransferAndCallFallBack { + function receiveToken(address _owner, uint256 _amount, address _token, bytes _data) public returns (bool); +} + + + +contract MuzikaCoin is MintableToken, Pausable { + string public name = 'Muzika'; + string public symbol = 'MZK'; + uint8 public decimals = 18; + + event Burn(address indexed burner, uint256 value); + + constructor(uint256 initialSupply) public { + totalSupply_ = initialSupply; + balances[msg.sender] = initialSupply; + emit Transfer(address(0), msg.sender, initialSupply); + } + + + function burn(uint256 _value) public onlyOwner { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } + + function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transferFrom(_from, _to, _value); + } + + function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public returns (bool) { + require(_spender != address(this)); + + increaseApproval(_spender, _addedValue); + + require( + ApprovalAndCallFallBack(_spender).receiveApproval( + msg.sender, + _addedValue, + address(this), + _data + ) + ); + + return true; + } + + function transferAndCall(address _to, uint _value, bytes _data) public returns (bool) { + require(_to != address(this)); + + transfer(_to, _value); + + require( + TransferAndCallFallBack(_to).receiveToken( + msg.sender, + _value, + address(this), + _data + ) + ); + + return true; + } + + function tokenDrain(ERC20 _token, uint256 _amount) public onlyOwner { + _token.transfer(owner, _amount); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/465.sol b/benchmark2/integer overflow/465.sol new file mode 100644 index 0000000000000000000000000000000000000000..b7b711f74d06588735bdd49b5242037746ba7e80 --- /dev/null +++ b/benchmark2/integer overflow/465.sol @@ -0,0 +1,115 @@ +pragma solidity ^0.4.10; + + +contract SafeMath { + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + +} + + + +contract StandardToken is Token , SafeMath { + + bool public status = true; + modifier on() { + require(status == true); + _; + } + + function transfer(address _to, uint256 _value) on returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0 && _to != 0X0) { + balances[msg.sender] -= _value; + balances[_to] = safeAdd(balances[_to],_value); + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) on returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] = safeAdd(balances[_to],_value); + balances[_from] = safeSubtract(balances[_from],_value); + allowed[_from][msg.sender] = safeSubtract(allowed[_from][msg.sender],_value); + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) on constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) on returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) on constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + + + + +contract ExShellToken is StandardToken { + string public name = "ExShellToken"; + uint8 public decimals = 8; + string public symbol = "ET"; + bool private init =true; + function turnon() controller { + status = true; + } + function turnoff() controller { + status = false; + } + function ExShellToken() { + require(init==true); + totalSupply = 2000000000; + balances[0xa089a405b1df71a6155705fb2bce87df2a86a9e4] = totalSupply; + init = false; + } + address public controller1 =0xa089a405b1df71a6155705fb2bce87df2a86a9e4; + address public controller2 =0x5aa64423529e43a53c7ea037a07f94abc0c3a111; + + modifier controller () { + require(msg.sender == controller1||msg.sender == controller2); + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/469.sol b/benchmark2/integer overflow/469.sol new file mode 100644 index 0000000000000000000000000000000000000000..6db15c38e4b26a2b99a0be2c484d8e7c41ffc2c6 --- /dev/null +++ b/benchmark2/integer overflow/469.sol @@ -0,0 +1,172 @@ +pragma solidity ^0.4.24; + + +library SafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return a / b; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20 { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); + + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +contract BasicToken is ERC20 { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract ShopCornToken is StandardToken { + + string public constant name = "ShopCornToken"; + string public constant symbol = "SHC"; + uint8 public constant decimals = 8; + + uint256 public constant INITIAL_SUPPLY = 2000000000 * (10 ** uint256(decimals)); + + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + emit Transfer(address(0), msg.sender, INITIAL_SUPPLY); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/480.sol b/benchmark2/integer overflow/480.sol new file mode 100644 index 0000000000000000000000000000000000000000..710858b3f17a2c472f0afcb16acbbf3d08bdb8d8 --- /dev/null +++ b/benchmark2/integer overflow/480.sol @@ -0,0 +1,195 @@ +pragma solidity ^0.4.23; + + +contract ERC20 { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); + + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +library SafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract MyanmarGoldToken is ERC20 { + using SafeMath for uint256; + + mapping(address => uint256) balances; + mapping (address => mapping (address => uint256)) internal allowed; + + uint256 totalSupply_; + string public constant name = "MyanmarGoldToken"; + string public constant symbol = "MGC"; + uint8 public constant decimals = 18; + + event Burn(address indexed burner, uint256 value); + + constructor(address _icoAddress) public { + totalSupply_ = 1000000000 * (10 ** uint256(decimals)); + balances[_icoAddress] = totalSupply_; + emit Transfer(address(0), _icoAddress, totalSupply_); + } + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function batchTransfer(address[] _tos, uint256[] _values) public returns (bool) { + require(_tos.length == _values.length); + uint256 arrayLength = _tos.length; + for(uint256 i = 0; i < arrayLength; i++) { + transfer(_tos[i], _values[i]); + } + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/508.sol b/benchmark2/integer overflow/508.sol new file mode 100644 index 0000000000000000000000000000000000000000..280fc54cfb2d4abe6bf9dc4ad3acacedabba95e2 --- /dev/null +++ b/benchmark2/integer overflow/508.sol @@ -0,0 +1,1089 @@ +pragma solidity ^0.4.23; + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + require(c / a == b, "Overflow - Multiplication"); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + require(b <= a, "Underflow - Subtraction"); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + require(c >= a, "Overflow - Addition"); + return c; + } +} + +library Contract { + + using SafeMath for uint; + + + + + modifier conditions(function () pure first, function () pure last) { + first(); + _; + last(); + } + + bytes32 internal constant EXEC_PERMISSIONS = keccak256('script_exec_permissions'); + + + + + + + + + + function authorize(address _script_exec) internal view { + + initialize(); + + + bytes32 perms = EXEC_PERMISSIONS; + bool authorized; + assembly { + + mstore(0, _script_exec) + mstore(0x20, perms) + + mstore(0, keccak256(0x0c, 0x34)) + + mstore(0x20, mload(0x80)) + + authorized := sload(keccak256(0, 0x40)) + } + if (!authorized) + revert("Sender is not authorized as a script exec address"); + } + + + + + + + + + + + function initialize() internal view { + + + require(freeMem() == 0x80, "Memory allocated prior to execution"); + + assembly { + mstore(0x80, sload(0)) + mstore(0xa0, sload(1)) + mstore(0xc0, 0) + mstore(0xe0, 0) + mstore(0x100, 0) + mstore(0x120, 0) + mstore(0x140, 0) + mstore(0x160, 0) + + + mstore(0x40, 0x180) + } + + assert(execID() != bytes32(0) && sender() != address(0)); + } + + + + function checks(function () view _check) conditions(validState, validState) internal view { + _check(); + } + + + + function checks(function () pure _check) conditions(validState, validState) internal pure { + _check(); + } + + + + function commit() conditions(validState, none) internal pure { + + bytes32 ptr = buffPtr(); + require(ptr >= 0x180, "Invalid buffer pointer"); + + assembly { + + let size := mload(add(0x20, ptr)) + mstore(ptr, 0x20) + + revert(ptr, add(0x40, size)) + } + } + + + + + function validState() private pure { + if (freeMem() < 0x180) + revert('Expected Contract.execute()'); + + if (buffPtr() != 0 && buffPtr() < 0x180) + revert('Invalid buffer pointer'); + + assert(execID() != bytes32(0) && sender() != address(0)); + } + + + function buffPtr() private pure returns (bytes32 ptr) { + assembly { ptr := mload(0xc0) } + } + + + function freeMem() private pure returns (bytes32 ptr) { + assembly { ptr := mload(0x40) } + } + + + function currentAction() private pure returns (bytes4 action) { + if (buffPtr() == bytes32(0)) + return bytes4(0); + + assembly { action := mload(0xe0) } + } + + + function isStoring() private pure { + if (currentAction() != STORES) + revert('Invalid current action - expected STORES'); + } + + + function isEmitting() private pure { + if (currentAction() != EMITS) + revert('Invalid current action - expected EMITS'); + } + + + function isPaying() private pure { + if (currentAction() != PAYS) + revert('Invalid current action - expected PAYS'); + } + + + function startBuffer() private pure { + assembly { + + let ptr := msize() + mstore(0xc0, ptr) + + mstore(ptr, 0) + mstore(add(0x20, ptr), 0) + + mstore(0x40, add(0x40, ptr)) + + mstore(0x100, 1) + } + } + + + function validStoreBuff() private pure { + + if (buffPtr() == bytes32(0)) + startBuffer(); + + + + if (stored() != 0 || currentAction() == STORES) + revert('Duplicate request - stores'); + } + + + function validEmitBuff() private pure { + + if (buffPtr() == bytes32(0)) + startBuffer(); + + + + if (emitted() != 0 || currentAction() == EMITS) + revert('Duplicate request - emits'); + } + + + function validPayBuff() private pure { + + if (buffPtr() == bytes32(0)) + startBuffer(); + + + + if (paid() != 0 || currentAction() == PAYS) + revert('Duplicate request - pays'); + } + + + function none() private pure { } + + + + + function execID() internal pure returns (bytes32 exec_id) { + assembly { exec_id := mload(0x80) } + require(exec_id != bytes32(0), "Execution id overwritten, or not read"); + } + + + function sender() internal pure returns (address addr) { + assembly { addr := mload(0xa0) } + require(addr != address(0), "Sender address overwritten, or not read"); + } + + + + + + function read(bytes32 _location) internal view returns (bytes32 data) { + data = keccak256(_location, execID()); + assembly { data := sload(data) } + } + + + + bytes4 internal constant EMITS = bytes4(keccak256('Emit((bytes32[],bytes)[])')); + bytes4 internal constant STORES = bytes4(keccak256('Store(bytes32[])')); + bytes4 internal constant PAYS = bytes4(keccak256('Pay(bytes32[])')); + bytes4 internal constant THROWS = bytes4(keccak256('Error(string)')); + + + enum NextFunction { + INVALID, NONE, STORE_DEST, VAL_SET, VAL_INC, VAL_DEC, EMIT_LOG, PAY_DEST, PAY_AMT + } + + + function validStoreDest() private pure { + + if (expected() != NextFunction.STORE_DEST) + revert('Unexpected function order - expected storage destination to be pushed'); + + + isStoring(); + } + + + function validStoreVal() private pure { + + if ( + expected() != NextFunction.VAL_SET && + expected() != NextFunction.VAL_INC && + expected() != NextFunction.VAL_DEC + ) revert('Unexpected function order - expected storage value to be pushed'); + + + isStoring(); + } + + + function validPayDest() private pure { + + if (expected() != NextFunction.PAY_DEST) + revert('Unexpected function order - expected payment destination to be pushed'); + + + isPaying(); + } + + + function validPayAmt() private pure { + + if (expected() != NextFunction.PAY_AMT) + revert('Unexpected function order - expected payment amount to be pushed'); + + + isPaying(); + } + + + function validEvent() private pure { + + if (expected() != NextFunction.EMIT_LOG) + revert('Unexpected function order - expected event to be pushed'); + + + isEmitting(); + } + + + + function storing() conditions(validStoreBuff, isStoring) internal pure { + bytes4 action_req = STORES; + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), action_req) + + mstore(add(0x24, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x24, mload(ptr))) + + mstore(0xe0, action_req) + + mstore(0x100, 2) + + mstore(sub(ptr, 0x20), add(ptr, mload(ptr))) + } + + setFreeMem(); + } + + + function set(bytes32 _field) conditions(validStoreDest, validStoreVal) internal pure returns (bytes32) { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _field) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 3) + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x120, add(1, mload(0x120))) + } + + setFreeMem(); + return _field; + } + + + function to(bytes32, bytes32 _val) conditions(validStoreVal, validStoreDest) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _val) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 2) + } + + setFreeMem(); + } + + + function to(bytes32 _field, uint _val) internal pure { + to(_field, bytes32(_val)); + } + + + function to(bytes32 _field, address _val) internal pure { + to(_field, bytes32(_val)); + } + + + function to(bytes32 _field, bool _val) internal pure { + to( + _field, + _val ? bytes32(1) : bytes32(0) + ); + } + + function increase(bytes32 _field) conditions(validStoreDest, validStoreVal) internal view returns (bytes32 val) { + + val = keccak256(_field, execID()); + assembly { + val := sload(val) + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _field) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 4) + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x120, add(1, mload(0x120))) + } + + setFreeMem(); + return val; + } + + function decrease(bytes32 _field) conditions(validStoreDest, validStoreVal) internal view returns (bytes32 val) { + + val = keccak256(_field, execID()); + assembly { + val := sload(val) + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _field) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 5) + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x120, add(1, mload(0x120))) + } + + setFreeMem(); + return val; + } + + function by(bytes32 _val, uint _amt) conditions(validStoreVal, validStoreDest) internal pure { + + + if (expected() == NextFunction.VAL_INC) + _amt = _amt.add(uint(_val)); + else if (expected() == NextFunction.VAL_DEC) + _amt = uint(_val).sub(_amt); + else + revert('Expected VAL_INC or VAL_DEC'); + + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _amt) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 2) + } + + setFreeMem(); + } + + + function byMaximum(bytes32 _val, uint _amt) conditions(validStoreVal, validStoreDest) internal pure { + + + if (expected() == NextFunction.VAL_DEC) { + if (_amt >= uint(_val)) + _amt = 0; + else + _amt = uint(_val).sub(_amt); + } else { + revert('Expected VAL_DEC'); + } + + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _amt) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 2) + } + + setFreeMem(); + } + + + + function emitting() conditions(validEmitBuff, isEmitting) internal pure { + bytes4 action_req = EMITS; + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), action_req) + + mstore(add(0x24, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x24, mload(ptr))) + + mstore(0xe0, action_req) + + mstore(0x100, 6) + + mstore(sub(ptr, 0x20), add(ptr, mload(ptr))) + } + + setFreeMem(); + } + + function log(bytes32 _data) conditions(validEvent, validEvent) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), 0) + + if eq(_data, 0) { + mstore(add(0x40, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x40, mload(ptr))) + } + + if iszero(eq(_data, 0)) { + + mstore(add(0x40, add(ptr, mload(ptr))), 0x20) + + mstore(add(0x60, add(ptr, mload(ptr))), _data) + + mstore(ptr, add(0x60, mload(ptr))) + } + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x140, add(1, mload(0x140))) + } + + setFreeMem(); + } + + function log(bytes32[1] memory _topics, bytes32 _data) conditions(validEvent, validEvent) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), 1) + + mstore(add(0x40, add(ptr, mload(ptr))), mload(_topics)) + + if eq(_data, 0) { + mstore(add(0x60, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x60, mload(ptr))) + } + + if iszero(eq(_data, 0)) { + + mstore(add(0x60, add(ptr, mload(ptr))), 0x20) + + mstore(add(0x80, add(ptr, mload(ptr))), _data) + + mstore(ptr, add(0x80, mload(ptr))) + } + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x140, add(1, mload(0x140))) + } + + setFreeMem(); + } + + function log(bytes32[2] memory _topics, bytes32 _data) conditions(validEvent, validEvent) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), 2) + + mstore(add(0x40, add(ptr, mload(ptr))), mload(_topics)) + mstore(add(0x60, add(ptr, mload(ptr))), mload(add(0x20, _topics))) + + if eq(_data, 0) { + mstore(add(0x80, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x80, mload(ptr))) + } + + if iszero(eq(_data, 0)) { + + mstore(add(0x80, add(ptr, mload(ptr))), 0x20) + + mstore(add(0xa0, add(ptr, mload(ptr))), _data) + + mstore(ptr, add(0xa0, mload(ptr))) + } + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x140, add(1, mload(0x140))) + } + + setFreeMem(); + } + + function log(bytes32[3] memory _topics, bytes32 _data) conditions(validEvent, validEvent) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), 3) + + mstore(add(0x40, add(ptr, mload(ptr))), mload(_topics)) + mstore(add(0x60, add(ptr, mload(ptr))), mload(add(0x20, _topics))) + mstore(add(0x80, add(ptr, mload(ptr))), mload(add(0x40, _topics))) + + if eq(_data, 0) { + mstore(add(0xa0, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0xa0, mload(ptr))) + } + + if iszero(eq(_data, 0)) { + + mstore(add(0xa0, add(ptr, mload(ptr))), 0x20) + + mstore(add(0xc0, add(ptr, mload(ptr))), _data) + + mstore(ptr, add(0xc0, mload(ptr))) + } + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x140, add(1, mload(0x140))) + } + + setFreeMem(); + } + + function log(bytes32[4] memory _topics, bytes32 _data) conditions(validEvent, validEvent) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), 4) + + mstore(add(0x40, add(ptr, mload(ptr))), mload(_topics)) + mstore(add(0x60, add(ptr, mload(ptr))), mload(add(0x20, _topics))) + mstore(add(0x80, add(ptr, mload(ptr))), mload(add(0x40, _topics))) + mstore(add(0xa0, add(ptr, mload(ptr))), mload(add(0x60, _topics))) + + if eq(_data, 0) { + mstore(add(0xc0, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0xc0, mload(ptr))) + } + + if iszero(eq(_data, 0)) { + + mstore(add(0xc0, add(ptr, mload(ptr))), 0x20) + + mstore(add(0xe0, add(ptr, mload(ptr))), _data) + + mstore(ptr, add(0xe0, mload(ptr))) + } + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x140, add(1, mload(0x140))) + } + + setFreeMem(); + } + + + + function paying() conditions(validPayBuff, isPaying) internal pure { + bytes4 action_req = PAYS; + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), action_req) + + mstore(add(0x24, add(ptr, mload(ptr))), 0) + + mstore(ptr, add(0x24, mload(ptr))) + + mstore(0xe0, action_req) + + mstore(0x100, 8) + + mstore(sub(ptr, 0x20), add(ptr, mload(ptr))) + } + + setFreeMem(); + } + + + function pay(uint _amount) conditions(validPayAmt, validPayDest) internal pure returns (uint) { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _amount) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 7) + + mstore( + mload(sub(ptr, 0x20)), + add(1, mload(mload(sub(ptr, 0x20)))) + ) + + mstore(0x160, add(1, mload(0x160))) + } + + setFreeMem(); + return _amount; + } + + + function toAcc(uint, address _dest) conditions(validPayDest, validPayAmt) internal pure { + assembly { + + let ptr := add(0x20, mload(0xc0)) + + mstore(add(0x20, add(ptr, mload(ptr))), _dest) + + mstore(ptr, add(0x20, mload(ptr))) + + mstore(0x100, 8) + } + + setFreeMem(); + } + + + function setFreeMem() private pure { + assembly { mstore(0x40, msize) } + } + + + function expected() private pure returns (NextFunction next) { + assembly { next := mload(0x100) } + } + + + function emitted() internal pure returns (uint num_emitted) { + if (buffPtr() == bytes32(0)) + return 0; + + + assembly { num_emitted := mload(0x140) } + } + + + function stored() internal pure returns (uint num_stored) { + if (buffPtr() == bytes32(0)) + return 0; + + + assembly { num_stored := mload(0x120) } + } + + + function paid() internal pure returns (uint num_paid) { + if (buffPtr() == bytes32(0)) + return 0; + + + assembly { num_paid := mload(0x160) } + } +} + +library Provider { + + using Contract for *; + + + function appIndex() internal pure returns (bytes32) + { return keccak256('index'); } + + + function execPermissions(address _exec) internal pure returns (bytes32) + { return keccak256(_exec, keccak256('script_exec_permissions')); } + + + function appSelectors(bytes4 _selector) internal pure returns (bytes32) + { return keccak256(_selector, 'implementation'); } + + + function registeredApps() internal pure returns (bytes32) + { return keccak256(bytes32(Contract.sender()), 'app_list'); } + + + function appBase(bytes32 _app) internal pure returns (bytes32) + { return keccak256(_app, keccak256(bytes32(Contract.sender()), 'app_base')); } + + + function appVersionList(bytes32 _app) internal pure returns (bytes32) + { return keccak256('versions', appBase(_app)); } + + + function versionBase(bytes32 _app, bytes32 _version) internal pure returns (bytes32) + { return keccak256(_version, 'version', appBase(_app)); } + + + function versionIndex(bytes32 _app, bytes32 _version) internal pure returns (bytes32) + { return keccak256('index', versionBase(_app, _version)); } + + + function versionSelectors(bytes32 _app, bytes32 _version) internal pure returns (bytes32) + { return keccak256('selectors', versionBase(_app, _version)); } + + + function versionAddresses(bytes32 _app, bytes32 _version) internal pure returns (bytes32) + { return keccak256('addresses', versionBase(_app, _version)); } + + + function previousVersion(bytes32 _app, bytes32 _version) internal pure returns (bytes32) + { return keccak256("previous version", versionBase(_app, _version)); } + + + function appVersionListAt(bytes32 _app, uint _index) internal pure returns (bytes32) + { return bytes32((32 * _index) + uint(appVersionList(_app))); } + + + function registerApp(bytes32 _app, address _index, bytes4[] _selectors, address[] _implementations) external view { + + Contract.authorize(msg.sender); + + + if (Contract.read(appBase(_app)) != bytes32(0)) + revert("app is already registered"); + + if (_selectors.length != _implementations.length || _selectors.length == 0) + revert("invalid input arrays"); + + + Contract.storing(); + + + uint num_registered_apps = uint(Contract.read(registeredApps())); + + Contract.increase(registeredApps()).by(uint(1)); + + Contract.set( + bytes32(32 * (num_registered_apps + 1) + uint(registeredApps())) + ).to(_app); + + + Contract.set(appBase(_app)).to(_app); + + + Contract.set(versionBase(_app, _app)).to(_app); + + + Contract.set(appVersionList(_app)).to(uint(1)); + + Contract.set( + bytes32(32 + uint(appVersionList(_app))) + ).to(_app); + + + Contract.set(versionIndex(_app, _app)).to(_index); + + + + Contract.set(versionSelectors(_app, _app)).to(_selectors.length); + Contract.set(versionAddresses(_app, _app)).to(_implementations.length); + for (uint i = 0; i < _selectors.length; i++) { + Contract.set(bytes32(32 * (i + 1) + uint(versionSelectors(_app, _app)))).to(_selectors[i]); + Contract.set(bytes32(32 * (i + 1) + uint(versionAddresses(_app, _app)))).to(_implementations[i]); + } + + + Contract.set(previousVersion(_app, _app)).to(uint(0)); + + + Contract.commit(); + } + + function registerAppVersion(bytes32 _app, bytes32 _version, address _index, bytes4[] _selectors, address[] _implementations) external view { + + Contract.authorize(msg.sender); + + + + if (Contract.read(appBase(_app)) == bytes32(0)) + revert("App has not been registered"); + + if (Contract.read(versionBase(_app, _version)) != bytes32(0)) + revert("Version already exists"); + + if ( + _selectors.length != _implementations.length || + _selectors.length == 0 + ) revert("Invalid input array lengths"); + + + Contract.storing(); + + + Contract.set(versionBase(_app, _version)).to(_version); + + + uint num_versions = uint(Contract.read(appVersionList(_app))); + Contract.set(appVersionListAt(_app, (num_versions + 1))).to(_version); + Contract.set(appVersionList(_app)).to(num_versions + 1); + + + Contract.set(versionIndex(_app, _version)).to(_index); + + + + Contract.set(versionSelectors(_app, _version)).to(_selectors.length); + Contract.set(versionAddresses(_app, _version)).to(_implementations.length); + for (uint i = 0; i < _selectors.length; i++) { + Contract.set(bytes32(32 * (i + 1) + uint(versionSelectors(_app, _version)))).to(_selectors[i]); + Contract.set(bytes32(32 * (i + 1) + uint(versionAddresses(_app, _version)))).to(_implementations[i]); + } + + + bytes32 prev_version = Contract.read(bytes32(32 * num_versions + uint(appVersionList(_app)))); + Contract.set(previousVersion(_app, _version)).to(prev_version); + + + Contract.commit(); + } + + + function updateInstance(bytes32 _app_name, bytes32 _current_version, bytes32 _registry_id) external view { + + Contract.authorize(msg.sender); + + + require(_app_name != 0 && _current_version != 0 && _registry_id != 0, 'invalid input'); + + + bytes4[] memory current_selectors = getVersionSelectors(_app_name, _current_version, _registry_id); + require(current_selectors.length != 0, 'invalid current version'); + + + bytes32 latest_version = getLatestVersion(_app_name, _registry_id); + require(latest_version != _current_version, 'current version is already latest'); + require(latest_version != 0, 'invalid latest version'); + + + + address latest_idx = getVersionIndex(_app_name, latest_version, _registry_id); + bytes4[] memory latest_selectors = getVersionSelectors(_app_name, latest_version, _registry_id); + address[] memory latest_impl = getVersionImplementations(_app_name, latest_version, _registry_id); + require(latest_idx != 0, 'invalid version idx address'); + require(latest_selectors.length != 0 && latest_selectors.length == latest_impl.length, 'invalid implementation specification'); + + + Contract.storing(); + + + for (uint i = 0; i < current_selectors.length; i++) + Contract.set(appSelectors(current_selectors[i])).to(address(0)); + + + Contract.set(appIndex()).to(latest_idx); + + + for (i = 0; i < latest_selectors.length; i++) { + require(latest_selectors[i] != 0 && latest_impl[i] != 0, 'invalid input - expected nonzero implementation'); + Contract.set(appSelectors(latest_selectors[i])).to(latest_impl[i]); + } + + + Contract.commit(); + } + + + function updateExec(address _new_exec_addr) external view { + + Contract.authorize(msg.sender); + + + require(_new_exec_addr != 0, 'invalid replacement'); + + + Contract.storing(); + + + Contract.set(execPermissions(msg.sender)).to(false); + + + Contract.set(execPermissions(_new_exec_addr)).to(true); + + + Contract.commit(); + } + + + + function registryRead(bytes32 _location, bytes32 _registry_id) internal view returns (bytes32 value) { + _location = keccak256(_location, _registry_id); + assembly { value := sload(_location) } + } + + + + + function getLatestVersion(bytes32 _app, bytes32 _registry_id) internal view returns (bytes32) { + uint length = uint(registryRead(appVersionList(_app), _registry_id)); + + return registryRead(appVersionListAt(_app, length), _registry_id); + } + + + function getVersionIndex(bytes32 _app, bytes32 _version, bytes32 _registry_id) internal view returns (address) { + return address(registryRead(versionIndex(_app, _version), _registry_id)); + } + + + function getVersionImplementations(bytes32 _app, bytes32 _version, bytes32 _registry_id) internal view returns (address[] memory impl) { + + uint length = uint(registryRead(versionAddresses(_app, _version), _registry_id)); + + impl = new address[](length); + + for (uint i = 0; i < length; i++) { + bytes32 location = bytes32(32 * (i + 1) + uint(versionAddresses(_app, _version))); + impl[i] = address(registryRead(location, _registry_id)); + } + } + + + function getVersionSelectors(bytes32 _app, bytes32 _version, bytes32 _registry_id) internal view returns (bytes4[] memory sels) { + + uint length = uint(registryRead(versionSelectors(_app, _version), _registry_id)); + + sels = new bytes4[](length); + + for (uint i = 0; i < length; i++) { + bytes32 location = bytes32(32 * (i + 1) + uint(versionSelectors(_app, _version))); + sels[i] = bytes4(registryRead(location, _registry_id)); + } + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/528.sol b/benchmark2/integer overflow/528.sol new file mode 100644 index 0000000000000000000000000000000000000000..a7b23a74b9592d37033500a7b6436d34d5e178a9 --- /dev/null +++ b/benchmark2/integer overflow/528.sol @@ -0,0 +1,269 @@ +pragma solidity 0.4.21; + +contract Ownable { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Ownable() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public returns (bool) { + paused = true; + emit Pause(); + return true; + } + + + function unpause() onlyOwner whenPaused public returns (bool) { + paused = false; + emit Unpause(); + return true; + } +} + + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + + +contract ROC is ERC20Interface, Pausable { + using SafeMath for uint; + + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + function ROC() public { + symbol = "ROC"; + name = "NeoWorld Rare Ore C"; + decimals = 18; + _totalSupply = 10000000 * 10**uint(decimals); + balances[owner] = _totalSupply; + emit Transfer(address(0), owner, _totalSupply); + } + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public whenNotPaused returns (bool success) { + balances[msg.sender] = balances[msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + return true; + } + + function increaseApproval (address _spender, uint _addedValue) public whenNotPaused + returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public whenNotPaused + returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) { + balances[from] = balances[from].sub(tokens); + allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/548.sol b/benchmark2/integer overflow/548.sol new file mode 100644 index 0000000000000000000000000000000000000000..57be32de3817bb2223b34d554e6522867c6791c6 --- /dev/null +++ b/benchmark2/integer overflow/548.sol @@ -0,0 +1,259 @@ +pragma solidity ^0.4.23; + + + + + + + + +contract SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + + + +contract Token { + + function totalSupply() constant returns (uint256 supply); + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); +} + + + + +contract AbstractToken is Token, SafeMath { + + function AbstractToken () { + + } + + + function balanceOf(address _owner) constant returns (uint256 balance) { + return accounts [_owner]; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + if (accounts [msg.sender] < _value) return false; + if (_value > 0 && msg.sender != _to) { + accounts [msg.sender] = safeSub (accounts [msg.sender], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer (msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(_to != address(0)); + if (allowances [_from][msg.sender] < _value) return false; + if (accounts [_from] < _value) return false; + + if (_value > 0 && _from != _to) { + allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value); + accounts [_from] = safeSub (accounts [_from], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer(_from, _to, _value); + return true; + } + + + function approve (address _spender, uint256 _value) returns (bool success) { + allowances [msg.sender][_spender] = _value; + emit Approval (msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) constant + returns (uint256 remaining) { + return allowances [_owner][_spender]; + } + + + mapping (address => uint256) accounts; + + + mapping (address => mapping (address => uint256)) private allowances; + +} + + + +contract IDXToken is AbstractToken { + + + + uint256 constant MAX_TOKEN_COUNT = 50000000 * (10**18); + + + address private owner; + + + mapping (address => bool) private frozenAccount; + + + uint256 tokenCount = 0; + + + + bool frozen = false; + + + + function IDXToken () { + owner = msg.sender; + } + + + function totalSupply() constant returns (uint256 supply) { + return tokenCount; + } + + string constant public name = "INDEX TOKEN"; + string constant public symbol = "IDX"; + uint8 constant public decimals = 18; + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(!frozenAccount[msg.sender]); + if (frozen) return false; + else return AbstractToken.transfer (_to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(!frozenAccount[_from]); + if (frozen) return false; + else return AbstractToken.transferFrom (_from, _to, _value); + } + + + function approve (address _spender, uint256 _value) + returns (bool success) { + require(allowance (msg.sender, _spender) == 0 || _value == 0); + return AbstractToken.approve (_spender, _value); + } + + + function createTokens(uint256 _value) + returns (bool success) { + require (msg.sender == owner); + + if (_value > 0) { + if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false; + + accounts [msg.sender] = safeAdd (accounts [msg.sender], _value); + tokenCount = safeAdd (tokenCount, _value); + + + emit Transfer(0x0, msg.sender, _value); + + return true; + } + + return false; + + } + + + + function setOwner(address _newOwner) { + require (msg.sender == owner); + + owner = _newOwner; + } + + + function freezeTransfers () { + require (msg.sender == owner); + + if (!frozen) { + frozen = true; + emit Freeze (); + } + } + + + function unfreezeTransfers () { + require (msg.sender == owner); + + if (frozen) { + frozen = false; + emit Unfreeze (); + } + } + + + + + function refundTokens(address _token, address _refund, uint256 _value) { + require (msg.sender == owner); + require(_token != address(this)); + AbstractToken token = AbstractToken(_token); + token.transfer(_refund, _value); + emit RefundTokens(_token, _refund, _value); + } + + + function freezeAccount(address _target, bool freeze) { + require (msg.sender == owner); + require (msg.sender != _target); + frozenAccount[_target] = freeze; + emit FrozenFunds(_target, freeze); + } + + + event Freeze (); + + + event Unfreeze (); + + + + event FrozenFunds(address target, bool frozen); + + + + + + event RefundTokens(address _token, address _refund, uint256 _value); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/564.sol b/benchmark2/integer overflow/564.sol new file mode 100644 index 0000000000000000000000000000000000000000..018c645c08902895b8f67b9e48ba233e1ec37b0c --- /dev/null +++ b/benchmark2/integer overflow/564.sol @@ -0,0 +1 @@ +pragma solidity ^0.4.23;contract Ownable {address public owner;event OwnershipRenounced(address indexed previousOwner);event OwnershipTransferred(address indexed previousOwner,address indexed newOwner);constructor() public {owner = msg.sender;}modifier onlyOwner() {require(msg.sender == owner);_;}function transferOwnership(address newOwner) public onlyOwner {require(newOwner != address(0));emit OwnershipTransferred(owner, newOwner);owner = newOwner;}function renounceOwnership() public onlyOwner {emit OwnershipRenounced(owner);owner = address(0);}}library SafeMath {function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {if (a == 0) {return 0;}c = a * b;assert(c / a == b);return c;}function div(uint256 a, uint256 b) internal pure returns (uint256) {return a / b;}function sub(uint256 a, uint256 b) internal pure returns (uint256) {assert(b <= a);return a - b;}function add(uint256 a, uint256 b) internal pure returns (uint256 c) {c = a + b;assert(c >= a);return c;}}contract ERC20Basic {function totalSupply() public view returns (uint256);function balanceOf(address who) public view returns (uint256);function transfer(address to, uint256 value) public returns (bool);event Transfer(address indexed from, address indexed to, uint256 value);}contract ERC20 is ERC20Basic {function allowance(address owner, address spender) public view returns (uint256);function transferFrom(address from, address to, uint256 value) public returns(bool);function approve(address spender, uint256 value) public returns (bool);event Approval(address indexed owner, address indexed spender, uint256 value);}contract BasicToken is ERC20Basic {using SafeMath for uint256;mapping(address => uint256) balances;uint256 totalSupply_;function totalSupply() public view returns (uint256) {return totalSupply_;}function transfer(address _to, uint256 _value) public returns (bool) {require(_to != address(0));require(_value <= balances[msg.sender]);balances[msg.sender] = balances[msg.sender].sub(_value);balances[_to] = balances[_to].add(_value);emit Transfer(msg.sender, _to, _value);return true;}function balanceOf(address _owner) public view returns (uint256) {return balances[_owner];}}contract StandardToken is ERC20, BasicToken {mapping (address => mapping (address => uint256)) internal allowed;function transferFrom(address _from, address _to, uint256 _value) public returns(bool) {require(_to != address(0));require(_value <= balances[_from]);require(_value <= allowed[_from][msg.sender]);balances[_from] = balances[_from].sub(_value);balances[_to] = balances[_to].add(_value);allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);emit Transfer(_from, _to, _value);return true;}function approve(address _spender, uint256 _value) public returns (bool) {require((_value == 0 ) || (allowed[msg.sender][_spender] == 0));allowed[msg.sender][_spender] = _value;emit Approval(msg.sender, _spender, _value);return true;}function allowance(address _owner, address _spender) public view returns (uint256) {return allowed[_owner][_spender];}function increaseApproval(address _spender, uint _addedValue) public returns (bool){allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);return true;}function decreaseApproval(address _spender, uint _subtractedValue) public returns(bool) {uint oldValue = allowed[msg.sender][_spender];if (_subtractedValue > oldValue) {allowed[msg.sender][_spender] = 0;} else {allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);}emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);return true;}}contract TokenContract is StandardToken{string public constant name="bbb";string public constant symbol="BBBB"; uint8 public constant decimals=18;uint256 public constant INITIAL_SUPPLY=10000000000000000000000;uint256 public constant MAX_SUPPLY = 100 * 10000 * 10000 * (10 **uint256(decimals));constructor() TokenContract() public {totalSupply_ = INITIAL_SUPPLY;balances[msg.sender] = INITIAL_SUPPLY;emit Transfer(0x0, msg.sender, INITIAL_SUPPLY);}function() payable public {revert();}} \ No newline at end of file diff --git a/benchmark2/integer overflow/571.sol b/benchmark2/integer overflow/571.sol new file mode 100644 index 0000000000000000000000000000000000000000..d39193a0cd780efc6c06f6be3f95e2337fe40e3b --- /dev/null +++ b/benchmark2/integer overflow/571.sol @@ -0,0 +1,306 @@ +pragma solidity ^0.4.24; + + + +contract Owned { + address public owner; + + function Owned() public { + owner = msg.sender; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function setOwner(address _owner) onlyOwner public { + owner = _owner; + } +} + + +contract SafeMath { + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + assert(c >= _a); + return c; + } + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_a >= _b); + return _a - _b; + } + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a * _b; + assert(_a == 0 || c / _a == _b); + return c; + } +} + + +contract Token is SafeMath, Owned { + uint256 constant DAY_IN_SECONDS = 86400; + string public constant standard = "0.777"; + string public name = ""; + string public symbol = ""; + uint8 public decimals = 0; + uint256 public totalSupply = 0; + mapping (address => uint256) public balanceP; + mapping (address => mapping (address => uint256)) public allowance; + + mapping (address => uint256[]) public lockTime; + mapping (address => uint256[]) public lockValue; + mapping (address => uint256) public lockNum; + mapping (address => bool) public locker; + uint256 public later = 0; + uint256 public earlier = 0; + + + + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + event TransferredLocked(address indexed _from, address indexed _to, uint256 _time, uint256 _value); + event TokenUnlocked(address indexed _address, uint256 _value); + + + function Token(string _name, string _symbol, uint8 _decimals, uint256 _totalSupply) public { + require(bytes(_name).length > 0 && bytes(_symbol).length > 0); + + name = _name; + symbol = _symbol; + decimals = _decimals; + totalSupply = _totalSupply; + + balanceP[msg.sender] = _totalSupply; + + } + + + modifier validAddress(address _address) { + require(_address != 0x0); + _; + } + + + function addLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = true; + } + + function removeLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = false; + } + + + function setUnlockEarlier(uint256 _earlier) public onlyOwner { + earlier = add(earlier, _earlier); + } + + function setUnlockLater(uint256 _later) public onlyOwner { + later = add(later, _later); + } + + + function balanceUnlocked(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function balanceLocked(address _address) public view returns (uint256 _balance) { + _balance = 0; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) < add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function balanceOf(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function showTime(address _address) public view validAddress(_address) returns (uint256[] _time) { + uint i = 0; + uint256[] memory tempLockTime = new uint256[](lockNum[_address]); + while (i < lockNum[_address]) { + tempLockTime[i] = sub(add(lockTime[_address][i], later), earlier); + i++; + } + return tempLockTime; + } + + function showValue(address _address) public view validAddress(_address) returns (uint256[] _value) { + return lockValue[_address]; + } + + + function calcUnlock(address _address) private { + uint256 i = 0; + uint256 j = 0; + uint256[] memory currentLockTime; + uint256[] memory currentLockValue; + uint256[] memory newLockTime = new uint256[](lockNum[_address]); + uint256[] memory newLockValue = new uint256[](lockNum[_address]); + currentLockTime = lockTime[_address]; + currentLockValue = lockValue[_address]; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(currentLockTime[i], later)) { + balanceP[_address] = add(balanceP[_address], currentLockValue[i]); + + + emit TokenUnlocked(_address, currentLockValue[i]); + } else { + newLockTime[j] = currentLockTime[i]; + newLockValue[j] = currentLockValue[i]; + j++; + } + i++; + } + uint256[] memory trimLockTime = new uint256[](j); + uint256[] memory trimLockValue = new uint256[](j); + i = 0; + while (i < j) { + trimLockTime[i] = newLockTime[i]; + trimLockValue[i] = newLockValue[i]; + i++; + } + lockTime[_address] = trimLockTime; + lockValue[_address] = trimLockValue; + lockNum[_address] = j; + } + + + function transfer(address _to, uint256 _value) public validAddress(_to) returns (bool success) { + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + if (balanceP[msg.sender] >= _value && _value > 0) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + + function transferLocked(address _to, uint256[] _time, uint256[] _value) public validAddress(_to) returns (bool success) { + require(_value.length == _time.length); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[msg.sender] >= totalValue && totalValue > 0) { + i = 0; + while (i < _time.length) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + + emit TransferredLocked(msg.sender, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + + emit Transfer(msg.sender, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + + function transferLockedFrom(address _from, address _to, uint256[] _time, uint256[] _value) public + validAddress(_from) validAddress(_to) returns (bool success) { + require(locker[msg.sender]); + require(_value.length == _time.length); + + if (lockNum[_from] > 0) calcUnlock(_from); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[_from] >= totalValue && totalValue > 0) { + i = 0; + while (i < _time.length) { + balanceP[_from] = sub(balanceP[_from], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + + emit TransferredLocked(_from, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + + emit Transfer(_from, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + + function transferFrom(address _from, address _to, uint256 _value) public validAddress(_from) validAddress(_to) returns (bool success) { + if (lockNum[_from] > 0) calcUnlock(_from); + if (balanceP[_from] >= _value && _value > 0) { + allowance[_from][msg.sender] = sub(allowance[_from][msg.sender], _value); + balanceP[_from] = sub(balanceP[_from], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + + function approve(address _spender, uint256 _value) public validAddress(_spender) returns (bool success) { + require(_value == 0 || allowance[msg.sender][_spender] == 0); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function () public payable { + revert(); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/574.sol b/benchmark2/integer overflow/574.sol new file mode 100644 index 0000000000000000000000000000000000000000..e62b80470ed6fbd40246fd6b74b09f9c20e534f5 --- /dev/null +++ b/benchmark2/integer overflow/574.sol @@ -0,0 +1,269 @@ +pragma solidity ^0.4.21; + +contract Ownable { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Ownable() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public returns (bool) { + paused = true; + emit Pause(); + return true; + } + + + function unpause() onlyOwner whenPaused public returns (bool) { + paused = false; + emit Unpause(); + return true; + } +} + + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + + +contract ROA is ERC20Interface, Pausable { + using SafeMath for uint; + + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + function ROA() public { + symbol = "ROA"; + name = "NeoWorld Rare Ore A"; + decimals = 18; + _totalSupply = 10000000 * 10**uint(decimals); + balances[owner] = _totalSupply; + emit Transfer(address(0), owner, _totalSupply); + } + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public whenNotPaused returns (bool success) { + balances[msg.sender] = balances[msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + return true; + } + + function increaseApproval (address _spender, uint _addedValue) public whenNotPaused + returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public whenNotPaused + returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) { + balances[from] = balances[from].sub(tokens); + allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/575.sol b/benchmark2/integer overflow/575.sol new file mode 100644 index 0000000000000000000000000000000000000000..999f98b0189e84215327818bb49aeb5eab6a0a59 --- /dev/null +++ b/benchmark2/integer overflow/575.sol @@ -0,0 +1,270 @@ +pragma solidity ^0.4.21; + +contract Ownable { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Ownable() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public returns (bool) { + paused = true; + emit Pause(); + return true; + } + + + function unpause() onlyOwner whenPaused public returns (bool) { + paused = false; + emit Unpause(); + return true; + } +} + + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + + +contract ROB is ERC20Interface, Pausable { + using SafeMath for uint; + + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + function ROB() public { + symbol = "ROB"; + name = "NeoWorld Rare Ore B"; + decimals = 18; + _totalSupply = 10000000 * 10**uint(decimals); + balances[owner] = _totalSupply; + emit Transfer(address(0), owner, _totalSupply); + } + + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public whenNotPaused returns (bool success) { + balances[msg.sender] = balances[msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + return true; + } + + function increaseApproval (address _spender, uint _addedValue) public whenNotPaused + returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public whenNotPaused + returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) { + balances[from] = balances[from].sub(tokens); + allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); + balances[to] = balances[to].add(tokens); + emit Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) { + allowed[msg.sender][spender] = tokens; + emit Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/6.sol b/benchmark2/integer overflow/6.sol new file mode 100644 index 0000000000000000000000000000000000000000..7acbd9654cf24ad0ed521a403d3d065b44997724 --- /dev/null +++ b/benchmark2/integer overflow/6.sol @@ -0,0 +1,144 @@ +pragma solidity ^0.4.18; + + +contract SafeMath { + function safeMul(uint256 a, uint256 b) internal returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b) internal returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function assert(bool assertion) internal { + if (!assertion) { + throw; + } + } +} +contract REL is SafeMath{ + string public name; + string public symbol; + uint8 public decimals; + uint256 public totalSupply; + address public owner; + + + mapping (address => uint256) public balanceOf; + mapping (address => uint256) public freezeOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Burn(address indexed from, uint256 value); + + + event Freeze(address indexed from, uint256 value); + + + event Unfreeze(address indexed from, uint256 value); + + + function REL( + uint256 initialSupply, + string tokenName, + uint8 decimalUnits, + string tokenSymbol + ) { + balanceOf[msg.sender] = initialSupply; + totalSupply = initialSupply; + name = tokenName; + symbol = tokenSymbol; + decimals = decimalUnits; + owner = msg.sender; + } + + + function transfer(address _to, uint256 _value) { + if (_to == 0x0) throw; + if (_value <= 0) throw; + if (balanceOf[msg.sender] < _value) throw; + if (balanceOf[_to] + _value < balanceOf[_to]) throw; + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + Transfer(msg.sender, _to, _value); + } + + + function approve(address _spender, uint256 _value) + returns (bool success) { + if (_value <= 0) throw; + allowance[msg.sender][_spender] = _value; + return true; + } + + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + if (_to == 0x0) throw; + if (_value <= 0) throw; + if (balanceOf[_from] < _value) throw; + if (balanceOf[_to] + _value < balanceOf[_to]) throw; + if (_value > allowance[_from][msg.sender]) throw; + balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value); + Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) returns (bool success) { + if (balanceOf[msg.sender] < _value) throw; + if (_value <= 0) throw; + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + totalSupply = SafeMath.safeSub(totalSupply,_value); + Burn(msg.sender, _value); + return true; + } + + function freeze(uint256 _value) returns (bool success) { + if (balanceOf[msg.sender] < _value) throw; + if (_value <= 0) throw; + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); + Freeze(msg.sender, _value); + return true; + } + + function unfreeze(uint256 _value) returns (bool success) { + if (freezeOf[msg.sender] < _value) throw; + if (_value <= 0) throw; + freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); + balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value); + Unfreeze(msg.sender, _value); + return true; + } + + + function withdrawEther(uint256 amount) { + if(msg.sender != owner)throw; + owner.transfer(amount); + } + + + function() payable { + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/600.sol b/benchmark2/integer overflow/600.sol new file mode 100644 index 0000000000000000000000000000000000000000..1abcfb2a5973cc36a7ac2387742f7a8e7f39116d --- /dev/null +++ b/benchmark2/integer overflow/600.sol @@ -0,0 +1,154 @@ +pragma solidity ^0.4.24; + + +library SafeMath { + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(a >= b); + return a - b; + } + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract Owned { + address public owner; + + event OwnershipTransfered(address indexed owner); + + constructor() public { + owner = msg.sender; + emit OwnershipTransfered(owner); + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) onlyOwner public { + owner = newOwner; + emit OwnershipTransfered(owner); + } +} + + +contract ERC20Token { + using SafeMath for uint256; + + string public constant name = "Ansforce Intelligence Token"; + string public constant symbol = "AIT"; + uint8 public constant decimals = 18; + uint256 public totalSupply = 0; + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed from, uint256 value, address indexed to, bytes extraData); + + constructor() public { + } + + + function _transfer(address from, address to, uint256 value) internal { + + require(balanceOf[from] >= value); + + + require(balanceOf[to] + value > balanceOf[to]); + + + uint256 previousBalances = balanceOf[from].add(balanceOf[to]); + + balanceOf[from] = balanceOf[from].sub(value); + balanceOf[to] = balanceOf[to].add(value); + + emit Transfer(from, to, value); + + + assert(balanceOf[from].add(balanceOf[to]) == previousBalances); + } + + + function transfer(address to, uint256 value) public { + _transfer(msg.sender, to, value); + } + + + function transferFrom(address from, address to, uint256 value) public returns (bool success) { + require(value <= allowance[from][msg.sender]); + allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); + _transfer(from, to, value); + return true; + } + + + function approve(address spender, uint256 value, bytes extraData) public returns (bool success) { + allowance[msg.sender][spender] = value; + emit Approval(msg.sender, value, spender, extraData); + return true; + } +} + + +contract AnsforceIntelligenceToken is Owned, ERC20Token { + constructor() public { + } + + function init(uint256 _supply, address _vault) public onlyOwner { + require(totalSupply == 0); + require(_supply > 0); + require(_vault != address(0)); + totalSupply = _supply; + balanceOf[_vault] = totalSupply; + } + + + bool public stopped = false; + + modifier isRunning { + require (!stopped); + _; + } + + function transfer(address to, uint256 value) isRunning public { + ERC20Token.transfer(to, value); + } + + function stop() public onlyOwner { + stopped = true; + } + + function start() public onlyOwner { + stopped = false; + } + + + mapping (address => uint256) public freezeOf; + + + event Freeze(address indexed target, uint256 value); + + + event Unfreeze(address indexed target, uint256 value); + + function freeze(address target, uint256 _value) public onlyOwner returns (bool success) { + require( _value > 0 ); + balanceOf[target] = SafeMath.sub(balanceOf[target], _value); + freezeOf[target] = SafeMath.add(freezeOf[target], _value); + emit Freeze(target, _value); + return true; + } + + function unfreeze(address target, uint256 _value) public onlyOwner returns (bool success) { + require( _value > 0 ); + freezeOf[target] = SafeMath.sub(freezeOf[target], _value); + balanceOf[target] = SafeMath.add(balanceOf[target], _value); + emit Unfreeze(target, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/607.sol b/benchmark2/integer overflow/607.sol new file mode 100644 index 0000000000000000000000000000000000000000..21e92e92fb96ca4a0534307fc7f2dbd336b735d8 --- /dev/null +++ b/benchmark2/integer overflow/607.sol @@ -0,0 +1,311 @@ +pragma solidity ^0.4.21; + +// File: contracts/ownership/Ownable.sol + +/** + * @title Ownable + * @dev The Ownable contract has an owner address, and provides basic authorization control + * functions, this simplifies the implementation of "user permissions". + */ +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + /** + * @dev The Ownable constructor sets the original `owner` of the contract to the sender + * account. + */ + function Ownable() public { + owner = msg.sender; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + + /** + * @dev Allows the current owner to relinquish control of the contract. + */ + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } +} + +// File: contracts/math/SafeMath.sol + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + // assert(b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return a / b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +// File: contracts/token/ERC20/ERC20Basic.sol + +/** + * @title ERC20Basic + * @dev Simpler version of ERC20 interface + * @dev see https://github.com/ethereum/EIPs/issues/179 + */ +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +// File: contracts/token/ERC20/BasicToken.sol + +/** + * @title Basic token + * @dev Basic version of StandardToken, with no allowances. + */ +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + /** + * @dev total number of tokens in existence + */ + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + /** + * @dev transfer token for a specified address + * @param _to The address to transfer to. + * @param _value The amount to be transferred. + */ + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + /** + * @dev Gets the balance of the specified address. + * @param _owner The address to query the the balance of. + * @return An uint256 representing the amount owned by the passed address. + */ + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + +// File: contracts/token/ERC20/ERC20.sol + +/** + * @title ERC20 interface + * @dev see https://github.com/ethereum/EIPs/issues/20 + */ +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +// File: contracts/token/ERC20/StandardToken.sol + +/** + * @title Standard ERC20 token + * + * @dev Implementation of the basic standard token. + * @dev https://github.com/ethereum/EIPs/issues/20 + * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol + */ +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + /** + * @dev Transfer tokens from one address to another + * @param _from address The address which you want to send tokens from + * @param _to address The address which you want to transfer to + * @param _value uint256 the amount of tokens to be transferred + */ + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + /** + * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. + * + * Beware that changing an allowance with this method brings the risk that someone may use both the old + * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this + * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * @param _spender The address which will spend the funds. + * @param _value The amount of tokens to be spent. + */ + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + /** + * @dev Function to check the amount of tokens that an owner allowed to a spender. + * @param _owner address The address which owns the funds. + * @param _spender address The address which will spend the funds. + * @return A uint256 specifying the amount of tokens still available for the spender. + */ + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + /** + * @dev Increase the amount of tokens that an owner allowed to a spender. + * + * approve should be called when allowed[_spender] == 0. To increment + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _addedValue The amount of tokens to increase the allowance by. + */ + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + /** + * @dev Decrease the amount of tokens that an owner allowed to a spender. + * + * approve should be called when allowed[_spender] == 0. To decrement + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _subtractedValue The amount of tokens to decrease the allowance by. + */ + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract DubaiGreenBlockChain is StandardToken, Ownable { + // Constants + string public constant name = "Dubai Green BlockChain"; + string public constant symbol = "DGBC"; + uint8 public constant decimals = 4; + uint256 public constant INITIAL_SUPPLY = 1000000000 * (10 ** uint256(decimals)); + + + mapping(address => bool) touched; + + + function DubaiGreenBlockChain() public { + totalSupply_ = INITIAL_SUPPLY; + + + + balances[msg.sender] = INITIAL_SUPPLY; + emit Transfer(0x0, msg.sender, INITIAL_SUPPLY); + } + + function _transfer(address _from, address _to, uint _value) internal { + require (balances[_from] >= _value); // Check if the sender has enough + require (balances[_to] + _value > balances[_to]); // Check for overflows + + balances[_from] = balances[_from].sub(_value); // Subtract from the sender + balances[_to] = balances[_to].add(_value); // Add the same to the recipient + + emit Transfer(_from, _to, _value); + } + + + function safeWithdrawal(uint _value ) onlyOwner public { + if (_value == 0) + owner.transfer(address(this).balance); + else + owner.transfer(_value); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/609.sol b/benchmark2/integer overflow/609.sol new file mode 100644 index 0000000000000000000000000000000000000000..f4f796833e1a40a92b7801ce93e14bde5addd1ff --- /dev/null +++ b/benchmark2/integer overflow/609.sol @@ -0,0 +1,262 @@ +pragma solidity ^0.4.13; + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract ArtBlockchainToken is StandardToken, Ownable { + string public name = "Art Blockchain Token"; + string public symbol = "ARTCN"; + uint public decimals = 18; + uint internal INITIAL_SUPPLY = (10 ** 9) * (10 ** decimals); + + mapping(address => uint256) private userLockedTokens; + event Freeze(address indexed account, uint256 value); + event UnFreeze(address indexed account, uint256 value); + + + constructor(address _addressFounder) public { + totalSupply_ = INITIAL_SUPPLY; + balances[_addressFounder] = INITIAL_SUPPLY; + emit Transfer(0x0, _addressFounder, INITIAL_SUPPLY); + } + + function balance(address _owner) internal view returns (uint256 token) { + return balances[_owner].sub(userLockedTokens[_owner]); + } + + function lockedTokens(address _owner) public view returns (uint256 token) { + return userLockedTokens[_owner]; + } + + function freezeAccount(address _userAddress, uint256 _amount) onlyOwner public returns (bool success) { + require(balance(_userAddress) >= _amount); + userLockedTokens[_userAddress] = userLockedTokens[_userAddress].add(_amount); + emit Freeze(_userAddress, _amount); + return true; + } + + function unfreezeAccount(address _userAddress, uint256 _amount) onlyOwner public returns (bool success) { + require(userLockedTokens[_userAddress] >= _amount); + userLockedTokens[_userAddress] = userLockedTokens[_userAddress].sub(_amount); + emit UnFreeze(_userAddress, _amount); + return true; + } + + function transfer(address _to, uint256 _value) public returns (bool success) { + require(balance(msg.sender) >= _value); + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(balance(_from) >= _value); + return super.transferFrom(_from, _to, _value); + } + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/626.sol b/benchmark2/integer overflow/626.sol new file mode 100644 index 0000000000000000000000000000000000000000..60d4ca87d60ec52bce9fe122d4e5620bff41f492 --- /dev/null +++ b/benchmark2/integer overflow/626.sol @@ -0,0 +1,185 @@ +pragma solidity ^0.4.24; + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract VerityToken is StandardToken { + string public name = "VerityToken"; + string public symbol = "VTY"; + uint8 public decimals = 18; + uint public INITIAL_SUPPLY = 500000000 * 10 ** uint(decimals); + + function VerityToken() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/634.sol b/benchmark2/integer overflow/634.sol new file mode 100644 index 0000000000000000000000000000000000000000..19f6777aefc420d19ae6632b499cde700375355e --- /dev/null +++ b/benchmark2/integer overflow/634.sol @@ -0,0 +1,179 @@ +pragma solidity ^0.4.16; + +contract owned { + address public owner; + + function owned() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) onlyOwner public { + owner = newOwner; + } +} + +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } + +contract TokenERC20 { + + string public name; + string public symbol; + uint8 public decimals = 18; + + uint256 public totalSupply; + + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + event Burn(address indexed from, uint256 value); + + + function TokenERC20( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) public { + totalSupply = initialSupply * 10 ** uint256(decimals); + balanceOf[msg.sender] = totalSupply; + name = tokenName; + symbol = tokenSymbol; + } + + + function _transfer(address _from, address _to, uint _value) internal { + + require(_to != 0x0); + + require(balanceOf[_from] >= _value); + + require(balanceOf[_to] + _value > balanceOf[_to]); + + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + + balanceOf[_from] -= _value; + + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + _transfer(msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public + returns (bool success) { + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function approveAndCall(address _spender, uint256 _value, bytes _extraData) + public + returns (bool success) { + tokenRecipient spender = tokenRecipient(_spender); + if (approve(_spender, _value)) { + spender.receiveApproval(msg.sender, _value, this, _extraData); + return true; + } + } + + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + emit Burn(msg.sender, _value); + return true; + } + + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + emit Burn(_from, _value); + return true; + } +} + + + + + +contract INCRYPTHEDGE is owned, TokenERC20 { + + + + mapping (address => bool) public frozenAccount; + + + event FrozenFunds(address target, bool frozen); + + + function INCRYPTHEDGE( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {} + + + function _transfer(address _from, address _to, uint _value) internal { + require (_to != 0x0); + require (balanceOf[_from] >= _value); + require (balanceOf[_to] + _value >= balanceOf[_to]); + require(!frozenAccount[_from]); + require(!frozenAccount[_to]); + balanceOf[_from] -= _value; + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + } + + + + + function mintToken(address target, uint256 mintedAmount) onlyOwner public { + balanceOf[target] += mintedAmount; + totalSupply += mintedAmount; + emit Transfer(0, this, mintedAmount); + emit Transfer(this, target, mintedAmount); + } + + + + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/635.sol b/benchmark2/integer overflow/635.sol new file mode 100644 index 0000000000000000000000000000000000000000..5faed7b2626275257182787ceb1d4addff6e8a14 --- /dev/null +++ b/benchmark2/integer overflow/635.sol @@ -0,0 +1,179 @@ +pragma solidity ^0.4.16; + +contract owned { + address public owner; + + function owned() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) onlyOwner public { + owner = newOwner; + } +} + +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } + +contract TokenERC20 { + + string public name; + string public symbol; + uint8 public decimals = 18; + + uint256 public totalSupply; + + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + event Burn(address indexed from, uint256 value); + + + function TokenERC20( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) public { + totalSupply = initialSupply * 10 ** uint256(decimals); + balanceOf[msg.sender] = totalSupply; + name = tokenName; + symbol = tokenSymbol; + } + + + function _transfer(address _from, address _to, uint _value) internal { + + require(_to != 0x0); + + require(balanceOf[_from] >= _value); + + require(balanceOf[_to] + _value > balanceOf[_to]); + + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + + balanceOf[_from] -= _value; + + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + _transfer(msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public + returns (bool success) { + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function approveAndCall(address _spender, uint256 _value, bytes _extraData) + public + returns (bool success) { + tokenRecipient spender = tokenRecipient(_spender); + if (approve(_spender, _value)) { + spender.receiveApproval(msg.sender, _value, this, _extraData); + return true; + } + } + + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + emit Burn(msg.sender, _value); + return true; + } + + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + emit Burn(_from, _value); + return true; + } +} + + + + + +contract INCRYPT is owned, TokenERC20 { + + + + mapping (address => bool) public frozenAccount; + + + event FrozenFunds(address target, bool frozen); + + + function INCRYPT( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {} + + + function _transfer(address _from, address _to, uint _value) internal { + require (_to != 0x0); + require (balanceOf[_from] >= _value); + require (balanceOf[_to] + _value >= balanceOf[_to]); + require(!frozenAccount[_from]); + require(!frozenAccount[_to]); + balanceOf[_from] -= _value; + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + } + + + + + function mintToken(address target, uint256 mintedAmount) onlyOwner public { + balanceOf[target] += mintedAmount; + totalSupply += mintedAmount; + emit Transfer(0, this, mintedAmount); + emit Transfer(this, target, mintedAmount); + } + + + + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/638.sol b/benchmark2/integer overflow/638.sol new file mode 100644 index 0000000000000000000000000000000000000000..08ef0dc5d424c04a31ab8432fd675013c7bf1833 --- /dev/null +++ b/benchmark2/integer overflow/638.sol @@ -0,0 +1,153 @@ +pragma solidity ^0.4.24; + + +contract SafeMath { + function safeMul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + +} + +contract AMeiToken is SafeMath { + address public owner; + string public name; + string public symbol; + uint public decimals; + uint256 public totalSupply; + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + event Transfer(address indexed from, address indexed to, uint256 value); + event Burn(address indexed from, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); + + mapping (address => bool) public frozenAccount; + event FrozenFunds(address target, bool frozen); + + bool lock = false; + + constructor( + uint256 initialSupply, + string tokenName, + string tokenSymbol, + uint decimalUnits + ) public { + owner = msg.sender; + name = tokenName; + symbol = tokenSymbol; + decimals = decimalUnits; + totalSupply = initialSupply * 10 ** uint256(decimals); + balanceOf[msg.sender] = totalSupply; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + modifier isLock { + require(!lock); + _; + } + + function setLock(bool _lock) onlyOwner public{ + lock = _lock; + } + + function transferOwnership(address newOwner) onlyOwner public { + if (newOwner != address(0)) { + owner = newOwner; + } + } + + + function _transfer(address _from, address _to, uint _value) isLock internal { + require (_to != 0x0); + require (balanceOf[_from] >= _value); + require (balanceOf[_to] + _value > balanceOf[_to]); + require(!frozenAccount[_from]); + require(!frozenAccount[_to]); + balanceOf[_from] -= _value; + balanceOf[_to] += _value; + emit Transfer(_from, _to, _value); + } + + function transfer(address _to, uint256 _value) public returns (bool success) { + _transfer(msg.sender, _to, _value); + return true; + } + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool success) { + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function burn(uint256 _value) onlyOwner public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) onlyOwner public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + emit Burn(_from, _value); + return true; + } + + function mintToken(address target, uint256 mintedAmount) onlyOwner public { + uint256 _amount = mintedAmount * 10 ** uint256(decimals); + balanceOf[target] += _amount; + totalSupply += _amount; + emit Transfer(this, target, _amount); + } + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + function transferBatch(address[] _to, uint256 _value) public returns (bool success) { + for (uint i=0; i<_to.length; i++) { + _transfer(msg.sender, _to[i], _value); + } + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/640.sol b/benchmark2/integer overflow/640.sol new file mode 100644 index 0000000000000000000000000000000000000000..74fe8dc8a02305f9a5707f2484c9aa3992f007fc --- /dev/null +++ b/benchmark2/integer overflow/640.sol @@ -0,0 +1,203 @@ +pragma solidity ^0.4.16; +/* 创建一个父类, 账户管理员 */ +contract owned { + + address public owner; + + function owned() public { + owner = msg.sender; + } + + /* modifier是修改标志 */ + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + /* 修改管理员账户, onlyOwner代表只能是用户管理员来修改 */ + function transferOwnership(address newOwner) onlyOwner public { + owner = newOwner; + } +} + +/* receiveApproval服务合约指示代币合约将代币从发送者的账户转移到服务合约的账户(通过调用服务合约的 */ +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } + +contract TokenERC20 { + // 代币(token)的公共变量 + string public name; //代币名字 + string public symbol; //代币符号 + uint8 public decimals = 18; //代币小数点位数, 18是默认, 尽量不要更改 + + uint256 public totalSupply; //代币总量 + + // 记录各个账户的代币数目 + mapping (address => uint256) public balanceOf; + + // A账户存在B账户资金 + mapping (address => mapping (address => uint256)) public allowance; + + // 转账通知事件 + event Transfer(address indexed from, address indexed to, uint256 value); + + // 销毁金额通知事件 + event Burn(address indexed from, uint256 value); + + /* 构造函数 */ + function TokenERC20( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) public { + totalSupply = initialSupply * 10 ** uint256(decimals); // 根据decimals计算代币的数量 + balanceOf[msg.sender] = totalSupply; // 给生成者所有的代币数量 + name = tokenName; // 设置代币的名字 + symbol = tokenSymbol; // 设置代币的符号 + } + + /* 私有的交易函数 */ + function _transfer(address _from, address _to, uint _value) internal { + // 防止转移到0x0, 用burn代替这个功能 + require(_to != 0x0); + // 检测发送者是否有足够的资金 + require(balanceOf[_from] >= _value); + // 检查是否溢出(数据类型的溢出) + require(balanceOf[_to] + _value > balanceOf[_to]); + // 将此保存为将来的断言, 函数最后会有一个检验 + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + // 减少发送者资产 + balanceOf[_from] -= _value; + // 增加接收者的资产 + balanceOf[_to] += _value; + Transfer(_from, _to, _value); + // 断言检测, 不应该为错 + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + } + + /* 传递tokens */ + function transfer(address _to, uint256 _value) public { + _transfer(msg.sender, _to, _value); + } + + /* 从其他账户转移资产 */ + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); // Check allowance + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + /* 授权第三方从发送者账户转移代币,然后通过transferFrom()函数来执行第三方的转移操作 */ + function approve(address _spender, uint256 _value) public + returns (bool success) { + allowance[msg.sender][_spender] = _value; + return true; + } + + /* + 为其他地址设置津贴, 并通知 + 发送者通知代币合约, 代币合约通知服务合约receiveApproval, 服务合约指示代币合约将代币从发送者的账户转移到服务合约的账户(通过调用服务合约的transferFrom) + */ + + function approveAndCall(address _spender, uint256 _value, bytes _extraData) + public + returns (bool success) { + tokenRecipient spender = tokenRecipient(_spender); + if (approve(_spender, _value)) { + spender.receiveApproval(msg.sender, _value, this, _extraData); + return true; + } + } + + /** + * 销毁代币 + */ + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); // Check if the sender has enough + balanceOf[msg.sender] -= _value; // Subtract from the sender + totalSupply -= _value; // Updates totalSupply + Burn(msg.sender, _value); + return true; + } + + /** + * 从其他账户销毁代币 + */ + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); // Check if the targeted balance is enough + require(_value <= allowance[_from][msg.sender]); // Check allowance + balanceOf[_from] -= _value; // Subtract from the targeted balance + allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance + totalSupply -= _value; // Update totalSupply + Burn(_from, _value); + return true; + } +} + +/******************************************/ +/* ADVANCED TOKEN STARTS HERE */ +/******************************************/ + +contract ROSCtoken is owned, TokenERC20 { + + uint256 public sellPrice; + uint256 public buyPrice; + + /* 冻结账户 */ + mapping (address => bool) public frozenAccount; + + /* This generates a public event on the blockchain that will notify clients */ + event FrozenFunds(address target, bool frozen); + + /* 构造函数 */ + function ROSCtoken( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {} + + /* 转账, 比父类加入了账户冻结 */ + function _transfer(address _from, address _to, uint _value) internal { + require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead + require (balanceOf[_from] >= _value); // Check if the sender has enough + require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows + require(!frozenAccount[_from]); // Check if sender is frozen + require(!frozenAccount[_to]); // Check if recipient is frozen + balanceOf[_from] -= _value; // Subtract from the sender + balanceOf[_to] += _value; // Add the same to the recipient + Transfer(_from, _to, _value); + } + +/// 向指定账户增发资金 + function mintToken(address target, uint256 mintedAmount) onlyOwner public { + balanceOf[target] += mintedAmount; + totalSupply += mintedAmount; + Transfer(0, this, mintedAmount); + Transfer(this, target, mintedAmount); + + } + + + /// 冻结 or 解冻账户 + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + FrozenFunds(target, freeze); + } + + function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public { + sellPrice = newSellPrice; + buyPrice = newBuyPrice; + } + + /// @notice Buy tokens from contract by sending ether + function buy() payable public { + uint amount = msg.value / buyPrice; // calculates the amount + _transfer(this, msg.sender, amount); // makes the transfers + } + + function sell(uint256 amount) public { + require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy + _transfer(msg.sender, this, amount); // makes the transfers + msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/651.sol b/benchmark2/integer overflow/651.sol new file mode 100644 index 0000000000000000000000000000000000000000..28ac30a09969cc22edd1446fb131946fc44515fb --- /dev/null +++ b/benchmark2/integer overflow/651.sol @@ -0,0 +1,339 @@ +pragma solidity ^0.4.24; + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address _who) public view returns (uint256); + function transfer(address _to, uint256 _value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + + + + if (_a == 0) { + return 0; + } + + c = _a * _b; + assert(c / _a == _b); + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + return _a / _b; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_b <= _a); + return _a - _b; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + c = _a + _b; + assert(c >= _a); + return c; + } +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) internal balances; + + uint256 internal totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + function approve(address _spender, uint256 _value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() public onlyOwner whenNotPaused { + paused = true; + emit Pause(); + } + + + function unpause() public onlyOwner whenPaused { + paused = false; + emit Unpause(); + } +} + + + + +contract PausableToken is StandardToken, Pausable { + + function transfer( + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(_to, _value); + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(_from, _to, _value); + } + + function approve( + address _spender, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(_spender, _value); + } + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + + + +contract TangguoTaoToken is PausableToken{ + string public name = "TangguoTao Token"; + string public symbol = "TCA"; + uint8 public decimals = 18; + uint public INITIAL_SUPPLY = 60000000000000000000000000000; + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/655.sol b/benchmark2/integer overflow/655.sol new file mode 100644 index 0000000000000000000000000000000000000000..0814d205dfc6f22ecd4114491fb86819b5d643c6 --- /dev/null +++ b/benchmark2/integer overflow/655.sol @@ -0,0 +1,1134 @@ +pragma solidity ^0.4.24; + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } +} + + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + + + +contract ERC721Basic { + function balanceOf(address _owner) public view returns (uint256 _balance); + function ownerOf(uint256 _tokenId) public view returns (address _owner); + function exists(uint256 _tokenId) public view returns (bool _exists); + + function approve(address _to, uint256 _tokenId) public; + function getApproved(uint256 _tokenId) public view returns (address _operator); + + function transferFrom(address _from, address _to, uint256 _tokenId) public; +} + + +contract HorseyExchange is Pausable { + + using SafeMath for uint256; + + event HorseyDeposit(uint256 tokenId, uint256 price); + event SaleCanceled(uint256 tokenId); + event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay); + + + uint256 public marketMakerFee = 3; + + + uint256 collectedFees = 0; + + + ERC721Basic public token; + + + struct SaleData { + uint256 price; + address owner; + } + + + mapping (uint256 => SaleData) market; + + + mapping (address => uint256[]) userBarn; + + + constructor() Pausable() public { + } + + + function setStables(address _token) external + onlyOwner() + { + require(address(_token) != 0,"Address of token is zero"); + token = ERC721Basic(_token); + } + + + function setMarketFees(uint256 fees) external + onlyOwner() + { + marketMakerFee = fees; + } + + + function getTokensOnSale(address user) external view returns(uint256[]) { + return userBarn[user]; + } + + + function getTokenPrice(uint256 tokenId) public view + isOnMarket(tokenId) returns (uint256) { + return market[tokenId].price + (market[tokenId].price.div(100).mul(marketMakerFee)); + } + + + function depositToExchange(uint256 tokenId, uint256 price) external + whenNotPaused() + isTokenOwner(tokenId) + nonZeroPrice(price) + tokenAvailable() { + require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer"); + + token.transferFrom(msg.sender, address(this), tokenId); + + + market[tokenId] = SaleData(price,msg.sender); + + + userBarn[msg.sender].push(tokenId); + + emit HorseyDeposit(tokenId, price); + } + + + function cancelSale(uint256 tokenId) external + whenNotPaused() + originalOwnerOf(tokenId) + tokenAvailable() returns (bool) { + + token.transferFrom(address(this),msg.sender,tokenId); + + + delete market[tokenId]; + + + _removeTokenFromBarn(tokenId, msg.sender); + + emit SaleCanceled(tokenId); + + + + return userBarn[msg.sender].length > 0; + } + + + function purchaseToken(uint256 tokenId) external payable + whenNotPaused() + isOnMarket(tokenId) + tokenAvailable() + notOriginalOwnerOf(tokenId) + { + + uint256 totalToPay = getTokenPrice(tokenId); + require(msg.value >= totalToPay, "Not paying enough"); + + + SaleData memory sale = market[tokenId]; + + + collectedFees += totalToPay - sale.price; + + + sale.owner.transfer(sale.price); + + + _removeTokenFromBarn(tokenId, sale.owner); + + + delete market[tokenId]; + + + + token.transferFrom(address(this), msg.sender, tokenId); + + + if(msg.value > totalToPay) + { + msg.sender.transfer(msg.value.sub(totalToPay)); + } + + emit HorseyPurchased(tokenId, msg.sender, totalToPay); + } + + + function withdraw() external + onlyOwner() + { + assert(collectedFees <= address(this).balance); + owner.transfer(collectedFees); + collectedFees = 0; + } + + + function _removeTokenFromBarn(uint tokenId, address barnAddress) internal { + uint256[] storage barnArray = userBarn[barnAddress]; + require(barnArray.length > 0,"No tokens to remove"); + int index = _indexOf(tokenId, barnArray); + require(index >= 0, "Token not found in barn"); + + + for (uint256 i = uint256(index); i 0,"Price is zero"); + _; + } + + + modifier tokenAvailable(){ + require(address(token) != 0,"Token address not set"); + _; + } +} + + + +contract BettingControllerInterface { + address public owner; +} + +contract EthorseRace { + + + struct chronus_info { + bool betting_open; + bool race_start; + bool race_end; + bool voided_bet; + uint32 starting_time; + uint32 betting_duration; + uint32 race_duration; + uint32 voided_timestamp; + } + + address public owner; + + + chronus_info public chronus; + + + mapping (bytes32 => bool) public winner_horse; + + + function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint); +} + + +contract EthorseHelpers { + + + bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")]; + mapping(address => bool) private _legitOwners; + + + function _addHorse(bytes32 newHorse) internal { + all_horses.push(newHorse); + } + + function _addLegitOwner(address newOwner) internal + { + _legitOwners[newOwner] = true; + } + + function getall_horsesCount() public view returns(uint) { + return all_horses.length; + } + + + function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32) + { + + EthorseRace race = EthorseRace(raceAddress); + + BettingControllerInterface bc = BettingControllerInterface(race.owner()); + + require(_legitOwners[bc.owner()]); + + bool voided_bet; + bool race_end; + (,,race_end,voided_bet,,,,) = race.chronus(); + + + if(voided_bet || !race_end) + return (false,bytes32(0)); + + + bytes32 horse; + bool found = false; + uint256 arrayLength = all_horses.length; + + + for(uint256 i = 0; i < arrayLength; i++) + { + if(race.winner_horse(all_horses[i])) { + horse = all_horses[i]; + found = true; + break; + } + } + + if(!found) + return (false,bytes32(0)); + + + uint256 bet_amount = 0; + if(eth_address != address(0)) { + (,,,, bet_amount) = race.getCoinIndex(horse, eth_address); + } + + + return (bet_amount > 0, horse); + } +} + + + +contract RoyalStablesInterface { + + struct Horsey { + address race; + bytes32 dna; + uint8 feedingCounter; + uint8 tier; + } + + mapping(uint256 => Horsey) public horseys; + mapping(address => uint32) public carrot_credits; + mapping(uint256 => string) public names; + address public master; + + function getOwnedTokens(address eth_address) public view returns (uint256[]); + function storeName(uint256 tokenId, string newName) public; + function storeCarrotsCredit(address client, uint32 amount) public; + function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public; + function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public; + function modifyHorseyDna(uint256 tokenId, bytes32 dna) public; + function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public; + function modifyHorseyTier(uint256 tokenId, uint8 tier) public; + function unstoreHorsey(uint256 tokenId) public; + function ownerOf(uint256 tokenId) public returns (address); +} + + +contract HorseyToken is EthorseHelpers,Pausable { + using SafeMath for uint256; + + + event Claimed(address raceAddress, address eth_address, uint256 tokenId); + + + event Feeding(uint256 tokenId); + + + event ReceivedCarrot(uint256 tokenId, bytes32 newDna); + + + event FeedingFailed(uint256 tokenId); + + + event HorseyRenamed(uint256 tokenId, string newName); + + + event HorseyFreed(uint256 tokenId); + + + RoyalStablesInterface public stables; + + + uint8 public carrotsMultiplier = 1; + + + uint8 public rarityMultiplier = 1; + + + uint256 public claimingFee = 0.008 ether; + + + struct FeedingData { + uint256 blockNumber; + uint256 horsey; + } + + + mapping(address => FeedingData) public pendingFeedings; + + + uint256 public renamingCostsPerChar = 0.001 ether; + + + constructor(address stablesAddress) + EthorseHelpers() + Pausable() public { + stables = RoyalStablesInterface(stablesAddress); + } + + + function setRarityMultiplier(uint8 newRarityMultiplier) external + onlyOwner() { + rarityMultiplier = newRarityMultiplier; + } + + + function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external + onlyOwner() { + carrotsMultiplier = newCarrotsMultiplier; + } + + + function setRenamingCosts(uint256 newRenamingCost) external + onlyOwner() { + renamingCostsPerChar = newRenamingCost; + } + + + function setClaimingCosts(uint256 newClaimingFee) external + onlyOwner() { + claimingFee = newClaimingFee; + } + + + function addLegitDevAddress(address newAddress) external + onlyOwner() { + _addLegitOwner(newAddress); + } + + + function withdraw() external + onlyOwner() { + owner.transfer(address(this).balance); + } + + + + function addHorseIndex(bytes32 newHorse) external + onlyOwner() { + _addHorse(newHorse); + } + + + function getOwnedTokens(address eth_address) public view returns (uint256[]) { + return stables.getOwnedTokens(eth_address); + } + + + function can_claim(address raceAddress, address eth_address) public view returns (bool) { + bool res; + (res,) = _isWinnerOf(raceAddress, eth_address); + return res; + } + + + function claim(address raceAddress) external payable + costs(claimingFee) + whenNotPaused() + { + + bytes32 winner; + (,winner) = _isWinnerOf(raceAddress, address(0)); + require(winner != bytes32(0),"Winner is zero"); + require(can_claim(raceAddress, msg.sender),"can_claim return false"); + + uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner); + emit Claimed(raceAddress, msg.sender, id); + } + + + function renameHorsey(uint256 tokenId, string newName) external + whenNotPaused() + onlyOwnerOf(tokenId) + costs(renamingCostsPerChar * bytes(newName).length) + payable { + uint256 renamingFee = renamingCostsPerChar * bytes(newName).length; + + if(msg.value > renamingFee) + { + msg.sender.transfer(msg.value.sub(renamingFee)); + } + + stables.storeName(tokenId,newName); + emit HorseyRenamed(tokenId,newName); + } + + + function freeForCarrots(uint256 tokenId) external + whenNotPaused() + onlyOwnerOf(tokenId) { + require(pendingFeedings[msg.sender].horsey != tokenId,""); + + uint8 feedingCounter; + (,,feedingCounter,) = stables.horseys(tokenId); + stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier)); + stables.unstoreHorsey(tokenId); + emit HorseyFreed(tokenId); + } + + + function getCarrotCredits() external view returns (uint32) { + return stables.carrot_credits(msg.sender); + } + + + function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) { + RoyalStablesInterface.Horsey memory temp; + (temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId); + return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId)); + } + + + function feed(uint256 tokenId) external + whenNotPaused() + onlyOwnerOf(tokenId) + carrotsMeetLevel(tokenId) + noFeedingInProgress() + { + pendingFeedings[msg.sender] = FeedingData(block.number,tokenId); + uint8 feedingCounter; + (,,feedingCounter,) = stables.horseys(tokenId); + stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter)); + emit Feeding(tokenId); + } + + + function stopFeeding() external + feedingInProgress() returns (bool) { + uint256 blockNumber = pendingFeedings[msg.sender].blockNumber; + uint256 tokenId = pendingFeedings[msg.sender].horsey; + + require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block"); + + delete pendingFeedings[msg.sender]; + + + + if(block.number - blockNumber > 255) { + + + emit FeedingFailed(tokenId); + return false; + } + + + if(stables.ownerOf(tokenId) != msg.sender) { + + + emit FeedingFailed(tokenId); + return false; + } + + + _feed(tokenId, blockhash(blockNumber)); + bytes32 dna; + (,dna,,) = stables.horseys(tokenId); + emit ReceivedCarrot(tokenId, dna); + return true; + } + + + function() external payable { + revert("Not accepting donations"); + } + + + function _feed(uint256 tokenId, bytes32 blockHash) internal { + + uint8 tier; + uint8 feedingCounter; + (,,feedingCounter,tier) = stables.horseys(tokenId); + uint256 probabilityByRarity = 10 ** (uint256(tier).add(1)); + uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity; + + + if(randNum <= (feedingCounter * rarityMultiplier)){ + _increaseRarity(tokenId, blockHash); + } + + + + if(feedingCounter < 255) { + stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1); + } + } + + + function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) { + return uint256(keccak256(abi.encodePacked(race, sender, coinIndex))); + } + + + function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) { + uint256 id = _makeSpecialId(race, eth_address, coinIndex); + + bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16); + + stables.storeHorsey(eth_address,id,race,dna,1,0); + return id; + } + + + function _increaseRarity(uint256 tokenId, bytes32 blockHash) private { + uint8 tier; + bytes32 dna; + (,dna,,tier) = stables.horseys(tokenId); + if(tier < 255) + stables.modifyHorseyTier(tokenId,tier+1); + uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash))); + + bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240)); + bytes32 newdna = dna | rarityMask; + stables.modifyHorseyDna(tokenId,newdna); + } + + + function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) { + return bytes32(uint256(data)*(2 ** n)); + } + + + function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) { + return bytes32(uint256(data)/(2 ** n)); + } + + + modifier carrotsMeetLevel(uint256 tokenId){ + uint256 feedingCounter; + (,,feedingCounter,) = stables.horseys(tokenId); + require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots"); + _; + } + + + modifier costs(uint256 amount) { + require(msg.value >= amount,"Not enough funds"); + _; + } + + + modifier validAddress(address addr) { + require(addr != address(0),"Address is zero"); + _; + } + + + modifier noFeedingInProgress() { + + require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding"); + _; + } + + + modifier feedingInProgress() { + + require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding"); + _; + } + + + modifier onlyOwnerOf(uint256 tokenId) { + require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token"); + _; + } +} + + + + + +contract HorseyPilot { + + using SafeMath for uint256; + + + event NewProposal(uint8 methodId, uint parameter, address proposer); + + + event ProposalPassed(uint8 methodId, uint parameter, address proposer); + + + + uint8 constant votingThreshold = 2; + + + + uint256 constant proposalLife = 7 days; + + + + uint256 constant proposalCooldown = 1 days; + + + uint256 cooldownStart; + + + address public jokerAddress; + address public knightAddress; + address public paladinAddress; + + + address[3] public voters; + + + uint8 constant public knightEquity = 40; + uint8 constant public paladinEquity = 10; + + + address public exchangeAddress; + address public tokenAddress; + + + mapping(address => uint) internal _cBalance; + + + struct Proposal{ + address proposer; + uint256 timestamp; + uint256 parameter; + uint8 methodId; + address[] yay; + address[] nay; + } + + + Proposal public currentProposal; + + + bool public proposalInProgress = false; + + + uint256 public toBeDistributed; + + + bool deployed = false; + + + constructor( + address _jokerAddress, + address _knightAddress, + address _paladinAddress, + address[3] _voters + ) public { + jokerAddress = _jokerAddress; + knightAddress = _knightAddress; + paladinAddress = _paladinAddress; + + for(uint i = 0; i < 3; i++) { + voters[i] = _voters[i]; + } + + + cooldownStart = block.timestamp - proposalCooldown; + } + + + function deployChildren(address stablesAddress) external { + require(!deployed,"already deployed"); + + exchangeAddress = new HorseyExchange(); + tokenAddress = new HorseyToken(stablesAddress); + + + HorseyExchange(exchangeAddress).setStables(stablesAddress); + + deployed = true; + } + + + function transferJokerOwnership(address newJoker) external + validAddress(newJoker) { + require(jokerAddress == msg.sender,"Not right role"); + _moveBalance(newJoker); + jokerAddress = newJoker; + } + + + function transferKnightOwnership(address newKnight) external + validAddress(newKnight) { + require(knightAddress == msg.sender,"Not right role"); + _moveBalance(newKnight); + knightAddress = newKnight; + } + + + function transferPaladinOwnership(address newPaladin) external + validAddress(newPaladin) { + require(paladinAddress == msg.sender,"Not right role"); + _moveBalance(newPaladin); + paladinAddress = newPaladin; + } + + + function withdrawCeo(address destination) external + onlyCLevelAccess() + validAddress(destination) { + + + if(toBeDistributed > 0){ + _updateDistribution(); + } + + + uint256 balance = _cBalance[msg.sender]; + + + if(balance > 0 && (address(this).balance >= balance)) { + destination.transfer(balance); + _cBalance[msg.sender] = 0; + } + } + + + function syncFunds() external { + uint256 prevBalance = address(this).balance; + HorseyToken(tokenAddress).withdraw(); + HorseyExchange(exchangeAddress).withdraw(); + uint256 newBalance = address(this).balance; + + toBeDistributed = toBeDistributed.add(newBalance - prevBalance); + } + + + function getNobleBalance() external view + onlyCLevelAccess() returns (uint256) { + return _cBalance[msg.sender]; + } + + + function makeProposal( uint8 methodId, uint256 parameter ) external + onlyCLevelAccess() + proposalAvailable() + cooledDown() + { + currentProposal.timestamp = block.timestamp; + currentProposal.parameter = parameter; + currentProposal.methodId = methodId; + currentProposal.proposer = msg.sender; + delete currentProposal.yay; + delete currentProposal.nay; + proposalInProgress = true; + + emit NewProposal(methodId,parameter,msg.sender); + } + + + function voteOnProposal(bool voteFor) external + proposalPending() + onlyVoters() + notVoted() { + + require((block.timestamp - currentProposal.timestamp) <= proposalLife); + if(voteFor) + { + currentProposal.yay.push(msg.sender); + + if( currentProposal.yay.length >= votingThreshold ) + { + _doProposal(); + proposalInProgress = false; + + return; + } + + } else { + currentProposal.nay.push(msg.sender); + + if( currentProposal.nay.length >= votingThreshold ) + { + proposalInProgress = false; + cooldownStart = block.timestamp; + return; + } + } + } + + + function _moveBalance(address newAddress) internal + validAddress(newAddress) { + require(newAddress != msg.sender); + _cBalance[newAddress] = _cBalance[msg.sender]; + _cBalance[msg.sender] = 0; + } + + + function _updateDistribution() internal { + require(toBeDistributed != 0,"nothing to distribute"); + uint256 knightPayday = toBeDistributed.div(100).mul(knightEquity); + uint256 paladinPayday = toBeDistributed.div(100).mul(paladinEquity); + + + uint256 jokerPayday = toBeDistributed.sub(knightPayday).sub(paladinPayday); + + _cBalance[jokerAddress] = _cBalance[jokerAddress].add(jokerPayday); + _cBalance[knightAddress] = _cBalance[knightAddress].add(knightPayday); + _cBalance[paladinAddress] = _cBalance[paladinAddress].add(paladinPayday); + + toBeDistributed = 0; + } + + + function _doProposal() internal { + + if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter); + + + if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter); + + + if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitDevAddress(address(currentProposal.parameter)); + + + if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter)); + + + if( currentProposal.methodId == 4 ) { + if(currentProposal.parameter == 0) { + HorseyExchange(exchangeAddress).unpause(); + HorseyToken(tokenAddress).unpause(); + } else { + HorseyExchange(exchangeAddress).pause(); + HorseyToken(tokenAddress).pause(); + } + } + + + if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter); + + + if( currentProposal.methodId == 8 ){ + HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter)); + } + + + if( currentProposal.methodId == 9 ){ + HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter)); + } + + emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer); + } + + + modifier validAddress(address addr) { + require(addr != address(0),"Address is zero"); + _; + } + + + modifier onlyCLevelAccess() { + require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level"); + _; + } + + + + modifier proposalAvailable(){ + require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending"); + _; + } + + + + modifier cooledDown( ){ + if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){ + revert("Cool down period not passed yet"); + } + _; + } + + + modifier proposalPending() { + require(proposalInProgress,"no proposal pending"); + _; + } + + + modifier notVoted() { + uint256 length = currentProposal.yay.length; + for(uint i = 0; i < length; i++) { + if(currentProposal.yay[i] == msg.sender) { + revert("Already voted"); + } + } + + length = currentProposal.nay.length; + for(i = 0; i < length; i++) { + if(currentProposal.nay[i] == msg.sender) { + revert("Already voted"); + } + } + _; + } + + + modifier onlyVoters() { + bool found = false; + uint256 length = voters.length; + for(uint i = 0; i < length; i++) { + if(voters[i] == msg.sender) { + found = true; + break; + } + } + if(!found) { + revert("not a voter"); + } + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/682.sol b/benchmark2/integer overflow/682.sol new file mode 100644 index 0000000000000000000000000000000000000000..6c941eb59ac390035bbbdf4ecf72f778cb5ffd1b --- /dev/null +++ b/benchmark2/integer overflow/682.sol @@ -0,0 +1,147 @@ +pragma solidity ^0.4.24; + + +library SafeMath { + function mul(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal constant returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal constant returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) constant returns (uint256); + function transfer(address to, uint256 value) returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + + function transfer(address _to, uint256 _value) returns (bool) { + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) constant returns (uint256); + function transferFrom(address from, address to, uint256 value) returns (bool); + function approve(address spender, uint256 value) returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool) { + var _allowance = allowed[_from][msg.sender]; + balances[_to] = balances[_to].add(_value); + balances[_from] = balances[_from].sub(_value); + allowed[_from][msg.sender] = _allowance.sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) returns (bool) { + + require((_value == 0) || (allowed[msg.sender][_spender] == 0)); + + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + +contract Ownable { + address public owner; + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } +} + + + + + + +contract IPM is StandardToken ,Ownable { + + string public constant name = "IPMCOIN"; + string public constant symbol = "IPM"; + uint256 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 3000000000 * 10 ** uint256(decimals); + + + function IPM() { + totalSupply = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + owner=msg.sender; + } + + + function Airdrop(ERC20 token, address[] _addresses, uint256 amount) public { + for (uint256 i = 0; i < _addresses.length; i++) { + token.transfer(_addresses[i], amount); + } + } + + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/683.sol b/benchmark2/integer overflow/683.sol new file mode 100644 index 0000000000000000000000000000000000000000..375b74d8a39e697700348ceb8fdbb73834d38198 --- /dev/null +++ b/benchmark2/integer overflow/683.sol @@ -0,0 +1,196 @@ +pragma solidity ^0.4.23; + +contract Ownable { + address public owner; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + constructor() public { + owner = msg.sender; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + modifier whenNotPaused() { + if (msg.sender != owner) { + require(!paused); + } + _; + } + + modifier whenPaused() { + if (msg.sender != owner) { + require(paused); + } + _; + } + + function pause() onlyOwner public { + paused = true; + emit Pause(); + } + + function unpause() onlyOwner public { + paused = false; + emit Unpause(); + } +} + +library SafeMath { + function mul(uint a, uint b) internal pure returns (uint) { + if (a == 0) { + return 0; + } + uint c = a * b; + assert(c / a == b); + return c; + } + + function div(uint a, uint b) internal pure returns (uint) { + + uint c = a / b; + + return c; + } + + function sub(uint a, uint b) internal pure returns (uint) { + assert(b <= a); + return a - b; + } + + function add(uint a, uint b) internal pure returns (uint) { + uint c = a + b; + assert(c >= a); + return c; + } +} + +contract ERC20 { + string public name; + string public symbol; + uint8 public decimals; + uint public totalSupply; + constructor(string _name, string _symbol, uint8 _decimals) public { + name = _name; + symbol = _symbol; + decimals = _decimals; + } + function balanceOf(address who) public view returns (uint); + function transfer(address to, uint value) public returns (bool); + function allowance(address owner, address spender) public view returns (uint); + function transferFrom(address from, address to, uint value) public returns (bool); + function approve(address spender, uint value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint value); + event Approval(address indexed owner, address indexed spender, uint value); +} + +contract Token is Pausable, ERC20 { + using SafeMath for uint; + event Burn(address indexed burner, uint256 value); + + mapping(address => uint) balances; + mapping (address => mapping (address => uint)) internal allowed; + mapping(address => uint) public balanceOfLocked; + mapping(address => bool) public addressLocked; + + constructor() ERC20("OCP", "OCP", 18) public { + totalSupply = 10000000000 * 10 ** uint(decimals); + balances[msg.sender] = totalSupply; + } + + modifier lockCheck(address from, uint value) { + require(addressLocked[from] == false); + require(balances[from] >= balanceOfLocked[from]); + require(value <= balances[from] - balanceOfLocked[from]); + _; + } + + function burn(uint _value) onlyOwner public { + balances[owner] = balances[owner].sub(_value); + totalSupply = totalSupply.sub(_value); + emit Burn(msg.sender, _value); + } + + function lockAddressValue(address _addr, uint _value) onlyOwner public { + balanceOfLocked[_addr] = _value; + } + + function lockAddress(address addr) onlyOwner public { + addressLocked[addr] = true; + } + + function unlockAddress(address addr) onlyOwner public { + addressLocked[addr] = false; + } + + function transfer(address _to, uint _value) lockCheck(msg.sender, _value) whenNotPaused public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function balanceOf(address _owner) public view returns (uint balance) { + return balances[_owner]; + } + + function transferFrom(address _from, address _to, uint _value) public lockCheck(_from, _value) whenNotPaused returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint _value) public whenNotPaused returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) public view returns (uint) { + return allowed[_owner][_spender]; + } + + function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/727.sol b/benchmark2/integer overflow/727.sol new file mode 100644 index 0000000000000000000000000000000000000000..317da94bc1772848bc9cb535d2f79dc1045f78e9 --- /dev/null +++ b/benchmark2/integer overflow/727.sol @@ -0,0 +1,137 @@ +pragma solidity 0.4.24; + + + + + +library SafeMath { + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; assert(c >= a); return c; } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0){return 0;} c = a * b; assert(c / a == b); return c; } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } +} + + + +contract ERC20Token { + function totalSupply() public view returns (uint256); + function balanceOf(address _targetAddress) public view returns (uint256); + function transfer(address _targetAddress, uint256 _value) public returns (bool); + event Transfer(address indexed _originAddress, address indexed _targetAddress, uint256 _value); + + function allowance(address _originAddress, address _targetAddress) public view returns (uint256); + function approve(address _originAddress, uint256 _value) public returns (bool); + function transferFrom(address _originAddress, address _targetAddress, uint256 _value) public returns (bool); + event Approval(address indexed _originAddress, address indexed _targetAddress, uint256 _value); +} + + + +contract Ownership { + address public owner; + + modifier onlyOwner() { require(msg.sender == owner); _; } + modifier validDestination(address _targetAddress) { require(_targetAddress != address(0x0)); _; } +} + + + +contract MAJz is ERC20Token, Ownership { + using SafeMath for uint256; + + string public symbol; + string public name; + uint256 public decimals; + uint256 public totalSupply; + + mapping(address => uint256) public balances; + mapping(address => mapping(address => uint256)) allowed; + + + constructor() public{ + symbol = "MAZ"; + name = "MAJz"; + decimals = 18; + totalSupply = 560000000000000000000000000; + balances[msg.sender] = totalSupply; + owner = msg.sender; + emit Transfer(address(0), msg.sender, totalSupply); + } + + + + + function totalSupply() public view returns (uint256) { + return totalSupply; + } + + function balanceOf(address _targetAddress) public view returns (uint256) { + return balances[_targetAddress]; + } + + + function transfer(address _targetAddress, uint256 _value) validDestination(_targetAddress) public returns (bool) { + balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value); + balances[_targetAddress] = SafeMath.add(balances[_targetAddress], _value); + emit Transfer(msg.sender, _targetAddress, _value); + return true; + } + + + function allowance(address _originAddress, address _targetAddress) public view returns (uint256){ + return allowed[_originAddress][_targetAddress]; + } + + function approve(address _targetAddress, uint256 _value) public returns (bool) { + allowed[msg.sender][_targetAddress] = _value; + emit Approval(msg.sender, _targetAddress, _value); + return true; + } + + function transferFrom(address _originAddress, address _targetAddress, uint256 _value) public returns (bool) { + balances[_originAddress] = SafeMath.sub(balances[_originAddress], _value); + allowed[_originAddress][msg.sender] = SafeMath.sub(allowed[_originAddress][msg.sender], _value); + balances[_targetAddress] = SafeMath.add(balances[_targetAddress], _value); + emit Transfer(_originAddress, _targetAddress, _value); + return true; + } + + function () public payable { + revert(); + } + + + + + function burnTokens(uint256 _value) public onlyOwner returns (bool){ + balances[owner] = SafeMath.sub(balances[owner], _value); + totalSupply = SafeMath.sub(totalSupply, _value); + emit BurnTokens(_value); + return true; + } + + + function emitTokens(uint256 _value) public onlyOwner returns (bool){ + balances[owner] = SafeMath.add(balances[owner], _value); + totalSupply = SafeMath.add(totalSupply, _value); + emit EmitTokens(_value); + return true; + } + + + function revertTransfer(address _targetAddress, uint256 _value) public onlyOwner returns (bool) { + balances[_targetAddress] = SafeMath.sub(balances[_targetAddress], _value); + balances[owner] = SafeMath.add(balances[owner], _value); + emit RevertTransfer(_targetAddress, _value); + return true; + } + + event RevertTransfer(address _targetAddress, uint256 _value); + event BurnTokens(uint256 _value); + event EmitTokens(uint256 _value); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/731.sol b/benchmark2/integer overflow/731.sol new file mode 100644 index 0000000000000000000000000000000000000000..4d83628fa8889c14213ade5dad728cbd49ede2e4 --- /dev/null +++ b/benchmark2/integer overflow/731.sol @@ -0,0 +1,471 @@ +pragma solidity ^0.4.24; +pragma solidity ^0.4.24; + + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + if (_a == 0) { + return 0; + } + + uint256 c = _a * _b; + require(c / _a == _b); + + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b > 0); + uint256 c = _a / _b; + + + return c; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b <= _a); + uint256 c = _a - _b; + + return c; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + require(c >= _a); + + return c; + } + + + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} +contract Base { + + using SafeMath for uint256; + address public owner; + + struct Client { + uint256 Tokens; + address Owner; + uint256 Category; + uint256[] LoansID; + } + struct Bank { + uint256 Tokens; + address Owner; + + mapping (uint256=>strCateg) Category; + uint256[] LoansID; + Loan[] LoanPending; + Portfolio[] Portfolios; + } + struct strCateg{ + mapping(uint256=>strAmount) Amount; + } + struct strAmount{ + mapping(uint256=>strInsta) Installment; + } + struct strInsta{ + uint256 value; + bool enable; + } + struct Loan{ + uint256 Debt; + + uint256 Installment; + uint256 Id; + uint256 ForSale; + address Client; + address Owner; + uint256 Category; + uint256 Amount; + uint256 StartTime; + uint256 EndTime; + } + struct Portfolio{ + uint256[] idLoans; + address Owner; + uint256 forSale; + } + + mapping(address => Client) clients; + mapping(address => Bank) banks; + Loan[] loans; + + function () public payable{ + require(false, "Should not go through this point"); + } + + +} +contract ClientFunctions is Base{ + + modifier isClient(){ + require(clients[msg.sender].Owner == msg.sender, "not a client"); + _; + } + + function askForALoan(address _bankAddress, uint256 _amount, uint256 _installment) isClient public { + + require(banks[_bankAddress].Owner==_bankAddress, "not a valid bank"); + require(banks[_bankAddress].Category[clients[msg.sender].Category].Amount[_amount].Installment[_installment].enable, "you not apply for that loan"); + + Loan memory _loan; + _loan.Debt = _amount; + _loan.Debt = _loan.Debt.add(banks[_bankAddress].Category[clients[msg.sender].Category].Amount[_amount].Installment[_installment].value); + + _loan.Client = msg.sender; + _loan.Owner = _bankAddress; + _loan.Installment = _installment; + _loan.Category = clients[msg.sender].Category; + _loan.Amount = _amount; + + banks[_bankAddress].LoanPending.push(_loan); + + + + } + + function findOutInterestByClientCategory(address _bankAddress, uint256 _amount, uint256 _installment) isClient public view returns(uint256 _value, bool _enable){ + _value = banks[_bankAddress].Category[clients[msg.sender].Category].Amount[_amount].Installment[_installment].value; + _enable = banks[_bankAddress].Category[clients[msg.sender].Category].Amount[_amount].Installment[_installment].enable; + } + + function removeClientToken(uint256 _value) isClient public{ + require(clients[msg.sender].Tokens >= _value, "You don't have that many tokens"); + clients[msg.sender].Tokens = clients[msg.sender].Tokens.sub(_value); + } + + function getClientBalance() isClient public view returns (uint256 _value){ + _value = clients[msg.sender].Tokens; + } + + + function getLoansLengthByClient() isClient public view returns(uint256){ + return clients[msg.sender].LoansID.length; + } + function getLoanIDbyClient(uint256 _indexLoan) isClient public view returns (uint256){ + return clients[msg.sender].LoansID[_indexLoan]; + } + function getClientCategory() isClient public view returns(uint256){ + + return clients[msg.sender].Category; + } +} +contract BankFunctions is ClientFunctions{ + modifier isBank(){ + require(banks[msg.sender].Owner==msg.sender, "you are not a bank"); + _; + } + modifier isLoanOwner(uint256 _id) { + require(banks[msg.sender].Owner==msg.sender, "you are not a bank"); + require(loans[_id].Owner == msg.sender, "not owner of loan"); + _; + } + + function GetClientCategory(address _client) isBank public view returns(uint256){ + + return clients[_client].Category; + } + + function removeBankToken(uint256 _value) isBank public{ + require(banks[msg.sender].Tokens >= _value, "You don't have that many tokens"); + banks[msg.sender].Tokens = banks[msg.sender].Tokens.sub(_value); + } + + function payOffClientDebt(uint256 _loanId, uint256 _value) isLoanOwner(_loanId) public{ + + + require(loans[_loanId].Debt > 0); + require(_value > 0); + require(loans[_loanId].Debt>= _value); + loans[loans.length-1].EndTime = now; + loans[_loanId].Debt = loans[_loanId].Debt.sub(_value); + + + } + + function ChangeInterest(uint256 _category, uint256 _amount, uint256 _installment, uint256 _value, bool _enable) isBank public{ + banks[msg.sender].Category[_category].Amount[_amount].Installment[_installment].value = _value; + banks[msg.sender].Category[_category].Amount[_amount].Installment[_installment].enable = _enable; + } + + function GetBankBalance() isBank public view returns (uint256 ){ + return banks[msg.sender].Tokens; + } + function findOutInterestByBank(uint256 _category, uint256 _amount, uint256 _installment) isBank public view returns(uint256 _value, bool _enable){ + _value = banks[msg.sender].Category[_category].Amount[_amount].Installment[_installment].value; + _enable = banks[msg.sender].Category[_category].Amount[_amount].Installment[_installment].enable; + } + + +} +contract LoansFunctions is BankFunctions{ + + + + function SellLoan(uint256 _loanId, uint256 _value) isLoanOwner(_loanId) public { + loans[_loanId].ForSale = _value; + } + + + function BuyLoan(address _owner, uint256 _loanId, uint256 _value) isBank public{ + require(loans[_loanId].ForSale > 0, "not for sale"); + require(banks[msg.sender].Tokens>= _value, "you dont have money"); + + SwitchLoanOwner( _owner, _loanId); + + + banks[msg.sender].Tokens = banks[msg.sender].Tokens.sub(_value); + banks[_owner].Tokens = banks[_owner].Tokens.add(_value); + } + + + function SwitchLoanOwner(address _owner, uint256 _loanId) internal{ + + require(loans[_loanId].Debt> 0, "at least one of the loans is already paid"); + require(loans[_loanId].Owner == _owner); + uint256 _indexLoan; + for (uint256 i; i=banks[msg.sender].LoanPending[_loanIndex].Amount, "the bank does not have that amount of tokens"); + + banks[msg.sender].LoanPending[_loanIndex].Id =loans.length; + loans.push(banks[msg.sender].LoanPending[_loanIndex]); + loans[loans.length-1].StartTime = now; + address _client = banks[msg.sender].LoanPending[_loanIndex].Client; + uint256 _amount = banks[msg.sender].LoanPending[_loanIndex].Amount; + + banks[msg.sender].LoansID.push(loans.length - 1); + clients[_client].LoansID.push(loans.length - 1); + + clients[_client].Tokens = clients[_client].Tokens.add(_amount); + banks[msg.sender].Tokens = banks[msg.sender].Tokens.sub(_amount); + + + if(banks[msg.sender].LoanPending.length !=1){ + banks[msg.sender].LoanPending[_loanIndex] = banks[msg.sender].LoanPending [banks[msg.sender].LoanPending.length - 1]; + } + + delete banks[msg.sender].LoanPending [banks[msg.sender].LoanPending.length - 1]; + banks[msg.sender].LoanPending.length--; + + } + + function GetLoansLenght(bool _pending) public isBank view returns (uint256) { + if (_pending){ + return banks[msg.sender].LoanPending.length; + }else{ + return banks[msg.sender].LoansID.length; + } + + } + function GetLoanInfo(uint256 _indexLoan, bool _pending) public view returns(uint256 _debt, address _client, uint256 _installment, uint256 _category , uint256 _amount, address _owner, uint256 _forSale, uint256 _StartTime, uint256 _EndTime){ + + Loan memory _loan; + if (_pending){ + require (_indexLoan < banks[msg.sender].LoanPending.length, "null value"); + _loan = banks[msg.sender].LoanPending[_indexLoan]; + }else{ + _loan = loans[_indexLoan]; + } + + _debt = _loan.Debt; + _client = _loan.Client; + _installment = _loan.Installment; + _category = _loan.Category; + _amount = _loan.Amount ; + _owner = _loan.Owner ; + _forSale = _loan.ForSale; + _StartTime = _loan.StartTime; + _EndTime = _loan.EndTime; + } + + + +} +contract PortfolioFunctions is LoansFunctions{ + modifier isOwnerPortfolio(uint256 _indexPortfolio) { + require(banks[msg.sender].Portfolios[_indexPortfolio].Owner== msg.sender, "not the owner of portfolio"); + _; + } + + function createPortfolio(uint256 _idLoan) isBank public returns (uint256 ) { + require(msg.sender== loans[_idLoan].Owner); + Portfolio memory _portfolio; + banks[msg.sender].Portfolios.push(_portfolio); + banks[msg.sender].Portfolios[banks[msg.sender].Portfolios.length-1].idLoans.push(_idLoan); + banks[msg.sender].Portfolios[banks[msg.sender].Portfolios.length-1].Owner= msg.sender; + + return banks[msg.sender].Portfolios.length-1; + } + function deletePortfolio(uint256 _indexPortfolio) isOwnerPortfolio(_indexPortfolio) public{ + uint256 _PortfolioLength = banks[msg.sender].Portfolios.length; + banks[msg.sender].Portfolios[_indexPortfolio] = banks[msg.sender].Portfolios[_PortfolioLength -1]; + delete banks[msg.sender].Portfolios[_PortfolioLength -1]; + banks[msg.sender].Portfolios.length --; + + } + + function addLoanToPortfolio(uint256 _indexPortfolio, uint256 _idLoan) isOwnerPortfolio (_indexPortfolio) public { + for(uint256 i; i0); + banks[msg.sender].Portfolios[_indexPortfolio].forSale = _value; + } + function buyPortfolio(address _owner, uint256 _indexPortfolio, uint256 _value) isBank public { + + require(banks[msg.sender].Tokens>=_value); + require(banks[_owner].Portfolios[_indexPortfolio].idLoans.length > 0); + require(banks[_owner].Portfolios[_indexPortfolio].forSale > 0); + require(banks[_owner].Portfolios[_indexPortfolio].forSale == _value ); + + + banks[msg.sender].Tokens = banks[msg.sender].Tokens.sub(_value); + banks[_owner].Tokens = banks[_owner].Tokens.add(_value); + + for(uint256 a;a< banks[_owner].Portfolios[_indexPortfolio].idLoans.length ;a++){ + SwitchLoanOwner(_owner, banks[_owner].Portfolios[_indexPortfolio].idLoans[a]); + } + + if (_indexPortfolio !=banks[_owner].Portfolios.length-1){ + banks[_owner].Portfolios[_indexPortfolio] = banks[_owner].Portfolios[banks[_owner].Portfolios.length-1]; + } + delete banks[_owner].Portfolios[banks[_owner].Portfolios.length -1]; + banks[_owner].Portfolios.length--; + } + function countPortfolios(address _bankAddress) isBank public view returns (uint256 _result){ + _result = banks[_bankAddress].Portfolios.length; + } + function GetLoanIdFromPortfolio(uint256 _indexPortfolio, uint256 _indexLoan) isBank public view returns(uint256 _ID){ + return banks[msg.sender].Portfolios[_indexPortfolio].idLoans[_indexLoan]; + } + + + +} +contract GobernanceFunctions is PortfolioFunctions{ + + modifier IsOwner{ + require(owner == msg.sender, "not the owner"); + _; + } + + function addBank(address _addressBank, uint256 _tokens) IsOwner public{ + require(banks[_addressBank].Owner==0); + require(clients[_addressBank].Owner == 0); + banks[_addressBank].Owner=_addressBank; + banks[_addressBank].Tokens = _tokens; + + } + function addClient (address _addressClient, uint256 _category) IsOwner public{ + require(banks[_addressClient].Owner!=_addressClient, "that addreess is a bank"); + require(clients[_addressClient].Owner!=_addressClient, "that client already exists"); + require (_category > 0); + clients[_addressClient].Owner = _addressClient; + clients[_addressClient].Category = _category; + clients[_addressClient].Tokens = 0; + } + function addTokensToBank(address _bank, uint256 _tokens) IsOwner public{ + require(banks[_bank].Owner==_bank, "not a Bank"); + banks[_bank].Tokens = banks[_bank].Tokens.add(_tokens); + } + function changeClientCategory (address _client, uint256 _category) IsOwner public{ + require (clients[_client].Owner==_client, "not a client"); + + clients[_client].Category = _category; + + } +} + +contract Deploy is GobernanceFunctions{ + + constructor() public { + owner = msg.sender; + forTesting(); + } + function forTesting() internal{ + addBank(0x14723a09acff6d2a60dcdf7aa4aff308fddc160c,1); + addBank(0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db,1); + addTokensToBank(0x14723a09acff6d2a60dcdf7aa4aff308fddc160c,20000); + addTokensToBank(0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db,40000); + addClient(0x583031d1113ad414f02576bd6afabfb302140225, 1); + addClient(0xdd870fa1b7c4700f2bd7f44238821c26f7392148, 1); + changeClientCategory(0x583031d1113ad414f02576bd6afabfb302140225, 5); + changeClientCategory(0xdd870fa1b7c4700f2bd7f44238821c26f7392148, 5); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/735.sol b/benchmark2/integer overflow/735.sol new file mode 100644 index 0000000000000000000000000000000000000000..9b6f9f6f2c346d63f29bcd8c690e955e504f0fb8 --- /dev/null +++ b/benchmark2/integer overflow/735.sol @@ -0,0 +1,150 @@ +pragma solidity ^0.4.12; + +library SafeMath { + function mul(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + function div(uint256 a, uint256 b) internal constant returns (uint256) { + + uint256 c = a / b; + + return c; + } + function sub(uint256 a, uint256 b) internal constant returns (uint256) { + assert(b <= a); + return a - b; + } + function add(uint256 a, uint256 b) internal constant returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} +contract Ownable { + address public owner; + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + function Ownable() { + owner = msg.sender; + } + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + function transferOwnership(address newOwner) onlyOwner public { + require(newOwner != address(0)); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + } +} +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) allowed; + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + + uint256 _allowance = allowed[_from][msg.sender]; + + + + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = _allowance.sub(_value); + Transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + function increaseApproval (address _spender, uint _addedValue) + returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) + returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } +} + +contract BurnableToken is StandardToken { + + event Burn(address indexed burner, uint256 value); + + function burn(uint256 _value) public { + require(_value > 0); + require(_value <= balances[msg.sender]); + + address burner = msg.sender; + balances[burner] = balances[burner].sub(_value); + totalSupply = totalSupply.sub(_value); + Burn(burner, _value); + } +} + +contract Cygnus is BurnableToken, Ownable { + + string public constant name = "Cygnus"; + string public constant symbol = "Cyg"; + uint public constant decimals = 18; + uint256 public constant initialSupply = 16000000000 * (10 ** uint256(decimals)); + + + function Cygnus() { + totalSupply = initialSupply; + balances[msg.sender] = initialSupply; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/737.sol b/benchmark2/integer overflow/737.sol new file mode 100644 index 0000000000000000000000000000000000000000..5bb314b92854b222d6b67f9dcf29f4a7308f2796 --- /dev/null +++ b/benchmark2/integer overflow/737.sol @@ -0,0 +1,159 @@ +pragma solidity ^0.4.17; + + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +library SafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } + +} + + +contract BasicToken is ERC20Basic { + + using SafeMath for uint256; + + mapping(address => uint256) balances; + + + function transfer(address _to, uint256 _value) public returns (bool) { + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) allowed; + + + function approve(address _spender, uint256 _value) public returns (bool) { + + + + + + require((_value == 0) || (allowed[msg.sender][_spender] == 0)); + + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) constant public returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + +contract Ownable { + + address public owner; + + + function Ownable() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) onlyOwner public { + require(newOwner != address(0)); + owner = newOwner; + } + +} + + + +contract MintableToken is StandardToken, Ownable { + + event Mint(address indexed to, uint256 amount); + + event MintFinished(); + + bool public mintingFinished = false; + + modifier canMint() { + require(!mintingFinished); + _; + } + + + function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { + totalSupply = totalSupply.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + return true; + } + + + function finishMinting() onlyOwner public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } + +} + +contract Veradium is MintableToken { + + string public constant name = "Veradium"; + + string public constant symbol = "VRDM"; + + uint32 public constant decimals = 18; + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/752.sol b/benchmark2/integer overflow/752.sol new file mode 100644 index 0000000000000000000000000000000000000000..d39193a0cd780efc6c06f6be3f95e2337fe40e3b --- /dev/null +++ b/benchmark2/integer overflow/752.sol @@ -0,0 +1,306 @@ +pragma solidity ^0.4.24; + + + +contract Owned { + address public owner; + + function Owned() public { + owner = msg.sender; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function setOwner(address _owner) onlyOwner public { + owner = _owner; + } +} + + +contract SafeMath { + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + assert(c >= _a); + return c; + } + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_a >= _b); + return _a - _b; + } + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a * _b; + assert(_a == 0 || c / _a == _b); + return c; + } +} + + +contract Token is SafeMath, Owned { + uint256 constant DAY_IN_SECONDS = 86400; + string public constant standard = "0.777"; + string public name = ""; + string public symbol = ""; + uint8 public decimals = 0; + uint256 public totalSupply = 0; + mapping (address => uint256) public balanceP; + mapping (address => mapping (address => uint256)) public allowance; + + mapping (address => uint256[]) public lockTime; + mapping (address => uint256[]) public lockValue; + mapping (address => uint256) public lockNum; + mapping (address => bool) public locker; + uint256 public later = 0; + uint256 public earlier = 0; + + + + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + event TransferredLocked(address indexed _from, address indexed _to, uint256 _time, uint256 _value); + event TokenUnlocked(address indexed _address, uint256 _value); + + + function Token(string _name, string _symbol, uint8 _decimals, uint256 _totalSupply) public { + require(bytes(_name).length > 0 && bytes(_symbol).length > 0); + + name = _name; + symbol = _symbol; + decimals = _decimals; + totalSupply = _totalSupply; + + balanceP[msg.sender] = _totalSupply; + + } + + + modifier validAddress(address _address) { + require(_address != 0x0); + _; + } + + + function addLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = true; + } + + function removeLocker(address _address) public validAddress(_address) onlyOwner { + locker[_address] = false; + } + + + function setUnlockEarlier(uint256 _earlier) public onlyOwner { + earlier = add(earlier, _earlier); + } + + function setUnlockLater(uint256 _later) public onlyOwner { + later = add(later, _later); + } + + + function balanceUnlocked(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function balanceLocked(address _address) public view returns (uint256 _balance) { + _balance = 0; + uint256 i = 0; + while (i < lockNum[_address]) { + if (add(now, earlier) < add(lockTime[_address][i], later)) _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function balanceOf(address _address) public view returns (uint256 _balance) { + _balance = balanceP[_address]; + uint256 i = 0; + while (i < lockNum[_address]) { + _balance = add(_balance, lockValue[_address][i]); + i++; + } + return _balance; + } + + + function showTime(address _address) public view validAddress(_address) returns (uint256[] _time) { + uint i = 0; + uint256[] memory tempLockTime = new uint256[](lockNum[_address]); + while (i < lockNum[_address]) { + tempLockTime[i] = sub(add(lockTime[_address][i], later), earlier); + i++; + } + return tempLockTime; + } + + function showValue(address _address) public view validAddress(_address) returns (uint256[] _value) { + return lockValue[_address]; + } + + + function calcUnlock(address _address) private { + uint256 i = 0; + uint256 j = 0; + uint256[] memory currentLockTime; + uint256[] memory currentLockValue; + uint256[] memory newLockTime = new uint256[](lockNum[_address]); + uint256[] memory newLockValue = new uint256[](lockNum[_address]); + currentLockTime = lockTime[_address]; + currentLockValue = lockValue[_address]; + while (i < lockNum[_address]) { + if (add(now, earlier) > add(currentLockTime[i], later)) { + balanceP[_address] = add(balanceP[_address], currentLockValue[i]); + + + emit TokenUnlocked(_address, currentLockValue[i]); + } else { + newLockTime[j] = currentLockTime[i]; + newLockValue[j] = currentLockValue[i]; + j++; + } + i++; + } + uint256[] memory trimLockTime = new uint256[](j); + uint256[] memory trimLockValue = new uint256[](j); + i = 0; + while (i < j) { + trimLockTime[i] = newLockTime[i]; + trimLockValue[i] = newLockValue[i]; + i++; + } + lockTime[_address] = trimLockTime; + lockValue[_address] = trimLockValue; + lockNum[_address] = j; + } + + + function transfer(address _to, uint256 _value) public validAddress(_to) returns (bool success) { + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + if (balanceP[msg.sender] >= _value && _value > 0) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + + function transferLocked(address _to, uint256[] _time, uint256[] _value) public validAddress(_to) returns (bool success) { + require(_value.length == _time.length); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[msg.sender] >= totalValue && totalValue > 0) { + i = 0; + while (i < _time.length) { + balanceP[msg.sender] = sub(balanceP[msg.sender], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + + emit TransferredLocked(msg.sender, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + + emit Transfer(msg.sender, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + + function transferLockedFrom(address _from, address _to, uint256[] _time, uint256[] _value) public + validAddress(_from) validAddress(_to) returns (bool success) { + require(locker[msg.sender]); + require(_value.length == _time.length); + + if (lockNum[_from] > 0) calcUnlock(_from); + uint256 i = 0; + uint256 totalValue = 0; + while (i < _value.length) { + totalValue = add(totalValue, _value[i]); + i++; + } + if (balanceP[_from] >= totalValue && totalValue > 0) { + i = 0; + while (i < _time.length) { + balanceP[_from] = sub(balanceP[_from], _value[i]); + lockTime[_to].length = lockNum[_to]+1; + lockValue[_to].length = lockNum[_to]+1; + lockTime[_to][lockNum[_to]] = add(now, _time[i]); + lockValue[_to][lockNum[_to]] = _value[i]; + + + emit TransferredLocked(_from, _to, lockTime[_to][lockNum[_to]], lockValue[_to][lockNum[_to]]); + + + emit Transfer(_from, _to, lockValue[_to][lockNum[_to]]); + lockNum[_to]++; + i++; + } + return true; + } + else { + return false; + } + } + + + function transferFrom(address _from, address _to, uint256 _value) public validAddress(_from) validAddress(_to) returns (bool success) { + if (lockNum[_from] > 0) calcUnlock(_from); + if (balanceP[_from] >= _value && _value > 0) { + allowance[_from][msg.sender] = sub(allowance[_from][msg.sender], _value); + balanceP[_from] = sub(balanceP[_from], _value); + balanceP[_to] = add(balanceP[_to], _value); + emit Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + + function approve(address _spender, uint256 _value) public validAddress(_spender) returns (bool success) { + require(_value == 0 || allowance[msg.sender][_spender] == 0); + + if (lockNum[msg.sender] > 0) calcUnlock(msg.sender); + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function () public payable { + revert(); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/759.sol b/benchmark2/integer overflow/759.sol new file mode 100644 index 0000000000000000000000000000000000000000..1bb6b7ed9fa14c86b60fc1c368089fe1cb1c60a6 --- /dev/null +++ b/benchmark2/integer overflow/759.sol @@ -0,0 +1,222 @@ +pragma solidity ^0.4.24; + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + +contract Claimable is Ownable { + address public pendingOwner; + + + modifier onlyPendingOwner() { + require(msg.sender == pendingOwner); + _; + } + + + function transferOwnership(address newOwner) onlyOwner public { + pendingOwner = newOwner; + } + + + function claimOwnership() onlyPendingOwner public { + emit OwnershipTransferred(owner, pendingOwner); + owner = pendingOwner; + pendingOwner = address(0); + } +} + +contract SimpleFlyDropToken is Claimable { + using SafeMath for uint256; + + ERC20 internal erc20tk; + + function setToken(address _token) onlyOwner public { + require(_token != address(0)); + erc20tk = ERC20(_token); + } + + + function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) { + require(_destAddrs.length == _values.length); + + uint256 i = 0; + for (; i < _destAddrs.length; i = i.add(1)) { + if (!erc20tk.transfer(_destAddrs[i], _values[i])) { + break; + } + } + + return (i); + } +} + +contract DelayedClaimable is Claimable { + + uint256 public end; + uint256 public start; + + + function setLimits(uint256 _start, uint256 _end) onlyOwner public { + require(_start <= _end); + end = _end; + start = _start; + } + + + function claimOwnership() onlyPendingOwner public { + require((block.number <= end) && (block.number >= start)); + emit OwnershipTransferred(owner, pendingOwner); + owner = pendingOwner; + pendingOwner = address(0); + end = 0; + } + +} + +contract FlyDropTokenMgr is DelayedClaimable { + using SafeMath for uint256; + + address[] dropTokenAddrs; + SimpleFlyDropToken currentDropTokenContract; + + + + function prepare(uint256 _rand, + address _from, + address _token, + uint256 _value) onlyOwner public returns (bool) { + require(_token != address(0)); + require(_from != address(0)); + require(_rand > 0); + + if (ERC20(_token).allowance(_from, this) < _value) { + return false; + } + + if (_rand > dropTokenAddrs.length) { + SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken(); + dropTokenAddrs.push(address(dropTokenContract)); + currentDropTokenContract = dropTokenContract; + } else { + currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]); + } + + currentDropTokenContract.setToken(_token); + return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value); + + + + } + + + + + + + + + + function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) { + require(address(currentDropTokenContract) != address(0)); + return currentDropTokenContract.multiSend(_destAddrs, _values); + } + +} + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/760.sol b/benchmark2/integer overflow/760.sol new file mode 100644 index 0000000000000000000000000000000000000000..3ec229fa837dfdbd82159a91f8c7ca6e5059bf5f --- /dev/null +++ b/benchmark2/integer overflow/760.sol @@ -0,0 +1,156 @@ +pragma solidity ^0.4.24; + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract CryptSureToken is StandardToken { + string public name = "CryptSureToken"; + string public symbol = "CPST"; + uint8 public decimals = 18; + + + uint256 public constant INITIAL_SUPPLY = 50000000; + + constructor() public { + totalSupply_ = INITIAL_SUPPLY * (10 ** uint256(decimals)); + balances[msg.sender] = totalSupply_; + transfer(msg.sender, totalSupply_); + } + + + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(this) ); + super.transfer(_to, _value); + } + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/773.sol b/benchmark2/integer overflow/773.sol new file mode 100644 index 0000000000000000000000000000000000000000..1ccc53dc6572785101a18950bd6c801fb5ecbda2 --- /dev/null +++ b/benchmark2/integer overflow/773.sol @@ -0,0 +1,161 @@ +pragma solidity ^0.4.21; + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + require((_value == 0) || allowed[msg.sender][_spender]== 0); + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract BFMToken is StandardToken { + + string public constant name = "Blockchain and Fintech Media Union"; + string public constant symbol = "BFM"; + uint8 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 500 * (10 ** uint256(decimals)); + + + constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + emit Transfer(0x0, msg.sender, INITIAL_SUPPLY); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/79.sol b/benchmark2/integer overflow/79.sol new file mode 100644 index 0000000000000000000000000000000000000000..522c561a8a1155cb0b6ee0f6345a8b8b0c0d7a1f --- /dev/null +++ b/benchmark2/integer overflow/79.sol @@ -0,0 +1,374 @@ +pragma solidity ^0.4.19; + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + +contract Ownable { + + address public owner; + + event OwnershipTransferred(address indexed from, address indexed to); + + + + function Ownable() public { + owner = msg.sender; + } + + + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address _newOwner) public onlyOwner { + require( + _newOwner != address(0) + && _newOwner != owner + ); + OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + + +contract ERCInterface { + function transferFrom(address _from, address _to, uint256 _value) public; + function balanceOf(address who) constant public returns (uint256); + function allowance(address owner, address spender) constant public returns (uint256); + function transfer(address to, uint256 value) public returns(bool); +} + + + +contract DappleAirdrops is Ownable { + + using SafeMath for uint256; + + mapping (address => uint256) public bonusDropsOf; + mapping (address => uint256) public ethBalanceOf; + mapping (address => bool) public tokenIsBanned; + mapping (address => uint256) public trialDrops; + + uint256 public rate; + uint256 public dropUnitPrice; + uint256 public bonus; + uint256 public maxDropsPerTx; + uint256 public maxTrialDrops; + string public constant website = "www.dappleairdrops.com"; + + event BonusCreditGranted(address indexed to, uint256 credit); + event BonusCreditRevoked(address indexed from, uint256 credit); + event CreditPurchased(address indexed by, uint256 etherValue, uint256 credit); + event AirdropInvoked(address indexed by, uint256 creditConsumed); + event BonustChanged(uint256 from, uint256 to); + event TokenBanned(address indexed tokenAddress); + event TokenUnbanned(address indexed tokenAddress); + event EthWithdrawn(address indexed by, uint256 totalWei); + event RateChanged(uint256 from, uint256 to); + event MaxDropsChanged(uint256 from, uint256 to); + event RefundIssued(address indexed to, uint256 totalWei); + event ERC20TokensWithdrawn(address token, address sentTo, uint256 value); + + + + function DappleAirdrops() public { + rate = 10000; + dropUnitPrice = 1e14; + bonus = 20; + maxDropsPerTx = 1000000; + maxTrialDrops = 1000000; + } + + + + function tokenHasFreeTrial(address _addressOfToken) public view returns(bool) { + return trialDrops[_addressOfToken] < maxTrialDrops; + } + + + + function getRemainingTrialDrops(address _addressOfToken) public view returns(uint256) { + if(tokenHasFreeTrial(_addressOfToken)) { + return maxTrialDrops.sub(trialDrops[_addressOfToken]); + } + return 0; + } + + + + function setRate(uint256 _newRate) public onlyOwner returns(bool) { + require( + _newRate != rate + && _newRate > 0 + ); + RateChanged(rate, _newRate); + rate = _newRate; + uint256 eth = 1 ether; + dropUnitPrice = eth.div(rate); + return true; + } + + + function getRate() public view returns(uint256) { + return rate; + } + + + + function getMaxDropsPerTx() public view returns(uint256) { + return maxDropsPerTx; + } + + + + function setMaxDrops(uint256 _maxDrops) public onlyOwner returns(bool) { + require(_maxDrops >= 1000000); + MaxDropsChanged(maxDropsPerTx, _maxDrops); + maxDropsPerTx = _maxDrops; + return true; + } + + + function setBonus(uint256 _newBonus) public onlyOwner returns(bool) { + require(bonus != _newBonus); + BonustChanged(bonus, _newBonus); + bonus = _newBonus; + } + + + + function grantBonusDrops(address _addr, uint256 _bonusDrops) public onlyOwner returns(bool) { + require( + _addr != address(0) + && _bonusDrops > 0 + ); + bonusDropsOf[_addr] = bonusDropsOf[_addr].add(_bonusDrops); + BonusCreditGranted(_addr, _bonusDrops); + return true; + } + + + + function revokeBonusCreditOf(address _addr, uint256 _bonusDrops) public onlyOwner returns(bool) { + require( + _addr != address(0) + && bonusDropsOf[_addr] >= _bonusDrops + ); + bonusDropsOf[_addr] = bonusDropsOf[_addr].sub(_bonusDrops); + BonusCreditRevoked(_addr, _bonusDrops); + return true; + } + + + + function getDropsOf(address _addr) public view returns(uint256) { + return (ethBalanceOf[_addr].mul(rate)).div(10 ** 18); + } + + + + function getBonusDropsOf(address _addr) public view returns(uint256) { + return bonusDropsOf[_addr]; + } + + + + function getTotalDropsOf(address _addr) public view returns(uint256) { + return getDropsOf(_addr).add(getBonusDropsOf(_addr)); + } + + + + function getEthBalanceOf(address _addr) public view returns(uint256) { + return ethBalanceOf[_addr]; + } + + + + function banToken(address _tokenAddr) public onlyOwner returns(bool) { + require(!tokenIsBanned[_tokenAddr]); + tokenIsBanned[_tokenAddr] = true; + TokenBanned(_tokenAddr); + return true; + } + + + + function unbanToken(address _tokenAddr) public onlyOwner returns(bool) { + require(tokenIsBanned[_tokenAddr]); + tokenIsBanned[_tokenAddr] = false; + TokenUnbanned(_tokenAddr); + return true; + } + + + + function getTokenAllowance(address _addr, address _addressOfToken) public view returns(uint256) { + ERCInterface token = ERCInterface(_addressOfToken); + return token.allowance(_addr, address(this)); + } + + + + function() public payable { + ethBalanceOf[msg.sender] = ethBalanceOf[msg.sender].add(msg.value); + CreditPurchased(msg.sender, msg.value, msg.value.mul(rate)); + } + + + + function withdrawEth(uint256 _eth) public returns(bool) { + require( + ethBalanceOf[msg.sender] >= _eth + && _eth > 0 + ); + uint256 toTransfer = _eth; + ethBalanceOf[msg.sender] = ethBalanceOf[msg.sender].sub(_eth); + msg.sender.transfer(toTransfer); + EthWithdrawn(msg.sender, toTransfer); + } + + + + function issueRefunds(address[] _addrs) public onlyOwner returns(bool) { + require(_addrs.length <= maxDropsPerTx); + for(uint i = 0; i < _addrs.length; i++) { + if(_addrs[i] != address(0) && ethBalanceOf[_addrs[i]] > 0) { + uint256 toRefund = ethBalanceOf[_addrs[i]]; + ethBalanceOf[_addrs[i]] = 0; + _addrs[i].transfer(toRefund); + RefundIssued(_addrs[i], toRefund); + } + } + } + + + + function singleValueAirdrop(address _addressOfToken, address[] _recipients, uint256 _value) public returns(bool) { + ERCInterface token = ERCInterface(_addressOfToken); + require( + _recipients.length <= maxDropsPerTx + && ( + getTotalDropsOf(msg.sender)>= _recipients.length + || tokenHasFreeTrial(_addressOfToken) + ) + && !tokenIsBanned[_addressOfToken] + ); + for(uint i = 0; i < _recipients.length; i++) { + if(_recipients[i] != address(0)) { + token.transferFrom(msg.sender, _recipients[i], _value); + } + } + if(tokenHasFreeTrial(_addressOfToken)) { + trialDrops[_addressOfToken] = trialDrops[_addressOfToken].add(_recipients.length); + } else { + updateMsgSenderBonusDrops(_recipients.length); + } + AirdropInvoked(msg.sender, _recipients.length); + return true; + } + + + + function multiValueAirdrop(address _addressOfToken, address[] _recipients, uint256[] _values) public returns(bool) { + ERCInterface token = ERCInterface(_addressOfToken); + require( + _recipients.length <= maxDropsPerTx + && _recipients.length == _values.length + && ( + getTotalDropsOf(msg.sender) >= _recipients.length + || tokenHasFreeTrial(_addressOfToken) + ) + && !tokenIsBanned[_addressOfToken] + ); + for(uint i = 0; i < _recipients.length; i++) { + if(_recipients[i] != address(0) && _values[i] > 0) { + token.transferFrom(msg.sender, _recipients[i], _values[i]); + } + } + if(tokenHasFreeTrial(_addressOfToken)) { + trialDrops[_addressOfToken] = trialDrops[_addressOfToken].add(_recipients.length); + } else { + updateMsgSenderBonusDrops(_recipients.length); + } + AirdropInvoked(msg.sender, _recipients.length); + return true; + } + + + + function updateMsgSenderBonusDrops(uint256 _drops) internal { + if(_drops <= getDropsOf(msg.sender)) { + bonusDropsOf[msg.sender] = bonusDropsOf[msg.sender].add(_drops.mul(bonus).div(100)); + ethBalanceOf[msg.sender] = ethBalanceOf[msg.sender].sub(_drops.mul(dropUnitPrice)); + owner.transfer(_drops.mul(dropUnitPrice)); + } else { + uint256 remainder = _drops.sub(getDropsOf(msg.sender)); + if(ethBalanceOf[msg.sender] > 0) { + bonusDropsOf[msg.sender] = bonusDropsOf[msg.sender].add(getDropsOf(msg.sender).mul(bonus).div(100)); + owner.transfer(ethBalanceOf[msg.sender]); + ethBalanceOf[msg.sender] = 0; + } + bonusDropsOf[msg.sender] = bonusDropsOf[msg.sender].sub(remainder); + } + } + + + + function withdrawERC20Tokens(address _addressOfToken, address _recipient, uint256 _value) public onlyOwner returns(bool){ + require( + _addressOfToken != address(0) + && _recipient != address(0) + && _value > 0 + ); + ERCInterface token = ERCInterface(_addressOfToken); + token.transfer(_recipient, _value); + ERC20TokensWithdrawn(_addressOfToken, _recipient, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/804.sol b/benchmark2/integer overflow/804.sol new file mode 100644 index 0000000000000000000000000000000000000000..5116b04746f8f6f2222cbecad3333aad7e3cbc33 --- /dev/null +++ b/benchmark2/integer overflow/804.sol @@ -0,0 +1,346 @@ +pragma solidity ^0.4.8; + + +library BobbySafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a / b; + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract BobbyERC20Base { + + address public ceoAddress; + address public cfoAddress; + + + bool public paused = false; + + constructor(address cfoAddr) public { + ceoAddress = msg.sender; + cfoAddress = cfoAddr; + } + + modifier onlyCEO() { + require(msg.sender == ceoAddress); + _; + } + + function setCEO(address _newCEO) public onlyCEO { + require(_newCEO != address(0)); + ceoAddress = _newCEO; + } + + modifier onlyCFO() { + require(msg.sender == cfoAddress); + _; + } + + modifier allButCFO() { + require(msg.sender != cfoAddress); + _; + } + + function setCFO(address _newCFO) public onlyCEO { + require(_newCFO != address(0)); + cfoAddress = _newCFO; + } + + modifier whenNotPaused() { + require(!paused); + _; + } + + modifier whenPaused { + require(paused); + _; + } + + function pause() external onlyCEO whenNotPaused { + paused = true; + } + + function unpause() public onlyCEO whenPaused { + paused = false; + } +} + +contract ERC20Interface { + + + event Approval(address indexed src, address indexed guy, uint wad); + event Transfer(address indexed src, address indexed dst, uint wad); + + + event Grant(address indexed src, address indexed dst, uint wad); + event Unlock(address indexed user, uint wad); + + function name() public view returns (string n); + function symbol() public view returns (string s); + function decimals() public view returns (uint8 d); + function totalSupply() public view returns (uint256 t); + function balanceOf(address _owner) public view returns (uint256 balance); + function transfer(address _to, uint256 _value) public returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); + function approve(address _spender, uint256 _value) public returns (bool success); + function allowance(address _owner, address _spender) public view returns (uint256 remaining); +} + + +contract ERC20 is ERC20Interface, BobbyERC20Base { + using BobbySafeMath for uint256; + + uint private _Thousand = 1000; + uint private _Billion = _Thousand * _Thousand * _Thousand; + + + string private _name = "BOBBYTest"; + string private _symbol = "BOBBYTest"; + uint8 private _decimals = 9; + uint256 private _totalSupply = 10 * _Billion * (10 ** uint256(_decimals)); + + + struct UserToken { + uint index; + address addr; + uint256 tokens; + + uint256 unlockUnit; + uint256 unlockPeriod; + uint256 unlockLeft; + uint256 unlockLastTime; + } + + mapping(address=>UserToken) private _balancesMap; + address[] private _balancesArray; + + uint32 private actionTransfer = 0; + uint32 private actionGrant = 1; + uint32 private actionUnlock = 2; + + struct LogEntry { + uint256 time; + uint32 action; + address from; + address to; + uint256 v1; + uint256 v2; + uint256 v3; + } + + LogEntry[] private _logs; + + + constructor(address cfoAddr) BobbyERC20Base(cfoAddr) public { + + + _balancesArray.push(address(0)); + + + + UserToken memory userCFO; + userCFO.index = _balancesArray.length; + userCFO.addr = cfoAddr; + userCFO.tokens = _totalSupply; + userCFO.unlockUnit = 0; + userCFO.unlockPeriod = 0; + userCFO.unlockLeft = 0; + userCFO.unlockLastTime = 0; + _balancesArray.push(cfoAddr); + _balancesMap[cfoAddr] = userCFO; + } + + + function name() public view returns (string n){ + n = _name; + } + + + function symbol() public view returns (string s){ + s = _symbol; + } + + + function decimals() public view returns (uint8 d){ + d = _decimals; + } + + + function totalSupply() public view returns (uint256 t){ + t = _totalSupply; + } + + + function balanceOf(address _owner) public view returns (uint256 balance){ + UserToken storage user = _balancesMap[_owner]; + balance = user.tokens.add(user.unlockLeft); + } + + + function transfer(address _to, uint256 _value) public returns (bool success){ + require(!paused); + require(msg.sender != cfoAddress); + require(msg.sender != _to); + + + if(_balancesMap[msg.sender].unlockLeft > 0){ + UserToken storage sender = _balancesMap[msg.sender]; + uint256 diff = now.sub(sender.unlockLastTime); + uint256 round = diff.div(sender.unlockPeriod); + if(round > 0) { + uint256 unlocked = sender.unlockUnit.mul(round); + if (unlocked > sender.unlockLeft) { + unlocked = sender.unlockLeft; + } + + sender.unlockLeft = sender.unlockLeft.sub(unlocked); + sender.tokens = sender.tokens.add(unlocked); + sender.unlockLastTime = sender.unlockLastTime.add(sender.unlockPeriod.mul(round)); + + emit Unlock(msg.sender, unlocked); + log(actionUnlock, msg.sender, 0, unlocked, 0, 0); + } + } + + require(_balancesMap[msg.sender].tokens >= _value); + _balancesMap[msg.sender].tokens = _balancesMap[msg.sender].tokens.sub(_value); + + uint index = _balancesMap[_to].index; + if(index == 0){ + UserToken memory user; + user.index = _balancesArray.length; + user.addr = _to; + user.tokens = _value; + user.unlockUnit = 0; + user.unlockPeriod = 0; + user.unlockLeft = 0; + user.unlockLastTime = 0; + _balancesMap[_to] = user; + _balancesArray.push(_to); + } + else{ + _balancesMap[_to].tokens = _balancesMap[_to].tokens.add(_value); + } + + emit Transfer(msg.sender, _to, _value); + log(actionTransfer, msg.sender, _to, _value, 0, 0); + success = true; + } + + function transferFrom(address, address, uint256) public returns (bool success){ + require(!paused); + success = true; + } + + function approve(address, uint256) public returns (bool success){ + require(!paused); + success = true; + } + + function allowance(address, address) public view returns (uint256 remaining){ + require(!paused); + remaining = 0; + } + + function grant(address _to, uint256 _value, uint256 _duration, uint256 _periods) public returns (bool success){ + require(msg.sender != _to); + require(_balancesMap[msg.sender].tokens >= _value); + require(_balancesMap[_to].unlockLastTime == 0); + + _balancesMap[msg.sender].tokens = _balancesMap[msg.sender].tokens.sub(_value); + + if(_balancesMap[_to].index == 0){ + UserToken memory user; + user.index = _balancesArray.length; + user.addr = _to; + user.tokens = 0; + user.unlockUnit = _value.div(_periods); + + user.unlockPeriod = _duration.mul(1 days).div(_periods); + user.unlockLeft = _value; + user.unlockLastTime = now; + _balancesMap[_to] = user; + _balancesArray.push(_to); + } + else{ + _balancesMap[_to].unlockUnit = _value.div(_periods); + + _balancesMap[_to].unlockPeriod = _duration.mul(1 days).div(_periods); + _balancesMap[_to].unlockLeft = _value; + _balancesMap[_to].unlockLastTime = now; + } + + emit Grant(msg.sender, _to, _value); + log(actionGrant, msg.sender, _to, _value, _duration, _periods); + success = true; + } + + function getBalanceAddr(uint256 _index) public view returns(address addr){ + require(_index < _balancesArray.length); + require(_index >= 0); + addr = _balancesArray[_index]; + } + + function getBalanceSize() public view returns(uint256 size){ + size = _balancesArray.length; + } + + function getLockInfo(address addr) public view returns (uint256 unlocked, uint256 unit, uint256 period, uint256 last) { + UserToken storage user = _balancesMap[addr]; + unlocked = user.unlockLeft; + unit = user.unlockUnit; + period = user.unlockPeriod; + last = user.unlockLastTime; + } + + function log(uint32 action, address from, address to, uint256 _v1, uint256 _v2, uint256 _v3) private { + LogEntry memory entry; + entry.action = action; + entry.time = now; + entry.from = from; + entry.to = to; + entry.v1 = _v1; + entry.v2 = _v2; + entry.v3 = _v3; + _logs.push(entry); + } + + function getLogSize() public view returns(uint256 size){ + size = _logs.length; + } + + function getLog(uint256 _index) public view returns(uint time, uint32 action, address from, address to, uint256 _v1, uint256 _v2, uint256 _v3){ + require(_index < _logs.length); + require(_index >= 0); + LogEntry storage entry = _logs[_index]; + action = entry.action; + time = entry.time; + from = entry.from; + to = entry.to; + _v1 = entry.v1; + _v2 = entry.v2; + _v3 = entry.v3; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/811.sol b/benchmark2/integer overflow/811.sol new file mode 100644 index 0000000000000000000000000000000000000000..e5596fabec2044f0d85f34f98343340b2a9a10b2 --- /dev/null +++ b/benchmark2/integer overflow/811.sol @@ -0,0 +1,109 @@ +pragma solidity ^0.4.19; + +contract BaseToken { + string public name; + string public symbol; + uint8 public decimals; + uint256 public totalSupply; + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); + + function _transfer(address _from, address _to, uint _value) internal { + require(_to != 0x0); + require(balanceOf[_from] >= _value); + require(balanceOf[_to] + _value > balanceOf[_to]); + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + balanceOf[_from] -= _value; + balanceOf[_to] += _value; + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + Transfer(_from, _to, _value); + } + + function transfer(address _to, uint256 _value) public returns (bool success) { + _transfer(msg.sender, _to, _value); + return true; + } + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool success) { + allowance[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } +} + +contract BurnToken is BaseToken { + event Burn(address indexed from, uint256 value); + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + Burn(_from, _value); + return true; + } +} + +contract AirdropToken is BaseToken { + uint256 public airAmount; + uint256 public airBegintime; + uint256 public airEndtime; + address public airSender; + uint32 public airLimitCount; + + mapping (address => uint32) public airCountOf; + + event Airdrop(address indexed from, uint32 indexed count, uint256 tokenValue); + + function airdrop() public payable { + require(now >= airBegintime && now <= airEndtime); + require(msg.value == 0); + if (airLimitCount > 0 && airCountOf[msg.sender] >= airLimitCount) { + revert(); + } + _transfer(airSender, msg.sender, airAmount); + airCountOf[msg.sender] += 1; + Airdrop(msg.sender, airCountOf[msg.sender], airAmount); + } +} + +contract CustomToken is BaseToken, BurnToken, AirdropToken { + function CustomToken() public { + totalSupply = 20000000000000000000000000000; + name = 'DuduTechnology'; + symbol = 'DUDU'; + decimals = 18; + balanceOf[0x828db0897afec00e04d77b4879082bcb7385a76a] = totalSupply; + Transfer(address(0), 0x828db0897afec00e04d77b4879082bcb7385a76a, totalSupply); + + airAmount = 6666666600000000000000; + airBegintime = 1520240400; + airEndtime = 2215389600; + airSender = 0xd686f4d45f96fb035de703206fc55fda8882d33b; + airLimitCount = 1; + } + + function() public payable { + airdrop(); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/814.sol b/benchmark2/integer overflow/814.sol new file mode 100644 index 0000000000000000000000000000000000000000..4fd1d149431e06a418e255c56ce3c4bfb5b3be81 --- /dev/null +++ b/benchmark2/integer overflow/814.sol @@ -0,0 +1,702 @@ +pragma solidity ^0.4.24; + +contract Ownable { + address public owner; + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + constructor() public { owner = msg.sender; } + + modifier onlyOwner() { + address sender = msg.sender; + address _owner = owner; + require(msg.sender == _owner); + _; + } + + function transferOwnership(address newOwner) onlyOwner public { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } +} + +library SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public constant returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + mapping(address => uint256) balances; + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) allowed; + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + uint256 _allowance = allowed[_from][msg.sender]; + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = _allowance.sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + + function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + modifier canMint() { + require(!mintingFinished); + _; + } + + + function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { + totalSupply = totalSupply.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(0x0, _to, _amount); + return true; + } + + + function mintFinalize(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { + totalSupply = totalSupply.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(0x0, _to, _amount); + return true; + } + + + function finishMinting() onlyOwner public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + +contract BrickToken is MintableToken { + + string public constant name = "Brick"; + string public constant symbol = "BRK"; + uint8 public constant decimals = 18; + + function getTotalSupply() view public returns (uint256) { + return totalSupply; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + super.transfer(_to, _value); + } + +} + +contract KycContractInterface { + function isAddressVerified(address _address) public view returns (bool); +} + +contract KycContract is Ownable { + + mapping (address => bool) verifiedAddresses; + + function isAddressVerified(address _address) public view returns (bool) { + return verifiedAddresses[_address]; + } + + function addAddress(address _newAddress) public onlyOwner { + require(!verifiedAddresses[_newAddress]); + + verifiedAddresses[_newAddress] = true; + } + + function removeAddress(address _oldAddress) public onlyOwner { + require(verifiedAddresses[_oldAddress]); + + verifiedAddresses[_oldAddress] = false; + } + + function batchAddAddresses(address[] _addresses) public onlyOwner { + for (uint cnt = 0; cnt < _addresses.length; cnt++) { + assert(!verifiedAddresses[_addresses[cnt]]); + verifiedAddresses[_addresses[cnt]] = true; + } + } +} + + + +contract BrickCrowdsale is Ownable { + using SafeMath for uint256; + + + uint256 public startTime; + uint256 public endTime; + + uint256 public weiRaised; + uint256 public limitDateSale; + + bool public isSoftCapHit = false; + bool public isStarted = false; + bool public isFinalized = false; + + uint256 icoPvtRate = 40; + uint256 icoPreRate = 50; + uint256 ico1Rate = 65; + uint256 ico2Rate = 75; + uint256 ico3Rate = 90; + + uint256 public pvtTokens = (40000) * (10**18); + uint256 public preSaleTokens = (6000000) * (10**18); + uint256 public ico1Tokens = (8000000) * (10**18); + uint256 public ico2Tokens = (8000000) * (10**18); + uint256 public ico3Tokens = (8000000) * (10**18); + uint256 public totalTokens = (40000000)* (10**18); + + + address public advisoryEthWallet = 0x0D7629d32546CD493bc33ADEF115D4489f5599Be; + address public infraEthWallet = 0x536D36a05F6592aa29BB0beE30cda706B1272521; + address public techDevelopmentEthWallet = 0x4d0B70d8E612b5dca3597C64643a8d1efd5965e1; + address public operationsEthWallet = 0xbc67B82924eEc8643A4f2ceDa59B5acfd888A967; + + address public wallet = 0x44d44CA0f75bdd3AE8806D02515E8268459c554A; + + struct ContributorData { + uint256 contributionAmountViewOnly; + uint256 tokensIssuedViewOnly; + uint256 contributionAmount; + uint256 tokensIssued; + } + + address[] public tokenSendFailures; + + mapping(address => ContributorData) public contributorList; + mapping(uint => address) contributorIndexes; + uint nextContributorIndex; + + constructor() public {} + + function init( uint256 _tokensForCrowdsale, + uint256 _etherInUSD, address _tokenAddress, uint256 _softCapInEthers, uint256 _hardCapInEthers, + uint _saleDurationInDays, address _kycAddress, uint bonus) onlyOwner public { + + + setTokensForCrowdSale(_tokensForCrowdsale); + + setRate(_etherInUSD); + setTokenAddress(_tokenAddress); + setSoftCap(_softCapInEthers); + setHardCap(_hardCapInEthers); + setSaleDuration(_saleDurationInDays); + setKycAddress(_kycAddress); + setSaleBonus(bonus); + + kyc = KycContract(_kycAddress); + start(); + + } + + + function start() onlyOwner public { + require(!isStarted); + require(!hasStarted()); + require(tokenAddress != address(0)); + require(kycAddress != address(0)); + require(saleDuration != 0); + require(totalTokens != 0); + require(tokensForCrowdSale != 0); + require(softCap != 0); + require(hardCap != 0); + + starting(); + emit BrickStarted(); + + isStarted = true; + + } + + function splitTokens() internal { + token.mint(techDevelopmentEthWallet,((totalTokens * 3).div(100))); + tokensIssuedTillNow = tokensIssuedTillNow + ((totalTokens * 3).div(100)); + token.mint(operationsEthWallet,((totalTokens * 7).div(100))); + tokensIssuedTillNow = tokensIssuedTillNow + ((totalTokens * 7).div(100)); + + } + + + uint256 public tokensForCrowdSale = 0; + function setTokensForCrowdSale(uint256 _tokensForCrowdsale) onlyOwner public { + tokensForCrowdSale = _tokensForCrowdsale * (10 ** 18); + } + + + uint256 public rate=0; + uint256 public etherInUSD; + function setRate(uint256 _etherInUSD) internal { + etherInUSD = _etherInUSD; + rate = (getCurrentRateInCents() * (10**18) / 100) / _etherInUSD; + } + + function setRate(uint256 rateInCents, uint256 _etherInUSD) public onlyOwner { + etherInUSD = _etherInUSD; + rate = (rateInCents * (10**18) / 100) / _etherInUSD; + } + + function updateRateInWei() internal { + require(etherInUSD != 0); + rate = (getCurrentRateInCents() * (10**18) / 100) / etherInUSD; + } + + function getCurrentRateInCents() public view returns (uint256) + { + if(currentRound == 1) { + return icoPvtRate; + } else if(currentRound == 2) { + return icoPreRate; + } else if(currentRound == 3) { + return ico1Rate; + } else if(currentRound == 4) { + return ico2Rate; + } else if(currentRound == 5) { + return ico3Rate; + } else { + return ico3Rate; + } + } + + BrickToken public token; + address tokenAddress = 0x0; + function setTokenAddress(address _tokenAddress) public onlyOwner { + tokenAddress = _tokenAddress; + token = BrickToken(_tokenAddress); + } + + + function setPvtTokens (uint256 _pvtTokens)onlyOwner public { + require(!icoPvtEnded); + pvtTokens = (_pvtTokens) * (10 ** 18); + } + function setPreSaleTokens (uint256 _preSaleTokens)onlyOwner public { + require(!icoPreEnded); + preSaleTokens = (_preSaleTokens) * (10 ** 18); + } + function setIco1Tokens (uint256 _ico1Tokens)onlyOwner public { + require(!ico1Ended); + ico1Tokens = (_ico1Tokens) * (10 ** 18); + } + function setIco2Tokens (uint256 _ico2Tokens)onlyOwner public { + require(!ico2Ended); + ico2Tokens = (_ico2Tokens) * (10 ** 18); + } + function setIco3Tokens (uint256 _ico3Tokens)onlyOwner public { + require(!ico3Ended); + ico3Tokens = (_ico3Tokens) * (10 ** 18); + } + + uint256 public softCap = 0; + function setSoftCap(uint256 _softCap) onlyOwner public { + softCap = _softCap * (10 ** 18); + } + + uint256 public hardCap = 0; + function setHardCap(uint256 _hardCap) onlyOwner public { + hardCap = _hardCap * (10 ** 18); + } + + + uint public saleDuration = 0; + function setSaleDuration(uint _saleDurationInDays) onlyOwner public { + saleDuration = _saleDurationInDays; + limitDateSale = startTime + (saleDuration * 1 days); + endTime = limitDateSale; + } + + address kycAddress = 0x0; + function setKycAddress(address _kycAddress) onlyOwner public { + kycAddress = _kycAddress; + } + + uint public saleBonus = 0; + function setSaleBonus(uint bonus) public onlyOwner{ + saleBonus = bonus; + } + + bool public isKYCRequiredToReceiveFunds = false; + function setKYCRequiredToReceiveFunds(bool IS_KYCRequiredToReceiveFunds) public onlyOwner{ + isKYCRequiredToReceiveFunds = IS_KYCRequiredToReceiveFunds; + } + + bool public isKYCRequiredToSendTokens = false; + function setKYCRequiredToSendTokens(bool IS_KYCRequiredToSendTokens) public onlyOwner{ + isKYCRequiredToSendTokens = IS_KYCRequiredToSendTokens; + } + + + + function () public payable { + buyPhaseTokens(msg.sender); + } + + KycContract public kyc; + function transferKycOwnerShip(address _address) onlyOwner public { + kyc.transferOwnership(_address); + } + + function transferTokenOwnership(address _address) onlyOwner public { + token.transferOwnership(_address); + } + + + function releaseAllTokens() onlyOwner public { + for(uint i=0; i < nextContributorIndex; i++) { + address addressToSendTo = contributorIndexes[i]; + releaseTokens(addressToSendTo); + } + } + + + function releaseTokens(address _contributerAddress) onlyOwner public { + if(isKYCRequiredToSendTokens){ + if(KycContractInterface(kycAddress).isAddressVerified(_contributerAddress)){ + release(_contributerAddress); + } + } else { + release(_contributerAddress); + } + } + + function release(address _contributerAddress) internal { + if(contributorList[_contributerAddress].tokensIssued > 0) { + if(token.mint(_contributerAddress, contributorList[_contributerAddress].tokensIssued)) { + contributorList[_contributerAddress].tokensIssued = 0; + contributorList[_contributerAddress].contributionAmount = 0; + } else { + tokenSendFailures.push(_contributerAddress); + } + } + } + + function tokenSendFailuresCount() public view returns (uint) { + return tokenSendFailures.length; + } + + function currentTokenSupply() public view returns(uint256){ + return token.getTotalSupply(); + } + + function buyPhaseTokens(address beneficiary) public payable + { + + require(beneficiary != address(0)); + require(validPurchase()); + if(isKYCRequiredToReceiveFunds){ + require(KycContractInterface(kycAddress).isAddressVerified(msg.sender)); + } + + uint256 weiAmount = msg.value; + + uint256 tokens = computeTokens(weiAmount); + require(isWithinTokenAllocLimit(tokens)); + + if(int(pvtTokens - tokensIssuedTillNow) > 0) { + require(int (tokens) < (int(pvtTokens - tokensIssuedTillNow))); + buyTokens(tokens,weiAmount,beneficiary); + } else if (int (preSaleTokens + pvtTokens - tokensIssuedTillNow) > 0) { + require(int(tokens) < (int(preSaleTokens + pvtTokens - tokensIssuedTillNow))); + buyTokens(tokens,weiAmount,beneficiary); + } else if(int(ico1Tokens + preSaleTokens + pvtTokens - tokensIssuedTillNow) > 0) { + require(int(tokens) < (int(ico1Tokens + preSaleTokens + pvtTokens -tokensIssuedTillNow))); + buyTokens(tokens,weiAmount,beneficiary); + } else if(int(ico2Tokens + ico1Tokens + preSaleTokens + pvtTokens - (tokensIssuedTillNow)) > 0) { + require(int(tokens) < (int(ico2Tokens + ico1Tokens + preSaleTokens + pvtTokens - (tokensIssuedTillNow)))); + buyTokens(tokens,weiAmount,beneficiary); + } else if(!ico3Ended && (int(tokensForCrowdSale - (tokensIssuedTillNow)) > 0)) { + require(int(tokens) < (int(tokensForCrowdSale - (tokensIssuedTillNow)))); + buyTokens(tokens,weiAmount,beneficiary); + } + } + uint256 public tokensIssuedTillNow=0; + function buyTokens(uint256 tokens,uint256 weiAmount ,address beneficiary) internal { + + + weiRaised = weiRaised.add(weiAmount); + + if (contributorList[beneficiary].contributionAmount == 0) { + contributorIndexes[nextContributorIndex] = beneficiary; + nextContributorIndex += 1; + } + + contributorList[beneficiary].contributionAmount += weiAmount; + contributorList[beneficiary].contributionAmountViewOnly += weiAmount; + contributorList[beneficiary].tokensIssued += tokens; + contributorList[beneficiary].tokensIssuedViewOnly += tokens; + tokensIssuedTillNow = tokensIssuedTillNow + tokens; + emit BrickTokenPurchase(msg.sender, beneficiary, weiAmount, tokens); + } + + + + event BrickTokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); + + function investorCount() constant public returns(uint) { + return nextContributorIndex; + } + + function hasStarted() public constant returns (bool) { + return (startTime != 0 && now > startTime); + } + + + + + + + + + + function forwardAllRaisedFunds() internal { + + require(advisoryEthWallet != address(0)); + require(infraEthWallet != address(0)); + require(techDevelopmentEthWallet != address(0)); + require(operationsEthWallet != address(0)); + + operationsEthWallet.transfer((weiRaised * 60) / 100); + advisoryEthWallet.transfer((weiRaised *5) / 100); + infraEthWallet.transfer((weiRaised * 10) / 100); + techDevelopmentEthWallet.transfer((weiRaised * 25) / 100); + } + + function isWithinSaleTimeLimit() internal view returns (bool) { + return now <= limitDateSale; + } + + function isWithinSaleLimit(uint256 _tokens) internal view returns (bool) { + return token.getTotalSupply().add(_tokens) <= tokensForCrowdSale; + } + + function computeTokens(uint256 weiAmount) view internal returns (uint256) { + return (weiAmount.div(rate)) * (10 ** 18); + } + + function isWithinTokenAllocLimit(uint256 _tokens) view internal returns (bool) { + return (isWithinSaleTimeLimit() && isWithinSaleLimit(_tokens)); + } + + function didSoftCapReached() internal returns (bool) { + if(weiRaised >= softCap){ + isSoftCapHit = true; + } else { + isSoftCapHit = false; + } + return isSoftCapHit; + } + + + + function validPurchase() internal constant returns (bool) { + bool withinCap = weiRaised.add(msg.value) <= hardCap; + bool withinPeriod = now >= startTime && now <= endTime; + bool nonZeroPurchase = msg.value != 0; + return (withinPeriod && nonZeroPurchase) && withinCap && isWithinSaleTimeLimit(); + } + + + + function hasEnded() public constant returns (bool) { + bool capReached = weiRaised >= hardCap; + return (endTime != 0 && now > endTime) || capReached; + } + + + + event BrickStarted(); + event BrickFinalized(); + + + function finalize() onlyOwner public { + require(!isFinalized); + + + finalization(); + emit BrickFinalized(); + + isFinalized = true; + } + + function starting() internal { + startTime = now; + limitDateSale = startTime + (saleDuration * 1 days); + endTime = limitDateSale; + } + + function finalization() internal { + splitTokens(); + + token.mintFinalize(wallet, totalTokens.sub(tokensIssuedTillNow)); + forwardAllRaisedFunds(); + } + + + + uint256 public currentRound = 1; + bool public icoPvtEnded = false; + bool public icoPreEnded = false; + bool public ico1Ended = false; + bool public ico2Ended = false; + bool public ico3Ended = false; + + function endPvtSale() onlyOwner public + { + require(!icoPvtEnded); + pvtTokens = tokensIssuedTillNow; + currentRound = 2; + updateRateInWei(); + icoPvtEnded = true; + + } + function endPreSale() onlyOwner public + { + require(!icoPreEnded && icoPvtEnded); + preSaleTokens = tokensIssuedTillNow - pvtTokens; + currentRound = 3; + updateRateInWei(); + icoPreEnded = true; + } + function endIcoSaleRound1() onlyOwner public + { + require(!ico1Ended && icoPreEnded); + ico1Tokens = tokensIssuedTillNow - preSaleTokens - pvtTokens; + currentRound = 4; + updateRateInWei(); + ico1Ended = true; + } + function endIcoSaleRound2() onlyOwner public + { + require(!ico2Ended && ico1Ended); + ico2Tokens = tokensIssuedTillNow - ico1Tokens - preSaleTokens - pvtTokens; + currentRound = 5; + updateRateInWei(); + ico2Ended=true; + } + function endIcoSaleRound3() onlyOwner public + { + require(!ico3Ended && ico2Ended); + ico3Tokens = tokensIssuedTillNow - ico2Tokens - ico1Tokens - preSaleTokens - pvtTokens; + updateRateInWei(); + ico3Ended = true; + } + + + modifier afterDeadline() { if (hasEnded() || isFinalized) _; } + + + function refundAllMoney() onlyOwner public { + for(uint i=0; i < nextContributorIndex; i++) { + address addressToSendTo = contributorIndexes[i]; + refundMoney(addressToSendTo); + } + } + + + function refundMoney(address _address) onlyOwner public { + uint amount = contributorList[_address].contributionAmount; + if (amount > 0 && _address.send(amount)) { + contributorList[_address].contributionAmount = 0; + contributorList[_address].tokensIssued = 0; + contributorList[_address].contributionAmountViewOnly = 0; + contributorList[_address].tokensIssuedViewOnly = 0; + } + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/815.sol b/benchmark2/integer overflow/815.sol new file mode 100644 index 0000000000000000000000000000000000000000..898f33edbe15242693a976f1e3154bef176754f4 --- /dev/null +++ b/benchmark2/integer overflow/815.sol @@ -0,0 +1,131 @@ +pragma solidity ^0.4.18; + + +contract SafeMath { + + function safeMul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + +} +contract CPX is SafeMath{ + string public name; + string public symbol; + uint8 public decimals = 18; + uint256 public totalSupply; + address public owner; + + + mapping (address => uint256) public balanceOf; + mapping (address => uint256) public freezeOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Burn(address indexed from, uint256 value); + + + event Freeze(address indexed from, uint256 value); + + + event Unfreeze(address indexed from, uint256 value); + + + function CPX( + uint256 initialSupply, + string tokenName, + string tokenSymbol, + address holder) public{ + totalSupply = initialSupply * 10 ** uint256(decimals); + balanceOf[holder] = totalSupply; + name = tokenName; + symbol = tokenSymbol; + owner = holder; + } + + + function transfer(address _to, uint256 _value) public{ + require(_to != 0x0); + require(_value > 0); + require(balanceOf[msg.sender] >= _value); + require(balanceOf[_to] + _value >= balanceOf[_to]); + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + Transfer(msg.sender, _to, _value); + } + + + function approve(address _spender, uint256 _value) public + returns (bool success) { + require(_value > 0); + allowance[msg.sender][_spender] = _value; + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_to != 0x0); + require(_value > 0); + require(balanceOf[_from] >= _value); + require(balanceOf[_to] + _value >= balanceOf[_to]); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value); + Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + require(_value > 0); + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + totalSupply = SafeMath.safeSub(totalSupply,_value); + Burn(msg.sender, _value); + return true; + } + + function freeze(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + require(_value > 0); + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); + Freeze(msg.sender, _value); + return true; + } + + function unfreeze(uint256 _value) public returns (bool success) { + require(freezeOf[msg.sender] >= _value); + require(_value > 0); + freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); + balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value); + Unfreeze(msg.sender, _value); + return true; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/820.sol b/benchmark2/integer overflow/820.sol new file mode 100644 index 0000000000000000000000000000000000000000..c302aec6492aab5a28204e7759d7a183ee36cd6d --- /dev/null +++ b/benchmark2/integer overflow/820.sol @@ -0,0 +1,297 @@ +pragma solidity ^0.4.24; + + + + +contract IOwned { + + function owner() public view returns (address) {} + + function transferOwnership(address _newOwner) public; + function acceptOwnership() public; +} + + + + +contract Owned is IOwned { + address public owner; + address public newOwner; + + event OwnerUpdate(address indexed _prevOwner, address indexed _newOwner); + + + constructor() public { + owner = msg.sender; + } + + + modifier ownerOnly { + assert(msg.sender == owner); + _; + } + + + function transferOwnership(address _newOwner) public ownerOnly { + require(_newOwner != owner); + newOwner = _newOwner; + } + + + function acceptOwnership() public { + require(msg.sender == newOwner); + emit OwnerUpdate(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + + + + +contract IERC20Token { + + function name() public view returns (string) {} + function symbol() public view returns (string) {} + function decimals() public view returns (uint8) {} + function totalSupply() public view returns (uint256) {} + function balanceOf(address _owner) public view returns (uint256) { _owner; } + function allowance(address _owner, address _spender) public view returns (uint256) { _owner; _spender; } + + function transfer(address _to, uint256 _value) public returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); + function approve(address _spender, uint256 _value) public returns (bool success); +} + + + + +contract Utils { + + constructor() public { + } + + + modifier greaterThanZero(uint256 _amount) { + require(_amount > 0); + _; + } + + + modifier validAddress(address _address) { + require(_address != address(0)); + _; + } + + + modifier notThis(address _address) { + require(_address != address(this)); + _; + } + + + + + function safeAdd(uint256 _x, uint256 _y) internal pure returns (uint256) { + uint256 z = _x + _y; + assert(z >= _x); + return z; + } + + + function safeSub(uint256 _x, uint256 _y) internal pure returns (uint256) { + assert(_x >= _y); + return _x - _y; + } + + + function safeMul(uint256 _x, uint256 _y) internal pure returns (uint256) { + uint256 z = _x * _y; + assert(_x == 0 || z / _x == _y); + return z; + } +} + + + + +contract ITokenHolder is IOwned { + function withdrawTokens(IERC20Token _token, address _to, uint256 _amount) public; +} + + + + +contract TokenHolder is ITokenHolder, Owned, Utils { + + constructor() public { + } + + + function withdrawTokens(IERC20Token _token, address _to, uint256 _amount) + public + ownerOnly + validAddress(_token) + validAddress(_to) + notThis(_to) + { + assert(_token.transfer(_to, _amount)); + } +} + + + + +contract ERC20Token is IERC20Token, Utils { + string public standard = 'Token 0.1'; + string public name = ''; + string public symbol = ''; + uint8 public decimals = 0; + uint256 public totalSupply = 0; + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + + constructor(string _name, string _symbol, uint8 _decimals) public { + require(bytes(_name).length > 0 && bytes(_symbol).length > 0); + + name = _name; + symbol = _symbol; + decimals = _decimals; + } + + + function transfer(address _to, uint256 _value) + public + validAddress(_to) + returns (bool success) + { + balanceOf[msg.sender] = safeSub(balanceOf[msg.sender], _value); + balanceOf[_to] = safeAdd(balanceOf[_to], _value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) + public + validAddress(_from) + validAddress(_to) + returns (bool success) + { + allowance[_from][msg.sender] = safeSub(allowance[_from][msg.sender], _value); + balanceOf[_from] = safeSub(balanceOf[_from], _value); + balanceOf[_to] = safeAdd(balanceOf[_to], _value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) + public + validAddress(_spender) + returns (bool success) + { + + require(_value == 0 || allowance[msg.sender][_spender] == 0); + + allowance[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } +} + + + + +contract ISmartToken is IOwned, IERC20Token { + function disableTransfers(bool _disable) public; + function issue(address _to, uint256 _amount) public; + function destroy(address _from, uint256 _amount) public; +} + + + + +contract SmartToken is ISmartToken, Owned, ERC20Token, TokenHolder { + string public version = '0.3'; + + bool public transfersEnabled = true; + + + event NewSmartToken(address _token); + + event Issuance(uint256 _amount); + + event Destruction(uint256 _amount); + + + constructor(string _name, string _symbol, uint8 _decimals) + public + ERC20Token(_name, _symbol, _decimals) + { + emit NewSmartToken(address(this)); + } + + + modifier transfersAllowed { + assert(transfersEnabled); + _; + } + + + function disableTransfers(bool _disable) public ownerOnly { + transfersEnabled = !_disable; + } + + + function issue(address _to, uint256 _amount) + public + ownerOnly + validAddress(_to) + notThis(_to) + { + totalSupply = safeAdd(totalSupply, _amount); + balanceOf[_to] = safeAdd(balanceOf[_to], _amount); + + emit Issuance(_amount); + emit Transfer(this, _to, _amount); + } + + + function destroy(address _from, uint256 _amount) public { + require(msg.sender == _from || msg.sender == owner); + + balanceOf[_from] = safeSub(balanceOf[_from], _amount); + totalSupply = safeSub(totalSupply, _amount); + + emit Transfer(_from, this, _amount); + emit Destruction(_amount); + } + + + + + function transfer(address _to, uint256 _value) public transfersAllowed returns (bool success) { + assert(super.transfer(_to, _value)); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public transfersAllowed returns (bool success) { + assert(super.transferFrom(_from, _to, _value)); + return true; + } +} + + + + +contract BAYToken is SmartToken ( "DAICO Bay Token", "BAY", 18){ + constructor() { + issue(msg.sender, 10**10 * 10**18); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/823.sol b/benchmark2/integer overflow/823.sol new file mode 100644 index 0000000000000000000000000000000000000000..697fa5fd7ea177ba38a61ca603f4c8a67b0938ea --- /dev/null +++ b/benchmark2/integer overflow/823.sol @@ -0,0 +1,264 @@ +pragma solidity ^0.4.24; +pragma experimental "v0.5.0"; + + +contract ERC20 { + function totalSupply() public view returns (uint256); + + function balanceOf(address _who) public view returns (uint256); + + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transfer(address _to, uint256 _value) public returns (bool); + + function approve(address _spender, uint256 _value) + public returns (bool); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); + + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + if (_a == 0) { + return 0; + } + + uint256 c = _a * _b; + require(c / _a == _b); + + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b > 0); + uint256 c = _a / _b; + + + return c; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b <= _a); + uint256 c = _a - _b; + + return c; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + require(c >= _a); + + return c; + } + + + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} + + + +contract StandardToken is ERC20 { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + mapping (address => mapping (address => uint256)) internal allowed; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + +contract DetailedStandardToken is StandardToken { + string public name; + string public symbol; + uint8 public decimals; + + constructor(string _name, string _symbol, uint8 _decimals) public { + name = _name; + symbol = _symbol; + decimals = _decimals; + } +} + +contract NovovivoToken is DetailedStandardToken, Ownable { + constructor() DetailedStandardToken("Novovivo Token Test", "NVT", 18) public { + totalSupply_ = 8 * 10**9 * 10**uint256(decimals); + balances[address(this)] = totalSupply_; + } + + function send(address _to, uint256 _value) onlyOwner public returns (bool) { + uint256 value = _value.mul(10 ** uint256(decimals)); + + ERC20 token; + token = ERC20(address(this)); + return token.transfer(_to, value); + } + + function stopTest() onlyOwner public { + selfdestruct(owner); + } + + function () external { + revert(); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/828.sol b/benchmark2/integer overflow/828.sol new file mode 100644 index 0000000000000000000000000000000000000000..b8ac8c5f20d94f345d3493ce5d9e78ae69154862 --- /dev/null +++ b/benchmark2/integer overflow/828.sol @@ -0,0 +1,223 @@ +pragma solidity ^0.4.18; + + + + + + + + + + + + + + + + + + + +contract SafeMath { + function safeAdd(uint a, uint b) public pure returns (uint c) { + c = a + b; + require(c >= a); + } + function safeSub(uint a, uint b) public pure returns (uint c) { + require(b <= a); + c = a - b; + } + function safeMul(uint a, uint b) public pure returns (uint c) { + c = a * b; + require(a == 0 || c / a == b); + } + function safeDiv(uint a, uint b) public pure returns (uint c) { + require(b > 0); + c = a / b; + } +} + + + + + + +contract ERC20Interface { + function totalSupply() public constant returns (uint); + function balanceOf(address tokenOwner) public constant returns (uint balance); + function allowance(address tokenOwner, address spender) public constant returns (uint remaining); + function transfer(address to, uint tokens) public returns (bool success); + function approve(address spender, uint tokens) public returns (bool success); + function transferFrom(address from, address to, uint tokens) public returns (bool success); + + event Transfer(address indexed from, address indexed to, uint tokens); + event Approval(address indexed tokenOwner, address indexed spender, uint tokens); +} + + + + + + + +contract ApproveAndCallFallBack { + function receiveApproval(address from, uint256 tokens, address token, bytes data) public; +} + + + + + +contract Owned { + address public owner; + address public newOwner; + + event OwnershipTransferred(address indexed _from, address indexed _to); + + function Owned() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnership(address _newOwner) public onlyOwner { + newOwner = _newOwner; + } + function acceptOwnership() public { + require(msg.sender == newOwner); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + newOwner = address(0); + } +} + + + + + + +contract ZIMBOCOIN is ERC20Interface, Owned, SafeMath { + string public symbol; + string public name; + uint8 public decimals; + uint public _totalSupply; + + mapping(address => uint) balances; + mapping(address => mapping(address => uint)) allowed; + + + + + + function ZIMBOCOIN() public { + symbol = "ZMB"; + name = "ZIMBOCOIN"; + decimals = 8; + _totalSupply = 100000000000000; + balances[0x9a33836F185A8CedFE56dB2799063133af1b6869] = _totalSupply; + Transfer(address(0), 0x9a33836F185A8CedFE56dB2799063133af1b6869, _totalSupply); + } + + + + + + function totalSupply() public constant returns (uint) { + return _totalSupply - balances[address(0)]; + } + + + + + + function balanceOf(address tokenOwner) public constant returns (uint balance) { + return balances[tokenOwner]; + } + + + + + + + + function transfer(address to, uint tokens) public returns (bool success) { + balances[msg.sender] = safeSub(balances[msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(msg.sender, to, tokens); + return true; + } + + + + + + + + + + + function approve(address spender, uint tokens) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + return true; + } + + + + + + + + + + + + function transferFrom(address from, address to, uint tokens) public returns (bool success) { + balances[from] = safeSub(balances[from], tokens); + allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); + balances[to] = safeAdd(balances[to], tokens); + Transfer(from, to, tokens); + return true; + } + + + + + + + function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { + return allowed[tokenOwner][spender]; + } + + + + + + + + function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { + allowed[msg.sender][spender] = tokens; + Approval(msg.sender, spender, tokens); + ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); + return true; + } + + + + + + function () public payable { + revert(); + } + + + + + + function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { + return ERC20Interface(tokenAddress).transfer(owner, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/842.sol b/benchmark2/integer overflow/842.sol new file mode 100644 index 0000000000000000000000000000000000000000..b10043afaeb7752c25c910b0cdaeafedf2b70744 --- /dev/null +++ b/benchmark2/integer overflow/842.sol @@ -0,0 +1,281 @@ +pragma solidity ^0.4.23; + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract DetailedERC20 is ERC20 { + string public name; + string public symbol; + uint8 public decimals; + + function DetailedERC20(string _name, string _symbol, uint8 _decimals) public { + name = _name; + symbol = _symbol; + decimals = _decimals; + } +} + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + +contract BurnableToken is BasicToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract Ownable { + address public owner; + + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + function Ownable() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + + +contract PausableToken is StandardToken, Pausable { + + function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transferFrom(_from, _to, _value); + } + + function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { + return super.approve(_spender, _value); + } + + function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + + + +contract Lara is DetailedERC20, StandardToken, BurnableToken, PausableToken { + + + function Lara( + uint256 totalSupply + ) DetailedERC20( + "Lara", + "LARA", + 8 + ) { + totalSupply_ = totalSupply; + balances[msg.sender] = totalSupply; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/843.sol b/benchmark2/integer overflow/843.sol new file mode 100644 index 0000000000000000000000000000000000000000..e1619cf1ab2407ee9063d425ac7a60efdb0e4899 --- /dev/null +++ b/benchmark2/integer overflow/843.sol @@ -0,0 +1,512 @@ +pragma solidity ^0.4.23; + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } +} + + + + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + modifier hasMintPermission() { + require(msg.sender == owner); + _; + } + + + function mint( + address _to, + uint256 _amount + ) + hasMintPermission + canMint + public + returns (bool) + { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() onlyOwner canMint public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + + + +library Roles { + struct Role { + mapping (address => bool) bearer; + } + + + function add(Role storage role, address addr) + internal + { + role.bearer[addr] = true; + } + + + function remove(Role storage role, address addr) + internal + { + role.bearer[addr] = false; + } + + + function check(Role storage role, address addr) + view + internal + { + require(has(role, addr)); + } + + + function has(Role storage role, address addr) + view + internal + returns (bool) + { + return role.bearer[addr]; + } +} + + + + +contract RBAC { + using Roles for Roles.Role; + + mapping (string => Roles.Role) private roles; + + event RoleAdded(address addr, string roleName); + event RoleRemoved(address addr, string roleName); + + + function checkRole(address addr, string roleName) + view + public + { + roles[roleName].check(addr); + } + + + function hasRole(address addr, string roleName) + view + public + returns (bool) + { + return roles[roleName].has(addr); + } + + + function addRole(address addr, string roleName) + internal + { + roles[roleName].add(addr); + emit RoleAdded(addr, roleName); + } + + + function removeRole(address addr, string roleName) + internal + { + roles[roleName].remove(addr); + emit RoleRemoved(addr, roleName); + } + + + modifier onlyRole(string roleName) + { + checkRole(msg.sender, roleName); + _; + } + + + + + + + + + + + + + + + +} + + + + +pragma solidity ^0.4.19; + + + + + +contract RBACMintableToken is MintableToken, RBAC { + + string public constant ROLE_MINTER = "minter"; + address[] internal minters; + + + modifier hasMintPermission() { + checkRole(msg.sender, ROLE_MINTER); + _; + } + + + function addMinter(address minter) onlyOwner public { + if (!hasRole(minter, ROLE_MINTER)) + minters.push(minter); + addRole(minter, ROLE_MINTER); + } + + + function removeMinter(address minter) onlyOwner public { + removeRole(minter, ROLE_MINTER); + removeMinterByValue(minter); + } + + function getNumberOfMinters() onlyOwner public view returns (uint) { + return minters.length; + } + + function getMinter(uint _index) onlyOwner public view returns (address) { + require(_index < minters.length); + return minters[_index]; + } + + function removeMinterByIndex(uint index) internal { + require(minters.length > 0); + if (minters.length > 1) { + minters[index] = minters[minters.length - 1]; + + delete (minters[minters.length - 1]); + } + minters.length--; + } + + function removeMinterByValue(address _client) internal { + for (uint i = 0; i < minters.length; i++) { + if (minters[i] == _client) { + removeMinterByIndex(i); + break; + } + } + } +} + + + + +contract BurnableToken is BasicToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} + + + + +pragma solidity ^0.4.19; + + + + +contract CappedToken is MintableToken { + + uint256 public cap; + + constructor(uint256 _cap) public { + require(_cap > 0); + cap = _cap; + } + + + function mint( + address _to, + uint256 _amount + ) + hasMintPermission + canMint + public + returns (bool) + { + require(totalSupply_.add(_amount) <= cap); + + return super.mint(_to, _amount); + } + +} + + + +contract DeviseToken is CappedToken, BurnableToken, RBACMintableToken { + string public name = "DEVISE"; + string public symbol = "DVZ"; + + uint8 public decimals = 6; + + function DeviseToken(uint256 _cap) public + CappedToken(_cap) { + addMinter(owner); + } + + + function transferOwnership(address newOwner) public onlyOwner { + removeMinter(owner); + addMinter(newOwner); + super.transferOwnership(newOwner); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/847.sol b/benchmark2/integer overflow/847.sol new file mode 100644 index 0000000000000000000000000000000000000000..b7b711f74d06588735bdd49b5242037746ba7e80 --- /dev/null +++ b/benchmark2/integer overflow/847.sol @@ -0,0 +1,115 @@ +pragma solidity ^0.4.10; + + +contract SafeMath { + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + +} + + + +contract StandardToken is Token , SafeMath { + + bool public status = true; + modifier on() { + require(status == true); + _; + } + + function transfer(address _to, uint256 _value) on returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0 && _to != 0X0) { + balances[msg.sender] -= _value; + balances[_to] = safeAdd(balances[_to],_value); + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) on returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] = safeAdd(balances[_to],_value); + balances[_from] = safeSubtract(balances[_from],_value); + allowed[_from][msg.sender] = safeSubtract(allowed[_from][msg.sender],_value); + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) on constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) on returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) on constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + + + + +contract ExShellToken is StandardToken { + string public name = "ExShellToken"; + uint8 public decimals = 8; + string public symbol = "ET"; + bool private init =true; + function turnon() controller { + status = true; + } + function turnoff() controller { + status = false; + } + function ExShellToken() { + require(init==true); + totalSupply = 2000000000; + balances[0xa089a405b1df71a6155705fb2bce87df2a86a9e4] = totalSupply; + init = false; + } + address public controller1 =0xa089a405b1df71a6155705fb2bce87df2a86a9e4; + address public controller2 =0x5aa64423529e43a53c7ea037a07f94abc0c3a111; + + modifier controller () { + require(msg.sender == controller1||msg.sender == controller2); + _; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/849.sol b/benchmark2/integer overflow/849.sol new file mode 100644 index 0000000000000000000000000000000000000000..8c0dd07d407487145444537a9b422be412fb7482 --- /dev/null +++ b/benchmark2/integer overflow/849.sol @@ -0,0 +1,563 @@ +pragma solidity ^0.4.24; + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + + +contract PausableToken is StandardToken, Pausable { + + function transfer( + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(_to, _value); + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(_from, _to, _value); + } + + function approve( + address _spender, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(_spender, _value); + } + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + modifier hasMintPermission() { + require(msg.sender == owner); + _; + } + + + function mint( + address _to, + uint256 _amount + ) + hasMintPermission + canMint + public + returns (bool) + { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() onlyOwner canMint public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + + +contract CappedToken is MintableToken { + + uint256 public cap; + + constructor(uint256 _cap) public { + require(_cap > 0); + cap = _cap; + } + + + function mint( + address _to, + uint256 _amount + ) + public + returns (bool) + { + require(totalSupply_.add(_amount) <= cap); + + return super.mint(_to, _amount); + } + +} + +library Roles { + struct Role { + mapping (address => bool) bearer; + } + + + function add(Role storage role, address addr) + internal + { + role.bearer[addr] = true; + } + + + function remove(Role storage role, address addr) + internal + { + role.bearer[addr] = false; + } + + + function check(Role storage role, address addr) + view + internal + { + require(has(role, addr)); + } + + + function has(Role storage role, address addr) + view + internal + returns (bool) + { + return role.bearer[addr]; + } +} + + + +contract RBAC { + using Roles for Roles.Role; + + mapping (string => Roles.Role) private roles; + + event RoleAdded(address indexed operator, string role); + event RoleRemoved(address indexed operator, string role); + + + function checkRole(address _operator, string _role) + view + public + { + roles[_role].check(_operator); + } + + + function hasRole(address _operator, string _role) + view + public + returns (bool) + { + return roles[_role].has(_operator); + } + + + function addRole(address _operator, string _role) + internal + { + roles[_role].add(_operator); + emit RoleAdded(_operator, _role); + } + + + function removeRole(address _operator, string _role) + internal + { + roles[_role].remove(_operator); + emit RoleRemoved(_operator, _role); + } + + + modifier onlyRole(string _role) + { + checkRole(msg.sender, _role); + _; + } + + + + + + + + + + + + + + + +} + + + +contract Superuser is Ownable, RBAC { + string public constant ROLE_SUPERUSER = "superuser"; + + constructor () public { + addRole(msg.sender, ROLE_SUPERUSER); + } + + + modifier onlySuperuser() { + checkRole(msg.sender, ROLE_SUPERUSER); + _; + } + + modifier onlyOwnerOrSuperuser() { + require(msg.sender == owner || isSuperuser(msg.sender)); + _; + } + + + function isSuperuser(address _addr) + public + view + returns (bool) + { + return hasRole(_addr, ROLE_SUPERUSER); + } + + + function transferSuperuser(address _newSuperuser) public onlySuperuser { + require(_newSuperuser != address(0)); + removeRole(msg.sender, ROLE_SUPERUSER); + addRole(_newSuperuser, ROLE_SUPERUSER); + } + + + function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser { + _transferOwnership(_newOwner); + } +} + + +contract CoinSmartt is Superuser, PausableToken, CappedToken { + + string public name = "CoinSmartt"; + string public symbol = "TURN"; + uint256 public decimals = 18; + + string public constant ROLE_MINTER = "minter"; + + constructor(address _minter) CappedToken(7663809523810000000000000000) { + + addRole(_minter, ROLE_MINTER); + } + + function mint( + address _to, + uint256 _amount + ) + onlyRole("minter") + canMint + public + returns (bool) + { + require(totalSupply_.add(_amount) <= cap); + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + function removeMinter(address _minter) onlyOwnerOrSuperuser { + removeRole(_minter, "minter"); + } + function addMinter(address _minter) onlyOwnerOrSuperuser { + addRole(_minter, "minter"); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/856.sol b/benchmark2/integer overflow/856.sol new file mode 100644 index 0000000000000000000000000000000000000000..add6720e3636c9d1e6427b088d25f1c8d3a93567 --- /dev/null +++ b/benchmark2/integer overflow/856.sol @@ -0,0 +1,241 @@ +pragma solidity 0.4.23; + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + + function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } +} + +contract Owned { + address public owner; + + constructor() public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } +} + + +contract MintableToken is StandardToken, Owned { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + modifier canMint() { + require(!mintingFinished); + _; + } + + + function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() onlyOwner canMint public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + +contract BidoohToken is MintableToken { + string public constant name = "Bidooh Token"; + string public constant symbol = "DOOH"; + uint8 public constant decimals = 18; + + + address public teamTokensAddress; + + + address public reserveTokensAddress; + + + address public saleTokensAddress; + + + address public bidoohAdminAddress; + + + bool public saleClosed = false; + + + modifier beforeSaleClosed { + require(!saleClosed); + _; + } + + constructor(address _teamTokensAddress, address _reserveTokensAddress, + address _saleTokensAddress, address _bidoohAdminAddress) public { + require(_teamTokensAddress != address(0)); + require(_reserveTokensAddress != address(0)); + require(_saleTokensAddress != address(0)); + require(_bidoohAdminAddress != address(0)); + + teamTokensAddress = _teamTokensAddress; + reserveTokensAddress = _reserveTokensAddress; + saleTokensAddress = _saleTokensAddress; + bidoohAdminAddress = _bidoohAdminAddress; + + + + uint256 saleTokens = 88200000000 * 10**uint256(decimals); + totalSupply_ = saleTokens; + balances[saleTokensAddress] = saleTokens; + + + uint256 reserveTokens = 18900000000 * 10**uint256(decimals); + totalSupply_ = totalSupply_.add(reserveTokens); + balances[reserveTokensAddress] = reserveTokens; + + + uint256 teamTokens = 18900000000 * 10**uint256(decimals); + totalSupply_ = totalSupply_.add(teamTokens); + balances[teamTokensAddress] = teamTokens; + } + + + function close() public onlyOwner beforeSaleClosed { + uint256 unsoldTokens = balances[saleTokensAddress]; + balances[reserveTokensAddress] = balances[reserveTokensAddress].add(unsoldTokens); + balances[saleTokensAddress] = 0; + emit Transfer(saleTokensAddress, reserveTokensAddress, unsoldTokens); + + owner = bidoohAdminAddress; + saleClosed = true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/86.sol b/benchmark2/integer overflow/86.sol new file mode 100644 index 0000000000000000000000000000000000000000..2eda44784a052e7a4f9184db63d788d3be0c21f0 --- /dev/null +++ b/benchmark2/integer overflow/86.sol @@ -0,0 +1,246 @@ +pragma solidity ^0.4.23; + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +library SafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + return a / b; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + +contract BurnableToken is BasicToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + function _burn(address _who, uint256 _value) internal { + require(_value <= balances[_who]); + + balances[_who] = balances[_who].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit Burn(_who, _value); + emit Transfer(_who, address(0), _value); + } +} + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract BitFast is StandardToken, BurnableToken { + string public constant name = "BitFast"; + string public constant symbol = "FAST"; + uint32 public constant decimals = 8; + uint256 public INITIAL_SUPPLY = 5000000000000000; + address public CrowdsaleAddress; + bool public lockTransfers = true; + + event AcceptToken(address indexed from, uint256 value); + + constructor(address _CrowdsaleAddress) public { + CrowdsaleAddress = _CrowdsaleAddress; + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + } + + modifier onlyOwner() { + + require(msg.sender == CrowdsaleAddress); + _; + } + + + function transfer(address _to, uint256 _value) public returns(bool){ + if (msg.sender != CrowdsaleAddress){ + require(!lockTransfers, "Transfers are prohibited in Crowdsale period"); + } + return super.transfer(_to,_value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns(bool){ + if (msg.sender != CrowdsaleAddress){ + require(!lockTransfers, "Transfers are prohibited in Crowdsale period"); + } + return super.transferFrom(_from,_to,_value); + } + + + function acceptTokens(address _from, uint256 _value) public onlyOwner returns (bool){ + require (balances[_from] >= _value); + balances[_from] = balances[_from].sub(_value); + totalSupply_ = totalSupply_.sub(_value); + emit AcceptToken(_from, _value); + return true; + } + + + function transferTokensFromSpecialAddress(address _from, address _to, uint256 _value) public onlyOwner returns (bool){ + require (balances[_from] >= _value); + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function lockTransfer(bool _lock) public onlyOwner { + lockTransfers = _lock; + } + + + + function() external payable { + revert("The token contract don`t receive ether"); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/862.sol b/benchmark2/integer overflow/862.sol new file mode 100644 index 0000000000000000000000000000000000000000..117ff80b99ad4164f7655539d0be82c07cfcc3d8 --- /dev/null +++ b/benchmark2/integer overflow/862.sol @@ -0,0 +1,332 @@ +pragma solidity ^0.4.24; + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract Ownable { + address public owner; + + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + +contract PausableToken is StandardToken, Pausable { + + function transfer( + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(_to, _value); + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(_from, _to, _value); + } + + function approve( + address _spender, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(_spender, _value); + } + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseApproval(_spender, _subtractedValue); + } + +} + + +contract MPCToken is PausableToken { + + string public name = "Miner Pass Card"; + string public symbol = "MPC"; + uint8 public decimals = 18; + + constructor() public { + totalSupply_ = 2000000000 * (10 ** uint256(decimals)); + balances[msg.sender] = totalSupply_; + emit Transfer(address(0), msg.sender, totalSupply_); + } + + function batchTransfer(address[] _to, uint256[] value) public whenNotPaused returns(bool success){ + require(_to.length == value.length); + for( uint256 i = 0; i < _to.length; i++ ){ + transfer(_to[i],value[i]); + } + return true; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/869.sol b/benchmark2/integer overflow/869.sol new file mode 100644 index 0000000000000000000000000000000000000000..adc3515311a4a7bb99b4c111b757c91ab4ffc228 --- /dev/null +++ b/benchmark2/integer overflow/869.sol @@ -0,0 +1,109 @@ +pragma solidity ^0.4.8; + + +contract SafeMath { + function safeMul(uint256 a, uint256 b) internal returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b) internal returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function assert(bool assertion) internal { + if (!assertion) { + throw; + } + } +} +contract YOPT is SafeMath{ + string public name; + string public symbol; + uint8 public decimals; + uint256 public totalSupply; + address public owner; + + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Burn(address indexed from, uint256 value); + + + function YOPT( + uint256 initialSupply, + string tokenName, + uint8 decimalUnits, + string tokenSymbol + ) { + totalSupply = initialSupply * 10 ** uint256(decimalUnits); + balanceOf[msg.sender] = totalSupply; + name = tokenName; + symbol = tokenSymbol; + decimals = decimalUnits; + owner = msg.sender; + } + + + function transfer(address _to, uint256 _value) { + if (_to == 0x0) throw; + if (_value <= 0) throw; + if (balanceOf[msg.sender] < _value) throw; + if (balanceOf[_to] + _value < balanceOf[_to]) throw; + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + Transfer(msg.sender, _to, _value); + } + + + function approve(address _spender, uint256 _value) + returns (bool success) { + if (_value <= 0) throw; + allowance[msg.sender][_spender] = _value; + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + if (_to == 0x0) throw; + if (_value <= 0) throw; + if (balanceOf[_from] < _value) throw; + if (balanceOf[_to] + _value < balanceOf[_to]) throw; + if (_value > allowance[_from][msg.sender]) throw; + balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); + allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value); + Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) returns (bool success) { + if (balanceOf[msg.sender] < _value) throw; + if (_value <= 0) throw; + balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); + totalSupply = SafeMath.safeSub(totalSupply,_value); + Burn(msg.sender, _value); + return true; + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/873.sol b/benchmark2/integer overflow/873.sol new file mode 100644 index 0000000000000000000000000000000000000000..9572a18a1755e5fa490f66b38043979471b3155c --- /dev/null +++ b/benchmark2/integer overflow/873.sol @@ -0,0 +1,233 @@ +pragma solidity ^0.4.24; + + + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract Ownable { + + address public owner; + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner)public onlyOwner { + require(newOwner != address(0)); + owner = newOwner; + } +} + + +contract ERC20Basic is Ownable { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + mapping (address => bool) public frozenAccount; + + + event FrozenFunds(address target, bool frozen); + + + + function freezeAccount(address target, bool freeze) public onlyOwner{ + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value)public returns (bool) { + require(!frozenAccount[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner)public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(!frozenAccount[_from]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + + +} + + +contract NoteChainToken is StandardToken { + + string public constant name = "NoteChain"; + string public constant symbol = "NOTE"; + uint256 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 20000000000 * 10**decimals; + + + constructor() public { + totalSupply = INITIAL_SUPPLY; + balances[address(0x750Da02fb96538AbAf5aDd7E09eAC25f1553109D)] = (INITIAL_SUPPLY.mul(20).div(100)); + balances[address(0xb85e5Eb2C4F43fE44c1dF949c1c49F1638cb772B)] = (INITIAL_SUPPLY.mul(20).div(100)); + balances[address(0xBd058b319A1355A271B732044f37BBF2Be07A0B1)] = (INITIAL_SUPPLY.mul(25).div(100)); + balances[address(0x53da2841810e6886254B514d338146d209B164a2)] = (INITIAL_SUPPLY.mul(35).div(100)); + } + + + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/889.sol b/benchmark2/integer overflow/889.sol new file mode 100644 index 0000000000000000000000000000000000000000..ffef3a5fd636e6f479168148b4669edc41329146 --- /dev/null +++ b/benchmark2/integer overflow/889.sol @@ -0,0 +1,162 @@ +pragma solidity ^0.4.24; + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract TCPC is StandardToken { + + string public constant name = "Test Coin PrimeCore"; + string public constant symbol = "TCPC"; + uint8 public constant decimals = 8; + address public constant tokenOwner = 0x3c9da12eda40d69713ef7c6129e5ebd75983ac3d; + uint256 public constant INITIAL_SUPPLY = 6750000000 * (10 ** uint256(decimals)); + + function TCPC() public { + totalSupply_ = INITIAL_SUPPLY; + balances[tokenOwner] = INITIAL_SUPPLY; + emit Transfer(0x0, tokenOwner, INITIAL_SUPPLY); + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/894.sol b/benchmark2/integer overflow/894.sol new file mode 100644 index 0000000000000000000000000000000000000000..c7a353b9bc4aa218d4f72c5b4e42547b5686e1d0 --- /dev/null +++ b/benchmark2/integer overflow/894.sol @@ -0,0 +1,116 @@ +pragma solidity ^0.4.18; + + + +contract ERC20 { + uint256 public totalSupply; + + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + + event Approval(address indexed owner, address indexed spender, uint256 value); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +pragma solidity ^0.4.18; + + + +library SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +pragma solidity ^0.4.18; + + + +contract TopPlayerToken is ERC20 { + using SafeMath for uint256; + + mapping(address => uint256) balances; + mapping (address => mapping (address => uint256)) internal allowed; + + string public name = "QTC Token"; + string public symbol = "QTCT"; + uint256 public decimals = 18; + + function TopPlayerToken() public { + totalSupply = 2000000000 * (10 ** decimals); + balances[msg.sender] = totalSupply; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/92.sol b/benchmark2/integer overflow/92.sol new file mode 100644 index 0000000000000000000000000000000000000000..fd147a1d9bbaf1bef3ce8dadaf32d2b0cc21e4b1 --- /dev/null +++ b/benchmark2/integer overflow/92.sol @@ -0,0 +1,243 @@ +pragma solidity ^0.4.24; + + + + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract Ownable { + + address public owner; + + + constructor() public { + owner = address(0xEFeAc37a6a5Fb3630313742a2FADa6760C6FF653); + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner)public onlyOwner { + require(newOwner != address(0)); + owner = newOwner; + } +} + + +contract ERC20Basic is Ownable { + uint256 public totalSupply; + function balanceOf(address who) public constant returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + mapping (address => bool) public frozenAccount; + + event FrozenFunds( + address target, + bool frozen + ); + + event Burn( + address indexed burner, + uint256 value + ); + + + + function burnTokens(address _who, uint256 _amount) public onlyOwner { + require(balances[_who] >= _amount); + + balances[_who] = balances[_who].sub(_amount); + + totalSupply = totalSupply.sub(_amount); + + emit Burn(_who, _amount); + emit Transfer(_who, address(0), _amount); + } + + + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value)public returns (bool) { + require(!frozenAccount[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner)public constant returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) + public view returns (uint256); + + function transferFrom(address from, address to, uint256 value) + public returns (bool); + + function approve(address spender, uint256 value) public returns (bool); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + +contract AdvanceToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(!frozenAccount[_from]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + returns (bool) + { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract CRYPTOLANCERSToken is AdvanceToken { + + string public constant name = "CRYPTOLANCERS"; + string public constant symbol = "CLT"; + uint256 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 100000000 * 10**decimals; + + + constructor() public { + totalSupply = INITIAL_SUPPLY; + balances[0xEFeAc37a6a5Fb3630313742a2FADa6760C6FF653] = totalSupply; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/928.sol b/benchmark2/integer overflow/928.sol new file mode 100644 index 0000000000000000000000000000000000000000..4b9464202abc5dea48b4d76613ea6d091e74fe0a --- /dev/null +++ b/benchmark2/integer overflow/928.sol @@ -0,0 +1,104 @@ +pragma solidity ^0.4.16; + +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } + +contract FEMCoin { + + string public name; + string public symbol; + uint8 public decimals = 2; + + uint256 public totalSupply; + + + mapping (address => uint256) public balanceOf; + mapping (address => mapping (address => uint256)) public allowance; + + + event Transfer(address indexed from, address indexed to, uint256 value); + + + event Burn(address indexed from, uint256 value); + + + function TokenERC20( + uint256 initialSupply, + string tokenName, + string tokenSymbol + ) public { + totalSupply = 10000000000; + balanceOf[msg.sender] = totalSupply; + name = "FEMCoin"; + symbol = "FEMC"; + } + + + function _transfer(address _from, address _to, uint _value) internal { + + require(_to != 0x0); + + require(balanceOf[_from] >= _value); + + require(balanceOf[_to] + _value > balanceOf[_to]); + + uint previousBalances = balanceOf[_from] + balanceOf[_to]; + + balanceOf[_from] -= _value; + + balanceOf[_to] += _value; + Transfer(_from, _to, _value); + + assert(balanceOf[_from] + balanceOf[_to] == previousBalances); + } + + + function transfer(address _to, uint256 _value) public { + _transfer(msg.sender, _to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(_value <= allowance[_from][msg.sender]); + allowance[_from][msg.sender] -= _value; + _transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public + returns (bool success) { + allowance[msg.sender][_spender] = _value; + return true; + } + + + function approveAndCall(address _spender, uint256 _value, bytes _extraData) + public + returns (bool success) { + tokenRecipient spender = tokenRecipient(_spender); + if (approve(_spender, _value)) { + spender.receiveApproval(msg.sender, _value, this, _extraData); + return true; + } + } + + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + Burn(msg.sender, _value); + return true; + } + + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(_value <= allowance[_from][msg.sender]); + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + Burn(_from, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/936.sol b/benchmark2/integer overflow/936.sol new file mode 100644 index 0000000000000000000000000000000000000000..a7953ed4ef5d96f24d919c9c88e66335f46cdaf4 --- /dev/null +++ b/benchmark2/integer overflow/936.sol @@ -0,0 +1,164 @@ +pragma solidity ^0.4.24; + + + + +library SafeMath { + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract Ownable { + address public owner; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + constructor() public { + owner = 0x96edbD4356309e21b72fA307BC7f20c7Aa30aA51; + } + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + +contract PTG_Token is StandardToken, Ownable { + + string public name; + string public symbol; + uint8 public decimals; + uint256 public initialSupply; + + constructor() public { + name = 'Petro.Global'; + symbol = 'PTG'; + decimals = 18; + initialSupply = 5000000 * 10 ** uint256(decimals); + totalSupply_ = initialSupply; + balances[owner] = initialSupply; + emit Transfer(0x0, owner, initialSupply); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/937.sol b/benchmark2/integer overflow/937.sol new file mode 100644 index 0000000000000000000000000000000000000000..c65bb454b510937b4ea7c3c93fd94c762797eb71 --- /dev/null +++ b/benchmark2/integer overflow/937.sol @@ -0,0 +1,236 @@ +pragma solidity ^0.4.23; + + + + +contract Ownable { + address public owner; + + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + function Ownable() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() onlyOwner whenNotPaused public { + paused = true; + emit Pause(); + } + + + function unpause() onlyOwner whenPaused public { + paused = false; + emit Unpause(); + } +} + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + if (a == 0) { + return 0; + } + c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + return a / b; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + +} + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract PausableToken is StandardToken, Pausable { + + function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transfer(_to, _value); + } + + function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { + return super.transferFrom(_from, _to, _value); + } + + function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { + return super.approve(_spender, _value); + } + + function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + +contract FrameCoin is PausableToken { + + string public constant name = "FrameCoin"; + string public constant symbol = "FRAC"; + uint8 public constant decimals = 18; + uint256 public constant INITIAL_SUPPLY = 265e6 * 10**uint256(decimals); + + function FrameCoin() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + Transfer(0x0, msg.sender, INITIAL_SUPPLY); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/940.sol b/benchmark2/integer overflow/940.sol new file mode 100644 index 0000000000000000000000000000000000000000..8420dd344bcf68b85c0097a83efdfc6c07486c2d --- /dev/null +++ b/benchmark2/integer overflow/940.sol @@ -0,0 +1,222 @@ +pragma solidity ^0.4.20; + +contract SafeMath { + function safeMul(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b)public pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b)public pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b)public pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function _assert(bool assertion)public pure { + assert(!assertion); + } +} + + +contract ERC20Interface { + string public name; + string public symbol; + uint8 public decimals; + uint public totalSupply; + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) view returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + } + +contract ERC20 is ERC20Interface,SafeMath { + + + mapping(address => uint256) public balanceOf; + + + mapping(address => mapping(address => uint256)) allowed; + + constructor(string _name) public { + name = _name; + symbol = "ETPP"; + decimals = 4; + totalSupply = 1038628770000; + balanceOf[msg.sender] = totalSupply; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(balanceOf[msg.sender] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] ,_value); + + + emit Transfer(msg.sender, _to, _value); + + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(allowed[_from][msg.sender] >= _value); + require(balanceOf[_from] >= _value); + require(balanceOf[_to] + _value >= balanceOf[_to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to],_value); + + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender], _value); + + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowed[msg.sender][_spender] = _value; + + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + +contract owned { + address public owner; + + constructor () public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnerShip(address newOwer) public onlyOwner { + owner = newOwer; + } + +} + +contract SelfDesctructionContract is owned { + + string public someValue; + modifier ownerRestricted { + require(owner == msg.sender); + _; + } + + function SelfDesctructionContract() { + owner = msg.sender; + } + + function setSomeValue(string value){ + someValue = value; + } + + function destroyContract() ownerRestricted { + selfdestruct(owner); + } +} + + + +contract AdvanceToken is ERC20, owned,SelfDesctructionContract{ + + mapping (address => bool) public frozenAccount; + + event AddSupply(uint amount); + event FrozenFunds(address target, bool frozen); + event Burn(address target, uint amount); + + constructor (string _name) ERC20(_name) public { + + } + + function mine(address target, uint amount) public onlyOwner { + totalSupply =SafeMath.safeAdd(totalSupply,amount) ; + balanceOf[target] = SafeMath.safeAdd(balanceOf[target],amount); + + emit AddSupply(amount); + emit Transfer(0, target, amount); + } + + function freezeAccount(address target, bool freeze) public onlyOwner { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + success = _transfer(msg.sender, _to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(allowed[_from][msg.sender] >= _value); + success = _transfer(_from, _to, _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value) ; + } + + function _transfer(address _from, address _to, uint256 _value) internal returns (bool) { + require(_to != address(0)); + require(!frozenAccount[_from]); + + require(balanceOf[_from] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; + + emit Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(allowed[_from][msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender], _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value); + + emit Burn(msg.sender, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/95.sol b/benchmark2/integer overflow/95.sol new file mode 100644 index 0000000000000000000000000000000000000000..3aec21a76143417e2e5a70874af17c2148701424 --- /dev/null +++ b/benchmark2/integer overflow/95.sol @@ -0,0 +1,395 @@ +pragma solidity ^0.4.24; + + + + +contract ERC20 { + function totalSupply() public view returns (uint256); + + function balanceOf(address _who) public view returns (uint256); + + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transfer(address _to, uint256 _value) public returns (bool); + + function approve(address _spender, uint256 _value) + public returns (bool); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); + + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + + + + +library SafeMath { + + + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + + + + if (_a == 0) { + return 0; + } + + uint256 c = _a * _b; + require(c / _a == _b); + + return c; + } + + + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b > 0); + uint256 c = _a / _b; + + + return c; + } + + + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b <= _a); + uint256 c = _a - _b; + + return c; + } + + + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + require(c >= _a); + + return c; + } + + + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} + + + + +contract StandardToken is ERC20 { + using SafeMath for uint256; + + mapping (address => uint256) internal balances; + + mapping (address => mapping (address => uint256)) internal allowed; + + uint256 internal totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function _mint(address _account, uint256 _amount) internal { + require(_account != 0); + totalSupply_ = totalSupply_.add(_amount); + balances[_account] = balances[_account].add(_amount); + emit Transfer(address(0), _account, _amount); + } + + + function _burn(address _account, uint256 _amount) internal { + require(_account != 0); + require(balances[_account] > _amount); + + totalSupply_ = totalSupply_.sub(_amount); + balances[_account] = balances[_account].sub(_amount); + emit Transfer(_account, address(0), _amount); + } + + + function _burnFrom(address _account, uint256 _amount) internal { + require(allowed[_account][msg.sender] > _amount); + + + + allowed[_account][msg.sender] = allowed[_account][msg.sender].sub(_amount); + _burn(_account, _amount); + } +} + + + + +contract BurnableToken is StandardToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + + function burnFrom(address _from, uint256 _value) public { + _burnFrom(_from, _value); + } + + + function _burn(address _who, uint256 _value) internal { + super._burn(_who, _value); + emit Burn(_who, _value); + } +} + + + + +contract Ownable { + address public owner; + + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + + + constructor() public { + owner = msg.sender; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(owner); + owner = address(0); + } + + + function transferOwnership(address _newOwner) public onlyOwner { + _transferOwnership(_newOwner); + } + + + function _transferOwnership(address _newOwner) internal { + require(_newOwner != address(0)); + emit OwnershipTransferred(owner, _newOwner); + owner = _newOwner; + } +} + + + + +contract Pausable is Ownable { + event Pause(); + event Unpause(); + + bool public paused = false; + + + + modifier whenNotPaused() { + require(!paused); + _; + } + + + modifier whenPaused() { + require(paused); + _; + } + + + function pause() public onlyOwner whenNotPaused { + paused = true; + emit Pause(); + } + + + function unpause() public onlyOwner whenPaused { + paused = false; + emit Unpause(); + } +} + + + + +contract PausableToken is BurnableToken, Pausable { + + function transfer( + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transfer(_to, _value); + } + + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.transferFrom(_from, _to, _value); + } + + function approve( + address _spender, + uint256 _value + ) + public + whenNotPaused + returns (bool) + { + return super.approve(_spender, _value); + } + + function increaseApproval( + address _spender, + uint _addedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.increaseApproval(_spender, _addedValue); + } + + function decreaseApproval( + address _spender, + uint _subtractedValue + ) + public + whenNotPaused + returns (bool success) + { + return super.decreaseApproval(_spender, _subtractedValue); + } +} + +contract KWATT_Token is PausableToken { + string public name = "4NEW"; + string public symbol = "KWATT"; + uint8 public decimals = 18; + uint public INITIAL_SUPPLY = 300000000000000000000000000; +constructor() public { + totalSupply_ = INITIAL_SUPPLY; + balances[msg.sender] = totalSupply_; +} + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/951.sol b/benchmark2/integer overflow/951.sol new file mode 100644 index 0000000000000000000000000000000000000000..08c6aa4b8ef39b6e770f8ba60ff6ba929ae04277 --- /dev/null +++ b/benchmark2/integer overflow/951.sol @@ -0,0 +1,195 @@ +pragma solidity ^0.4.18; + + +contract Ownable { + address public owner; + + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + function Ownable() public { + owner = msg.sender; + } + + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + + +library SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + +contract ERC20Basic { + uint256 public totalSupply; + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) public balances; + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + +contract BurnableToken is StandardToken { + + event Burn(address indexed burner, uint256 value); + + + function burn(uint256 _value) public { + require(_value > 0); + require(_value <= balances[msg.sender]); + + + + address burner = msg.sender; + balances[burner] = balances[burner].sub(_value); + totalSupply = totalSupply.sub(_value); + Burn(burner, _value); + } +} + + +contract CABoxToken is BurnableToken, Ownable { + + string public constant name = "CABox"; + string public constant symbol = "CAB"; + uint8 public constant decimals = 18; + + uint256 public constant INITIAL_SUPPLY = 500 * 1000000 * (10 ** uint256(decimals)); + + + function CABoxToken() public { + totalSupply = INITIAL_SUPPLY; + balances[msg.sender] = INITIAL_SUPPLY; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/958.sol b/benchmark2/integer overflow/958.sol new file mode 100644 index 0000000000000000000000000000000000000000..a21c8d25de784c930c6d649386cd01228651da4d --- /dev/null +++ b/benchmark2/integer overflow/958.sol @@ -0,0 +1,585 @@ +pragma solidity 0.4.24; + + + +library SafeMath { + + + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + +contract Ownable { + address public owner; + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + constructor(address _owner) public { + owner = _owner; + } + + + modifier onlyOwner() { + require(msg.sender == owner); + _; + } + + + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; + } + +} + + +contract Whitelist is Ownable { + mapping(address => bool) internal investorMap; + + + event Approved(address indexed investor); + + + event Disapproved(address indexed investor); + + constructor(address _owner) + public + Ownable(_owner) + { + + } + + + function isInvestorApproved(address _investor) external view returns (bool) { + require(_investor != address(0)); + return investorMap[_investor]; + } + + + function approveInvestor(address toApprove) external onlyOwner { + investorMap[toApprove] = true; + emit Approved(toApprove); + } + + + function approveInvestorsInBulk(address[] toApprove) external onlyOwner { + for (uint i = 0; i < toApprove.length; i++) { + investorMap[toApprove[i]] = true; + emit Approved(toApprove[i]); + } + } + + + function disapproveInvestor(address toDisapprove) external onlyOwner { + delete investorMap[toDisapprove]; + emit Disapproved(toDisapprove); + } + + + function disapproveInvestorsInBulk(address[] toDisapprove) external onlyOwner { + for (uint i = 0; i < toDisapprove.length; i++) { + delete investorMap[toDisapprove[i]]; + emit Disapproved(toDisapprove[i]); + } + } +} + + + +contract Validator { + address public validator; + + event NewValidatorSet(address indexed previousOwner, address indexed newValidator); + + + constructor() public { + validator = msg.sender; + } + + + modifier onlyValidator() { + require(msg.sender == validator); + _; + } + + + function setNewValidator(address newValidator) public onlyValidator { + require(newValidator != address(0)); + emit NewValidatorSet(validator, newValidator); + validator = newValidator; + } +} + + + +contract ERC20Basic { + function totalSupply() public view returns (uint256); + function balanceOf(address who) public view returns (uint256); + function transfer(address to, uint256 value) public returns (bool); + event Transfer(address indexed from, address indexed to, uint256 value); +} + + + +contract ERC20 is ERC20Basic { + function allowance(address owner, address spender) public view returns (uint256); + function transferFrom(address from, address to, uint256 value) public returns (bool); + function approve(address spender, uint256 value) public returns (bool); + event Approval(address indexed owner, address indexed spender, uint256 value); +} + + + +contract BasicToken is ERC20Basic { + using SafeMath for uint256; + + mapping(address => uint256) balances; + + uint256 totalSupply_; + + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[msg.sender]); + + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + + function balanceOf(address _owner) public view returns (uint256 balance) { + return balances[_owner]; + } + +} + + + +contract StandardToken is ERC20, BasicToken { + + mapping (address => mapping (address => uint256)) internal allowed; + + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { + require(_to != address(0)); + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) public view returns (uint256) { + return allowed[_owner][_spender]; + } + + + function increaseApproval(address _spender, uint _addedValue) public returns (bool) { + allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + + function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { + uint oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue > oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + +} + + + +contract MintableToken is StandardToken, Ownable { + event Mint(address indexed to, uint256 amount); + event MintFinished(); + + bool public mintingFinished = false; + + + modifier canMint() { + require(!mintingFinished); + _; + } + + constructor(address _owner) + public + Ownable(_owner) + { + } + + + function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { + totalSupply_ = totalSupply_.add(_amount); + balances[_to] = balances[_to].add(_amount); + emit Mint(_to, _amount); + emit Transfer(address(0), _to, _amount); + return true; + } + + + function finishMinting() onlyOwner canMint public returns (bool) { + mintingFinished = true; + emit MintFinished(); + return true; + } +} + + +contract DetailedERC20 { + string public name; + string public symbol; + uint8 public decimals; + + constructor(string _name, string _symbol, uint8 _decimals) public { + name = _name; + symbol = _symbol; + decimals = _decimals; + } +} + + + +contract CompliantToken is Validator, DetailedERC20, MintableToken { + Whitelist public whiteListingContract; + + struct TransactionStruct { + address from; + address to; + uint256 value; + uint256 fee; + address spender; + } + + mapping (uint => TransactionStruct) public pendingTransactions; + mapping (address => mapping (address => uint256)) public pendingApprovalAmount; + uint256 public currentNonce = 0; + uint256 public transferFee; + address public feeRecipient; + + modifier checkIsInvestorApproved(address _account) { + require(whiteListingContract.isInvestorApproved(_account)); + _; + } + + modifier checkIsAddressValid(address _account) { + require(_account != address(0)); + _; + } + + modifier checkIsValueValid(uint256 _value) { + require(_value > 0); + _; + } + + + event TransferRejected( + address indexed from, + address indexed to, + uint256 value, + uint256 indexed nonce, + uint256 reason + ); + + + event TransferWithFee( + address indexed from, + address indexed to, + uint256 value, + uint256 fee + ); + + + event RecordedPendingTransaction( + address indexed from, + address indexed to, + uint256 value, + uint256 fee, + address indexed spender, + uint256 nonce + ); + + + event WhiteListingContractSet(address indexed _whiteListingContract); + + + event FeeSet(uint256 indexed previousFee, uint256 indexed newFee); + + + event FeeRecipientSet(address indexed previousRecipient, address indexed newRecipient); + + + constructor( + address _owner, + string _name, + string _symbol, + uint8 _decimals, + address whitelistAddress, + address recipient, + uint256 fee + ) + public + MintableToken(_owner) + DetailedERC20(_name, _symbol, _decimals) + Validator() + { + setWhitelistContract(whitelistAddress); + setFeeRecipient(recipient); + setFee(fee); + } + + + function setWhitelistContract(address whitelistAddress) + public + onlyValidator + checkIsAddressValid(whitelistAddress) + { + whiteListingContract = Whitelist(whitelistAddress); + emit WhiteListingContractSet(whiteListingContract); + } + + + function setFee(uint256 fee) + public + onlyValidator + { + emit FeeSet(transferFee, fee); + transferFee = fee; + } + + + function setFeeRecipient(address recipient) + public + onlyValidator + checkIsAddressValid(recipient) + { + emit FeeRecipientSet(feeRecipient, recipient); + feeRecipient = recipient; + } + + + function updateName(string _name) public onlyOwner { + require(bytes(_name).length != 0); + name = _name; + } + + + function updateSymbol(string _symbol) public onlyOwner { + require(bytes(_symbol).length != 0); + symbol = _symbol; + } + + + function transfer(address _to, uint256 _value) + public + checkIsInvestorApproved(msg.sender) + checkIsInvestorApproved(_to) + checkIsValueValid(_value) + returns (bool) + { + uint256 pendingAmount = pendingApprovalAmount[msg.sender][address(0)]; + + if (msg.sender == feeRecipient) { + require(_value.add(pendingAmount) <= balances[msg.sender]); + pendingApprovalAmount[msg.sender][address(0)] = pendingAmount.add(_value); + } else { + require(_value.add(pendingAmount).add(transferFee) <= balances[msg.sender]); + pendingApprovalAmount[msg.sender][address(0)] = pendingAmount.add(_value).add(transferFee); + } + + pendingTransactions[currentNonce] = TransactionStruct( + msg.sender, + _to, + _value, + transferFee, + address(0) + ); + + emit RecordedPendingTransaction(msg.sender, _to, _value, transferFee, address(0), currentNonce); + currentNonce++; + + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) + public + checkIsInvestorApproved(_from) + checkIsInvestorApproved(_to) + checkIsValueValid(_value) + returns (bool) + { + uint256 allowedTransferAmount = allowed[_from][msg.sender]; + uint256 pendingAmount = pendingApprovalAmount[_from][msg.sender]; + + if (_from == feeRecipient) { + require(_value.add(pendingAmount) <= balances[_from]); + require(_value.add(pendingAmount) <= allowedTransferAmount); + pendingApprovalAmount[_from][msg.sender] = pendingAmount.add(_value); + } else { + require(_value.add(pendingAmount).add(transferFee) <= balances[_from]); + require(_value.add(pendingAmount).add(transferFee) <= allowedTransferAmount); + pendingApprovalAmount[_from][msg.sender] = pendingAmount.add(_value).add(transferFee); + } + + pendingTransactions[currentNonce] = TransactionStruct( + _from, + _to, + _value, + transferFee, + msg.sender + ); + + emit RecordedPendingTransaction(_from, _to, _value, transferFee, msg.sender, currentNonce); + currentNonce++; + + return true; + } + + + function approveTransfer(uint256 nonce) + external + onlyValidator + checkIsInvestorApproved(pendingTransactions[nonce].from) + checkIsInvestorApproved(pendingTransactions[nonce].to) + checkIsValueValid(pendingTransactions[nonce].value) + returns (bool) + { + address from = pendingTransactions[nonce].from; + address spender = pendingTransactions[nonce].spender; + address to = pendingTransactions[nonce].to; + uint256 value = pendingTransactions[nonce].value; + uint256 allowedTransferAmount = allowed[from][spender]; + uint256 pendingAmount = pendingApprovalAmount[from][spender]; + uint256 fee = pendingTransactions[nonce].fee; + uint256 balanceFrom = balances[from]; + uint256 balanceTo = balances[to]; + + delete pendingTransactions[nonce]; + + if (from == feeRecipient) { + fee = 0; + balanceFrom = balanceFrom.sub(value); + balanceTo = balanceTo.add(value); + + if (spender != address(0)) { + allowedTransferAmount = allowedTransferAmount.sub(value); + } + pendingAmount = pendingAmount.sub(value); + + } else { + balanceFrom = balanceFrom.sub(value.add(fee)); + balanceTo = balanceTo.add(value); + balances[feeRecipient] = balances[feeRecipient].add(fee); + + if (spender != address(0)) { + allowedTransferAmount = allowedTransferAmount.sub(value).sub(fee); + } + pendingAmount = pendingAmount.sub(value).sub(fee); + } + + emit TransferWithFee( + from, + to, + value, + fee + ); + + emit Transfer( + from, + to, + value + ); + + balances[from] = balanceFrom; + balances[to] = balanceTo; + allowed[from][spender] = allowedTransferAmount; + pendingApprovalAmount[from][spender] = pendingAmount; + return true; + } + + + function rejectTransfer(uint256 nonce, uint256 reason) + external + onlyValidator + checkIsAddressValid(pendingTransactions[nonce].from) + { + address from = pendingTransactions[nonce].from; + address spender = pendingTransactions[nonce].spender; + + if (from == feeRecipient) { + pendingApprovalAmount[from][spender] = pendingApprovalAmount[from][spender] + .sub(pendingTransactions[nonce].value); + } else { + pendingApprovalAmount[from][spender] = pendingApprovalAmount[from][spender] + .sub(pendingTransactions[nonce].value).sub(pendingTransactions[nonce].fee); + } + + emit TransferRejected( + from, + pendingTransactions[nonce].to, + pendingTransactions[nonce].value, + nonce, + reason + ); + + delete pendingTransactions[nonce]; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/973.sol b/benchmark2/integer overflow/973.sol new file mode 100644 index 0000000000000000000000000000000000000000..f18977a41145e350f4a3c32a0152753d726c7370 --- /dev/null +++ b/benchmark2/integer overflow/973.sol @@ -0,0 +1,966 @@ +pragma solidity ^0.4.23; + + + + + +library SafeMath { + + + + + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + + + + + + + + if (a == 0) { + + return 0; + + } + + + c = a * b; + + assert(c / a == b); + + return c; + + } + + + + + function div(uint256 a, uint256 b) internal pure returns (uint256) { + + + + + + + + return a / b; + + } + + + + + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + + assert(b <= a); + + return a - b; + + } + + + + + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + + c = a + b; + + assert(c >= a); + + return c; + + } + +} + + + + + +library AddressUtils { + + + + + function isContract(address addr) internal view returns (bool) { + + uint256 size; + + + + + + + + + + + + + + + + assembly { size := extcodesize(addr) } + + return size > 0; + + } + + +} + + + + + +contract ERC721Receiver { + + + + bytes4 internal constant ERC721_RECEIVED = 0xf0b9e5ba; + + + + + function onERC721Received(address _from, uint256 _tokenId, bytes _data) public returns(bytes4); + +} + + + + +interface ERC165 { + + + + + function supportsInterface(bytes4 _interfaceId) external view returns (bool); + +} + + + + + +contract ERC721Basic is ERC165 { + + event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); + + event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId); + + event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); + + + function balanceOf(address _owner) public view returns (uint256 _balance); + + function ownerOf(uint256 _tokenId) public view returns (address _owner); + + function exists(uint256 _tokenId) public view returns (bool _exists); + + + function approve(address _to, uint256 _tokenId) public; + + function getApproved(uint256 _tokenId) public view returns (address _operator); + + + function setApprovalForAll(address _operator, bool _approved) public; + + function isApprovedForAll(address _owner, address _operator) public view returns (bool); + + + function transferFrom(address _from, address _to, uint256 _tokenId) public; + + function safeTransferFrom(address _from, address _to, uint256 _tokenId) public; + + + function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes _data) public; + +} + + + + + +contract ERC721Enumerable is ERC721Basic { + + function totalSupply() public view returns (uint256); + + function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256 _tokenId); + + function tokenByIndex(uint256 _index) public view returns (uint256); + +} + + + + + +contract ERC721Metadata is ERC721Basic { + + function name() external view returns (string _name); + + function symbol() external view returns (string _symbol); + + function tokenURI(uint256 _tokenId) public view returns (string); + +} + + + + + +contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { + + +} + + + +contract ERC721Holder is ERC721Receiver { + + function onERC721Received(address, uint256, bytes) public returns(bytes4) { + + return ERC721_RECEIVED; + + } + +} + + + + + +contract SupportsInterfaceWithLookup is ERC165 { + + bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; + + + + + + + mapping(bytes4 => bool) internal supportedInterfaces; + + + + + constructor() public { + + _registerInterface(InterfaceId_ERC165); + + } + + + + + function supportsInterface(bytes4 _interfaceId) external view returns (bool) { + + return supportedInterfaces[_interfaceId]; + + } + + + + + function _registerInterface(bytes4 _interfaceId) internal { + + require(_interfaceId != 0xffffffff); + + supportedInterfaces[_interfaceId] = true; + + } + +} + + + + + +contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic { + + + bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd; + + + + + bytes4 private constant InterfaceId_ERC721Exists = 0x4f558e79; + + + + + using SafeMath for uint256; + + using AddressUtils for address; + + + + + + + bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; + + + + + mapping (uint256 => address) internal tokenOwner; + + + + + mapping (uint256 => address) internal tokenApprovals; + + + + + mapping (address => uint256) internal ownedTokensCount; + + + + + mapping (address => mapping (address => bool)) internal operatorApprovals; + + + + + modifier onlyOwnerOf(uint256 _tokenId) { + + require(ownerOf(_tokenId) == msg.sender); + + _; + + } + + + + + modifier canTransfer(uint256 _tokenId) { + + require(isApprovedOrOwner(msg.sender, _tokenId)); + + _; + + } + + + constructor() public { + + + + _registerInterface(InterfaceId_ERC721); + + _registerInterface(InterfaceId_ERC721Exists); + + } + + + + + function balanceOf(address _owner) public view returns (uint256) { + + require(_owner != address(0)); + + return ownedTokensCount[_owner]; + + } + + + + + function ownerOf(uint256 _tokenId) public view returns (address) { + + address owner = tokenOwner[_tokenId]; + + require(owner != address(0)); + + return owner; + + } + + + + + function exists(uint256 _tokenId) public view returns (bool) { + + address owner = tokenOwner[_tokenId]; + + return owner != address(0); + + } + + + + + function approve(address _to, uint256 _tokenId) public { + + address owner = ownerOf(_tokenId); + + require(_to != owner); + + require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); + + + tokenApprovals[_tokenId] = _to; + + emit Approval(owner, _to, _tokenId); + + } + + + + + function getApproved(uint256 _tokenId) public view returns (address) { + + return tokenApprovals[_tokenId]; + + } + + + + + function setApprovalForAll(address _to, bool _approved) public { + + require(_to != msg.sender); + + operatorApprovals[msg.sender][_to] = _approved; + + emit ApprovalForAll(msg.sender, _to, _approved); + + } + + + + + function isApprovedForAll(address _owner, address _operator) public view returns (bool) { + + return operatorApprovals[_owner][_operator]; + + } + + + + + function transferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) { + + require(_from != address(0)); + + require(_to != address(0)); + + + clearApproval(_from, _tokenId); + + removeTokenFrom(_from, _tokenId); + + addTokenTo(_to, _tokenId); + + + emit Transfer(_from, _to, _tokenId); + + } + + + + + function safeTransferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) { + + + + safeTransferFrom(_from, _to, _tokenId, ""); + + } + + + + + function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes _data) public canTransfer(_tokenId) { + + transferFrom(_from, _to, _tokenId); + + + + require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data)); + + } + + + + + function isApprovedOrOwner( + + address _spender, + + uint256 _tokenId + + ) + + internal + + view + + returns (bool) + + { + + address owner = ownerOf(_tokenId); + + + + + + + + return ( + + _spender == owner || + + getApproved(_tokenId) == _spender || + + isApprovedForAll(owner, _spender) + + ); + + } + + + + + function _mint(address _to, uint256 _tokenId) internal { + + require(_to != address(0)); + + addTokenTo(_to, _tokenId); + + emit Transfer(address(0), _to, _tokenId); + + } + + + + + function clearApproval(address _owner, uint256 _tokenId) internal { + + require(ownerOf(_tokenId) == _owner); + + if (tokenApprovals[_tokenId] != address(0)) { + + tokenApprovals[_tokenId] = address(0); + + emit Approval(_owner, address(0), _tokenId); + + } + + } + + + + + function addTokenTo(address _to, uint256 _tokenId) internal { + + require(tokenOwner[_tokenId] == address(0)); + + tokenOwner[_tokenId] = _to; + + ownedTokensCount[_to] = ownedTokensCount[_to].add(1); + + } + + + + + function removeTokenFrom(address _from, uint256 _tokenId) internal { + + require(ownerOf(_tokenId) == _from); + + ownedTokensCount[_from] = ownedTokensCount[_from].sub(1); + + tokenOwner[_tokenId] = address(0); + + } + + + + + function checkAndCallSafeTransfer( + + address _from, + + address _to, + + uint256 _tokenId, + + bytes _data + + ) + + internal + + returns (bool) + + { + + if (!_to.isContract()) { + + return true; + + } + + + bytes4 retval = ERC721Receiver(_to).onERC721Received( + + _from, _tokenId, _data); + + return (retval == ERC721_RECEIVED); + + } + +} + + + + + + contract Ownable { + + address public owner; + + address public pendingOwner; + + address public manager; + + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + + + + modifier onlyOwner() { + + require(msg.sender == owner); + + _; + + } + + + + + modifier onlyManager() { + + require(msg.sender == manager); + + _; + + } + + + + + modifier onlyPendingOwner() { + + require(msg.sender == pendingOwner); + + _; + + } + + + constructor() public { + + owner = msg.sender; + + } + + + + + function transferOwnership(address newOwner) public onlyOwner { + + pendingOwner = newOwner; + + } + + + + + function claimOwnership() public onlyPendingOwner { + + emit OwnershipTransferred(owner, pendingOwner); + + owner = pendingOwner; + + pendingOwner = address(0); + + } + + + + + function setManager(address _manager) public onlyOwner { + + require(_manager != address(0)); + + manager = _manager; + + } + + + } + + + + + + +contract AviationSecurityToken is SupportsInterfaceWithLookup, ERC721, ERC721BasicToken, Ownable { + + + bytes4 private constant InterfaceId_ERC721Enumerable = 0x780e9d63; + + + + + bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f; + + + + + + + string public name_ = "AviationSecurityToken"; + + + + + string public symbol_ = "AVNS"; + + + + + mapping(address => uint256[]) internal ownedTokens; + + + + + mapping(uint256 => uint256) internal ownedTokensIndex; + + + + + uint256[] internal allTokens; + + + + + mapping(uint256 => uint256) internal allTokensIndex; + + + + + mapping(uint256 => string) internal tokenURIs; + + + struct Data{ + + string liscence; + + string URL; + + } + + + + mapping(uint256 => Data) internal tokenData; + + + + constructor() public { + + + + + + _registerInterface(InterfaceId_ERC721Enumerable); + + _registerInterface(InterfaceId_ERC721Metadata); + + } + + + + + function mint(address _to, uint256 _id) external onlyManager { + + _mint(_to, _id); + + } + + + + + function name() external view returns (string) { + + return name_; + + } + + + + + function symbol() external view returns (string) { + + return symbol_; + + } + + + function arrayOfTokensByAddress(address _holder) public view returns(uint256[]) { + + return ownedTokens[_holder]; + + } + + + + + function tokenURI(uint256 _tokenId) public view returns (string) { + + require(exists(_tokenId)); + + return tokenURIs[_tokenId]; + + } + + + + + function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256) { + + require(_index < balanceOf(_owner)); + + return ownedTokens[_owner][_index]; + + } + + + + + function totalSupply() public view returns (uint256) { + + return allTokens.length; + + } + + + + + function tokenByIndex(uint256 _index) public view returns (uint256) { + + require(_index < totalSupply()); + + return allTokens[_index]; + + } + + + + + function _setTokenURI(uint256 _tokenId, string _uri) internal { + + require(exists(_tokenId)); + + tokenURIs[_tokenId] = _uri; + + } + + + + + function addTokenTo(address _to, uint256 _tokenId) internal { + + super.addTokenTo(_to, _tokenId); + + uint256 length = ownedTokens[_to].length; + + ownedTokens[_to].push(_tokenId); + + ownedTokensIndex[_tokenId] = length; + + } + + + + + function removeTokenFrom(address _from, uint256 _tokenId) internal { + + super.removeTokenFrom(_from, _tokenId); + + + uint256 tokenIndex = ownedTokensIndex[_tokenId]; + + uint256 lastTokenIndex = ownedTokens[_from].length.sub(1); + + uint256 lastToken = ownedTokens[_from][lastTokenIndex]; + + + ownedTokens[_from][tokenIndex] = lastToken; + + ownedTokens[_from][lastTokenIndex] = 0; + + + + + + + + + + + ownedTokens[_from].length--; + + ownedTokensIndex[_tokenId] = 0; + + ownedTokensIndex[lastToken] = tokenIndex; + + } + + + + + function _mint(address _to, uint256 _id) internal { + + allTokens.push(_id); + + allTokensIndex[_id] = _id; + + super._mint(_to, _id); + + } + + + + function addTokenData(uint _tokenId, string _liscence, string _URL) public { + + require(ownerOf(_tokenId) == msg.sender); + + tokenData[_tokenId].liscence = _liscence; + + tokenData[_tokenId].URL = _URL; + + + + + } + + + + function getTokenData(uint _tokenId) public view returns(string Liscence, string URL){ + + require(exists(_tokenId)); + + Liscence = tokenData[_tokenId].liscence; + + URL = tokenData[_tokenId].URL; + + } + +} \ No newline at end of file diff --git a/benchmark2/integer overflow/980.sol b/benchmark2/integer overflow/980.sol new file mode 100644 index 0000000000000000000000000000000000000000..377fb4fa68635994431d0030a8ac5e87cfd03f81 --- /dev/null +++ b/benchmark2/integer overflow/980.sol @@ -0,0 +1,247 @@ +pragma solidity ^0.4.12; + +contract IMigrationContract { + function migrate(address addr, uint256 nas) returns (bool success); +} + + +contract SafeMath { + + + function safeAdd(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x + y; + assert((z >= x) && (z >= y)); + return z; + } + + function safeSubtract(uint256 x, uint256 y) internal returns(uint256) { + assert(x >= y); + uint256 z = x - y; + return z; + } + + function safeMult(uint256 x, uint256 y) internal returns(uint256) { + uint256 z = x * y; + assert((x == 0)||(z/x == y)); + return z; + } + +} + +contract Token { + uint256 public totalSupply; + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); +} + + + +contract StandardToken is Token { + + function transfer(address _to, uint256 _value) returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0) { + balances[msg.sender] -= _value; + balances[_to] += _value; + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] += _value; + balances[_from] -= _value; + allowed[_from][msg.sender] -= _value; + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } + + function balanceOf(address _owner) constant returns (uint256 balance) { + return balances[_owner]; + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) constant returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; +} + +contract HKHCToken is StandardToken, SafeMath { + + + string public constant name = "Happily keep health"; + string public constant symbol = "HKHC"; + uint256 public constant decimals = 18; + string public version = "1.0"; + + + address public ethFundDeposit; + address public newContractAddr; + + + bool public isFunding; + uint256 public fundingStartBlock; + uint256 public fundingStopBlock; + + uint256 public currentSupply; + uint256 public tokenRaised = 0; + uint256 public tokenMigrated = 0; + uint256 public tokenExchangeRate = 625; + + + event AllocateToken(address indexed _to, uint256 _value); + event IssueToken(address indexed _to, uint256 _value); + event IncreaseSupply(uint256 _value); + event DecreaseSupply(uint256 _value); + event Migrate(address indexed _to, uint256 _value); + + + function formatDecimals(uint256 _value) internal returns (uint256 ) { + return _value * 10 ** decimals; + } + + + function HKHCToken( + address _ethFundDeposit, + uint256 _currentSupply) + { + ethFundDeposit = _ethFundDeposit; + + isFunding = false; + fundingStartBlock = 0; + fundingStopBlock = 0; + + currentSupply = formatDecimals(_currentSupply); + totalSupply = formatDecimals(1000000000); + balances[msg.sender] = totalSupply; + if(currentSupply > totalSupply) throw; + } + + modifier isOwner() { require(msg.sender == ethFundDeposit); _; } + + + function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external { + if (_tokenExchangeRate == 0) throw; + if (_tokenExchangeRate == tokenExchangeRate) throw; + + tokenExchangeRate = _tokenExchangeRate; + } + + + function increaseSupply (uint256 _value) isOwner external { + uint256 value = formatDecimals(_value); + if (value + currentSupply > totalSupply) throw; + currentSupply = safeAdd(currentSupply, value); + IncreaseSupply(value); + } + + + function decreaseSupply (uint256 _value) isOwner external { + uint256 value = formatDecimals(_value); + if (value + tokenRaised > currentSupply) throw; + + currentSupply = safeSubtract(currentSupply, value); + DecreaseSupply(value); + } + + + function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external { + if (isFunding) throw; + if (_fundingStartBlock >= _fundingStopBlock) throw; + if (block.number >= _fundingStartBlock) throw; + + fundingStartBlock = _fundingStartBlock; + fundingStopBlock = _fundingStopBlock; + isFunding = true; + } + + + function stopFunding() isOwner external { + if (!isFunding) throw; + isFunding = false; + } + + + function setMigrateContract(address _newContractAddr) isOwner external { + if (_newContractAddr == newContractAddr) throw; + newContractAddr = _newContractAddr; + } + + + function changeOwner(address _newFundDeposit) isOwner() external { + if (_newFundDeposit == address(0x0)) throw; + ethFundDeposit = _newFundDeposit; + } + + + function migrate() external { + if(isFunding) throw; + if(newContractAddr == address(0x0)) throw; + + uint256 tokens = balances[msg.sender]; + if (tokens == 0) throw; + + balances[msg.sender] = 0; + tokenMigrated = safeAdd(tokenMigrated, tokens); + + IMigrationContract newContract = IMigrationContract(newContractAddr); + if (!newContract.migrate(msg.sender, tokens)) throw; + + Migrate(msg.sender, tokens); + } + + + function transferETH() isOwner external { + if (this.balance == 0) throw; + if (!ethFundDeposit.send(this.balance)) throw; + } + + + function allocateToken (address _addr, uint256 _eth) isOwner external { + if (_eth == 0) throw; + if (_addr == address(0x0)) throw; + + uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate); + if (tokens + tokenRaised > currentSupply) throw; + + tokenRaised = safeAdd(tokenRaised, tokens); + balances[_addr] += tokens; + + AllocateToken(_addr, tokens); + } + + + function () payable { + if (!isFunding) throw; + if (msg.value == 0) throw; + + if (block.number < fundingStartBlock) throw; + if (block.number > fundingStopBlock) throw; + + uint256 tokens = safeMult(msg.value, tokenExchangeRate); + if (tokens + tokenRaised > currentSupply) throw; + + tokenRaised = safeAdd(tokenRaised, tokens); + balances[msg.sender] += tokens; + + IssueToken(msg.sender, tokens); + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/983.sol b/benchmark2/integer overflow/983.sol new file mode 100644 index 0000000000000000000000000000000000000000..e3f82a2bf074b643c07c0da17105a3de44074b90 --- /dev/null +++ b/benchmark2/integer overflow/983.sol @@ -0,0 +1,222 @@ +pragma solidity ^0.4.20; + +contract SafeMath { + function safeMul(uint256 a, uint256 b) public pure returns (uint256) { + uint256 c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b)public pure returns (uint256) { + assert(b > 0); + uint256 c = a / b; + assert(a == b * c + a % b); + return c; + } + + function safeSub(uint256 a, uint256 b)public pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b)public pure returns (uint256) { + uint256 c = a + b; + assert(c>=a && c>=b); + return c; + } + + function _assert(bool assertion)public pure { + assert(!assertion); + } +} + + +contract ERC20Interface { + string public name; + string public symbol; + uint8 public decimals; + uint public totalSupply; + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) view returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + } + +contract ERC20 is ERC20Interface,SafeMath { + + + mapping(address => uint256) public balanceOf; + + + mapping(address => mapping(address => uint256)) allowed; + + constructor(string _name) public { + name = _name; + symbol = "CONG"; + decimals = 4; + totalSupply = 100000000000000; + balanceOf[msg.sender] = totalSupply; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(balanceOf[msg.sender] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] ,_value); + + + emit Transfer(msg.sender, _to, _value); + + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + require(allowed[_from][msg.sender] >= _value); + require(balanceOf[_from] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to],_value); + + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender], _value); + + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) returns (bool success) { + allowed[msg.sender][_spender] = _value; + + emit Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} + + +contract owned { + address public owner; + + constructor () public { + owner = msg.sender; + } + + modifier onlyOwner { + require(msg.sender == owner); + _; + } + + function transferOwnerShip(address newOwer) public onlyOwner { + owner = newOwer; + } + +} + +contract SelfDesctructionContract { + address public owner; + string public someValue; + modifier ownerRestricted { + require(owner == msg.sender); + _; + } + + function SelfDesctructionContract() { + owner = msg.sender; + } + + function setSomeValue(string value){ + someValue = value; + } + + function destroyContract() ownerRestricted { + selfdestruct(owner); + } +} + + + +contract AdvanceToken is ERC20, owned,SelfDesctructionContract{ + + mapping (address => bool) public frozenAccount; + + event AddSupply(uint amount); + event FrozenFunds(address target, bool frozen); + event Burn(address target, uint amount); + + constructor (string _name) ERC20(_name) public { + + } + + function mine(address target, uint amount) public onlyOwner { + totalSupply =SafeMath.safeAdd(totalSupply,amount) ; + balanceOf[target] = SafeMath.safeAdd(balanceOf[target],amount); + + emit AddSupply(amount); + emit Transfer(0, target, amount); + } + + function freezeAccount(address target, bool freeze) public onlyOwner { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + + function transfer(address _to, uint256 _value) public returns (bool success) { + success = _transfer(msg.sender, _to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { + require(allowed[_from][msg.sender] >= _value); + success = _transfer(_from, _to, _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value) ; + } + + function _transfer(address _from, address _to, uint256 _value) internal returns (bool) { + require(_to != address(0)); + require(!frozenAccount[_from]); + + require(balanceOf[_from] >= _value); + require(balanceOf[ _to] + _value >= balanceOf[ _to]); + + balanceOf[_from] =SafeMath.safeSub(balanceOf[_from],_value) ; + balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to],_value) ; + + emit Transfer(_from, _to, _value); + return true; + } + + function burn(uint256 _value) public returns (bool success) { + require(balanceOf[msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender],_value) ; + + emit Burn(msg.sender, _value); + return true; + } + + function burnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(allowed[_from][msg.sender] >= _value); + + totalSupply =SafeMath.safeSub(totalSupply,_value) ; + balanceOf[msg.sender] =SafeMath.safeSub(balanceOf[msg.sender], _value); + allowed[_from][msg.sender] =SafeMath.safeSub(allowed[_from][msg.sender],_value); + + emit Burn(msg.sender, _value); + return true; + } +} \ No newline at end of file diff --git a/benchmark2/integer overflow/988.sol b/benchmark2/integer overflow/988.sol new file mode 100644 index 0000000000000000000000000000000000000000..c916dd6c155dd88458b7b9f4f3634c3cbbd7074b --- /dev/null +++ b/benchmark2/integer overflow/988.sol @@ -0,0 +1,259 @@ +pragma solidity ^0.4.23; + + + + + + + + +contract SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + + + +contract Token { + + function totalSupply() constant returns (uint256 supply); + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); +} + + + + +contract AbstractToken is Token, SafeMath { + + function AbstractToken () { + + } + + + function balanceOf(address _owner) constant returns (uint256 balance) { + return accounts [_owner]; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + if (accounts [msg.sender] < _value) return false; + if (_value > 0 && msg.sender != _to) { + accounts [msg.sender] = safeSub (accounts [msg.sender], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer (msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(_to != address(0)); + if (allowances [_from][msg.sender] < _value) return false; + if (accounts [_from] < _value) return false; + + if (_value > 0 && _from != _to) { + allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value); + accounts [_from] = safeSub (accounts [_from], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer(_from, _to, _value); + return true; + } + + + function approve (address _spender, uint256 _value) returns (bool success) { + allowances [msg.sender][_spender] = _value; + emit Approval (msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) constant + returns (uint256 remaining) { + return allowances [_owner][_spender]; + } + + + mapping (address => uint256) accounts; + + + mapping (address => mapping (address => uint256)) private allowances; + +} + + + +contract CLASSYToken is AbstractToken { + + + + uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18); + + + address private owner; + + + mapping (address => bool) private frozenAccount; + + + uint256 tokenCount = 0; + + + + bool frozen = false; + + + + function CLASSYToken () { + owner = msg.sender; + } + + + function totalSupply() constant returns (uint256 supply) { + return tokenCount; + } + + string constant public name = "CLASSY"; + string constant public symbol = "CLASSY"; + uint8 constant public decimals = 18; + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(!frozenAccount[msg.sender]); + if (frozen) return false; + else return AbstractToken.transfer (_to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(!frozenAccount[_from]); + if (frozen) return false; + else return AbstractToken.transferFrom (_from, _to, _value); + } + + + function approve (address _spender, uint256 _value) + returns (bool success) { + require(allowance (msg.sender, _spender) == 0 || _value == 0); + return AbstractToken.approve (_spender, _value); + } + + + function createTokens(uint256 _value) + returns (bool success) { + require (msg.sender == owner); + + if (_value > 0) { + if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false; + + accounts [msg.sender] = safeAdd (accounts [msg.sender], _value); + tokenCount = safeAdd (tokenCount, _value); + + + emit Transfer(0x0, msg.sender, _value); + + return true; + } + + return false; + + } + + + + function setOwner(address _newOwner) { + require (msg.sender == owner); + + owner = _newOwner; + } + + + function freezeTransfers () { + require (msg.sender == owner); + + if (!frozen) { + frozen = true; + emit Freeze (); + } + } + + + function unfreezeTransfers () { + require (msg.sender == owner); + + if (frozen) { + frozen = false; + emit Unfreeze (); + } + } + + + + + function refundTokens(address _token, address _refund, uint256 _value) { + require (msg.sender == owner); + require(_token != address(this)); + AbstractToken token = AbstractToken(_token); + token.transfer(_refund, _value); + emit RefundTokens(_token, _refund, _value); + } + + + function freezeAccount(address _target, bool freeze) { + require (msg.sender == owner); + require (msg.sender != _target); + frozenAccount[_target] = freeze; + emit FrozenFunds(_target, freeze); + } + + + event Freeze (); + + + event Unfreeze (); + + + + event FrozenFunds(address target, bool frozen); + + + + + + event RefundTokens(address _token, address _refund, uint256 _value); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/994.sol b/benchmark2/integer overflow/994.sol new file mode 100644 index 0000000000000000000000000000000000000000..858dbcde7d8c9126d5b4918ad75c34d10c50779f --- /dev/null +++ b/benchmark2/integer overflow/994.sol @@ -0,0 +1,296 @@ +pragma solidity ^0.4.24; + + + + + + + + +contract SafeMath { + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { + + uint256 c = a / b; + + return c; + } + + function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} + + + + + +contract Token { + + function totalSupply() constant returns (uint256 supply); + function balanceOf(address _owner) constant returns (uint256 balance); + function transfer(address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) returns (bool success); + function allowance(address _owner, address _spender) constant returns (uint256 remaining); + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); +} + + + + +contract AbstractToken is Token, SafeMath { + + function AbstractToken () { + + } + + + function balanceOf(address _owner) constant returns (uint256 balance) { + return accounts [_owner]; + } + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(_to != address(0)); + if (accounts [msg.sender] < _value) return false; + if (_value > 0 && msg.sender != _to) { + accounts [msg.sender] = safeSub (accounts [msg.sender], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer (msg.sender, _to, _value); + return true; + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(_to != address(0)); + if (allowances [_from][msg.sender] < _value) return false; + if (accounts [_from] < _value) return false; + + if (_value > 0 && _from != _to) { + allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value); + accounts [_from] = safeSub (accounts [_from], _value); + accounts [_to] = safeAdd (accounts [_to], _value); + } + emit Transfer(_from, _to, _value); + return true; + } + + + function approve (address _spender, uint256 _value) returns (bool success) { + allowances [msg.sender][_spender] = _value; + emit Approval (msg.sender, _spender, _value); + return true; + } + + + function allowance(address _owner, address _spender) constant + returns (uint256 remaining) { + return allowances [_owner][_spender]; + } + + + mapping (address => uint256) accounts; + + + mapping (address => mapping (address => uint256)) private allowances; + +} + + + +contract XERA is AbstractToken { + + + + uint256 constant MAX_TOKEN_COUNT = 95000000 * (10**18); + + + address private owner; + + + mapping (address => bool) private frozenAccount; + + + + mapping (address => bool) private burningAccount; + + + + uint256 tokenCount = 0; + + + + bool frozen = false; + + + + function XERA () { + owner = msg.sender; + } + + + function totalSupply() constant returns (uint256 supply) { + return tokenCount; + } + + string constant public name = "XERA"; + string constant public symbol = "XERA"; + uint8 constant public decimals = 18; + + + function transfer(address _to, uint256 _value) returns (bool success) { + require(!frozenAccount[msg.sender]); + if (frozen) return false; + else return AbstractToken.transfer (_to, _value); + } + + + function transferFrom(address _from, address _to, uint256 _value) + returns (bool success) { + require(!frozenAccount[_from]); + if (frozen) return false; + else return AbstractToken.transferFrom (_from, _to, _value); + } + + + function approve (address _spender, uint256 _value) + returns (bool success) { + require(allowance (msg.sender, _spender) == 0 || _value == 0); + return AbstractToken.approve (_spender, _value); + } + + + function createTokens(uint256 _value) + returns (bool success) { + require (msg.sender == owner); + + if (_value > 0) { + if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false; + + accounts [msg.sender] = safeAdd (accounts [msg.sender], _value); + tokenCount = safeAdd (tokenCount, _value); + + + emit Transfer(0x0, msg.sender, _value); + + return true; + } + + return false; + + } + + + + function burningCapableAccount(address[] _target) { + + require (msg.sender == owner); + + for (uint i = 0; i < _target.length; i++) { + burningAccount[_target[i]] = true; + } + } + + + + function burn(uint256 _value) public returns (bool success) { + + require(accounts[msg.sender] >= _value); + + require(burningAccount[msg.sender]); + + accounts [msg.sender] = safeSub (accounts [msg.sender], _value); + + tokenCount = safeSub (tokenCount, _value); + + emit Burn(msg.sender, _value); + + return true; + } + + + + function setOwner(address _newOwner) { + require (msg.sender == owner); + + owner = _newOwner; + } + + + function freezeTransfers () { + require (msg.sender == owner); + + if (!frozen) { + frozen = true; + emit Freeze (); + } + } + + + function unfreezeTransfers () { + require (msg.sender == owner); + + if (frozen) { + frozen = false; + emit Unfreeze (); + } + } + + + + + function refundTokens(address _token, address _refund, uint256 _value) { + require (msg.sender == owner); + require(_token != address(this)); + AbstractToken token = AbstractToken(_token); + token.transfer(_refund, _value); + emit RefundTokens(_token, _refund, _value); + } + + + function freezeAccount(address _target, bool freeze) { + require (msg.sender == owner); + require (msg.sender != _target); + frozenAccount[_target] = freeze; + emit FrozenFunds(_target, freeze); + } + + + event Freeze (); + + + event Unfreeze (); + + + + event FrozenFunds(address target, bool frozen); + + + + event Burn(address target,uint256 _value); + + + + + + event RefundTokens(address _token, address _refund, uint256 _value); +} \ No newline at end of file diff --git a/benchmark2/integer overflow/999.sol b/benchmark2/integer overflow/999.sol new file mode 100644 index 0000000000000000000000000000000000000000..9d5e97b2ef74d60962f8211ff5f417170bac78ef --- /dev/null +++ b/benchmark2/integer overflow/999.sol @@ -0,0 +1,131 @@ +pragma solidity ^0.4.24; + + +library SafeMath { + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { if (_a == 0) { return 0; } uint256 c = _a * _b; assert(c / _a == _b); return c; } + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { uint256 c = _a / _b; return c; } + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { assert(_b <= _a); uint256 c = _a - _b; return c;} + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { uint256 c = _a + _b; assert(c >= _a); return c;} +} + + +contract ERC20 { + function totalSupply() public view returns (uint256); + function balanceOf(address _who) public view returns (uint256); + function allowance(address _owner, address _spender) public view returns (uint256); + function transfer(address _to, uint256 _value) public returns (bool); + function approve(address _spender, uint256 _value) public returns (bool); + function transferFrom(address _from, address _to, uint256 _value) public returns (bool); +} + + +contract OwnerHeapX { + address public owner; + constructor() public { owner = msg.sender; } + modifier onlyOwner { require(msg.sender == owner); _;} + function transferOwnership(address newOwner) onlyOwner public { owner = newOwner; } +} + + +contract HeapX is OwnerHeapX, ERC20 { + + string public name; + string public symbol; + uint8 public decimals; + uint256 public totalSupply_; + address public owner; + + constructor() public { + name = "HeapX"; + symbol = "HEAP"; + decimals = 9; + totalSupply_ = 500000000000000000; + owner = msg.sender; + balances[msg.sender] = totalSupply_; + emit Transfer(address(0), msg.sender, totalSupply_); + } + + using SafeMath for uint256; + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) internal allowed; + mapping (address => bool) public frozenAccount; + mapping (address => mapping (address => uint256)) public allowance; + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner,address indexed spender,uint256 value); + event Burn(address indexed from, uint256 value); + event FrozenFunds(address target, bool frozen); + + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + function allowance(address _owner, address _spender) public view returns (uint256){ + return allowed[_owner][_spender]; + } + + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + require(!frozenAccount[_to]); + require(!frozenAccount[msg.sender]); + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + function transferFrom( address _from, address _to, uint256 _value) public returns (bool){ + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + require(!frozenAccount[_to]); + require(!frozenAccount[_from]); + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + function increaseApproval(address _spender, uint256 _addedValue) public returns (bool){ + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function decreaseApproval(address _spender, uint256 _subtractedValue) public returns (bool){ + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + function freezeAccount(address target, bool freeze) onlyOwner public { + frozenAccount[target] = freeze; + emit FrozenFunds(target, freeze); + } + + function burn(uint256 _value) public returns (bool success) { + require(balances[msg.sender] >= _value); + balances[msg.sender] -= _value; + totalSupply_ -= _value; + emit Burn(msg.sender, _value); + return true; + } + +} \ No newline at end of file