Skip to content

Commit ae3fbba

Browse files
Apply suggestions from code review
Co-authored-by: Dra Murphy <149679879+kmurphypolygon@users.noreply.github.com>
1 parent ae56b29 commit ae3fbba

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

docs/zkEVM/architecture/effective-gas/implement-egp-strat.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ $$
7474

7575
where $\texttt{DataCost}$ is the cost in gas for data stored in L1.
7676

77-
The cost of data in Ethereum varies according to whether it involves zero bytes or non-zero bytes. In particular, non-zero bytes cost $16$ gas units, while zero bytes cost $4$ gas unints.
77+
The cost of data in Ethereum varies according to whether it involves zero bytes or non-zero bytes. In particular, non-zero bytes cost $16$ gas units, while zero bytes cost $4$ gas units.
7878

79-
Also, recall that the computation of the cost for _non-zero bytes_ must take into account the constant data which always appear in a transaction but not included in the RLP:
79+
Also, recall that the computation of the cost for _non-zero bytes_ must take into account constants that appear in transactions but are not included in the RLP, which includes:
8080

8181
- The signature, which consists of $65$ bytes.
82-
- The previously defined $\texttt{EffectivePercentageByte}$, which consists in a single byte.
82+
- The previously defined $\texttt{EffectivePercentageByte}$, which consists of a single byte.
8383

8484
This results in a total of $66$ constantly present bytes.
8585

86-
Taking all in consideration, $\texttt{DataCost}$ can be computed as:
86+
Taking everything into consideration, $\texttt{DataCost}$ can be computed as:
8787

8888
$$
8989
\texttt{DataCost} = (\texttt{TxConstBytes} + \texttt{TxNonZeroBytes}) \cdot \texttt{NonZeroByteGasCost} \\
@@ -94,9 +94,9 @@ where $\texttt{TxNonZeroBytes}$ represents the count of non-zero bytes in a raw
9494

9595
#### Computational costs
9696

97-
Costs associated with transaction execution is denoted by $\texttt{ExecutionCost}$, and it is measured in gas.
97+
Costs associated with transaction execution is denoted by $\texttt{ExecutionCost}$, and is measured in gas.
9898

99-
In contrast to costs for data availability, calculating computational costs necessecitates transactions to be executed.
99+
In contrast to costs for data availability, calculating computational costs requires executing transactions.
100100

101101
So then,
102102

@@ -144,11 +144,11 @@ $$
144144
\texttt{SignedGasPrice} > \texttt{BreakEvenGasPrice}.
145145
$$
146146

147-
However, a problem arises:
147+
However, a problem arises:
148148

149149
In the RPC component, we’re only pre-executing the transaction, meaning we’re using an incorrect state root. Consequently, the $\texttt{GasUsed}$ is only an approximation.
150150

151-
This implies that we need to multiply the result by a chosen factor before comparing it to the signed price.
151+
This implies that we need to multiply the result by a chosen factor before comparing it to the signed price to hedge against unforeseen costs.
152152

153153
This ensures that the costs are covered in case more gas is ultimately required to execute the transaction. This factor is named $\texttt{BreakEvenFactor}$.
154154

@@ -160,7 +160,7 @@ $$
160160

161161
then it is safe to accept the transaction.
162162

163-
Observe that we still need to introduce gas price prioritization, which will be covered later on.
163+
Observe that we still need to introduce gas price prioritization, which we explain later.
164164

165165
### Example (Breakeven gas price)
166166

@@ -170,11 +170,11 @@ The figure below depicts the current situation.
170170

171171
![Figure: Timeline current L1GasPrice](../../../img/zkEVM/timeline-current-l1gasprice.png)
172172

173-
Suppose the user sends a transaction that has $200$ non-zero bytes, including the constant ones and $100$ zero bytes.
173+
Suppose the user sends a transaction that has $200$ non-zero bytes, including the constants and $100$ zero bytes.
174174

175-
Moreover, at the time of pre-executing the transaction, which is done without getting an out-of-counters (OOC) error, $60,000$ gas units are consumed.
175+
Moreover, on pre-executing the transaction without an out-of-counters (OOC) error, $60,000$ gas units are consumed.
176176

177-
Recall that, since we are using a "wrong" state root, this gas is only an estimation.
177+
Recall that, since we are using a "wrong" state root, this amount is only an estimation.
178178

