Skip to content

Commit

Permalink
Crowdsale.buyTokens is now nonReentrant. (#1438)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6d415c5)
  • Loading branch information
nventuro authored and come-maiz committed Oct 20, 2018
1 parent ecae760 commit 1a4009f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.4.24;
import "../token/ERC20/IERC20.sol";
import "../math/SafeMath.sol";
import "../token/ERC20/SafeERC20.sol";
import "../utils/ReentrancyGuard.sol";

/**
* @title Crowdsale
Expand All @@ -16,7 +17,7 @@ import "../token/ERC20/SafeERC20.sol";
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/
contract Crowdsale {
contract Crowdsale is ReentrancyGuard {
using SafeMath for uint256;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -111,9 +112,11 @@ contract Crowdsale {

/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
* @param beneficiary Recipient of the token purchase
*/
function buyTokens(address beneficiary) public payable {
function buyTokens(address beneficiary) public nonReentrant payable {

uint256 weiAmount = msg.value;
_preValidatePurchase(beneficiary, weiAmount);
Expand Down
9 changes: 4 additions & 5 deletions contracts/utils/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ contract ReentrancyGuard {

/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* If you mark a function `nonReentrant`, you should also
* mark it `external`. Calling one `nonReentrant` function from
* another is not supported. Instead, you can implement a
* `private` function doing the actual work, and an `external`
* wrapper marked as `nonReentrant`.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_guardCounter += 1;
Expand Down

0 comments on commit 1a4009f

Please sign in to comment.