Torsten Stüber, 2025-10-20
This is a continuation of the document Gas Mapping Challenges (Revised).
This document specifies how pallet-revive tracks resources during contract execution. These resources are (Substrate) weight, storage deposits and (Ethereum) gas. We specifically define:
We will see that we need to introduce two sets of such definitions depending on whether the transaction as a whole defines a) a weight limit and a deposit limit (a Substrate transaction) or b) only a gas limit (an Ethereum transaction). The former set of definitions is fairly obvious whereas the latter set of definitions is more complex. You can find an overview of all definitions in the summary.
Since the definitions for Ethereum transactions are not obvious, we will additionally prove that they are correct, effective and optimal in some specific sense, see the according section.
Table of Contents
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$.
<aside> ☝
In the sequel we consider only one fixed transaction, therefore $l$ has a fixed value throughout this document. Also note that the base extrinsic weight $b$ is a fixed constant.
</aside>
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.
For weights $w=(w_r, w_p)$ and $w'=(w'_r, w'_p)$ we write $w\geq w'$ if both $w_r\geq w'_r$ and $w_p\geq w'_p$. Furthermore $\min(w,w')$ is the weight $\bigl(\min(w_r,w_r'), \min(w_p,w_p')\bigr)$, i.e, the minimum is taken component-wise.
For example, for $x\geq x'$ we have $\varphi^{-1}(x)\geq \varphi^{-1}(x')$ by the definition of $\varphi^{-1}$.
<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, given an argument $x$, the function $\varphi^{-1}$ returns the maximal weight $w$ that has the property $\varphi(w)=x$; i.e., whenever $\varphi(w)=x$, then $\varphi^{-1}(x)\geq w$.
Also note, that the opposite is not true: in general $\varphi^{-1}(\varphi(w))\not =w$, given an arbitrary weight $w$. However, the fact from the previous sentence implies $\varphi^{-1}(\varphi(w))\geq w$.
</aside>