Skip to content

Commit 74cd965

Browse files
authored
Merge pull request 0xPolygon#270 from 0xPolygon/edit-user-fees
Update zkEVM docs - Edit "User fees" doc
2 parents f14da71 + bf0ab08 commit 74cd965

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

docs/zkEVM/architecture/user-fees.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
The aim with this document is to describe the Effective Gas Price (EGP), a mechanism by which the Polygon zkEVM network charges gas fees in a more fair and accurate manner. These fees cover L1 data-availability and L2 execution costs. It is meant to help users set the $\texttt{gasPrice}$ such that there's little chance for a transaction revert or failure.
22

33

4-
54
## Basic Ethereum fee schema
65

76
Let's make a quick recollection of the basic fee schema used in Ethereum.
@@ -38,8 +37,7 @@ $$
3837
\texttt{initialBalance} − \texttt{gasLimit} \cdot \texttt{gasPrice}
3938
$$
4039

41-
where $\texttt{initialBalance}$ represents the balance of the source account before the execution of the transaction.
42-
40+
where $\texttt{initialBalance}$ represents the balance of the source account before the execution of the transaction.
4341

4442

4543
## Generic gas fee strategy for L2s
@@ -82,19 +80,15 @@ Their corresponding pertinent questions are:
8280
- How do L2 solutions address and reconcile any discrepancies between the L1 gas schema and the real resource utilization on L2?
8381

8482

85-
8683
### Time-related variations
8784

8885
So, how can the fact that the L1 $\texttt{gasPrice}$ varies with time be taken into account?
8986

9087
In order to obtain L1 gas prices, we can poll for it every 5 seconds. As shown in the timeline below, gas prices vary with time.
9188

92-
93-
9489
![Figure: Gas price timeline](../../img/zkEVM/gas-timeline-001.png)
9590

9691

97-
9892
## Gas price suggester
9993

10094
Let's take a quick view of the initial phase of the process, which involves the RPC component of zkEVM.
@@ -107,12 +101,9 @@ Pre-execution of a transaction involves the following stages:
107101

108102
See the the picture below for an overview of the pre-execution process.
109103

110-
111-
112104
![Figure: RPC tx pre-execution](../../img/zkEVM/rpc-tx-preexec.png)
113105

114106

115-
116107
### Naïve approach
117108

118109
Let's look at this in two parts; gasPrice suggestion, and transaction sending.
@@ -426,7 +417,18 @@ where $\texttt{TxNonZeroBytes}$ represents the count of non-zero bytes in a raw
426417

427418
### Computational costs
428419

429-
Computational cost is calculated with the following formula:
420+
421+
Costs associated with transaction execution is denoted by $\texttt{ExecutionCost}$, and it is measured in gas.
422+
423+
In contrast to costs for data availability, calculating computational costs necessecitates transactions to be executed.
424+
425+
So then,
426+
427+
$$
428+
\texttt{GasUsed} = \texttt{DataCost} + \texttt{ExecutionCost}
429+
$$
430+
431+
The total fees received by L2 are calculated with the following formula:
430432

431433
$$
432434
\texttt{GasUsed} \cdot \texttt{L2GasPrice}
@@ -440,7 +442,7 @@ $$
440442

441443
In particular, we choose a factor of $0.04$.
442444

443-
In contrast to costs for data availability, calculating computational costs necessecitates transactions to be executed.
445+
444446

445447

446448

@@ -838,11 +840,7 @@ Let’s examine the above figure in more detail.
838840
Recall that the $\texttt{GasUsedRPC}$ is obtained in the RPC pre-execution using;
839841

840842
- A previous state root, which has now changed, and
841-
- The current $\texttt{L1GasPrice}$, which may also differ from the one used when sending the transaction to the RPC, for all the transactions stored in the Pool, and sequence the one having higher $\texttt{EEGP}$.
842-
843-
It is important to note that this should be done in this precise order.
844-
845-
We could have calculated the $\texttt{EEGP}$ just before storing the transactions in the Pool and sorting it by EEGP, but this would not yield the same result because the $\texttt{L1GasPrice}$ at that moment is different from the one at the time of sequencing a transaction, potentially changing the $\texttt{EEGP}$ as well as the prioritization order of transactions.
843+
- The current $\texttt{L1GasPrice}$, which may also differ from the one used when sending the transaction to the RPC.
846844

847845
2. At this point, we have two options:
848846

0 commit comments

Comments
 (0)