# L1 Gas Costs for the B52 and Fernet Proposals
<style>
body {
counterreset: heading;
}
h2:before {
content: counter(heading)". ";
counterincrement: heading;
}
h2 {
counterreset: subheading;
}
h3:before {
content: counter(heading)"." counter(subheading)". ";
counterincrement: subheading;
}
h3 {
counterreset: subsubheading;
}
h4:before {
content: counter(heading)"." counter(subheading)"." counter(subsubheading)". ";
counterincrement: subsubheading;
}
h4 {
counterreset: subsubsubheading;
}
h5:before {
content: counter(heading)"." counter(subheading)"." counter(subsubheading)"."counter(subsubsubheading)". ";
counterincrement: subsubsubheading;
}
</style>
*Danilo Lessa Bernardineli (BlockScience), August 2023*
## Introduction
On this document, we breakdown the B52 & Fernet coordination costs on L1 by introducing a mathematical formalism over their gas / blobgas costs and using them to derive relevant metrics. Based on those, assumptions are made on the variables form (eg. constant vs dynamical function vs stochastic) and numerical values.
## Preliminaries
### Terminology
 Term  Unit  Meaning 
      
 $N_p$  #  Number of blockproposing sequencers during the round 
 $N_s$  #  Number of proofcommiting sequencers during the round 
 $N_u$  #  Number of uncles 
 $N_t$  #  Number of transactions 
 $p_g$  $\frac{\text{Gwei}}{\text{Gas}}$  Average price in Gwei for 1 unit of Gas 
 $p_b$  $\frac{\text{Gwei}}{\text{Gas}}$  Average price in Gwei for 1 unit of Blob Gas 
 $g_i^P$  Gas  Total Gas for Phase $i$ for proposal $P$
 $g^P$  Gas  Total Gas for proposal $P$ for a single round
 $T_0$  Gas  Base Transaction Gas Cost 
 $T_v$  Gas  Standard Plonk Verification Gas Cost 
 $T_i$  Gas  `StoreBlockIdentifier` associated gas 
 $T_c^P$  Gas  `CallData` associated gas for proposal $P$ 
 $T_r^P$  Gas  Rollup Scoring Logic associated gas for proposal $P$ 
 $T_\pi^P$  Gas  `StoreRewardReferences` associated gas for proposal $P$ 
 $b_i^P$  Blob Bytes  Total blob bytes for Phase $i$ for proposal $P$
 $b^P$  Blob Bytes  Total blob bytes for proposal $P$ for a single round
 $B_h$  Blob Bytes  Block Header Bytes 
 $B_t$  Blob Bytes  Transaction Bytes 
 $C_i^P$  Gwei Total cost for Phase $i$ for proposal $P$
 $C^P$  Blob Bytes  Total cost for Phase $i$ for proposal $P$ for a single round
### Linking Gas Units to Values
#### Gas & Blob Gas to Gwei
Let $X$ be the transaction of interest, then we can define its costs in Gwei (or $10^{9} \text{ ETH}$) as:
$$
\begin{align}
& \text{Gas Units to Gwei: } & \bar{g}_X &= \text{GasQuantity}(X) * p_g(t) \\
& \text{Blob Gas Units to Gwei: } & \bar{b}_X &= \text{BlobBytes}(X) * p_b(t)
\end{align}
$$
Mapping the Gas Units to actual Gwei values can use a variety of approaches. The simpler one is to assume constant value (eg. $p_g(t) = 34$ and $p_b(t) = 1$). Else it is possible to use: 1) univariate random distributions (eg. Gaussian or Laplacian distributions; 2) standard timeseries analysis models (eg. ARIMA and/or VAR models)  in fact the Average Gas Price Fee has been documented to have properties that are similar to a `SARIMA(2,0,1)(0,1,1)` model; 3) Building explicit dynamical models, which can be particularly useful for the BlobGas price, as there's no data available for it and the price change obeys an exponential rule depending on the congestion after/before a threshold.
#### Gwei to ETH and USD
The first step to compute $g_X$ and $b_X$ in terms of meaningful values is to convert from Gwei to ETH. This is done by
multiplying them by $10^{9}$ so that $g_{X}^{\text{ETH}}= g_X * 10^{9}$ and $b_{X}^{\text{ETH}}= b_X * 10^{9}$
Converting to USD requires again an variety of approaches. The simplest one is to adopt an constant value (eg. `1 ETH = 1650 USD`), and
more complicated ones can involve sampling from univariate random distributions (eg. Gaussian & Laplace) and timeseries models (eg. ARFIMA).
## Formal description of the gas costs across the proposals (B52 and Fernet)
The total gas per phase as denominated in Conventional and Blob Gas can be described through the below equations.
### B52
$$
\begin{align}
& \text{1. Block Proposal: } & g_1^{B52} &= \sum_{N_p} (T_0 + T_s +T_c^{\text{B52}}) & b_1^{B52} &= 0 \\
& \text{2. Block Submission: } & g_2^{B52} &= \sum_{N_s} T_0, & b_2^{B52} &= \sum_{N_s} (B_h + \sum_{N_t} B_t)\\
& \text{3. Block Reveal: } & g_3^{B52} &= \sum_{N_s} (T_0 + T_r^{B52} + T_v) & b_3^{B52} &= 0 \\
& \text{4. Finalization: } & g_4^{B52} &= T_0 + T_i + T_\pi^{B52} & b_4^{B52} &= 0
\end{align}
$$
### Fernet
$$
\begin{align}
& \text{1. Block Proposal: } & g_1^{Fernet} &= \sum_{N_p} (T_0 + T_s +T_c^{\text{Fernet}}) & b_1^{Fernet} &= 0 \\
& \text{2. Proof Submission: } & g_2^{Fernet} &= \sum_{N_s} (T_0 + T_r^{Fernet} + T_v) & b_2^{Fernet} &= 0 \\
& \text{3. Block Submission: } & g_3^{Fernet} &= \sum_{N_s} T_0, & b_3^{Fernet} &= \sum_{N_s} (B_h + \sum_{N_t} B_t)\\
& \text{4. Finalization: } & g_4^{Fernet} &= T_0 + T_i + T_\pi^{\text{Fernet}} & b_4^{Fernet} &= 0
\end{align}
$$
### Converting Gas to Gwei
Converting Gas / BlobGas to Gwei (assuming average transaction fees) requires multiplying the summation terms by the average price term while taking into consideration the event time. As an example, the cost in Gwei for the B52 Phase 2 is formally expressed as: $C_2^{B52} = \sum^{N_s}_i p_g(t_2(i)) T_0 + \sum^{N_s}_i p_s(t_2(i)) \sum_{N_s} (B_h + \sum_{N_t} B_t)$, where $t_2(i)$ is the time on which Agent $i$ has submited the L1 transaction for Phase 2.
We've omitted expressing explicitly the full expression in Gwei for sake of simplicity.
One simplifying assumption is to assume that the gas prices are equal for the entirety of an block cycle. In that case, the total costs in Gwei can be expressed as:
$$
\begin{align}
C^{\text{B52}} &= p_g(t)(T_0 + T_i + T_\pi^{\text{B52}} +N_s(2T_0 + T_r^{\text{B52}}+T_v) + N_p(T_0 +T_s + T^{\text{B52}}_c)) +p_b N_s(B_h + N_t \langle B_t \rangle) \\
C^{\text{Fernet}} &= p_g(t)(T_0 + T_i + T_\pi^{\text{Fernet}} +N_s(2T_0 + T_r^{\text{Fernet}}+T_v) + N_p(T_0 +T_s + T^{\text{Fernet}}_c)) +p_b N_s(B_h + N_t \langle B_t \rangle)
\end{align}
$$
### Metrics
$$
\begin{align}
& \text{L1 Cost per Rollup: } & & C_1(N_p) + C_2(N_u) + C_3(N_u) + C_4 \\
& \text{L1 Cost per Transaction: } & & \frac{C(N_p, N_u)}{N_t} \\
& \text{L1 Cost per Proposer: } & & \frac{C(N_p, N_u)}{N_p} \\
& \text{L1 Cost per Submitter: } & & \frac{C(N_p, N_u)}{N_s} \\
& \text{L1 Cost for the Proposer: } & & c_1 \\
& \text{L1 Cost for the Submiter: } & & c_1 + c_2 + c_3 \\
& \text{L1 Cost for the Finalizer: } & & c_1 + c_2 + c_3 + c_4 \\
& \text{L1 Coordination Overhead for the Finalizer: } & & 1  \frac{C  (c_1 + c_2 + c_3 + c_4)}{C} \\
& \text{B52 Relative Advantage over Fernet: } & & \frac{\Delta C}{C_{B52}} \\
\end{align}
$$
Where the $\Delta$ operator is defined such that $\Delta f = f^{\text{B52}}  f^{\text{Fernet}}$, then by applying it on $C$, we the Gas Costs difference between the B52 and Fernet proposals, which gives us:
$\Delta C = p_g(\Delta T_\pi + N_s \Delta T_r + N_p \Delta T_c)$
## Putting Numbers on Variables
On this section, assumptions on the variables's form and pointlike numbers will be provided to the best of our knowledge and intuition. For uncertain values, observations will be provided that could further inform evaluation through the usage of probability distributions.
### Proposal Agnostic Numbers
 Variable  Type  Assumed Value  Unit  Notes 
          
 $T_0$  Constant  21,000 Gas   
 $T_v$  Constant  210,000  Gas  There's some uncertainty on the exact value (eg. ~30%) 
 $T_s$  Constant  5,000  Gas   
 $T_i$  Constant  20,000  Gas   
 $B_h$  Constant  600  Blob Bytes   
 $B_t$  Stochastic  700  Blob Bytes  Between 50B and 50kB with mean on 700B 
 $N_p$  Stochastic  10  #  Likely to be Between 1 and 100
 $N_s$  Stochastic  3  #  Likely to be Between 1 and 5 
 $N_t$  Stochastic  2048  #  Between 0 and 8192. Assumption consider an 25% usage rate. 
