A Quick Introduction to Transaction Fees in Mantle
Understanding Fee Basics on Mantle Network
Transaction fees on Mantle network are similar to those on Ethereum. However, as Mantle Network operates as a layer 2 (L2) blockchain, there are new paradigms in the fee structure that distinguish it from Ethereum's fees.
As Mantle Network continuously enhances its EVM compatibility, dApps can conveniently adapt to any changes with minimal modifications. Let's explore the two sources of transaction costs on Mantle:
- L2 Execution Fee
- Cost of executing transactions on L2
- L1 Rollup Fee
- Cost of submitting rollup state root to L1 (distributed equally among users whose transactions are included in the batch)
- Write data credentials submitted to the DA contract on L1
The L2 Execution Fee
Similar to Ethereum, transactions on Mantle Network must pay the gas fee for the computational and storage resources used. Each L2 transaction incurs some execution fees, calculated as the product of the gas used and the gas price associated with the transaction.
Mathematically, this is represented as:
This fee reflects the computational and execution costs of completing transactions on the L2 network. The L2 execution fee paid by users is directly proportional to the computational and network resources consumed by their transactions.
The L1 Rollup Fee
All state roots generated on L2 due to transaction execution are published to Ethereum. This step is crucial for the security properties of L2, ensuring that all the latest block data from the L2 network is consistently available on Ethereum L1 for sync nodes.
L2 aggregates states and essential transaction data into batches, publishing them to Ethereum, with the cost distributed among users whose transactions are included in the batch. The L1 rollup Fee is calculated based on factors such as:
- The current gas price on Ethereum
- A fixed
overhead
(a fixed cost for committing data to L1, auto-adjusted and set into gas oracle) - The scaling factor
scalar
- Parameters related to the size of the transaction are stored as calldata in L1 called
rollupDataGas
Values such as overhead
and scalar
can be obtained through the BVM_GasPriceOracle
contract or SystemConfigProxy
contract.
We highly recommend fetching the overhead
and scalar
from the BVM_GasPriceOracle
contract. L1 Contracts may be subject to update delays.
Mathematically, this is represented as:
This fee covers the computational costs of integrating and submitting transaction batches from L2 to L1, including the gas needed for data storage and additional overhead. The L1 rollup fee is a crucial component ensuring the overall system's secure operation and also affects the overall transaction costs.
For a more in-depth understanding, it is highly recommended to read the Mantle research team's study on fees in Rollups: Transaction Fees on Rollups
Understanding Fees on Mantle v2 Tectonic
In Mantle v2 Tectonic, the introduction of Mantle's native token design incorporates a tokenRatio
parameter to adjust the fee:
L2 Execution Fee in Mantle v2 Tectonic
The size of the L2 Execution Fee is primarily influenced by two key factors that directly shape the cost of executing transactions on L2.
Let's delve into these factors:
L2 gasUsed - Complexity of Transaction Execution
L2 gasUsed is the amount of gas consumed to execute a transaction on layer 2. This value is directly related to the complexity of the transaction and reflects the amount of work involved in executing the contract, computing, and processing the data. As a result, more complex transactions typically require more gas to complete, directly affecting the size of the L2 execution fee. This factor ensures that the transaction fee is proportional to the actual computational resources used.
L2 gasPrice - Depends on the transaction type
L2 gasPrice is the unit price of gas used on L2, which depends on the specific transaction type chosen. L2 gasPrice is calculated differently for different transaction types:
- For EIP-1559 transaction types, L2 gasPrice is affected by the
GasTipCap
parameter, which is a parameter that is issued as a reward to sequencers and can be set to0
by the user and does not affect the packing of transactions. - For legacy transaction types,
GasTipCap
takes the default value (0.1 GWEI). In this case,eth_gasPrice
is equal to the sum ofGasTipCap
andBASEFEE
. This mechanism ensures the relative stability of the transaction costs, while providing the user with default values and simplifying the setup of the transaction parameters.
Due to EVM compatibility, transactions on Mantle Network generally have similar gasUsed
to Ethereum. Gas prices fluctuate with time and congestion, but you can always check the current estimated L2 Gas prices on the public Mantle dashboard. Moreover, as gas fees on Mantle Network are denominated in $MNT
, transaction costs remain significantly lower than other L2 networks using $ETH as the gas token, even at the same gas price.
L1 Rollup Fee in Mantle v2 Tectonic
Since the cost of transaction on L1 is much higher than that of transaction on L2, this is the largest part of the total transaction cost, and calculating the cost of L1 is a complex task due to the volatility of gasPrice in L1.
Let's delve into these factors:
rollupDataGas
Calculation
The major portion of the L1 gas fee is rollupDataGas
, which relates to the size of the transaction stored as calldata in L1, and typically accounts for more than 85% of the L1 GasUsed.
Mantle v2 Tectonic chooses the Op Stack's rollupDataGas calculation, which counts the number of zero bytes and non-zero bytes in the transaction data, with each zero byte costing 4 Gas and each non-zero byte costing 16 Gas, thus:
With the EigenDA-powered Mantle DA module online with Mantle Mainnet, only state roots and a limited amount of necessary transaction data are sent to L1, while the transaction batch data is posted to the DA network. For dApps with high gas consumption, they can be executed at the same cost as an ordinary transaction (like a transfer), and the L1 fee will not increase with the complexity of L2 transaction execution. As a result, for transactions with high complexity, this can even save up to more than 90% of the cost compared to the original L1 rollup fee.
Fetch overhead
and scalar
overhead
and scalar
are currently loaded from configurations, not supporting dynamic changes, you can fetch them from the BVM_GasPriceOracle
contract, while L1gasPrice
needs to be read from L1 blocks.
Control of tokenRatio
tokenRatio
is a parameter adjusting fees in Mantle. By obtaining prices for ETH and MNT from multiple price oracles and calculating their exchange rate (eth_price/mnt_price
), Mantle v2 Tectonic limits the value of the current tokenRatio
to the interval of the previous tokenRatio
to prevent sudden and significant fluctuations in gasPrice caused by abrupt changes in the exchange rate.
Mantle v2 Tectonic introduces a BVM_GasPriceOracle
contract in Layer 2 to manage permissions for setting and updating tokenRatio
. Users with permission (a multi-signature address managed through HSM) can update tokenRatio
through an L2 transaction, dynamically adjusting gas fees.
Fee Optimization
Compared to Mantle v1, Mantle v2 Tectonic has made improvements and optimizations in fee design, including:
- EIP-1559 Support: Mantle v2 Tectonic will support various transaction types, including EIP-1559, freeing users from the constraints of old transaction structures. For more details, refer to this. (We highly recommend you to set the
baseFee
to0.02 gwei
andpriorityfee
to0
in your L2 transaction. Refer to this for more details.) - Fee Estimation: The
estimateGas
API in Mantle v1 only returns the L2 gas cost, the L1 gas estimation needs to be calculated separately, while in Mantle v2 Tectonic it will support returning the total gas of the user's transaction directly. Developers also need to be mindful of the impact this optimization may have on transaction construction. For more details about how to calculate the gas fee, refer to this.
Mantle v2 Tectonic Fee Showcase
Mantle v2 Tectonic | Mantle v1 Alpha | |
---|---|---|
Token Transfer | 0.0047 MNT | 0.3715 MNT |
ERC-20 Contract Deployment | 0.1088 MNT | 0.1304 MNT |