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.
45 lines
904 B
45 lines
904 B
7 years ago
|
pragma solidity ^0.4.18;
|
||
8 years ago
|
|
||
7 years ago
|
import '../ReentrancyGuard.sol';
|
||
8 years ago
|
import './ReentrancyAttack.sol';
|
||
|
|
||
|
contract ReentrancyMock is ReentrancyGuard {
|
||
|
|
||
|
uint256 public counter;
|
||
|
|
||
7 years ago
|
function ReentrancyMock() public {
|
||
8 years ago
|
counter = 0;
|
||
|
}
|
||
|
|
||
|
function count() private {
|
||
|
counter += 1;
|
||
|
}
|
||
|
|
||
8 years ago
|
function countLocalRecursive(uint256 n) public nonReentrant {
|
||
8 years ago
|
if(n > 0) {
|
||
|
count();
|
||
|
countLocalRecursive(n - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function countThisRecursive(uint256 n) public nonReentrant {
|
||
|
bytes4 func = bytes4(keccak256("countThisRecursive(uint256)"));
|
||
|
if(n > 0) {
|
||
|
count();
|
||
|
bool result = this.call(func, n - 1);
|
||
7 years ago
|
require(result == true);
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
function countAndCall(ReentrancyAttack attacker) public nonReentrant {
|
||
|
count();
|
||
|
bytes4 func = bytes4(keccak256("callback()"));
|
||
|
attacker.callSender(func);
|
||
|
}
|
||
|
|
||
|
function callback() external nonReentrant {
|
||
|
count();
|
||
|
}
|
||
|
|
||
|
}
|