You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starknet 0.13.4 introduces runtime L2 gas accounting. A dedicated withdraw_gas libfunc call is added by the compiler into loops. For non-tail-recursive calls withdraw_gas always requires the worst-case gas amount to be available, so the compiler inserts redeposit_gas libfunc calls onto paths that cost less than the worst-case. (For a detailed analysis please check this document.)
This means that simply taking the L2 gas costs of a transaction execution and using that as a fee cap when submitting a transaction might lead to the transaction reverting due to insufficient gas. Whether or not this happens depends on whether there are paths during the execution where worst-case gas requirements are significantly larger than the actual costs.
To get a fee estimate that guarantees that the transaction will succeed we have to resort to trial-and-error:
Run transaction with a large fee cap (maybe balance induced but can be max as well), get consumed gas g.
Unfortunately the VM doesn't currently do accounting on gas refunds (g'), so let's just assume that in most cases the transaction does not have a pathological case and try executing it with (1 + epsilon) * g gas.
If that succeeds, just use that as a fee estimate.
If the transaction reverts, check that the cause of the revert is insufficient gas and do a binary search for a sufficient gas cap within [ (1 + epsilon) * g, max ].
The text was updated successfully, but these errors were encountered:
Starknet 0.13.4 introduces runtime L2 gas accounting. A dedicated
withdraw_gas
libfunc call is added by the compiler into loops. For non-tail-recursive callswithdraw_gas
always requires the worst-case gas amount to be available, so the compiler insertsredeposit_gas
libfunc calls onto paths that cost less than the worst-case. (For a detailed analysis please check this document.)This means that simply taking the L2 gas costs of a transaction execution and using that as a fee cap when submitting a transaction might lead to the transaction reverting due to insufficient gas. Whether or not this happens depends on whether there are paths during the execution where worst-case gas requirements are significantly larger than the actual costs.
To get a fee estimate that guarantees that the transaction will succeed we have to resort to trial-and-error:
g
.g'
), so let's just assume that in most cases the transaction does not have a pathological case and try executing it with(1 + epsilon) * g
gas.[ (1 + epsilon) * g, max ]
.The text was updated successfully, but these errors were encountered: