You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
911 B
31 lines
911 B
7 years ago
|
pragma solidity ^0.4.24;
|
||
8 years ago
|
|
||
7 years ago
|
|
||
8 years ago
|
/**
|
||
7 years ago
|
* @title Helps contracts guard against reentrancy attacks.
|
||
7 years ago
|
* @author Remco Bloemen <remco@2π.com>, Eenae <alexey@mixbytes.io>
|
||
7 years ago
|
* @dev If you mark a function `nonReentrant`, you should also
|
||
8 years ago
|
* mark it `external`.
|
||
|
*/
|
||
8 years ago
|
contract ReentrancyGuard {
|
||
|
|
||
7 years ago
|
/// @dev counter to allow mutex lock with only one SSTORE operation
|
||
|
uint256 private guardCounter = 1;
|
||
8 years ago
|
|
||
8 years ago
|
/**
|
||
|
* @dev Prevents a contract from calling itself, directly or indirectly.
|
||
7 years ago
|
* If you mark a function `nonReentrant`, you should also
|
||
|
* mark it `external`. Calling one `nonReentrant` function from
|
||
8 years ago
|
* another is not supported. Instead, you can implement a
|
||
7 years ago
|
* `private` function doing the actual work, and an `external`
|
||
8 years ago
|
* wrapper marked as `nonReentrant`.
|
||
|
*/
|
||
8 years ago
|
modifier nonReentrant() {
|
||
7 years ago
|
guardCounter += 1;
|
||
|
uint256 localCounter = guardCounter;
|
||
8 years ago
|
_;
|
||
7 years ago
|
require(localCounter == guardCounter);
|
||
8 years ago
|
}
|
||
|
|
||
|
}
|