179179
Hence, using the previously explained formulas, the total transaction cost is:
180180

@@ -195,7 +195,7 @@ $$
195195

196196
We have introduced a $\texttt{NetProfit}$ value of $1.2$, indicating a target of a $20\%$ gain in this process.
197197

198-
At a first glance, we might conclude acceptance since:
198+
At first glance, we might conclude the transaction has been accepted:
199199

200200
$$
201201
\texttt{SignedGasPrice} = 3.3 > 2.52
@@ -209,7 +209,7 @@ $$
209209
\texttt{SignedGasPrice} = 3.3 > 3.276 = 2.52 · 1.3 = \texttt{BreakEvenGasPrice} \cdot \texttt{BreakEvenFactor}
210210
$$
211211

212-
Consequently, we decide to accept the transaction.
212+
Consequently, the system accepts the transaction.
213213

214214
### Example (Breakeven factor)
215215

@@ -223,11 +223,11 @@ $$
223223

224224
However, let's assume the correct execution at the time of sequencing consumes $35,000$ gas.
225225

226-
If we recompute $\texttt{BreakEvenGasPrice}$ using this updated used gas, we get $3.6\ \texttt{GWei/Gas}$, which is way higher than the original one.
226+
If we recompute $\texttt{BreakEvenGasPrice}$ using this updated used gas, we get $3.6\ \texttt{GWei/Gas}$, which is way higher than the original estimation.
227227

228228
That means we should have charged the user a higher gas price in order to cover the whole transaction cost, standing at $105,000\ \texttt{GWei}$.
229229

230-
But, since we are accepting all the transactions that sign more than $2.85$ of gas price, we do not have any margin to increase more.
230+
But, since we are accepting all the transactions that sign more than $2.85$ of gas price, we do not have any margin to increase it.
231231

232232
In the worst case we are losing:
233233

@@ -249,4 +249,4 @@ $$
249249
105, 000 − 35, 000 · 3.27 < 0
250250
$$
251251

252-
**Final Note**: In the above example, even though we assumed that a decrease in the $\texttt{BreakEvenGasPrice}$ is a result of executing with a correct state root, it can also decrease significantly due to a substantial reduction in $\texttt{L1GasPrice}$.
252+
**Final Note**: In the above example, even though we assume that a decrease in the $\texttt{BreakEvenGasPrice}$ is a result of executing with a correct state root, it can also decrease significantly due to a substantial reduction in $\texttt{L1GasPrice}$.

docs/zkEVM/architecture/effective-gas/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Now that the EGP is in place, you can reduce any chance for a transaction revert
66

77
## How gas fees work in Ethereum
88

9-
There are two adjustable parameters, in Ethereum, that have a direct impact on transaction gas fees:
9+
In Ethereum, there are two adjustable parameters that have a direct impact on transaction gas fees:
1010

1111
- The $\texttt{gasLimit}$, which is the maximum amount of gas units the user is willing to buy in order for their transactions to be included in a block and processed on chain.
1212
- The $\texttt{gasPrice}$, that is, the amount of ETH a user is willing to pay for 1 gas unit. For instance, a gas price of 10 Gwei means the user is willing to pay 0.00000001 ETH for each unit of gas.

docs/zkEVM/architecture/effective-gas/user-tx-flow/rpc-flow-egp.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ The RPC flow is summarized in the figure below.
5959

6060
## Example (RPC tx flow)
6161

62-
Consider a scenario where a user sends a query for a suggested gas price during a certain 5-minute interval, as shown in the figure below.
62+
Consider a scenario where a user sends a query for a suggested gas price during a 5-minute interval, as shown in the figure below.
6363

64-
Values of L1 gas prices polled every 5 seconds are displayed above the timeline, while the corresponding L2 gas prices are depicted below the timeline. See the figure below.
64+
Values of L1 gas prices, polled every 5 seconds, are displayed above the timeline, while the corresponding L2 gas prices are depicted below the timeline. See the figure below.
6565

6666
![Figure: Suggested gas price (first)](../../../../img/zkEVM/timeline-current-l1gasprice-suggstd.png)
6767

68-
6968
1. Observe that, in the above timeline, the user sends a query at the time indicated by the dotted-arrow on the left. And that's when $\texttt{L1GasPrice}$ is $19$.
7069

