From 6fe9b340b46c42b117bfd6450b8ac2c00474efca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Mon, 8 Oct 2018 12:45:58 -0300 Subject: [PATCH] Added assertions to leaf initializers of (some) pseudo-abstract contracts. --- contracts/crowdsale/distribution/RefundableCrowdsale.sol | 5 +++++ contracts/crowdsale/emission/AllowanceCrowdsale.sol | 5 +++++ contracts/crowdsale/price/IncreasingPriceCrowdsale.sol | 4 ++++ contracts/crowdsale/validation/CappedCrowdsale.sol | 5 +++++ .../crowdsale/validation/IndividuallyCappedCrowdsale.sol | 5 +++++ contracts/crowdsale/validation/TimedCrowdsale.sol | 5 +++++ 6 files changed, 29 insertions(+) diff --git a/contracts/crowdsale/distribution/RefundableCrowdsale.sol b/contracts/crowdsale/distribution/RefundableCrowdsale.sol index c55252347..c988f6061 100644 --- a/contracts/crowdsale/distribution/RefundableCrowdsale.sol +++ b/contracts/crowdsale/distribution/RefundableCrowdsale.sol @@ -26,6 +26,11 @@ contract RefundableCrowdsale is Initializable, FinalizableCrowdsale { * @param goal Funding goal */ function initialize(uint256 goal) public initializer { + // Make sure TimedCrowdsale.initialize (which FinalizableCrowdsale depends on) has been + // called before this initializer is executed + require(openingTime() > 0); + require(closingTime() > 0); + require(goal > 0); // conditional added to make initializer idempotent in case of diamond inheritance diff --git a/contracts/crowdsale/emission/AllowanceCrowdsale.sol b/contracts/crowdsale/emission/AllowanceCrowdsale.sol index abe9604f7..3d8503e05 100644 --- a/contracts/crowdsale/emission/AllowanceCrowdsale.sol +++ b/contracts/crowdsale/emission/AllowanceCrowdsale.sol @@ -22,6 +22,11 @@ contract AllowanceCrowdsale is Initializable, Crowdsale { * @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale */ function initialize(address tokenWallet) public initializer { + // Make sure Crowdsale.initialize has been called before this initializer is executed + assert(rate() > 0); + assert(wallet() != address(0)); + assert(token() != address(0)); + require(tokenWallet != address(0)); _tokenWallet = tokenWallet; } diff --git a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol index 119f47d02..dfd45f46a 100644 --- a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol +++ b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol @@ -23,6 +23,10 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale { * @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale */ function initialize(uint256 initialRate, uint256 finalRate) public initializer { + // Make sure TimedCrowdsale.initialize has been called before this initializer is executed + require(openingTime() > 0); + require(closingTime() > 0); + require(finalRate > 0); require(initialRate >= finalRate); _initialRate = initialRate; diff --git a/contracts/crowdsale/validation/CappedCrowdsale.sol b/contracts/crowdsale/validation/CappedCrowdsale.sol index 0e6f4edfb..7fab109cb 100644 --- a/contracts/crowdsale/validation/CappedCrowdsale.sol +++ b/contracts/crowdsale/validation/CappedCrowdsale.sol @@ -19,6 +19,11 @@ contract CappedCrowdsale is Initializable, Crowdsale { * @param cap Max amount of wei to be contributed */ function initialize(uint256 cap) public initializer { + // Make sure Crowdsale.initialize has been called before this initializer is executed + assert(rate() > 0); + assert(wallet() != address(0)); + assert(token() != address(0)); + require(cap > 0); _cap = cap; } diff --git a/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol b/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol index 5b7938213..f52f5c26a 100644 --- a/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol +++ b/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol @@ -17,6 +17,11 @@ contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole { mapping(address => uint256) private _caps; function initialize(address sender) public initializer { + // Make sure Crowdsale.initialize has been called before this initializer is executed + assert(rate() > 0); + assert(wallet() != address(0)); + assert(token() != address(0)); + CapperRole.initialize(sender); } diff --git a/contracts/crowdsale/validation/TimedCrowdsale.sol b/contracts/crowdsale/validation/TimedCrowdsale.sol index 7e1012d35..f1ff7cd33 100644 --- a/contracts/crowdsale/validation/TimedCrowdsale.sol +++ b/contracts/crowdsale/validation/TimedCrowdsale.sol @@ -29,6 +29,11 @@ contract TimedCrowdsale is Initializable, Crowdsale { * @param closingTime Crowdsale closing time */ function initialize(uint256 openingTime, uint256 closingTime) public initializer { + // Make sure Crowdsale.initialize has been called before this initializer is executed + assert(rate() > 0); + assert(wallet() != address(0)); + assert(token() != address(0)); + // solium-disable-next-line security/no-block-members require(openingTime >= block.timestamp); require(closingTime >= openingTime);