ReentrancyMock.sol 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. pragma solidity ^0.4.23;
  2. import "../ReentrancyGuard.sol";
  3. import "./ReentrancyAttack.sol";
  4. contract ReentrancyMock is ReentrancyGuard {
  5. uint256 public counter;
  6. constructor() public {
  7. counter = 0;
  8. }
  9. function callback() external nonReentrant {
  10. count();
  11. }
  12. function countLocalRecursive(uint256 n) public nonReentrant {
  13. if (n > 0) {
  14. count();
  15. countLocalRecursive(n - 1);
  16. }
  17. }
  18. function countThisRecursive(uint256 n) public nonReentrant {
  19. bytes4 func = bytes4(keccak256("countThisRecursive(uint256)"));
  20. if (n > 0) {
  21. count();
  22. // solium-disable-next-line security/no-low-level-calls
  23. bool result = address(this).call(func, n - 1);
  24. require(result == true);
  25. }
  26. }
  27. function countAndCall(ReentrancyAttack attacker) public nonReentrant {
  28. count();
  29. bytes4 func = bytes4(keccak256("callback()"));
  30. attacker.callSender(func);
  31. }
  32. function count() private {
  33. counter += 1;
  34. }
  35. }