71-
The RPC node therefore responds with a $2.85 \texttt{ GWei/Gas}$, as the value of the suggested L2 gas price.
70+
The RPC node responds with a $2.85 \texttt{ GWei/Gas}$, as the value of the suggested L2 gas price.
7271

7372
This value is obtained as follows:
7473

@@ -78,7 +77,7 @@ Values of L1 gas prices polled every 5 seconds are displayed above the timeline,
7877

7978
where $0.15$ is the zkEVM's suggested factor.
8079

81-
2. Let's suppose the user sends a transaction signed with a gas price of $3$. That is, $\texttt{SignedGasPrice} = 3$
80+
2. Let's suppose the user sends a transaction signed with a gas price of $3$. That is, $\texttt{SignedGasPrice} = 3$.
8281

8382
However, by the time the user sends the signed transaction, the L1 gas price is no longer $19$ but $21$. And its correponding suggested gas price is $\mathtt{3.15 = 21 \cdot 0.15}$.
8483

@@ -116,13 +115,13 @@ Values of L1 gas prices polled every 5 seconds are displayed above the timeline,
116115
\texttt{BreakEvenGasPrice} \cdot \texttt{BreakEvenFactor} = 2.52 \cdot 1.3 = 3.276
117116
$$
118117

119-
And since $\texttt{SignedGasPrice} = 3 < 3.276$, the transaction is not immediately stored in the pool of transaction.
118+
And since $\texttt{SignedGasPrice} = 3 < 3.276$, the transaction is not immediately stored in the transaction pool.
120119

121120
6. However, since
122121

123122
$$
124123
\texttt{SignedGasPrice} = 3 ≥ 2.85 = \texttt{GasPriceSuggested}
125124
$$
126125

127-
and despite the risk of the network sponsoring the transaction, it is included into the transaction pool.
126+
and despite the risk of the network sponsoring the transaction, it is included in the transaction pool.
128127

docs/zkEVM/architecture/effective-gas/user-tx-flow/sequencer-flow-egp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In this phase of the end-to-end transaction flow, transactions go through differ
3434
![Figure: Sequencer flow](../../../../img/zkEVM/tx-flow-seq-component.png)
3535

3636

37-
### Example (Sequencer Flow)
37+
### Example (Sequencer flow)
3838

3939
Let's continue the numerical example we have been using throughout this document.
4040

@@ -53,7 +53,7 @@ $$
5353

5454
Recall how we previously obtained the $\texttt{BreakEvenGasPriceRPC}$ of $2.52\ \texttt{GWei/Gas}$.
5555

56-
According to the above figure, the network recommends a gas price of $3$, which corresponds to an L1 gas price of $20$.
56+
According to the figure above, the network recommends a gas price of $3$, which corresponds to an L1 gas price of $20$.
5757

5858
This results in the following priority factor:
5959

@@ -93,15 +93,15 @@ $$
9393

9494
which is bigger than the RPC-estimated gas of $60,000$.
9595

96-
4. With the new $\texttt{GasUsedNew}$, an adjusted effective gas price ($\texttt{NEGP}$) can be computed in the following steps.
96+
4. With the new $\texttt{GasUsedNew}$, an adjusted effective gas price ($\texttt{NEGP}$) can be computed by the following steps.
9797

9898
Firstly, the total transaction cost:
9999

100100
$$
101101
\texttt{TxCostNew} = (200 · 16 + 100 · 4) · 20 + 95,000 · 20 · 0.04 = 148,000 \ \texttt{GWei}
102102
$$
103103

104-
It is assumed that the transaction has 200 non-zero bytes and 100 zero bytes.
104+
We assume that the transaction has 200 non-zero bytes and 100 zero bytes.
105105

106106
Secondly, the new breakeven gas price:
107107

@@ -122,7 +122,7 @@ $$
122122
\end{aligned}
123123
$$
124124

125-
Observe that the transaction cost is way higher than the RPC-estimated one of $126,000$ even when the L1 gas price has decreased from 21 to 20 due to a huge increase in gas.
125+
Observe that the transaction cost is much higher than the RPC-estimation of $126,000$, even when the L1 gas price has decreased from 21 to 20 due to a huge increase in gas.
126126

127127
5. Observe that there is a significant deviation between both effective gas prices:
128128

0 commit comments

Comments
 (0)