ReentrancyGuard.sol 915 B

123456789101112131415161718192021222324252627282930
  1. pragma solidity ^0.4.24;
  2. /**
  3. * @title Helps contracts guard against reentrancy attacks.
  4. * @author Remco Bloemen <remco@2π.com>, Eenae <alexey@mixbytes.io>
  5. * @dev If you mark a function `nonReentrant`, you should also
  6. * mark it `external`.
  7. */
  8. contract ReentrancyGuard {
  9. /// @dev counter to allow mutex lock with only one SSTORE operation
  10. uint256 private _guardCounter = 1;
  11. /**
  12. * @dev Prevents a contract from calling itself, directly or indirectly.
  13. * If you mark a function `nonReentrant`, you should also
  14. * mark it `external`. Calling one `nonReentrant` function from
  15. * another is not supported. Instead, you can implement a
  16. * `private` function doing the actual work, and an `external`
  17. * wrapper marked as `nonReentrant`.
  18. */
  19. modifier nonReentrant() {
  20. _guardCounter += 1;
  21. uint256 localCounter = _guardCounter;
  22. _;
  23. require(localCounter == _guardCounter);
  24. }
  25. }