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
out of gas. There is also another question about handling this error, which is unfortunately unanswered. – mahdi Aug 17 '21 at 09:55