ReentrancyGuard.sol 963 B

123456789101112131415161718192021222324252627282930313233
  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;
  11. constructor() public {
  12. _guardCounter = 1;
  13. }
  14. /**
  15. * @dev Prevents a contract from calling itself, directly or indirectly.
  16. * If you mark a function `nonReentrant`, you should also
  17. * mark it `external`. Calling one `nonReentrant` function from
  18. * another is not supported. Instead, you can implement a
  19. * `private` function doing the actual work, and an `external`
  20. * wrapper marked as `nonReentrant`.
  21. */
  22. modifier nonReentrant() {
  23. _guardCounter += 1;
  24. uint256 localCounter = _guardCounter;
  25. _;
  26. require(localCounter == _guardCounter);
  27. }
  28. }