Ethernaut: Level 13 Gatekeeper One: correct opcode for gasleft().mod(8191)


I’m struggling with this level. I’m not able to pass gateTwo because I don’t know when the compiler will evaluate gasleft().mod(8191) (see below). When does the compiler will evaluate it ? I assumed that the compiler will first read the code then look in Safemath what mod() do and then evaluate it, but apparently it’s not the case.

You can find the code I used here (

Best regards,

1 Like

Hi @caladay,

I suggest having a look at the community solution, there is a bit of trial and error to get the gas left:

(There are a number of community solutions for the different levels: Ethernaut Community Solutions).

Alternatively you can look at the attack in the repository:

Dear abcoathup,

Thank you very much for your answer. I looked at it but don’t find the response to my question. I performed some test in order to find the proper opcode but somehow still doesn’t work when using a call…

For example I used the following file:

The remaining gas will be the one shown after the opcode gas (in the picture the remaining gas shown in 0518 PUSH2 044d). If you input this value in the code it works (as you can see switcher1 and switcher2 have both been updated).

However, I tried to use the same technique but this time using a call (see picture below) but it doesn’t work (the switcher is not updated). I don’t know why. Do you have any idea why it doesn’t work ?


1 Like

Hi @caladay,

Unfortunately I haven’t gone through this level yet. I am also not sure of the opcode.

I suggest trying the approach in the following community solution to solve the level:

Unless someone in the community can answer.

Dear abcoathup,

After several trial and error it finally seems to work \o/

Here are my key takeaways:
i) when you hit “copy value to clipboard” wait till you have confirmation (sometimes I was calling the wrong contract, i.e. the value in the clipboard was from a previously deployed contract -_-)
ii) The remaining gas appears after the opcode GAS, i.e. PUSH2 ****
iii) Be sure to increase the gas limit of RemixIDE and to add enough gas:
- for instance if you add 8’191’000 gas in the call but the limit is 3’000’000; Remix will take 3’000’000
- If you don’t add a lot of gas it simply doesn’t work (f.i. 8191 instead of 8’191’000) I don’t understand why
it doesn’t tell you antything (run out of gas, etc.).

Thank you for your help

1 Like