0

Suppose we have a contact like this:

contract x {

   function y() external
   {
      // do some magic!
      if (some_condition) {
        another_contract_address.call(abi.encodeWithSignature("another_contract_func()"));
      }
   }

}

which does something in a function y and then dynamically calls another method of another contract as its last sentence under specific conditions. As far as I know, all the remaining gas of the caller contract will be used for executing the callee function. Regarding the fact that this dynamic call is the last expression in y, what will happen if this dynamic call exhausts all the remaining gas? Does the transaction finish successfully (due to the fact that the RETURN opcode uses 0 gas) or it will be failed with an out of gas error?

2 Answers 2

0

The states will get reverted back to initial state (the state when you called the function). But the gas fees and incentive which you'ld have provided to miner will not be refunded . Transaction block will be present there for eternity. any amount of ether if you have paid will be returned back. Dynamic call will function like if it was a function call of same contract. So on revertion process the state variable of dynamic contract calling and caller contract both will get reverted.

1
  • I'm not sure your answer is the most accurate because I've seen many transactions in which a dynamic call gets reverted (i.e. due to a direct call of revert in the callee external function), but the original transaction was succeeded (and in fact, that is why dynamic calls exist in the first place). Commented Apr 29, 2022 at 8:33
0

According to this OpenZeppelin blog post:

Given that every call can end in an out-of-gas (OOG) exception, to avoid security issues at least 1/64th of the sender’s remaining gas will be saved. This allows senders to handle inner calls’ out-of-gas errors, so that they are able to finish its execution without themselves running out of gas, and thus bubbling the exception up.

UPDATE: Apparently, what I mentioned above is implemented in EIP-150.

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.