1

I know that a fallback function called with a .transfer only has gas limit of 2300. What happens if the fallback function deletes some storage variables in the fallback function? Would the fallback function be able to use more than the 2300 gas limit because some gas is being refunded? Let's say it sets one variable to 0, which the gas refund is 10000. Then would the fallback function have gas limit of 12300? I.e. be able to set 2 variables each action having a cost of 5000 gas?

Also, I've read that .transfer, .send will have a limit of 2300 gas and call.value will transfer gas from the transaction. But what about a non matching function? According to the docs a non matching function identifier will trigger the fallback function. So what happens if someone calls my contract with "thisMethodDoesntExist()", would the fallback have a limit of 2300?

1
  • Then would the fallback function have gas limit of 12300? - No, because gas refund is at most half of what you spend. In addition to that, the refund is provided only at the end of the function, so you cannot spend more than 2300 even if you start with "earning" those 10000. Commented Nov 14, 2020 at 9:16

1 Answer 1

1

Would the fallback function be able to use more than the 2300 gas limit because some gas is being refunded?

First of all, the amount of gas refunded is at most half the gas used, so the theoretical gas limit of the fallback function is at most 2300 + 1150 = 3450 gas.

Second, the gas refund itself is provided only at the end of the transaction, which means that the function being executed cannot use its own gas refund.

This means that even the additional amount of 1150 gas is not available for the fallback function, hence its gas limit remains 2300 gas.

2
  • What about the second question I had? Which was that a fallback function is also triggered when no function identifier matches. transfer and send have a 2300 limit for the fallback function, but what if the fallback is called with a someMethodThatDoesNotExist() ? Commented Nov 14, 2020 at 14:14
  • @TerenceChow: Please post each question separately. Commented Nov 14, 2020 at 16:03

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.