$N_u$  Stochastic  2  #  Likely to be Between 1 and 3 
$N_\text{prover}$  Stochastic  30  #  Likely to be Between 1 and 1000 
 $p_g$  Stochastic  34  Gwei per Gas  Can be modelled through an SARIMA process. Typical ranges are between 18 and 50 Gwei per Gas 
 $p_s$  Stochastic  1  Gwei per Blob Byte  Can be modelled through an EIP4844 simulator. It is unbounded and it is not unrealistic to it to be sustainably larger than 50 Gwei per BlobGas as per [EIP4844 Research Notes](/k2zCTJ2bQZOm6cvrj71w4Q) 
### Proposal Specific Numbers
 Variable  B52 Type  Fernet Type  B52 Assumed Value  Fernet Assumed Value  Unit  Notes 
              
 $T_c$  Constant  Constant  26,108  27,384  Gas  The B52 number is certain. The Fernet number should be validated and it is possible to attach an 5% uncertainty margin on it for now. 
 $T_r$  Dynamic  Constant  200,000  150,000  Gas  $T_r^{\text{B52}}$ is likely to have the $k_1 f(N_{provers}) + k_2$ form although it could potentially be approximated by an constant. $T_r^{\text{Fernet}}$ is expected to be between [1, 100] times smaller on average than B52, with guessestimate on 1.33x 
 $T_\pi$  Dynamic (?)  Constant  26,400  2,400  Gas  The unit gas cost is 800 and it is multiplied by the rewards recipients count, which is assumed to be equal to $n_\pi=1 + N_u$ on the Fernet case, and $n_\pi=1 + N_u + N_{\text{provers}}$ on the B52 case. 
## Analysis
### B52 vs Fernet Direct Comparison
By plugging the Section 4 numbers on Section 3 metrics, we're able to provide an direct comparison between both proposals in terms of L1 costs. An notebook for that can be found at this [link](https://github.com/BlockScience/aztec/blob/39141dfa6fa275a74072187ced9d2029fd4e8622/notebooks/aztec_b52_vs_fernet.ipynb).
The first numerical result is that under the baseline assumptions, Fernet is going to have 7.8% less coordination costs when compared to B52. Specifically, it is expected that Fernet will incur an 0.065 ETH in total cost and B52 will incur 0.070 ETH. When dividing per transaction count, then the value becomes 0.0000317 ETH/tx for Fernet and 0.0000344 ETH/tx for B52.
Additionally, by leaving an variable free while the others being fixed, it is possible to perform an limited sensitivity analysis of the Fernet advantage under various cirumcunstances, such as number of transactions, Blob Gas Price and Gas Price. We can observe the following: 1) Fernet relative advantage becomes smaller as the number of transactions go up, 2) Larger Blob Gas Prices tends to decrease Fernet's relative advantage and 3) Larger Gas Prices tends to increase Fernet's relative advantage.
 Number of Transactions  Blob Gas Price  Gas Price 
      
