How gas fees work in Ethereum
In Ethereum, there are two adjustable parameters that have a direct impact on transaction gas fees:- The , 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.
- The , 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.
Computing L2 gas fees
The L2 gas price cannot simply be set to be the same as the L1 gas price (especially in the case of rollups where the goal is to reduce gas fees). Hence, we make the distinction between the two gas prices, and denote them as and respectively. It is important to calculate the appropriate L2 gas price while ensuring that transactions are successfully executed. Although the same formula is used, that is, and success is guaranteed if is greater than , the gas used is determined by the gas cost for data availability plus the gas cost for transaction execution in L2. That is, The total fees paid by the user is given by: Note that data availability is charged in L1 using the prevailing L1 gas price at the time of posting data. The main challenge is adjusting in terms of the to account for L2 resources spent when processing transactions. The general strategy is to use an such thatExample (L1 gas price factor)
For a transaction with an L1 gas price of 20 Gwei, the L2 gas price in the Polygon zkEVM network is calculated using a 4% factor as follows: Current L2 fees can be viewed here https://l2fees.info. The is used in the Polygon zkEVM network and is set to . There are a few complications that need to be carefully considered. There are 3 scenarios we aim to avoid when determining the to sign transactions with:- Transactions getting rejected due to the being less than L2’s minimum expected gas price ().
- Incurring losses in the L2 network because of high transaction gas costs.
- Transactions receiving the least priority for sequencing.