ReentrancyMock.sol 925 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. pragma solidity ^0.4.8;
  2. import '../../contracts/ReentrancyGuard.sol';
  3. import './ReentrancyAttack.sol';
  4. contract ReentrancyMock is ReentrancyGuard {
  5. uint256 public counter;
  6. function ReentrancyMock() {
  7. counter = 0;
  8. }
  9. function count() private {
  10. counter += 1;
  11. }
  12. function countLocalRecursive(uint 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. bool result = this.call(func, n - 1);
  23. if(result != true) {
  24. throw;
  25. }
  26. }
  27. }
  28. function countAndCall(ReentrancyAttack attacker) public nonReentrant {
  29. count();
  30. bytes4 func = bytes4(keccak256("callback()"));
  31. attacker.callSender(func);
  32. }
  33. function callback() external nonReentrant {
  34. count();
  35. }
  36. }