Torsten Stüber, 2025-10-20

This is a continuation of the document Gas Mapping Challenges (Revised).


The notation in this document is based on the notation in the first document. Since here we don’t consider gas estimation but only transaction execution, we don’t need to distinguish between $m_d, f_d, l_d$ on the one hand and $m_e, f_e, l_e$ on the other hand and just use the symbols $m, f, l$. In the sequel we consider only one fixed transaction, therefore $l$ has a fixed value throughout this document.

For convenience, we introduce the inverse $\varphi^{-1}$ of the function $\varphi$, which derives a weight from a fee $x$:

$$ \varphi^{-1}(x)=\Bigl(\frac{x}{\alpha},\frac{x}{\beta}\Bigr)\;; $$

this notation means that $x/\alpha$ is the ref time part of the weight and $x/\beta$ is the proof size part of the weight. This inverse function is called fee_to_weight in the pallet-revive code.

<aside> 💡

Observe that for every amount $x$, $\varphi(\varphi^{-1}(x))=\max\bigl(\frac{x}{\alpha}\cdot\alpha, \frac{x}{\beta}\cdot\beta\bigr)=x$.

In fact, this function returns that maximum possible weight $w$ so that $\varphi(w)=x$.

Also note, that the opposite is not true: in general $\varphi^{-1}(\varphi(w))\not =w$, given an arbitrary weight $w$.

</aside>

Consumed Resources

Pallet-revive does not track consumed gas, instead it only tracks consumed weight and consumed storage deposit. If at a certain point of the transaction execution the total consumed weight is $w$ the totally charged storage deposit is $d$, then the cost for the transaction up to that point consists of

Thus, the total cost $C$ at that point is

$$ C(w,d)=d+f(w+w^\mathrm{extra},l)=d+\varphi(b)+\lambda(l)+m\cdot \varphi\bigl(w+w^\mathrm{extra}\bigr)\;. $$

Gas is a direct measure of cost and one unit of gas has the price $m$. That means that the consumed gas $g$ is a function of $w$ and $d$ as follows:

$$ g(w,d)=C(w,d)/m=\frac{d+\varphi(b)+\lambda(l)}{m}+\varphi(w+w^\mathrm{extra})\;. $$

Maximizing Arguments

Given a weight $w$ and amounts $d$ and $y$, we will frequently have to determine the maximum weight $w'$ such that $g(w+w',d)=y$ and the maximum deposit $d'$ such that $g(w,d+d')=y$.

Let’s first consider how to determine $w'$. First expand the condition: