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?
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.