0

I was working on the 13th level of Ethernaut when I discovered that calling a function of a contract with an explicit amount of gas results in a revert with no further description, even though the cause of revert was too little gas being passed to the function being called. The following example illustrates this:

pragma solidity ^0.6.0;

contract GatekeeperOne {

  address public entrant;

  function enter() public {
    entrant = tx.origin;
  }
  
  function debugEnter() external {
      this.enter{gas: 1}();
  }
}

When I compile this with the v0.6.12 compiler and run debugEnter(), etherscan reports only a revert error, and says nothing about running out of gas. I understand the recommended way to detect this is to return a bool regarding the success of the function, but how can I detect this if calling a contract that I have no control over?

This is a related question, it seems that it is not even possible to catch the error and handle the case of too little gas being passed on: Catch Internal Out of Gas Exception in Solidity Code

0

You can access Geth Debug Trace_2 from Etherscan (in right top corner hamburger button), which shows all the calls and the result of each of them. This link is the result of clicking on debug trace for your mentioned tx, where you can see the out of gas error.

  "type": "CALL",
  "from": "0x07475a9a0866345684f4c8753e6d040e30b74f66",
  "to": "0x35b525d253beb7a8a044ab679deaae11cb02d8b5",
  "value": "0x0",
  "gas": "0x2d7478",
  "gasUsed": "0x1cf",
  "input": "0x0c303c89",
  "error": "execution reverted",
  "time": "1.9999ms",
  "calls": [
    {
      "type": "CALL",
      "from": "0x35b525d253beb7a8a044ab679deaae11cb02d8b5",
      "to": "0x35b525d253beb7a8a044ab679deaae11cb02d8b5",
      "value": "0x0",
      "input": "0xe97dcb62",
      "error": "out of gas"
    }
  ]
}
2
  • can you also detect this case from the code? eg. to handle it within solidity?
    – Griffin
    Aug 16 at 21:23
  • @Griffin Solidity supports try-catch blocks as mentioned in here, but I'm not sure you can catch out of gas. There is also another question about handling this error, which is unfortunately unanswered.
    – mahdi
    Aug 17 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.