Torsten Stüber, 2025-11-03
Gas is a direct measure of cost. The cost of a transaction is the sum of its transaction fee and its storage deposit. The transaction fee itself depends on the weight that has been consumed during execution – this can be expressed as a function $f(w)$, where $w$ is the weight. If $w$ is the total consumed weight and $d$ is the total consumed storage deposit during execution of the transaction, then the total cost is $f(w)+d$.
Let’s call the total cost function $C$, it is a function that depends on $w$ and $d$: $C(w,d)=f(w)+d$.
This expression allows us to measure the consumed cost during the execution. We us meters to keep track of the consumed weight and consumed storage deposit: when at a certain point during the execution we consumed weight $w'$ and storage deposit $d'$, then the accrued cost at that point in time is $C(w',d')$.
If we are given a gas price $p$, we can convert the cost $C(w,d)$ into an amount of gas as $C(w,d)/p$. The question is just what gas price to use. There are two natural candidates:
The effective gas price is always at least the base price.
Given one specific transaction, we need to distinguish between two different effective gas prices: the one used for dry running (which falls back to the base price if not provided) and the effective gas price from the actual transaction to be executed. Both of these can be different.
Let’s denote these prices as:
Thus, $m\leq p_\mathrm d$ and $m\leq p_\mathrm e$.
In theory the base price $m$ can be slightly different between dry running and execution, but we ignore this difference here as it is usually much smaller than the difference between the effective gas prices and the base price.
During dry running, the RPC node executes the transaction, meters a total consumed weight $w_\mathrm d$, a total consumed storage deposit $d_\mathrm d$ and determines the total cost $C(w_\mathrm d,d_\mathrm d)$. We can use one of two options to model the choice of the gas price: either use $m$ or $p_\mathrm d$ to determine the gas estimate $g$: thus, we either have $g=C(w_\mathrm d,d_\mathrm d)/m$ or $g=C(w_\mathrm d,d_\mathrm d)/p_\mathrm d$.
The RPC node will then report this estimate to the user. The user (their wallet) will then choose a gas limit $g^\mathrm{limit}\geq g$ and the effective gas price $p_\mathrm e\geq m$ and put these as parameters in the transaction to execute.