![](https://hackmd.io/_uploads/H1n8zeO2h.png)![](https://hackmd.io/_uploads/BkQmgO3n.png)![](https://hackmd.io/_uploads/SycbQeOhn.png)

![](https://hackmd.io/_uploads/BJkFze_32.png)![](https://hackmd.io/_uploads/SkhGQgdh2.png)![](https://hackmd.io/_uploads/ryW7Qeu2h.png)
Also, we can notice that Fernet's advantage only holds while the number of proposers is low, and it can quickly go down. In fact, under baseline assumptions B52 starts to be advantageous after the number of proposers is above circa 150. We can also observe that Fernet's advantage is highly dependent on the Rollup Scoring Logic gas costs.
 Rolling Scoring Logic  Number of Proposers 
    
![](https://hackmd.io/_uploads/SJw4Xeuh3.png) ![](https://hackmd.io/_uploads/Bkw4gO22.png)
Further analysis can explicit include the uncertainty ranges that are expressed on Section 4 as well as to include the stochastic effects of price.
### Blob Storage
The Baseline Assumption expects a 4.10MB worth usage of Blob Bytes per Rollup. This is 11x the Target Blob Bytes, and 5.5x the Maximum Blob Bytes. This is somewhat problematic, as it means:
1. A rollup that depends on the current state of EIP4844 would require at minimum 5.5x L1 blocks to be viable.
2. In practice, due to the EIP4844 pricing mechanism and competiting blob storage users, it is unlikely that rollups could sustainbly be performed within less than 11 blocks.
One reason for concern is that the available Blob Storage goes down, as the Blob Gas Price increases, as the Maximum Blob Gas Fee is capped. For instance, a Blob Gas Price of 10 Gwei implies that 78.4kB worth of maximum blob storage would be available. This is problematic for protocols that require predictable throughput, as it creates a reinforcing feedback loop of insuficient throughput increasing price which then reduces throughput even more. More details can be found on the [EIP4844 Research Notes](/k2zCTJ2bQZOm6cvrj71w4Q) document.
Assuming that the Blob Gas price is 1 Gwei per BlobByte, and assuming that the Blob Storage would always be at target, then the expected throughput is `32.0 kB/s` or `1.9MB/min` or `112.5 MB/hr` or `2.6 GB/day`. The rollup blob storage throughput is only feasible if below those numbers (and conditional on usage from other actors)
Assuming that time is not an concern (eg. rollups could be spread among infinitely many blocks), then Blob Storage Price is only going to be an relevant Coordination Cost after the Blob Gas Price price is above `30 Gwei` per BlobBytes, which maximally renders `25.6 kB` worth of blobs per block, or an throughput of `2.1 kB/s`.
## Key Learnings
1. Under baseline assumptions, Fernet is expected to have lower coordination costs on L1 than B52 by ~8%. Specifically, we highlight the following uncertainty points.
 (favorable to B52) There is the possibility, that B52 would be cheaper than Fernet if the number of block proposers is high (around ~150 proposers under baseline assumptions). This is because the `CallData` for proposing is expected to be somewhat more expensive on Fernet (around ~3.7%)
 (favorable to Fernet) There is a large degree of uncertainty around Fernet costs on the Rollup Scoring Logic. Our baseline assumption is that it costs 75% of B52, however this could be way lower, while the B52 cost is potentially dynamic. Taken together, it is likely that the uncertainty around the actual gas costs tends to favor Fernet.
 (favorable to Fernet) B52 may incur additional L1 gas costs due to the possibility of rewarding provers during the finalization phase.
2. Under the Baseline Assumptions, the average total L1 overhead cost is estimated to be 0.0070 ETH for Fernet and 0.0065 ETH for B52
 With the 2048 transactions to be rolledup assumption, this gives an 0.0000343 ETH/tx for B52 and 0.0000317 ETH/tx for Fernet
4. Blob Storage is not directly relevant to the Decision among the two proposals as per Coordination Costs.
5. Blob Storage & Pricing as per the EIP4844 spec may not be operationally sustainable as there's an significant Congestion risk due to insufficient Blob Throughput.
 Specifically, the Maximum Storage that can be stored on Blob Storage is conditional on the Blob Gas Price. Specifically: `MaxBlobFee = 768kB equivalent of 1 Blob Gas = 1 Gwei`. If the Blob Price doubles, then `MaxBlobFee = 384kB equivalent of 1 Blob Gas = 2 Gwei`.
 This can be particularly problematic, as the baseline assumption expects
## Recommendations
1. Under an exclusive L1 Coordination Cost objective, Fernet is to be selected over B52.
 This recommendation becomes uncertain if the Number of Block Proposers is expected to be mostly above `200`
2. Further research, mostly focused on vulnerabilities & attack vectors, is to be done over the implications of using EIP4844 Blob Storage, as well as to explore options and their tradeoffs if the Blob Storage usage asis is shown to be infeasible.