0

I want to consider a scenario, lets suppose that a contract performs a transfer using send. At this point, out of gas occurs and send returns -1. Now the contract has no gas, and send does not revert, what would happen to the EVM, will it block because of no gas? How will EVM come out of this blocking situation? Kindly provide some link from Ethereum documentation.

contract TestOutofGas{
     :
     :
      function transaction(address otherContract, uint x) public returns () {
       :
       retVal = otherContract.send(1000);//out of gas
       bool success = findPrime(x);
         :
        :
      }//func transaction
}//contract OutofGas

Now suppose the other case,

contract TestOutofGas{
     uint trnNo=0;
     :
     function transaction(address otherContract) public returns (uint) {
       :
         retVal = otherContract.send(1000);//out of gas
         require(retVal);
         trnNo++;
       :
       :
     }//func ends
}//contract ends

Will the EVM be able to execute the require(…) instruction if the contract does not have any gas?

Zulfi.

1 Answer 1

1

Let's analyze the second case

 function transaction(address otherContract) public returns (uint) {
   :
     retVal = otherContract.send(1000);//out of gas
     require(retVal);
     trnNo++;
   :
   :
 }//func ends

When otherContract.send fails the EVM was processing a CALL opcode it will leave 0 (false) on the top stack entry.

The EVM will try to execute the next opcode to assign 0 to retVal. Whatever the opcode it is trying to execute if there isn't enough gas to pay for it the EVM will stop immediately reverting any change.

require() is a fancy way to return an error message. The EVM can revert without a require if there is an error like division by zero, invalid opcode, etc.

2
  • Hi, @Ismael, the article at: ronan.eth.link/blog/ethereum-gas-dangers, states that due to EIP150, we have the concept of 1/64, i.e. the caller has 1/64 amount of gas, callee will suffer from out of gas, but caller can still run due to 1/64 amount of gas, how can we implement the concept of 1/64 here?
    – zak100
    Mar 1, 2021 at 4:45
  • 1
    @zak100 The analysis will be quite similar, the only difference is after CALL opcode returns there will be at least some gas left and the EVM will be able to continue the execution. If there's enough gas it might complete the transaction execution (calling REVERT if it was present). If the gas isn't enough to complete execution the EVM will halt execution and revert any change.
    – Ismael
    Mar 1, 2021 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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