Commit 18581f13 by Peter Murray Committed by Francisco Giordano

converted if() throw convention to require()/assert()/revert()

parent f3867f84
...@@ -19,9 +19,7 @@ contract Bounty is PullPayment, Destructible { ...@@ -19,9 +19,7 @@ contract Bounty is PullPayment, Destructible {
* @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed. * @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed.
*/ */
function() payable { function() payable {
if (claimed) { require(!claimed);
throw;
}
} }
/** /**
...@@ -48,13 +46,9 @@ contract Bounty is PullPayment, Destructible { ...@@ -48,13 +46,9 @@ contract Bounty is PullPayment, Destructible {
*/ */
function claim(Target target) { function claim(Target target) {
address researcher = researchers[target]; address researcher = researchers[target];
if (researcher == 0) { require(researcher != 0);
throw;
}
// Check Target contract invariants // Check Target contract invariants
if (target.checkInvariant()) { require(!target.checkInvariant());
throw;
}
asyncSend(researcher, this.balance); asyncSend(researcher, this.balance);
claimed = true; claimed = true;
} }
......
...@@ -67,9 +67,7 @@ contract DayLimit { ...@@ -67,9 +67,7 @@ contract DayLimit {
* @dev Simple modifier for daily limit. * @dev Simple modifier for daily limit.
*/ */
modifier limitedDaily(uint256 _value) { modifier limitedDaily(uint256 _value) {
if (!underLimit(_value)) { require(underLimit(_value));
throw;
}
_; _;
} }
} }
...@@ -23,9 +23,7 @@ contract LimitBalance { ...@@ -23,9 +23,7 @@ contract LimitBalance {
* @dev Checks if limit was reached. Case true, it throws. * @dev Checks if limit was reached. Case true, it throws.
*/ */
modifier limitedPayable() { modifier limitedPayable() {
if (this.balance > limit) { require(this.balance <= limit);
throw;
}
_; _;
} }
......
...@@ -61,7 +61,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { ...@@ -61,7 +61,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
SingleTransact(msg.sender, _value, _to, _data); SingleTransact(msg.sender, _value, _to, _data);
// yes - just execute the call. // yes - just execute the call.
if (!_to.call.value(_value)(_data)) { if (!_to.call.value(_value)(_data)) {
throw; revert();
} }
return 0; return 0;
} }
...@@ -82,9 +82,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { ...@@ -82,9 +82,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
*/ */
function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) { function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
if (txs[_h].to != 0) { if (txs[_h].to != 0) {
if (!txs[_h].to.call.value(txs[_h].value)(txs[_h].data)) { assert(txs[_h].to.call.value(txs[_h].value)(txs[_h].data));
throw;
}
MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data); MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data);
delete txs[_h]; delete txs[_h];
return true; return true;
......
...@@ -22,13 +22,10 @@ contract ReentrancyGuard { ...@@ -22,13 +22,10 @@ contract ReentrancyGuard {
* wrapper marked as `nonReentrant`. * wrapper marked as `nonReentrant`.
*/ */
modifier nonReentrant() { modifier nonReentrant() {
if(rentrancy_lock == false) { require(!rentrancy_lock);
rentrancy_lock = true; rentrancy_lock = true;
_; _;
rentrancy_lock = false; rentrancy_lock = false;
} else {
throw;
}
} }
} }
...@@ -19,7 +19,7 @@ contract Pausable is Ownable { ...@@ -19,7 +19,7 @@ contract Pausable is Ownable {
* @dev modifier to allow actions only when the contract IS paused * @dev modifier to allow actions only when the contract IS paused
*/ */
modifier whenNotPaused() { modifier whenNotPaused() {
if (paused) throw; require(!paused);
_; _;
} }
...@@ -27,7 +27,7 @@ contract Pausable is Ownable { ...@@ -27,7 +27,7 @@ contract Pausable is Ownable {
* @dev modifier to allow actions only when the contract IS NOT paused * @dev modifier to allow actions only when the contract IS NOT paused
*/ */
modifier whenPaused { modifier whenPaused {
if (!paused) throw; require(paused);
_; _;
} }
......
...@@ -16,9 +16,7 @@ contract Claimable is Ownable { ...@@ -16,9 +16,7 @@ contract Claimable is Ownable {
* @dev Modifier throws if called by any account other than the pendingOwner. * @dev Modifier throws if called by any account other than the pendingOwner.
*/ */
modifier onlyPendingOwner() { modifier onlyPendingOwner() {
if (msg.sender != pendingOwner) { require(msg.sender == pendingOwner);
throw;
}
_; _;
} }
......
...@@ -21,8 +21,7 @@ contract DelayedClaimable is Claimable { ...@@ -21,8 +21,7 @@ contract DelayedClaimable is Claimable {
* @param _end The latest time ownership can be claimed. * @param _end The latest time ownership can be claimed.
*/ */
function setLimits(uint256 _start, uint256 _end) onlyOwner { function setLimits(uint256 _start, uint256 _end) onlyOwner {
if (_start > _end) require(_start <= _end);
throw;
end = _end; end = _end;
start = _start; start = _start;
} }
...@@ -33,8 +32,7 @@ contract DelayedClaimable is Claimable { ...@@ -33,8 +32,7 @@ contract DelayedClaimable is Claimable {
* the specified start and end time. * the specified start and end time.
*/ */
function claimOwnership() onlyPendingOwner { function claimOwnership() onlyPendingOwner {
if ((block.number > end) || (block.number < start)) require((block.number <= end) && (block.number >= start));
throw;
owner = pendingOwner; owner = pendingOwner;
pendingOwner = 0x0; pendingOwner = 0x0;
end = 0; end = 0;
......
...@@ -22,9 +22,7 @@ contract HasNoEther is Ownable { ...@@ -22,9 +22,7 @@ contract HasNoEther is Ownable {
* we could use assembly to access msg.value. * we could use assembly to access msg.value.
*/ */
function HasNoEther() payable { function HasNoEther() payable {
if(msg.value > 0) { require(msg.value == 0);
throw;
}
} }
/** /**
...@@ -37,8 +35,6 @@ contract HasNoEther is Ownable { ...@@ -37,8 +35,6 @@ contract HasNoEther is Ownable {
* @dev Transfer all Ether held by the contract to the owner. * @dev Transfer all Ether held by the contract to the owner.
*/ */
function reclaimEther() external onlyOwner { function reclaimEther() external onlyOwner {
if(!owner.send(this.balance)) { assert(owner.send(this.balance));
throw;
}
} }
} }
...@@ -19,7 +19,7 @@ contract HasNoTokens is Ownable { ...@@ -19,7 +19,7 @@ contract HasNoTokens is Ownable {
* @param data_ Bytes The data passed from the caller. * @param data_ Bytes The data passed from the caller.
*/ */
function tokenFallback(address from_, uint256 value_, bytes data_) external { function tokenFallback(address from_, uint256 value_, bytes data_) external {
throw; revert();
} }
/** /**
......
...@@ -23,9 +23,7 @@ contract Ownable { ...@@ -23,9 +23,7 @@ contract Ownable {
* @dev Throws if called by any account other than the owner. * @dev Throws if called by any account other than the owner.
*/ */
modifier onlyOwner() { modifier onlyOwner() {
if (msg.sender != owner) { require(msg.sender == owner);
throw;
}
_; _;
} }
......
...@@ -36,9 +36,7 @@ contract Shareable { ...@@ -36,9 +36,7 @@ contract Shareable {
// simple single-sig function modifier. // simple single-sig function modifier.
modifier onlyOwner { modifier onlyOwner {
if (!isOwner(msg.sender)) { require(isOwner(msg.sender));
throw;
}
_; _;
} }
...@@ -67,9 +65,7 @@ contract Shareable { ...@@ -67,9 +65,7 @@ contract Shareable {
ownerIndex[_owners[i]] = 2 + i; ownerIndex[_owners[i]] = 2 + i;
} }
required = _required; required = _required;
if (required > owners.length) { require(required <= owners.length);
throw;
}
} }
/** /**
...@@ -138,9 +134,7 @@ contract Shareable { ...@@ -138,9 +134,7 @@ contract Shareable {
// determine what index the present sender is: // determine what index the present sender is:
uint256 index = ownerIndex[msg.sender]; uint256 index = ownerIndex[msg.sender];
// make sure they're an owner // make sure they're an owner
if (index == 0) { require(index != 0);
throw;
}
var pending = pendings[_operation]; var pending = pendings[_operation];
// if we're not yet working on this operation, switch over and reset the confirmation status. // if we're not yet working on this operation, switch over and reset the confirmation status.
......
...@@ -32,19 +32,12 @@ contract PullPayment { ...@@ -32,19 +32,12 @@ contract PullPayment {
address payee = msg.sender; address payee = msg.sender;
uint256 payment = payments[payee]; uint256 payment = payments[payee];
if (payment == 0) { require(payment != 0);
throw; require(this.balance >= payment);
}
if (this.balance < payment) {
throw;
}
totalPayments = totalPayments.sub(payment); totalPayments = totalPayments.sub(payment);
payments[payee] = 0; payments[payee] = 0;
if (!payee.send(payment)) { assert(payee.send(payment));
throw;
}
} }
} }
...@@ -23,7 +23,7 @@ contract LimitedTransferToken is ERC20 { ...@@ -23,7 +23,7 @@ contract LimitedTransferToken is ERC20 {
* @dev Checks whether it can transfer or otherwise throws. * @dev Checks whether it can transfer or otherwise throws.
*/ */
modifier canTransfer(address _sender, uint256 _value) { modifier canTransfer(address _sender, uint256 _value) {
if (_value > transferableTokens(_sender, uint64(now))) throw; require(_value <= transferableTokens(_sender, uint64(now)));
_; _;
} }
......
...@@ -21,7 +21,7 @@ contract MintableToken is StandardToken, Ownable { ...@@ -21,7 +21,7 @@ contract MintableToken is StandardToken, Ownable {
modifier canMint() { modifier canMint() {
if(mintingFinished) throw; require(!mintingFinished);
_; _;
} }
......
...@@ -27,7 +27,7 @@ contract StandardToken is ERC20, BasicToken { ...@@ -27,7 +27,7 @@ contract StandardToken is ERC20, BasicToken {
var _allowance = allowed[_from][msg.sender]; var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw; // require (_value <= _allowance);
balances[_to] = balances[_to].add(_value); balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value); balances[_from] = balances[_from].sub(_value);
...@@ -47,7 +47,7 @@ contract StandardToken is ERC20, BasicToken { ...@@ -47,7 +47,7 @@ contract StandardToken is ERC20, BasicToken {
// allowance to zero by calling `approve(_spender, 0)` if it is not // allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here: // already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw; require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value; allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value); Approval(msg.sender, _spender, _value);
......
...@@ -45,11 +45,9 @@ contract VestedToken is StandardToken, LimitedTransferToken { ...@@ -45,11 +45,9 @@ contract VestedToken is StandardToken, LimitedTransferToken {
) public { ) public {
// Check for date inconsistencies that may cause unexpected behavior // Check for date inconsistencies that may cause unexpected behavior
if (_cliff < _start || _vesting < _cliff) { require(_cliff >= _start && _vesting >= _cliff);
throw;
}
if (tokenGrantsCount(_to) > MAX_GRANTS_PER_ADDRESS) throw; // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting). require(tokenGrantsCount(_to) <= MAX_GRANTS_PER_ADDRESS); // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting).
uint256 count = grants[_to].push( uint256 count = grants[_to].push(
TokenGrant( TokenGrant(
...@@ -76,13 +74,8 @@ contract VestedToken is StandardToken, LimitedTransferToken { ...@@ -76,13 +74,8 @@ contract VestedToken is StandardToken, LimitedTransferToken {
function revokeTokenGrant(address _holder, uint256 _grantId) public { function revokeTokenGrant(address _holder, uint256 _grantId) public {
TokenGrant grant = grants[_holder][_grantId]; TokenGrant grant = grants[_holder][_grantId];
if (!grant.revokable) { // Check if grant was revokable require(grant.revokable);
throw; require(grant.granter == msg.sender); // Only granter can revoke it
}
if (grant.granter != msg.sender) { // Only granter can revoke it
throw;
}
address receiver = grant.burnsOnRevoke ? 0xdead : msg.sender; address receiver = grant.burnsOnRevoke ? 0xdead : msg.sender;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment