Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
1a4009f8
Commit
1a4009f8
authored
Oct 19, 2018
by
Nicolás Venturo
Committed by
Leo Arias
Oct 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Crowdsale.buyTokens is now nonReentrant. (#1438)
(cherry picked from commit
6d415c50
)
parent
ecae7608
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
Crowdsale.sol
contracts/crowdsale/Crowdsale.sol
+5
-2
ReentrancyGuard.sol
contracts/utils/ReentrancyGuard.sol
+4
-5
No files found.
contracts/crowdsale/Crowdsale.sol
View file @
1a4009f8
...
@@ -3,6 +3,7 @@ pragma solidity ^0.4.24;
...
@@ -3,6 +3,7 @@ pragma solidity ^0.4.24;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/IERC20.sol";
import "../math/SafeMath.sol";
import "../math/SafeMath.sol";
import "../token/ERC20/SafeERC20.sol";
import "../token/ERC20/SafeERC20.sol";
import "../utils/ReentrancyGuard.sol";
/**
/**
* @title Crowdsale
* @title Crowdsale
...
@@ -16,7 +17,7 @@ import "../token/ERC20/SafeERC20.sol";
...
@@ -16,7 +17,7 @@ import "../token/ERC20/SafeERC20.sol";
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
* behavior.
*/
*/
contract Crowdsale {
contract Crowdsale
is ReentrancyGuard
{
using SafeMath for uint256;
using SafeMath for uint256;
using SafeERC20 for IERC20;
using SafeERC20 for IERC20;
...
@@ -111,9 +112,11 @@ contract Crowdsale {
...
@@ -111,9 +112,11 @@ contract Crowdsale {
/**
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @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
* @param beneficiary Recipient of the token purchase
*/
*/
function buyTokens(address beneficiary) public payable {
function buyTokens(address beneficiary) public
nonReentrant
payable {
uint256 weiAmount = msg.value;
uint256 weiAmount = msg.value;
_preValidatePurchase(beneficiary, weiAmount);
_preValidatePurchase(beneficiary, weiAmount);
...
...
contracts/utils/ReentrancyGuard.sol
View file @
1a4009f8
...
@@ -19,11 +19,10 @@ contract ReentrancyGuard {
...
@@ -19,11 +19,10 @@ contract ReentrancyGuard {
/**
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* @dev Prevents a contract from calling itself, directly or indirectly.
* If you mark a function `nonReentrant`, you should also
* Calling a `nonReentrant` function from another `nonReentrant`
* mark it `external`. Calling one `nonReentrant` function from
* function is not supported. It is possible to prevent this from happening
* another is not supported. Instead, you can implement a
* by making the `nonReentrant` function external, and make it call a
* `private` function doing the actual work, and an `external`
* `private` function that does the actual work.
* wrapper marked as `nonReentrant`.
*/
*/
modifier nonReentrant() {
modifier nonReentrant() {
_guardCounter += 1;
_guardCounter += 1;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment