EVM: out of gas while executing send

Hi,
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?

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

Now suppose that 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++;
             :
             :
            :
       }//function ends
}//contract ends

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

Zulfi.

1 Like

Hello @zak100,

First of all, Using address.send (and address.transfer()) is not good practice. We encourage you to use the Address.sendValue function provided by @openzeppelin/contracts/utils/Address.sol.

To answer your question, I think the best thing is for you to read @wighawag 's excellent blog post on gas.

3 Likes

Hi,
@Amxx, Thanks lot for that link. Do you know the date of that article? I have one question:
How can we implement the concept of 1/64 for the following contract?

> 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

Thanks @Amxx for linking to the article
@zak100 it was published in February 2020 and it is still accurate

2 Likes