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..fb8dcdaa 100644 --- a/contracts/BonusFinalizeAgent.sol +++ b/contracts/BonusFinalizeAgent.sol @@ -35,17 +35,11 @@ contract BonusFinalizeAgent is FinalizeAgent { uint public allocatedBonus; function BonusFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig) { + require(address(_crowdsale) != 0); + require(address(_teamMultisig) != 0); token = _token; crowdsale = _crowdsale; - if(address(crowdsale) == 0) { - throw; - } - teamMultisig = _teamMultisig; - if(address(teamMultisig) == 0) { - throw; - } - bonusBasePoints = _bonusBasePoints; } @@ -56,9 +50,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 8a42bf5d..3a5da440 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; } @@ -162,8 +151,7 @@ contract Crowdsale is Haltable { /** * Don't expect to just send in money and get tokens. */ - function() payable { - throw; + function() { } /** @@ -181,15 +169,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; + revert(); } uint weiAmount = msg.value; @@ -197,10 +183,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 +203,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; + multisigWallet.transfer(weiAmount); // Tell us invest was success Invested(receiver, weiAmount, tokenAmount, customerId); @@ -270,8 +251,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 +260,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 +269,8 @@ contract Crowdsale is Haltable { * Allow anonymous contributions to this crowdsale. */ function invest(address addr) public payable { - if(requireCustomerId) throw; // Crowdsale needs to track participants 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 +307,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 +323,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,13 +372,8 @@ contract Crowdsale is Haltable { */ function setEndsAt(uint time) onlyOwner { - if(now > time) { - throw; // Don't change past - } - - if(startsAt > time) { - throw; // Prevent human mistakes - } + require(now <= time); // Don't change past + require(time > startsAt); // Don't allow to end before we start endsAt = time; EndsAtChanged(endsAt); @@ -413,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; } /** @@ -431,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; } @@ -444,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); } @@ -456,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; + msg.sender.transfer(weiValue); } /** @@ -517,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/CrowdsaleToken.sol b/contracts/CrowdsaleToken.sol index e370bbbc..a856e72a 100644 --- a/contracts/CrowdsaleToken.sol +++ b/contracts/CrowdsaleToken.sol @@ -47,6 +47,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() @@ -69,9 +72,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 - } } } 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..14ea6bc4 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 @@ -161,8 +153,8 @@ contract EthTranchePricing is PricingStrategy, Ownable { return value.times(multiplier) / price; } - function() payable { - throw; // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/ExtraFinalizeAgent.sol b/contracts/ExtraFinalizeAgent.sol index 47fe5850..d3e58a8f 100644 --- a/contracts/ExtraFinalizeAgent.sol +++ b/contracts/ExtraFinalizeAgent.sol @@ -38,17 +38,13 @@ contract ExtraFinalizeAgent is FinalizeAgent { uint public accountedTokenSales; function ExtraFinalizeAgent(CrowdsaleToken _token, Crowdsale _crowdsale, uint _bonusBasePoints, address _teamMultisig, uint _accountedTokenSales) { + require(address(_crowdsale) != 0); + require(address(_teamMultisig) != 0); + token = _token; crowdsale = _crowdsale; - if(address(crowdsale) == 0) { - throw; - } - teamMultisig = _teamMultisig; - if(address(teamMultisig) == 0) { - throw; - } accountedTokenSales = _accountedTokenSales; } @@ -60,9 +56,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/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; 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 7962ae0e..95569a3d 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 3d8291a0..0a37fcc7 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 @@ -149,8 +143,8 @@ contract MilestonePricing is PricingStrategy, Ownable { return false; } - function() payable { - throw; // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/MintableToken.sol b/contracts/MintableToken.sol index d2e8d4e5..d3a57056 100644 --- a/contracts/MintableToken.sol +++ b/contracts/MintableToken.sol @@ -54,15 +54,13 @@ contract MintableToken is StandardTokenExt, 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..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 - if(!teamMultisig.send(weiAmount)) throw; + teamMultisig.transfer(weiAmount); } /** diff --git a/contracts/PreICOProxyBuyer.sol b/contracts/PreICOProxyBuyer.sol index 7004b412..e65f630e 100644 --- a/contracts/PreICOProxyBuyer.sol +++ b/contracts/PreICOProxyBuyer.sol @@ -87,21 +87,12 @@ contract PreICOProxyBuyer is Ownable, Haltable { */ 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); + require(_weiMinimumLimit != 0); + require(_weiMaximumLimit != 0); - if(_weiMaximumLimit == 0) { - throw; - } + owner = _owner; weiMinimumLimit = _weiMinimumLimit; weiMaximumLimit = _weiMaximumLimit; @@ -113,9 +104,7 @@ contract PreICOProxyBuyer is Ownable, Haltable { * 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 +115,9 @@ contract PreICOProxyBuyer is Ownable, Haltable { 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 +126,7 @@ contract PreICOProxyBuyer is Ownable, Haltable { balances[investor] = balances[investor].add(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 +135,7 @@ contract PreICOProxyBuyer is Ownable, Haltable { } weiRaised = weiRaised.add(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 +158,11 @@ contract PreICOProxyBuyer is Ownable, Haltable { */ 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 +170,8 @@ contract PreICOProxyBuyer is Ownable, Haltable { // 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 +182,7 @@ contract PreICOProxyBuyer is Ownable, Haltable { 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 balances[investor].mul(tokensBought) / weiRaised; } @@ -228,14 +207,10 @@ contract PreICOProxyBuyer is Ownable, Haltable { 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 +230,13 @@ contract PreICOProxyBuyer is Ownable, Haltable { 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; + investor.transfer(amount); Refunded(investor, amount); } @@ -269,10 +244,10 @@ contract PreICOProxyBuyer is Ownable, Haltable { * 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 +260,7 @@ contract PreICOProxyBuyer is Ownable, Haltable { /// 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); } /** @@ -312,7 +287,6 @@ contract PreICOProxyBuyer is Ownable, Haltable { } /** Explicitly call function from your wallet. */ - function() payable { - throw; + function() { } } diff --git a/contracts/PresaleFundCollector.sol b/contracts/PresaleFundCollector.sol index 42ebd73c..e180e734 100644 --- a/contracts/PresaleFundCollector.sol +++ b/contracts/PresaleFundCollector.sol @@ -55,17 +55,11 @@ contract PresaleFundCollector is Ownable { */ function PresaleFundCollector(address _owner, uint _freezeEndsAt, uint _weiMinimumLimit) { - owner = _owner; - // Give argument - if(_freezeEndsAt == 0) { - throw; - } + require(_freezeEndsAt != 0); + require(_weiMinimumLimit != 0); - // Give argument - if(_weiMinimumLimit == 0) { - throw; - } + owner = _owner; weiMinimumLimit = _weiMinimumLimit; freezeEndsAt = _freezeEndsAt; @@ -77,7 +71,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 +80,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 +101,7 @@ contract PresaleFundCollector is Ownable { function participateCrowdsaleInvestor(address investor) public { // Crowdsale not yet set - if(address(crowdsale) == 0) throw; + require(address(crowdsale) != 0); moving = true; @@ -139,16 +131,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; + investor.transfer(amount); Refunded(investor, amount); } @@ -160,7 +152,6 @@ contract PresaleFundCollector is Ownable { } /** Explicitly call function from your wallet. */ - function() payable { - throw; + function() { } } 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/TimeVault.sol b/contracts/TimeVault.sol index aa29b8ee..ea50b8cf 100644 --- a/contracts/TimeVault.sol +++ b/contracts/TimeVault.sol @@ -34,14 +34,13 @@ contract TimeVault { event Unlocked(); function TimeVault(address _teamMultisig, StandardTokenExt _token, uint _unlockedAt) { + // Sanity check + require(_teamMultisig != 0x0); + require(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 +49,7 @@ contract TimeVault { 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 +58,7 @@ contract TimeVault { } // disallow ETH payment for this vault - function () { throw; } + function () { + } } diff --git a/contracts/TokenTranchePricing.sol b/contracts/TokenTranchePricing.sol index a6464b5f..9b545029 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 @@ -149,8 +143,8 @@ contract TokenTranchePricing is PricingStrategy, Ownable { return value.times(multiplier) / price; } - function() payable { - throw; // No money on this contract + function() { + // No money on this contract } } diff --git a/contracts/TokenVault.sol b/contracts/TokenVault.sol index 455eb068..337e96ad 100644 --- a/contracts/TokenVault.sol +++ b/contracts/TokenVault.sol @@ -81,29 +81,22 @@ contract TokenVault is Ownable { */ function TokenVault(address _owner, uint _freezeEndsAt, CrowdsaleToken _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 fe12033a..8033299c 100644 --- a/contracts/UpgradeableToken.sol +++ b/contracts/UpgradeableToken.sol @@ -60,13 +60,10 @@ contract UpgradeableToken is StandardTokenExt { 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] = balances[msg.sender].sub(value); @@ -84,23 +81,21 @@ contract UpgradeableToken is StandardTokenExt { */ 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,8 @@ contract UpgradeableToken is StandardTokenExt { * 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); + require(msg.sender == upgradeMaster); upgradeMaster = master; } diff --git a/contracts/test/TestMigrationTarget.sol b/contracts/test/TestMigrationTarget.sol index 82ee0f41..74564ea2 100644 --- a/contracts/test/TestMigrationTarget.sol +++ b/contracts/test/TestMigrationTarget.sol @@ -22,19 +22,15 @@ contract TestMigrationTarget is StandardTokenExt, 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); @@ -42,8 +38,7 @@ contract TestMigrationTarget is StandardTokenExt, UpgradeAgent { Transfer(0, _from, _value); } - function() public payable { - throw; + function() public { } } diff --git a/zeppelin b/zeppelin index 287b873a..1df75a95 160000 --- a/zeppelin +++ b/zeppelin @@ -1 +1 @@ -Subproject commit 287b873add003494828c143f74f631224aa219f4 +Subproject commit 1df75a951f37a176303df5cc60b689001948d7cc