From 53c72f5c322433b01fe62e629b031674350a2b82 Mon Sep 17 00:00:00 2001 From: Tim Loh Date: Mon, 11 Sep 2017 11:51:59 +0800 Subject: [PATCH 1/4] Eliminate throw() per issue #44. --- contracts/AllocatedCrowdsale.sol | 2 +- contracts/BonusFinalizeAgent.sol | 13 +--- contracts/Crowdsale.sol | 86 +++++++++----------------- contracts/DefaultFinalizeAgent.sol | 4 +- contracts/EthTranchePricing.sol | 18 ++---- contracts/ExtraFinalizeAgent.sol | 13 +--- contracts/Haltable.sol | 6 +- contracts/Issuer.sol | 2 +- contracts/MilestonePricing.sol | 14 ++--- contracts/MintableToken.sol | 6 +- contracts/PaymentForwarder.sol | 2 +- contracts/PreICOProxyBuyer.sol | 75 +++++++--------------- contracts/PresaleFundCollector.sol | 29 +++------ contracts/RelaunchedCrowdsale.sol | 8 +-- contracts/ReleasableToken.sol | 16 +---- contracts/StandardToken.sol | 2 +- contracts/TimeVault.sol | 10 ++- contracts/TokenTranchePricing.sol | 14 ++--- contracts/TokenVault.sol | 68 ++++++-------------- contracts/UpgradeableToken.sol | 26 +++----- contracts/test/TestMigrationTarget.sol | 12 ++-- 21 files changed, 134 insertions(+), 292 deletions(-) diff --git a/contracts/AllocatedCrowdsale.sol b/contracts/AllocatedCrowdsale.sol index 76265c75..3e4b19e5 100644 --- a/contracts/AllocatedCrowdsale.sol +++ b/contracts/AllocatedCrowdsale.sol @@ -57,6 +57,6 @@ contract AllocatedCrowdsale is Crowdsale { * Use approve() given to this crowdsale to distribute the tokens. */ function assignTokens(address receiver, uint tokenAmount) private { - if(!token.transferFrom(beneficiary, receiver, tokenAmount)) throw; + require(token.transferFrom(beneficiary, receiver, tokenAmount)); } } diff --git a/contracts/BonusFinalizeAgent.sol b/contracts/BonusFinalizeAgent.sol index 4e2b06d8..7300f3ee 100644 --- a/contracts/BonusFinalizeAgent.sol +++ b/contracts/BonusFinalizeAgent.sol @@ -35,17 +35,10 @@ contract BonusFinalizeAgent is FinalizeAgent { uint public allocatedBonus; function BonusFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig) { + require(address(_crowdsale) != 0 && address(_teamMultisig) != 0); token = _token; crowdsale = _crowdsale; - if(address(crowdsale) == 0) { - throw; - } - teamMultisig = _teamMultisig; - if(address(teamMultisig) == 0) { - throw; - } - bonusBasePoints = _bonusBasePoints; } @@ -56,9 +49,7 @@ contract BonusFinalizeAgent is FinalizeAgent { /** Called once by crowdsale finalize() if the sale was success. */ function finalizeCrowdsale() { - if(msg.sender != address(crowdsale)) { - throw; - } + require(msg.sender == address(crowdsale)); // How many % of tokens the founders and others get uint tokensSold = crowdsale.tokensSold(); diff --git a/contracts/Crowdsale.sol b/contracts/Crowdsale.sol index 4a901d56..7187747e 100644 --- a/contracts/Crowdsale.sol +++ b/contracts/Crowdsale.sol @@ -127,6 +127,12 @@ contract Crowdsale is Haltable { function Crowdsale(address _token, PricingStrategy _pricingStrategy, address _multisigWallet, uint _start, uint _end, uint _minimumFundingGoal) { + require(_multisigWallet != 0); + require(_start != 0 && _end != 0); + + // Don't mess the dates + require(_start < _end); + owner = msg.sender; token = FractionalERC20(_token); @@ -134,27 +140,10 @@ contract Crowdsale is Haltable { setPricingStrategy(_pricingStrategy); multisigWallet = _multisigWallet; - if(multisigWallet == 0) { - throw; - } - - if(_start == 0) { - throw; - } - startsAt = _start; - if(_end == 0) { - throw; - } - endsAt = _end; - // Don't mess the dates - if(startsAt >= endsAt) { - throw; - } - // Minimum funding goal can be zero minimumFundingGoal = _minimumFundingGoal; } @@ -163,7 +152,7 @@ contract Crowdsale is Haltable { * Don't expect to just send in money and get tokens. */ function() payable { - throw; + require(false); } /** @@ -181,15 +170,13 @@ contract Crowdsale is Haltable { // Determine if it's a good time to accept investment from this participant if(getState() == State.PreFunding) { // Are we whitelisted for early deposit - if(!earlyParticipantWhitelist[receiver]) { - throw; - } + require(earlyParticipantWhitelist[receiver]); } else if(getState() == State.Funding) { // Retail participants can only come in when the crowdsale is running // pass } else { // Unwanted state - throw; + assert(false); } uint weiAmount = msg.value; @@ -197,10 +184,7 @@ contract Crowdsale is Haltable { // Account presale sales separately, so that they do not count against pricing tranches uint tokenAmount = pricingStrategy.calculatePrice(weiAmount, weiRaised - presaleWeiRaised, tokensSold, msg.sender, token.decimals()); - if(tokenAmount == 0) { - // Dust transaction - throw; - } + require(tokenAmount != 0); // Dust transaction if(investedAmountOf[receiver] == 0) { // A new investor @@ -220,14 +204,12 @@ contract Crowdsale is Haltable { } // Check that we did not bust the cap - if(isBreakingCap(weiAmount, tokenAmount, weiRaised, tokensSold)) { - throw; - } + require(!isBreakingCap(weiAmount, tokenAmount, weiRaised, tokensSold)); assignTokens(receiver, tokenAmount); // Pocket the money - if(!multisigWallet.send(weiAmount)) throw; + require(multisigWallet.send(weiAmount)); // Tell us invest was success Invested(receiver, weiAmount, tokenAmount, customerId); @@ -270,8 +252,8 @@ contract Crowdsale is Haltable { */ function investWithSignedAddress(address addr, uint128 customerId, uint8 v, bytes32 r, bytes32 s) public payable { bytes32 hash = sha256(addr); - if (ecrecover(hash, v, r, s) != signerAddress) throw; - if(customerId == 0) throw; // UUIDv4 sanity check + require(ecrecover(hash, v, r, s) == signerAddress); + require(customerId != 0); // UUIDv4 sanity check investInternal(addr, customerId); } @@ -279,8 +261,8 @@ contract Crowdsale is Haltable { * Track who is the customer making the payment so we can send thank you email. */ function investWithCustomerId(address addr, uint128 customerId) public payable { - if(requiredSignedAddress) throw; // Crowdsale allows only server-side signed participants - if(customerId == 0) throw; // UUIDv4 sanity check + require(!requiredSignedAddress); // Crowdsale allows only server-side signed participants + require(customerId != 0); // UUIDv4 sanity check investInternal(addr, customerId); } @@ -288,8 +270,8 @@ contract Crowdsale is Haltable { * Allow anonymous contributions to this crowdsale. */ function invest(address addr) public payable { - if(requireCustomerId) throw; // Crowdsale needs to track partipants for thank you email - if(requiredSignedAddress) throw; // Crowdsale allows only server-side signed participants + require(!requireCustomerId); // Crowdsale needs to track partipants for thank you email + require(!requiredSignedAddress); // Crowdsale allows only server-side signed participants investInternal(addr, 0); } @@ -326,9 +308,7 @@ contract Crowdsale is Haltable { function finalize() public inState(State.Success) onlyOwner stopInEmergency { // Already finalized - if(finalized) { - throw; - } + require(!finalized); // Finalizing is optional. We only call it if we are given a finalizing agent. if(address(finalizeAgent) != 0) { @@ -344,12 +324,10 @@ contract Crowdsale is Haltable { * Design choice: no state restrictions on setting this, so that we can fix fat finger mistakes. */ function setFinalizeAgent(FinalizeAgent addr) onlyOwner { - finalizeAgent = addr; // Don't allow setting bad agent - if(!finalizeAgent.isFinalizeAgent()) { - throw; - } + require(addr.isFinalizeAgent()); + finalizeAgent = addr; } /** @@ -395,9 +373,7 @@ contract Crowdsale is Haltable { */ function setEndsAt(uint time) onlyOwner { - if(now > time) { - throw; // Don't change past - } + require(now <= time); // Don't change past endsAt = time; EndsAtChanged(endsAt); @@ -409,12 +385,10 @@ contract Crowdsale is Haltable { * Design choice: no state restrictions on the set, so that we can fix fat finger mistakes. */ function setPricingStrategy(PricingStrategy _pricingStrategy) onlyOwner { - pricingStrategy = _pricingStrategy; // Don't allow setting bad agent - if(!pricingStrategy.isPricingStrategy()) { - throw; - } + require(_pricingStrategy.isPricingStrategy()); + pricingStrategy = _pricingStrategy; } /** @@ -427,9 +401,7 @@ contract Crowdsale is Haltable { function setMultisig(address addr) public onlyOwner { // Change - if(investorCount > MAX_INVESTMENTS_BEFORE_MULTISIG_CHANGE) { - throw; - } + require(investorCount <= MAX_INVESTMENTS_BEFORE_MULTISIG_CHANGE); multisigWallet = addr; } @@ -440,7 +412,7 @@ contract Crowdsale is Haltable { * The team can transfer the funds back on the smart contract in the case the minimum goal was not reached.. */ function loadRefund() public payable inState(State.Failure) { - if(msg.value == 0) throw; + require(msg.value != 0); loadedRefund = loadedRefund.plus(msg.value); } @@ -452,11 +424,11 @@ contract Crowdsale is Haltable { */ function refund() public inState(State.Refunding) { uint256 weiValue = investedAmountOf[msg.sender]; - if (weiValue == 0) throw; + require(weiValue != 0); investedAmountOf[msg.sender] = 0; weiRefunded = weiRefunded.plus(weiValue); Refund(msg.sender, weiValue); - if (!msg.sender.send(weiValue)) throw; + require(msg.sender.send(weiValue)); } /** @@ -513,7 +485,7 @@ contract Crowdsale is Haltable { /** Modified allowing execution only if the crowdsale is currently running. */ modifier inState(State state) { - if(getState() != state) throw; + require(getState() == state); _; } diff --git a/contracts/DefaultFinalizeAgent.sol b/contracts/DefaultFinalizeAgent.sol index b5ea5588..c4880cc6 100644 --- a/contracts/DefaultFinalizeAgent.sol +++ b/contracts/DefaultFinalizeAgent.sol @@ -31,9 +31,7 @@ contract DefaultFinalizeAgent is FinalizeAgent { /** Called once by crowdsale finalize() if the sale was success. */ function finalizeCrowdsale() public { - if(msg.sender != address(crowdsale)) { - throw; - } + require(msg.sender == address(crowdsale)); token.releaseTokenTransfer(); } diff --git a/contracts/EthTranchePricing.sol b/contracts/EthTranchePricing.sol index 9de60246..5f92ab07 100644 --- a/contracts/EthTranchePricing.sol +++ b/contracts/EthTranchePricing.sol @@ -48,9 +48,7 @@ contract EthTranchePricing is PricingStrategy, Ownable { /// @param _tranches uint[] tranches Pairs of (start amount, price) function EthTranchePricing(uint[] _tranches) { // Need to have tuples, length check - if(_tranches.length % 2 == 1 || _tranches.length >= MAX_TRANCHES*2) { - throw; - } + require((_tranches.length % 2 == 0) && (_tranches.length < MAX_TRANCHES*2)); trancheCount = _tranches.length / 2; @@ -61,22 +59,16 @@ contract EthTranchePricing is PricingStrategy, Ownable { tranches[i].price = _tranches[i*2+1]; // No invalid steps - if((highestAmount != 0) && (tranches[i].amount <= highestAmount)) { - throw; - } + require((highestAmount == 0) || (tranches[i].amount > highestAmount)); highestAmount = tranches[i].amount; } // We need to start from zero, otherwise we blow up our deployment - if(tranches[0].amount != 0) { - throw; - } + require(tranches[0].amount == 0); // Last tranche price must be zero, terminating the crowdale - if(tranches[trancheCount-1].price != 0) { - throw; - } + require(tranches[trancheCount-1].price == 0); } /// @dev This is invoked once for every pre-ICO address, set pricePerToken @@ -162,7 +154,7 @@ contract EthTranchePricing is PricingStrategy, Ownable { } function() payable { - throw; // No money on this contract + require(false); // No money on this contract } } diff --git a/contracts/ExtraFinalizeAgent.sol b/contracts/ExtraFinalizeAgent.sol index 47fe5850..1e36f284 100644 --- a/contracts/ExtraFinalizeAgent.sol +++ b/contracts/ExtraFinalizeAgent.sol @@ -38,17 +38,12 @@ contract ExtraFinalizeAgent is FinalizeAgent { uint public accountedTokenSales; function ExtraFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig, uint _accountedTokenSales) { + require(address(_crowdsale) != 0 && address(_teamMultisig) != 0); + token = _token; crowdsale = _crowdsale; - if(address(crowdsale) == 0) { - throw; - } - teamMultisig = _teamMultisig; - if(address(teamMultisig) == 0) { - throw; - } accountedTokenSales = _accountedTokenSales; } @@ -60,9 +55,7 @@ contract ExtraFinalizeAgent is FinalizeAgent { /** Called once by crowdsale finalize() if the sale was success. */ function finalizeCrowdsale() { - if(msg.sender != address(crowdsale)) { - throw; - } + require(msg.sender == address(crowdsale)); // How many % of tokens the founders and others get uint tokensSold = crowdsale.tokensSold().minus(accountedTokenSales); diff --git a/contracts/Haltable.sol b/contracts/Haltable.sol index 63c2c001..8cb53fa3 100644 --- a/contracts/Haltable.sol +++ b/contracts/Haltable.sol @@ -21,17 +21,17 @@ contract Haltable is Ownable { bool public halted; modifier stopInEmergency { - if (halted) throw; + require(!halted); _; } modifier stopNonOwnersInEmergency { - if (halted && msg.sender != owner) throw; + require(!halted || msg.sender == owner); _; } modifier onlyInEmergency { - if (!halted) throw; + require(halted); _; } diff --git a/contracts/Issuer.sol b/contracts/Issuer.sol index c91a94d0..331c7b60 100644 --- a/contracts/Issuer.sol +++ b/contracts/Issuer.sol @@ -43,7 +43,7 @@ contract Issuer is Ownable { } function issue(address benefactor, uint amount) onlyOwner { - if(issued[benefactor]) throw; + require(!issued[benefactor]); token.transferFrom(allower, benefactor, amount); issued[benefactor] = true; issuedCount += amount; diff --git a/contracts/MilestonePricing.sol b/contracts/MilestonePricing.sol index f0c5ec21..630a31c2 100644 --- a/contracts/MilestonePricing.sol +++ b/contracts/MilestonePricing.sol @@ -46,9 +46,7 @@ contract MilestonePricing is PricingStrategy, Ownable { /// @param _milestones uint[] milestones Pairs of (time, price) function MilestonePricing(uint[] _milestones) { // Need to have tuples, length check - if(_milestones.length % 2 == 1 || _milestones.length >= MAX_MILESTONE*2) { - throw; - } + require((_milestones.length % 2 == 0) && (_milestones.length < MAX_MILESTONE*2)); milestoneCount = _milestones.length / 2; @@ -59,17 +57,13 @@ contract MilestonePricing is PricingStrategy, Ownable { milestones[i].price = _milestones[i*2+1]; // No invalid steps - if((lastTimestamp != 0) && (milestones[i].time <= lastTimestamp)) { - throw; - } + require((lastTimestamp == 0) || (milestones[i].time > lastTimestamp)); lastTimestamp = milestones[i].time; } // Last milestone price must be zero, terminating the crowdale - if(milestones[milestoneCount-1].price != 0) { - throw; - } + require(milestones[milestoneCount-1].price == 0); } /// @dev This is invoked once for every pre-ICO address, set pricePerToken @@ -143,7 +137,7 @@ contract MilestonePricing is PricingStrategy, Ownable { } function() payable { - throw; // No money on this contract + require(false); // No money on this contract } } diff --git a/contracts/MintableToken.sol b/contracts/MintableToken.sol index ca1f5b93..dddab407 100644 --- a/contracts/MintableToken.sol +++ b/contracts/MintableToken.sol @@ -53,15 +53,13 @@ contract MintableToken is StandardToken, Ownable { modifier onlyMintAgent() { // Only crowdsale contracts are allowed to mint new tokens - if(!mintAgents[msg.sender]) { - throw; - } + require(mintAgents[msg.sender]); _; } /** Make sure we are not done yet. */ modifier canMint() { - if(mintingFinished) throw; + require(!mintingFinished); _; } } diff --git a/contracts/PaymentForwarder.sol b/contracts/PaymentForwarder.sol index 743869a3..8849b428 100644 --- a/contracts/PaymentForwarder.sol +++ b/contracts/PaymentForwarder.sol @@ -68,7 +68,7 @@ contract PaymentForwarder is Haltable { paymentsByBenefactor[benefactor] += weiAmount; // May run out of gas - if(!teamMultisig.send(weiAmount)) throw; + require(teamMultisig.send(weiAmount)); } /** diff --git a/contracts/PreICOProxyBuyer.sol b/contracts/PreICOProxyBuyer.sol index 24bd56e1..69f2aca9 100644 --- a/contracts/PreICOProxyBuyer.sol +++ b/contracts/PreICOProxyBuyer.sol @@ -87,21 +87,10 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { */ function PreICOProxyBuyer(address _owner, uint _freezeEndsAt, uint _weiMinimumLimit, uint _weiMaximumLimit, uint _weiCap) { - owner = _owner; - - // Give argument - if(_freezeEndsAt == 0) { - throw; - } - // Give argument - if(_weiMinimumLimit == 0) { - throw; - } + require(_freezeEndsAt != 0 && _weiMinimumLimit != 0 && _weiMaximumLimit != 0); - if(_weiMaximumLimit == 0) { - throw; - } + owner = _owner; weiMinimumLimit = _weiMinimumLimit; weiMaximumLimit = _weiMaximumLimit; @@ -113,9 +102,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { * Get the token we are distributing. */ function getToken() public constant returns(FractionalERC20) { - if(address(crowdsale) == 0) { - throw; - } + require(address(crowdsale) != 0); return crowdsale.token(); } @@ -126,9 +113,9 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function invest(uint128 customerId) private { // Cannot invest anymore through crowdsale when moving has begun - if(getState() != State.Funding) throw; + require(getState() == State.Funding); - if(msg.value == 0) throw; // No empty buys + require(msg.value != 0); // No empty buys address investor = msg.sender; @@ -137,9 +124,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { balances[investor] = safeAdd(balances[investor], msg.value); // Need to satisfy minimum and maximum limits - if(balances[investor] < weiMinimumLimit || balances[investor] > weiMaximumLimit) { - throw; - } + require(balances[investor] >= weiMinimumLimit && balances[investor] <= weiMaximumLimit); // This is a new investor if(!existing) { @@ -148,9 +133,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { } weiRaised = safeAdd(weiRaised, msg.value); - if(weiRaised > weiCap) { - throw; - } + require(weiRaised <= weiCap); // We will use the same event form the Crowdsale for compatibility reasons // despite not having a token amount. @@ -173,13 +156,11 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { */ function buyForEverybody() stopNonOwnersInEmergency public { - if(getState() != State.Funding) { - // Only allow buy once - throw; - } + // Only allow buy once + require(getState() == State.Funding) ; // Crowdsale not yet set - if(address(crowdsale) == 0) throw; + require(address(crowdsale) != 0); // Buy tokens on the contract crowdsale.invest.value(weiRaised)(address(this)); @@ -187,10 +168,8 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { // Record how many tokens we got tokensBought = getToken().balanceOf(address(this)); - if(tokensBought == 0) { - // Did not get any tokens - throw; - } + // Did not get any tokens + require(tokensBought != 0); TokensBoughts(tokensBought); } @@ -201,9 +180,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function getClaimAmount(address investor) public constant returns (uint) { // Claims can be only made if we manage to buy tokens - if(getState() != State.Distributing) { - throw; - } + require(getState() == State.Distributing); return safeMul(balances[investor], tokensBought) / weiRaised; } @@ -228,14 +205,10 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function claim(uint amount) stopInEmergency { address investor = msg.sender; - if(amount == 0) { - throw; - } + require(amount != 0); - if(getClaimLeft(investor) < amount) { - // Woops we cannot get more than we have left - throw; - } + // Woops we cannot get more than we have left + require(getClaimLeft(investor) >= amount); // We track who many investor have (partially) claimed their tokens if(claimed[investor] == 0) { @@ -255,13 +228,13 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function refund() stopInEmergency { // Trying to ask refund too soon - if(getState() != State.Refunding) throw; + require(getState() == State.Refunding); address investor = msg.sender; - if(balances[investor] == 0) throw; + require(balances[investor] != 0); uint amount = balances[investor]; delete balances[investor]; - if(!(investor.call.value(amount)())) throw; + require(investor.call.value(amount)()); Refunded(investor, amount); } @@ -269,10 +242,10 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { * Set the target crowdsale where we will move presale funds when the crowdsale opens. */ function setCrowdsale(Crowdsale _crowdsale) public onlyOwner { - crowdsale = _crowdsale; - // Check interface - if(!crowdsale.isCrowdsale()) true; + require(_crowdsale.isCrowdsale()); + + crowdsale = _crowdsale; } /// @dev This is used in the first case scenario, this will force the state @@ -285,7 +258,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { /// we can't use Crowdsale's refund, since our default function does not /// accept money in. function loadRefund() public payable { - if(getState() != State.Refunding) throw; + require(getState() == State.Refunding); } /** @@ -313,6 +286,6 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { /** Explicitly call function from your wallet. */ function() payable { - throw; + require(false); } } diff --git a/contracts/PresaleFundCollector.sol b/contracts/PresaleFundCollector.sol index 645256ee..0b6e8e98 100644 --- a/contracts/PresaleFundCollector.sol +++ b/contracts/PresaleFundCollector.sol @@ -55,17 +55,10 @@ contract PresaleFundCollector is Ownable { */ function PresaleFundCollector(address _owner, uint _freezeEndsAt, uint _weiMinimumLimit) { - owner = _owner; - // Give argument - if(_freezeEndsAt == 0) { - throw; - } + require(_freezeEndsAt != 0 && _weiMinimumLimit != 0); - // Give argument - if(_weiMinimumLimit == 0) { - throw; - } + owner = _owner; weiMinimumLimit = _weiMinimumLimit; freezeEndsAt = _freezeEndsAt; @@ -77,7 +70,7 @@ contract PresaleFundCollector is Ownable { function invest() public payable { // Cannot invest anymore through crowdsale when moving has begun - if(moving) throw; + require(!moving); address investor = msg.sender; @@ -86,15 +79,13 @@ contract PresaleFundCollector is Ownable { balances[investor] = balances[investor].plus(msg.value); // Need to fulfill minimum limit - if(balances[investor] < weiMinimumLimit) { - throw; - } + require(balances[investor] >= weiMinimumLimit); // This is a new investor if(!existing) { // Limit number of investors to prevent too long loops - if(investorCount >= MAX_INVESTORS) throw; + require(investorCount < MAX_INVESTORS); investors.push(investor); investorCount++; @@ -109,7 +100,7 @@ contract PresaleFundCollector is Ownable { function parcipateCrowdsaleInvestor(address investor) public { // Crowdsale not yet set - if(address(crowdsale) == 0) throw; + require(address(crowdsale) != 0); moving = true; @@ -139,16 +130,16 @@ contract PresaleFundCollector is Ownable { function refund() { // Trying to ask refund too soon - if(now < freezeEndsAt) throw; + require(now >= freezeEndsAt); // We have started to move funds moving = true; address investor = msg.sender; - if(balances[investor] == 0) throw; + require(balances[investor] != 0); uint amount = balances[investor]; delete balances[investor]; - if(!investor.send(amount)) throw; + require(investor.send(amount)); Refunded(investor, amount); } @@ -161,6 +152,6 @@ contract PresaleFundCollector is Ownable { /** Explicitly call function from your wallet. */ function() payable { - throw; + require(false); } } diff --git a/contracts/RelaunchedCrowdsale.sol b/contracts/RelaunchedCrowdsale.sol index 22703a03..c52cc21d 100644 --- a/contracts/RelaunchedCrowdsale.sol +++ b/contracts/RelaunchedCrowdsale.sol @@ -59,16 +59,12 @@ contract RelaunchedCrowdsale is MintedTokenCappedCrowdsale { function setInvestorDataAndIssueNewToken(address _addr, uint _weiAmount, uint _tokenAmount, uint _originalTxHash) onlyOwner public { // This transaction has already been rebuild - if(reissuedTransactions[_originalTxHash]) { - throw; - } + require(!reissuedTransactions[_originalTxHash]); setInvestorData(_addr, _weiAmount, _tokenAmount, _originalTxHash); // Check that we did not bust the cap in the restoration process - if(isBreakingCap(_weiAmount, _tokenAmount, weiRaised, tokensSold)) { - throw; - } + require(!isBreakingCap(_weiAmount, _tokenAmount, weiRaised, tokensSold)); // Mark transaction processed reissuedTransactions[_originalTxHash] = true; diff --git a/contracts/ReleasableToken.sol b/contracts/ReleasableToken.sol index 18dfd302..b09b5624 100644 --- a/contracts/ReleasableToken.sol +++ b/contracts/ReleasableToken.sol @@ -29,13 +29,7 @@ contract ReleasableToken is ERC20, Ownable { * */ modifier canTransfer(address _sender) { - - if(!released) { - if(!transferAgents[_sender]) { - throw; - } - } - + require(released || transferAgents[_sender]); _; } @@ -68,17 +62,13 @@ contract ReleasableToken is ERC20, Ownable { /** The function can be called only before or after the tokens have been releasesd */ modifier inReleaseState(bool releaseState) { - if(releaseState != released) { - throw; - } + require(releaseState == released); _; } /** The function can be called only by a whitelisted release agent. */ modifier onlyReleaseAgent() { - if(msg.sender != releaseAgent) { - throw; - } + require(msg.sender == releaseAgent); _; } diff --git a/contracts/StandardToken.sol b/contracts/StandardToken.sol index 6c8e4d7e..17deef51 100644 --- a/contracts/StandardToken.sol +++ b/contracts/StandardToken.sol @@ -60,7 +60,7 @@ contract StandardToken is ERC20, SafeMath { // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // 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; Approval(msg.sender, _spender, _value); diff --git a/contracts/TimeVault.sol b/contracts/TimeVault.sol index 81c7bbb6..fc6c52bc 100644 --- a/contracts/TimeVault.sol +++ b/contracts/TimeVault.sol @@ -34,14 +34,12 @@ contract TimeVault is SafeMath { event Unlocked(); function TimeVault(address _teamMultisig, StandardToken _token, uint _unlockedAt) { + // Sanity check + require(_teamMultisig != 0x0 && address(_token) != 0x0); teamMultisig = _teamMultisig; token = _token; unlockedAt = _unlockedAt; - - // Sanity check - if (teamMultisig == 0x0) throw; - if (address(token) == 0x0) throw; } function getTokenBalance() public constant returns (uint) { @@ -50,7 +48,7 @@ contract TimeVault is SafeMath { function unlock() public { // Wait your turn! - if (now < unlockedAt) throw; + require(now >= unlockedAt); // StandardToken will throw in the case of transaction fails token.transfer(teamMultisig, getTokenBalance()); @@ -59,6 +57,6 @@ contract TimeVault is SafeMath { } // disallow ETH payment for this vault - function () { throw; } + function () { require(false); } } diff --git a/contracts/TokenTranchePricing.sol b/contracts/TokenTranchePricing.sol index a6464b5f..c79df17a 100644 --- a/contracts/TokenTranchePricing.sol +++ b/contracts/TokenTranchePricing.sol @@ -48,9 +48,7 @@ contract TokenTranchePricing is PricingStrategy, Ownable { /// @param _tranches uint[] tranches Pairs of (start amount, price) function TokenTranchePricing(uint[] _tranches) { // Need to have tuples, length check - if(_tranches.length % 2 == 1 || _tranches.length >= MAX_TRANCHES*2) { - throw; - } + require((_tranches.length % 2 == 0) && (_tranches.length < MAX_TRANCHES*2)); trancheCount = _tranches.length / 2; @@ -61,17 +59,13 @@ contract TokenTranchePricing is PricingStrategy, Ownable { tranches[i].price = _tranches[i*2+1]; // No invalid steps - if((highestAmount != 0) && (tranches[i].amount <= highestAmount)) { - throw; - } + require((highestAmount == 0) || (tranches[i].amount > highestAmount)); highestAmount = tranches[i].amount; } // Last tranche price must be zero, terminating the crowdale - if(tranches[trancheCount-1].price != 0) { - throw; - } + require(tranches[trancheCount-1].price == 0); } /// @dev This is invoked once for every pre-ICO address, set pricePerToken @@ -150,7 +144,7 @@ contract TokenTranchePricing is PricingStrategy, Ownable { } function() payable { - throw; // No money on this contract + require(false); // No money on this contract } } diff --git a/contracts/TokenVault.sol b/contracts/TokenVault.sol index f3cb5e0f..22f2019a 100644 --- a/contracts/TokenVault.sol +++ b/contracts/TokenVault.sol @@ -81,29 +81,22 @@ contract TokenVault is Ownable { */ function TokenVault(address _owner, uint _freezeEndsAt, StandardToken _token, uint _tokensToBeAllocated) { - owner = _owner; // Invalid owenr - if(owner == 0) { - throw; - } - - token = _token; + require(_owner != 0); // Check the address looks like a token contract - if(!token.isToken()) { - throw; - } + require(_token.isToken()); // Give argument - if(_freezeEndsAt == 0) { - throw; - } + require(_freezeEndsAt != 0); // Sanity check on _tokensToBeAllocated - if(_tokensToBeAllocated == 0) { - throw; - } + require(_tokensToBeAllocated != 0); + + owner = _owner; + + token = _token; freezeEndsAt = _freezeEndsAt; tokensToBeAllocated = _tokensToBeAllocated; @@ -112,17 +105,13 @@ contract TokenVault is Ownable { /// @dev Add a presale participating allocation function setInvestor(address investor, uint amount) public onlyOwner { - if(lockedAt > 0) { - // Cannot add new investors after the vault is locked - throw; - } + // Cannot add new investors after the vault is locked + require(lockedAt == 0); - if(amount == 0) throw; // No empty buys + require(amount != 0); // No empty buys // Don't allow reset - if(balances[investor] > 0) { - throw; - } + require(balances[investor] == 0); balances[investor] = amount; @@ -139,19 +128,13 @@ contract TokenVault is Ownable { /// - Checks are in place to prevent creating a vault that is locked with incorrect token balances. function lock() onlyOwner { - if(lockedAt > 0) { - throw; // Already locked - } + require(lockedAt == 0); // Already locked // Spreadsheet sum does not match to what we have loaded to the investor data - if(tokensAllocatedTotal != tokensToBeAllocated) { - throw; - } + require(tokensAllocatedTotal == tokensToBeAllocated); // Do not lock the vault if the given tokens are not on this contract - if(token.balanceOf(address(this)) != tokensAllocatedTotal) { - throw; - } + require(token.balanceOf(address(this)) == tokensAllocatedTotal); lockedAt = now; @@ -160,9 +143,7 @@ contract TokenVault is Ownable { /// @dev In the case locking failed, then allow the owner to reclaim the tokens on the contract. function recoverFailedLock() onlyOwner { - if(lockedAt > 0) { - throw; - } + require(lockedAt == 0); // Transfer all tokens on this contract back to the owner token.transfer(owner, token.balanceOf(address(this))); @@ -179,22 +160,13 @@ contract TokenVault is Ownable { address investor = msg.sender; - if(lockedAt == 0) { - throw; // We were never locked - } + require(lockedAt > 0); // We were never locked - if(now < freezeEndsAt) { - throw; // Trying to claim early - } + require(now >= freezeEndsAt); // Trying to claim early - if(balances[investor] == 0) { - // Not our investor - throw; - } + require(balances[investor] != 0); // Not our investor - if(claimed[investor] > 0) { - throw; // Already claimed - } + require(claimed[investor] == 0); // Already claimed uint amount = balances[investor]; diff --git a/contracts/UpgradeableToken.sol b/contracts/UpgradeableToken.sol index 4fd3429c..e34d4120 100644 --- a/contracts/UpgradeableToken.sol +++ b/contracts/UpgradeableToken.sol @@ -60,13 +60,10 @@ contract UpgradeableToken is StandardToken { function upgrade(uint256 value) public { UpgradeState state = getUpgradeState(); - if(!(state == UpgradeState.ReadyToUpgrade || state == UpgradeState.Upgrading)) { - // Called in a bad state - throw; - } + require(state == UpgradeState.ReadyToUpgrade || state == UpgradeState.Upgrading); // Called in a bad state // Validate input value. - if (value == 0) throw; + require(value != 0); balances[msg.sender] = safeSub(balances[msg.sender], value); @@ -84,23 +81,21 @@ contract UpgradeableToken is StandardToken { */ function setUpgradeAgent(address agent) external { - if(!canUpgrade()) { - // The token is not yet in a state that we could think upgrading - throw; - } + // The token is not yet in a state that we could think upgrading + require(canUpgrade()); - if (agent == 0x0) throw; + require(agent != 0x0); // Only a master can designate the next agent - if (msg.sender != upgradeMaster) throw; + require(msg.sender == upgradeMaster); // Upgrade has already begun for an agent - if (getUpgradeState() == UpgradeState.Upgrading) throw; + require(getUpgradeState() != UpgradeState.Upgrading); upgradeAgent = UpgradeAgent(agent); // Bad interface - if(!upgradeAgent.isUpgradeAgent()) throw; + require(upgradeAgent.isUpgradeAgent()); // Make sure that token supplies match in source and target - if (upgradeAgent.originalSupply() != totalSupply) throw; + require(upgradeAgent.originalSupply() == totalSupply); UpgradeAgentSet(upgradeAgent); } @@ -121,8 +116,7 @@ contract UpgradeableToken is StandardToken { * This allows us to set a new owner for the upgrade mechanism. */ function setUpgradeMaster(address master) public { - if (master == 0x0) throw; - if (msg.sender != upgradeMaster) throw; + require(master != 0x0 && msg.sender == upgradeMaster); upgradeMaster = master; } diff --git a/contracts/test/TestMigrationTarget.sol b/contracts/test/TestMigrationTarget.sol index aacf7416..cdaebdb7 100644 --- a/contracts/test/TestMigrationTarget.sol +++ b/contracts/test/TestMigrationTarget.sol @@ -22,19 +22,15 @@ contract TestMigrationTarget is StandardToken, UpgradeAgent { oldToken = _oldToken; // Let's not set bad old token - if(address(oldToken) == 0) { - throw; - } + require(address(oldToken) != 0); // Let's make sure we have something to migrate originalSupply = _oldToken.totalSupply(); - if(originalSupply == 0) { - throw; - } + require(originalSupply != 0); } function upgradeFrom(address _from, uint256 _value) public { - if (msg.sender != address(oldToken)) throw; // only upgrade from oldToken + require(msg.sender == address(oldToken)); // only upgrade from oldToken // Mint new tokens to the migrator totalSupply = totalSupply.plus(_value); @@ -43,7 +39,7 @@ contract TestMigrationTarget is StandardToken, UpgradeAgent { } function() public payable { - throw; + require(false); } } From af7f0f2770b632bf0c0af581b63fa0b62a2cdb54 Mon Sep 17 00:00:00 2001 From: Tim Loh Date: Sat, 16 Sep 2017 02:15:13 +0800 Subject: [PATCH 2/4] Eliminate throw from CrowdsaleToken.sol. --- contracts/CrowdsaleToken.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/CrowdsaleToken.sol b/contracts/CrowdsaleToken.sol index a13c0c64..29ab3ee7 100644 --- a/contracts/CrowdsaleToken.sol +++ b/contracts/CrowdsaleToken.sol @@ -48,6 +48,9 @@ contract CrowdsaleToken is ReleasableToken, MintableToken, UpgradeableToken { function CrowdsaleToken(string _name, string _symbol, uint _initialSupply, uint _decimals, bool _mintable) UpgradeableToken(msg.sender) { + // Cannot create a token without supply and no minting + require(_mintable || _initialSupply != 0); + // Create any address, can be transferred // to team multisig via changeOwner(), // also remember to call setUpgradeMaster() @@ -70,9 +73,6 @@ contract CrowdsaleToken is ReleasableToken, MintableToken, UpgradeableToken { // No more new supply allowed after the token creation if(!_mintable) { mintingFinished = true; - if(totalSupply == 0) { - throw; // Cannot create a token without supply and no minting - } } } From a6e94f189f05d20c0ef7ec09c812677bb2c3c2c6 Mon Sep 17 00:00:00 2001 From: Tim Loh Date: Sat, 16 Sep 2017 02:50:28 +0800 Subject: [PATCH 3/4] Eliminate throw from GnosisWallet.sol. --- contracts/GnosisWallet.sol | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/contracts/GnosisWallet.sol b/contracts/GnosisWallet.sol index 647de7fc..daf5cfc0 100644 --- a/contracts/GnosisWallet.sol +++ b/contracts/GnosisWallet.sol @@ -36,59 +36,50 @@ contract MultiSigWallet { } modifier onlyWallet() { - if (msg.sender != address(this)) - throw; + require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { - if (isOwner[owner]) - throw; + require(!isOwner[owner]); _; } modifier ownerExists(address owner) { - if (!isOwner[owner]) - throw; + require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { - if (transactions[transactionId].destination == 0) - throw; + require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { - if (!confirmations[transactionId][owner]) - throw; + require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { - if (confirmations[transactionId][owner]) - throw; + require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { - if (transactions[transactionId].executed) - throw; + require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { - if (_address == 0) - throw; + require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { - if ( ownerCount > MAX_OWNER_COUNT - || _required > ownerCount - || _required == 0 - || ownerCount == 0) - throw; + require(ownerCount <= MAX_OWNER_COUNT + && _required <= ownerCount + && _required != 0 + && ownerCount != 0); _; } @@ -111,8 +102,7 @@ contract MultiSigWallet { validRequirement(_owners.length, _required) { for (uint i=0; i<_owners.length; i++) { - if (isOwner[_owners[i]] || _owners[i] == 0) - throw; + require(!isOwner[_owners[i]] && _owners[i] != 0); isOwner[_owners[i]] = true; } owners = _owners; From 6e5a19ca9d99656a7eada270a7a5bcc2825b84d6 Mon Sep 17 00:00:00 2001 From: Tim Loh Date: Mon, 16 Oct 2017 01:20:45 +0800 Subject: [PATCH 4/4] Changes as requested by @villesundell. --- contracts/BonusFinalizeAgent.sol | 3 ++- contracts/Crowdsale.sol | 9 ++++----- contracts/EthTranchePricing.sol | 6 +++--- contracts/ExtraFinalizeAgent.sol | 3 ++- contracts/MilestonePricing.sol | 6 +++--- contracts/PaymentForwarder.sol | 2 +- contracts/PreICOProxyBuyer.sol | 11 ++++++----- contracts/PresaleFundCollector.sol | 8 ++++---- contracts/TimeVault.sol | 6 ++++-- contracts/TokenTranchePricing.sol | 6 +++--- contracts/UpgradeableToken.sol | 3 ++- contracts/test/TestMigrationTarget.sol | 3 +-- 12 files changed, 35 insertions(+), 31 deletions(-) diff --git a/contracts/BonusFinalizeAgent.sol b/contracts/BonusFinalizeAgent.sol index 7300f3ee..fb8dcdaa 100644 --- a/contracts/BonusFinalizeAgent.sol +++ b/contracts/BonusFinalizeAgent.sol @@ -35,7 +35,8 @@ contract BonusFinalizeAgent is FinalizeAgent { uint public allocatedBonus; function BonusFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig) { - require(address(_crowdsale) != 0 && address(_teamMultisig) != 0); + require(address(_crowdsale) != 0); + require(address(_teamMultisig) != 0); token = _token; crowdsale = _crowdsale; teamMultisig = _teamMultisig; diff --git a/contracts/Crowdsale.sol b/contracts/Crowdsale.sol index bdb97672..beba784c 100644 --- a/contracts/Crowdsale.sol +++ b/contracts/Crowdsale.sol @@ -151,8 +151,7 @@ contract Crowdsale is Haltable { /** * Don't expect to just send in money and get tokens. */ - function() payable { - require(false); + function() { } /** @@ -176,7 +175,7 @@ contract Crowdsale is Haltable { // pass } else { // Unwanted state - assert(false); + revert(); } uint weiAmount = msg.value; @@ -209,7 +208,7 @@ contract Crowdsale is Haltable { assignTokens(receiver, tokenAmount); // Pocket the money - require(multisigWallet.send(weiAmount)); + multisigWallet.transfer(weiAmount); // Tell us invest was success Invested(receiver, weiAmount, tokenAmount, customerId); @@ -428,7 +427,7 @@ contract Crowdsale is Haltable { investedAmountOf[msg.sender] = 0; weiRefunded = weiRefunded.plus(weiValue); Refund(msg.sender, weiValue); - require(msg.sender.send(weiValue)); + msg.sender.transfer(weiValue); } /** diff --git a/contracts/EthTranchePricing.sol b/contracts/EthTranchePricing.sol index 5f92ab07..14ea6bc4 100644 --- a/contracts/EthTranchePricing.sol +++ b/contracts/EthTranchePricing.sol @@ -48,7 +48,7 @@ contract EthTranchePricing is PricingStrategy, Ownable { /// @param _tranches uint[] tranches Pairs of (start amount, price) function EthTranchePricing(uint[] _tranches) { // Need to have tuples, length check - require((_tranches.length % 2 == 0) && (_tranches.length < MAX_TRANCHES*2)); + require((_tranches.length % 2 == 0) && (_tranches.length <= MAX_TRANCHES*2)); trancheCount = _tranches.length / 2; @@ -153,8 +153,8 @@ contract EthTranchePricing is PricingStrategy, Ownable { return value.times(multiplier) / price; } - function() payable { - require(false); // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/ExtraFinalizeAgent.sol b/contracts/ExtraFinalizeAgent.sol index 1e36f284..d3e58a8f 100644 --- a/contracts/ExtraFinalizeAgent.sol +++ b/contracts/ExtraFinalizeAgent.sol @@ -38,7 +38,8 @@ contract ExtraFinalizeAgent is FinalizeAgent { uint public accountedTokenSales; function ExtraFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig, uint _accountedTokenSales) { - require(address(_crowdsale) != 0 && address(_teamMultisig) != 0); + require(address(_crowdsale) != 0); + require(address(_teamMultisig) != 0); token = _token; crowdsale = _crowdsale; diff --git a/contracts/MilestonePricing.sol b/contracts/MilestonePricing.sol index 630a31c2..f8e65bc7 100644 --- a/contracts/MilestonePricing.sol +++ b/contracts/MilestonePricing.sol @@ -46,7 +46,7 @@ contract MilestonePricing is PricingStrategy, Ownable { /// @param _milestones uint[] milestones Pairs of (time, price) function MilestonePricing(uint[] _milestones) { // Need to have tuples, length check - require((_milestones.length % 2 == 0) && (_milestones.length < MAX_MILESTONE*2)); + require((_milestones.length % 2 == 0) && (_milestones.length <= MAX_MILESTONE*2)); milestoneCount = _milestones.length / 2; @@ -136,8 +136,8 @@ contract MilestonePricing is PricingStrategy, Ownable { return value.times(multiplier) / price; } - function() payable { - require(false); // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/PaymentForwarder.sol b/contracts/PaymentForwarder.sol index 8849b428..2e0cbfe9 100644 --- a/contracts/PaymentForwarder.sol +++ b/contracts/PaymentForwarder.sol @@ -68,7 +68,7 @@ contract PaymentForwarder is Haltable { paymentsByBenefactor[benefactor] += weiAmount; // May run out of gas - require(teamMultisig.send(weiAmount)); + teamMultisig.transfer(weiAmount); } /** diff --git a/contracts/PreICOProxyBuyer.sol b/contracts/PreICOProxyBuyer.sol index 69f2aca9..ca59f1f4 100644 --- a/contracts/PreICOProxyBuyer.sol +++ b/contracts/PreICOProxyBuyer.sol @@ -88,7 +88,9 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function PreICOProxyBuyer(address _owner, uint _freezeEndsAt, uint _weiMinimumLimit, uint _weiMaximumLimit, uint _weiCap) { // Give argument - require(_freezeEndsAt != 0 && _weiMinimumLimit != 0 && _weiMaximumLimit != 0); + require(_freezeEndsAt != 0); + require(_weiMinimumLimit != 0); + require(_weiMaximumLimit != 0); owner = _owner; @@ -157,7 +159,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { function buyForEverybody() stopNonOwnersInEmergency public { // Only allow buy once - require(getState() == State.Funding) ; + require(getState() == State.Funding); // Crowdsale not yet set require(address(crowdsale) != 0); @@ -234,7 +236,7 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { require(balances[investor] != 0); uint amount = balances[investor]; delete balances[investor]; - require(investor.call.value(amount)()); + investor.transfer(amount); Refunded(investor, amount); } @@ -285,7 +287,6 @@ contract PreICOProxyBuyer is Ownable, Haltable, SafeMath { } /** Explicitly call function from your wallet. */ - function() payable { - require(false); + function() { } } diff --git a/contracts/PresaleFundCollector.sol b/contracts/PresaleFundCollector.sol index be57f161..e180e734 100644 --- a/contracts/PresaleFundCollector.sol +++ b/contracts/PresaleFundCollector.sol @@ -56,7 +56,8 @@ contract PresaleFundCollector is Ownable { function PresaleFundCollector(address _owner, uint _freezeEndsAt, uint _weiMinimumLimit) { // Give argument - require(_freezeEndsAt != 0 && _weiMinimumLimit != 0); + require(_freezeEndsAt != 0); + require(_weiMinimumLimit != 0); owner = _owner; @@ -139,7 +140,7 @@ contract PresaleFundCollector is Ownable { require(balances[investor] != 0); uint amount = balances[investor]; delete balances[investor]; - require(investor.send(amount)); + investor.transfer(amount); Refunded(investor, amount); } @@ -151,7 +152,6 @@ contract PresaleFundCollector is Ownable { } /** Explicitly call function from your wallet. */ - function() payable { - require(false); + function() { } } diff --git a/contracts/TimeVault.sol b/contracts/TimeVault.sol index fc6c52bc..7d005d16 100644 --- a/contracts/TimeVault.sol +++ b/contracts/TimeVault.sol @@ -35,7 +35,8 @@ contract TimeVault is SafeMath { function TimeVault(address _teamMultisig, StandardToken _token, uint _unlockedAt) { // Sanity check - require(_teamMultisig != 0x0 && address(_token) != 0x0); + require(_teamMultisig != 0x0); + require(address(_token) != 0x0); teamMultisig = _teamMultisig; token = _token; @@ -57,6 +58,7 @@ contract TimeVault is SafeMath { } // disallow ETH payment for this vault - function () { require(false); } + function () { + } } diff --git a/contracts/TokenTranchePricing.sol b/contracts/TokenTranchePricing.sol index c79df17a..9b545029 100644 --- a/contracts/TokenTranchePricing.sol +++ b/contracts/TokenTranchePricing.sol @@ -48,7 +48,7 @@ contract TokenTranchePricing is PricingStrategy, Ownable { /// @param _tranches uint[] tranches Pairs of (start amount, price) function TokenTranchePricing(uint[] _tranches) { // Need to have tuples, length check - require((_tranches.length % 2 == 0) && (_tranches.length < MAX_TRANCHES*2)); + require((_tranches.length % 2 == 0) && (_tranches.length <= MAX_TRANCHES*2)); trancheCount = _tranches.length / 2; @@ -143,8 +143,8 @@ contract TokenTranchePricing is PricingStrategy, Ownable { return value.times(multiplier) / price; } - function() payable { - require(false); // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/UpgradeableToken.sol b/contracts/UpgradeableToken.sol index e34d4120..c4fdbef1 100644 --- a/contracts/UpgradeableToken.sol +++ b/contracts/UpgradeableToken.sol @@ -116,7 +116,8 @@ contract UpgradeableToken is StandardToken { * This allows us to set a new owner for the upgrade mechanism. */ function setUpgradeMaster(address master) public { - require(master != 0x0 && msg.sender == upgradeMaster); + require(master != 0x0); + require(msg.sender == upgradeMaster); upgradeMaster = master; } diff --git a/contracts/test/TestMigrationTarget.sol b/contracts/test/TestMigrationTarget.sol index cdaebdb7..4401b718 100644 --- a/contracts/test/TestMigrationTarget.sol +++ b/contracts/test/TestMigrationTarget.sol @@ -38,8 +38,7 @@ contract TestMigrationTarget is StandardToken, UpgradeAgent { Transfer(0, _from, _value); } - function() public payable { - require(false); + function() public { } }