Mantle 백서

Mantle

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 37쪽 중 6쪽

Mechanism**: * In each transaction, take the smallest value of `GasTip` and `(GasFeeCap - BaseFee)` and multiply it by `gasUsed` as an award to the validator, have it collected in [SequencerFeeVault](https://github.com/mantlenetworkio/mantle-v2/blob/develop/specs/predeploys.md#sequencerfeevault), and support withdrawal to L1. * Mantle v2 Tectonic, in an effort to further reduce fees, chose the [FIFO](https://en.wikipedia.org/wiki/FIFO) method of transaction sequencing to minimize the impact of `priorityfee`. Through these adjustments, Mantle v2 Tectonic builds on EIP-1559 to provide a more flexible and efficient transaction fee management mechanism. {% hint style="info" %} Mantle v2 Tectonic sets a very low `BASEFEE`, we also recommend that you set the `MaxPriorityFeePerGas` of your EIP-1559 transactions to 0, so that your transaction fees will be very low!<br> {% endhint %} # Estimate Fees ## Estimate Fees in Mantle v2[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#estimate-fees-in-mantle-v2-tectonic) <a href="#estimate-fees-in-mantle-v2-tectonic" id="estimate-fees-in-mantle-v2-tectonic"></a> Concerning the selection of the gas fee token on Rollup, Mantle v2 departs from the conventional ETH solution adopted by most rollups, and employs MNT instead. This introduces a variable called [`tokenRatio`](/network/system-information/fee-mechanism#control-of-tokenratio) for dynamic adjustment of gas fees. The overall gas fee calculation is as follows: $$ L2ExecutionFee=L2gasPrice∗L2gasUsed∗tokenRatio $$ $$ L1RollupFee=(rollupDataGas+overhead)∗L1gasPrice∗tokenRatio∗scalar $$ Let's break down the variables involved. Both `scalar` and `overhead` are retrieved from the [`BVM_GasPriceOracle`](/network/system-information/off-chain-system/key-l2-contract-address) contract, while `L1gasPrice` can be obtained from layer 1 (L1). `tokenRatio` is a variable updated through an external Oracle contract, which you can fetch from the [`BVM_GasPriceOracle`](/network/system-information/off-chain-system/key-l2-contract-address) contract. Therefore, obtaining `L2gasPrice` and `rollupDataGas` allows the calculation of a suitable `gasLimit`. {% hint style="info" %} **Why is a suitable gasLimit necessary?** Determining an appropriate `gasLimit` is crucial. If the `gasLimit` is set too low, the transaction may fail to execute. If set too high, the computed upfront transaction fee might exceed the user's balance, leading to insufficient funds. Additionally, setting a high `gasLimit` may discourage validators from including the transaction in a block, as validators tend to prefer including more transactions with lower `gasLimit` within the fixed block `gasLimit`. Therefore, estimating the fee is a pivotal step. The Rollup block gasLimit for Mantle can be checked [here](https://etherscan.io/address/0x427Ea0710FA5252057F0D88274f7aeb308386cAf#readProxyContract#F5), currently set at 200,000,000,000. {% endhint %} ### How to Obtain Parameters for`BVM_GasPriceOracle`[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#how-to-obtain-parameters-for-bvm_gaspriceoracle) <a href="#how-to-obtain-parameters-for-bvm_gaspriceoracle" id="how-to-obtain-parameters-for-bvm_gaspriceoracle"></a> #### **`overhead`**[**​**](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#overhead) ``` cast call --rpc-url https://rpc.mantle.xyz 0x420000000000000000000000000000000000000F 'overhead()(uint256)' ``` #### **`scalar`**[**​**](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#scalar) ``` cast call --rpc-url https://rpc.mantle.xyz 0x420000000000000000000000000000000000000F 'scalar()(uint256)' ``` You need to divide the value you get by `1,000,000` to get the true scalar value. For example, if the value you get is `10,000`, you need to divide it by `1,000,000` to get `0.01`. #### **`tokenRatio`**[**​**](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#tokenratio) ``` cast call --rpc-url https://rpc.mantle.xyz 0x420000000000000000000000000000000000000F 'tokenRatio()(uint256)' ``` #### **`L1gasPrice`**[**​**](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#l1gasprice) Also known as `L1BaseFee`. ``` cast call --rpc-url https://rpc.mantle.xyz 0x420000000000000000000000000000000000000F 'l1BaseFee()(uint256)' ``` ### How to Obtain L2 gasPrice[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#how-to-obtain-l2-gasprice) <a href="#how-to-obtain-l2-gasprice" id="how-to-obtain-l2-gasprice"></a> Different transaction types, such as Legacy and EIP-1559 transactions, require distinct handling. For detailed information, please refer to [this](/network/system-information/fee-mechanism#l2-gasprice-depends-on-the-transaction-type). ### How to Obtain rollupDataGas[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#how-to-obtain-rollupdatagas) <a href="#how-to-obtain-rollupdatagas" id="how-to-obtain-rollupdatagas"></a> It's essential to note that `rollupDataGas` is not constructed during the `estimateGas` process in the OP Stack codebase. Thus, an interface is needed to estimate the cost. Mantle addresses this by constructing `rollupDataGas` and introducing a constant to cover `V`, `R`, `S` signatures, and other data, ensuring that the `estimateGas`'s `gasLimit` covers L1 costs. We provide interfaces that return `L1GasUsed` data directly, i.e., the sum of `(rollupDataGas + overhead)` ``` # _data is rlp-encoded data of the signed tx cast call --rpc-url https://rpc.mantle.xyz 0x420000000000000000000000000000000000000F 'getL1GasUsed(_data)(uint256)' ``` If you want to learn more, please refer to [this](/network/system-information/fee-mechanism#rollupdatagascalculation). ### Ensuring transaction success[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#ensuring-transaction-success) <a href="#ensuring-transaction-success" id="ensuring-transaction-success"></a> `estimateGas` provides only an estimate. To prevent transaction failure due to insufficient gas fees, Mantle Network internally magnifies the estimate by a factor, ensuring the correct execution of transactions. ## Why Do We Need to Use`estimateGas`[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#why-we-need-to-use-estimategas) <a href="#why-we-need-to-use-estimategas" id="why-we-need-to-use-estimategas"></a> The cost of fees on L1 is difficult to predict accurately due to the influence of L1 gasPrice, therefore, in Mantle v1, the `estimateGas` function only returns an estimate of the L2 gas fee. However, in Mantle v2, we have addressed this issue by providing an optimized solution. The `estimateGas` interface now returns an estimate of the total gas fee, including both L1 and L2 costs. Consequently, when constructing transactions, adjustments need to be made to accommodate this optimization. We encourage all transactions to first call `estimateGas` to obtain an estimate of the gas fee before construction. ### Example[​](https://docs-v2.mantle.xyz/devs/concepts/tx-fee/ef#example) <a href="#example" id="example"></a> Here is an example illustrating the difference in `gasLimit` settings for transaction construction between Mantle v1 and Mantle v2. In Mantle v1, the `gasUsed` on a typical native token transfer on L2 is a fixed value (21,000), so developers might opt to skip calling `estimateGas` and set it to a fixed value. <img src="https://docs-v2.mantle.xyz/assets/images/mantle-v1-gas-ad78f23e971e23c1d8e5f18753ca574f.png" alt="" height="172" width="788"> However, in Mantle v2, the `gasLimit` that developers need to set when constructing transactions will include both L1 and L2 components, so without calling `estimateGas` and setting it to a fixed value may result in transaction failures. <img src="https://docs-v2.mantle.xyz/assets/images/mantle-v2-gas-7bd15eb1c0d692e6048692211fbedd16.png" alt="" height="189" width="770"> **To avoid transaction failures, we recommend calling `estimateGas` when constructing transactions to obtain an estimate of the gas fee.** {% hint style="info" %} If you want to do `estimateGas` with the Mantle SDK, here's a [demo](https://github.com/mantlenetworkio/mantle-tutorial/tree/main/sdk-estimate-gas). {% endhint %} # Fee Model Handbook (After Arsia) {% hint style="info" icon="exclamation" %} **Warning** The content of this fee model is effective only after the Mantle Arsia upgrade. It is currently valid solely on **Mantle Sepolia**. {% endhint %} ### Overviews As a Rollup, Mantle has operated under a stable fee calculation model since the launch of Mantle v2 Tectonic. However, as the underlying technology has evolved, the original fee model is no longer fully compatible with current requirements. To address this, Mantle introduces a new Fee Model that modularizes transaction fees and aligns with the OP Stack’s Jovian upgrade, clearly distinguishing different sources of cost. #### The Pre-Arsia Era Before the Arsia upgrade, Mantle adopted a relatively coarse **"gas amplification"** strategy to handle L1 data costs. In this model, L1 costs were not explicitly separated; instead, they were implicitly embedded into L2 gas consumption. This manifested in the following ways: * Gas amplification mechanism * Because Mantle uses **MNT** rather than **ETH** as its gas token, and the price difference between the two can be significant, Mantle’s gas values (e.g., `gasUsed`) differed by orders of magnitude from other L2s. This increased the adaptation burden for developers. * Inaccurate estimation semantics * The legacy model converted L1 data costs and included them in the value returned by `eth_estimateGas`. As a result, L2 gas usage became tightly coupled with L1 fee market fluctuations. Even for identical transactions (e.g., a simple transfer), the estimated gas limit could vary significantly over time due to L1 fee volatility. This undermined the stability of gas limits as a measure of computational complexity and made accurate cost estimation difficult for developers. #### The Post-Arsia Era The current Mantle fee model adopts a **modular and decoupled design**. The total cost of a transaction is now clearly decomposed into three independent components, each corresponding to a distinct category of network resource consumption: ```rust TotalFee = L2ExecutionFee + L1DataFee + OperatorFee ``` This model is aligned with the OP Stack Jovian upgrade and is specifically designed to support more complex and modular blockchain execution environments, such as ZK Rollups. {% hint style="info" %} For frontend developers, the `TotalFee` of the current transaction can be estimated by calling the `estimateTotalFee` method provided in the Mantle-Viem SDK.&#x20; For backend developers, a similar `eth_estimateTotalFee` RPC is available in Geth, which directly returns the total fee without requiring manual aggregation of individual components. {% endhint %} ### L2 Execution Fee #### Design Rationale and Mechanism The **L2 Execution Fee** is the most fundamental component of the fee model. It strictly follows Ethereum’s standard EVM gas accounting rules and directly corresponds to the computational resources and state storage resources consumed by the Mantle Sequencer when executing a transaction. Its pricing fully adheres to the EIP-1559 model and is jointly determined by the **Base Fee** and the **Priority Fee**. **Difference between Pre-Arsia and Post-Arsia** <table data-header-hidden data-full-width="true"><thead><tr><th width="143.6484375"></th><th></th><th></th></tr></thead><tbody><tr><td><br></td><td><strong>Pre-Arsia</strong></td><td><strong>Post-Arsia</strong></td></tr><tr><td><strong>Difference</strong><br></td><td>Before Arsia, <code>eth_estimateGas</code> on Mantle returned a gas value that already incorporated amortized L1 data costs, instead of reflecting pure L2 execution.Although the model followed an EIP-1559 structure in form, the base fee was static with respect to block usage, and users were generally encouraged to set the priority fee to zero, resulting in a simplified version of EIP-1559.</td><td>The L2 execution fee returns to the fundamental definition of gas. The value returned by <code>eth_estimateGas</code> now reflects <strong>pure EVM execution cost only</strong>. This means that if your contract logic does not change, your estimated gas limit will remain stable regardless of L1 market fluctuations.</td></tr></tbody></table> {% hint style="info" %} With the Arsia upgrade, Mantle restores a full EIP-1559 execution fee model. The L2 base fee responds dynamically to block utilization, while priority fees are explicitly supported as a congestion signal. This ensures that gas pricing once again serves as a stable measure of execution complexity, independent of L1 fee volatility. {% endhint %} #### Formula With L1-related costs removed from gas estimation, the L2 execution fee becomes a direct function of gas usage and the EIP-1559 pricing parameters on Mantle L2. The fee calculation can therefore be expressed as: ```rust // Calculate Total L2 Execution Fee L2ExecutionFee = L2GasUsed * L2GasPrice ``` **Parameter Breakdown** <table data-header-hidden><thead><tr><th width="144.24609375"></th><th></th><th></th></tr></thead><tbody><tr><td>Parameter</td><td>Description</td><td>How to obtain</td></tr><tr><td><code>L2GasUsed</code></td><td><em>Total gas consumed by EVM instruction execution</em></td><td>We recommend calling <code>eth_estimateGas</code> directly to retrieve it.</td></tr><tr><td><code>L2GasPrice</code></td><td><em>The current gas unit price of the L2 network.</em>Under EIP-1559, it is calculated as: <code>BaseFee + min(MaxPriorityFee, MaxFee − BaseFee)</code></td><td>We recommend calling <code>eth_gasPrice</code> directly to retrieve it.<br></td></tr></tbody></table> #### How to Retrieve the L2 Fee Retrieving the L2 Fee follows the standard Ethereum development workflow. You can use the standard RPC interface `eth_estimateGas` to obtain the amount of gas required for the transaction, and then use `eth_gasPrice` to fetch the current gas price. {% hint style="info" %} Under Mantle’s current design, the value returned by `eth_estimateGas` reflects only pure L2 execution costs. Unlike implementations prior to Mantle Arsia, it no longer includes L1 data costs. Therefore, when calculating the total transaction fee, it is critical not to omit the other two fee components. {% endhint %} ### L1 Data Fee #### Design Rationale and Mechanism As a Rollup, Mantle must publish transaction data to Ethereum mainnet in order to inherit its security guarantees. Since Ethereum data storage is expensive, Mantle introduces a data compression–based fee estimation mechanism.The core of the L1 fee model is a **linear regression–based cost estimator**. Mantle does not compute the exact compressed size for each transaction by running full compression, as doing so would introduce significant time overhead in the sequencing pipeline. Instead, following the OP Stack approach, Mantle first applies the FastLZ algorithm to obtain an approximate size, then uses a pre-trained linear regression model to approximate the final on-chain data size. Although not perfectly precise, this estimation is sufficiently accurate for pricing purposes. The final fee is computed by combining the fitted `BaseFeeScalar` and `BlobFeeScalar`, and then converting from ETH to MNT using the ETH/MNT `TokenRatio`. **Difference between Pre-Arsia and Post-Arsia** <table data-header-hidden><thead><tr><th width="123.15234375"></th><th></th><th></th></tr></thead><tbody><tr><td><br></td><td><strong>Pre-Arsia</strong></td><td><strong>Post-Arsia</strong></td></tr><tr><td><strong>Difference</strong><br></td><td>L1 costs were converted into L2 gas, causing users to pay them implicitly as part of gas fees.</td><td>L1 costs are charged as an independent fee component. They no longer consume L2 gas limit, but are instead deducted directly from the sender’s balance as an additional MNT fee. This separation ensures that even sharp increases in L1 fees do not cause L2 transactions to fail due to block gas limit constraints.</td></tr></tbody></table> #### Formula Based on the estimation pipeline described above, the L1 fee can be expressed as a function of the estimated compressed data size, Ethereum L1 fee parameters, and the token conversion ratio. Formally, the L1 fee calculation is defined as follows: ```rust // 1. Estimate compressed data size (Linear Regression) EstimatedSize = COST_INTERCEPT + (COST_FASTLZ_COEF * _fastLzSize) // 2. Compute weighted L1 fee (ETH) WeightedL1Fee = (BaseFeeScalar * L1BaseFee * 16) + (BlobFeeScalar * L1BlobFee) // 3. Compute final L1 data fee (MNT) L1DataFee = EstimatedSize * WeightedL1Fee * TokenRatio ``` **Parameter Breakdown** <table data-header-hidden><thead><tr><th width="181.984375"></th><th></th><th></th></tr></thead><tbody><tr><td>Parameter</td><td>Description</td><td>How to obtain</td></tr><tr><td><code>_fastLzSize</code></td><td>FastLZ-compressed transaction size; Byte length of the FastLZ-compressed input data plus 68 bytes (signature overhead)</td><td>Runtime calculation: <code>LibZip.flzCompress(_data).length + 68</code></td></tr><tr><td><code>COST_INTERCEPT</code></td><td>Regression intercept; Constant term in the linear regression model, used to correct estimation bias</td><td>Contract constant, hardcoded in <code>GasPriceOracle</code> (<code>-42_585_600</code>)</td></tr><tr><td><code>COST_FASTLZ_COEF</code></td><td>Regression coefficient; Slope of the linear regression, capturing the correlation between FastLZ and Brotli compression</td><td>Contract constant, hardcoded in <code>GasPriceOracle</code> (<code>836_500</code>)</td></tr><tr><td><code>BaseFeeScalar</code></td><td>Per-byte share of the L1 EVM gas cost incurred by the Batch Submitter<br></td><td>Stored in the <code>L1Block</code> contract; adjustable via governance</td></tr><tr><td><code>16</code></td><td>Gas cost of a non-zero byte in the Ethereum EVM</td><td>-</td></tr><tr><td><code>L1BaseFee</code></td><td>Current Ethereum base fee</td><td><em>Periodically synced into the <code>basefee</code> field of the <code>L1Block</code> contract</em></td></tr><tr><td><code>BlobFeeScalar</code></td><td><em>Per-byte share of Blob data usage introduced by the Batch Submitter</em></td><td><em>Stored in the <code>L1Block</code> contract; adjustable via governance</em></td></tr><tr><td><code>L1BlobFee</code></td><td>Current Blob base fee on Ethereum mainnet</td><td>Periodically synced into the <code>blobBaseFee</code> field of the <code>L1Block</code> contract</td></tr></tbody></table> #### How to Retrieve the L1 Fee Developers can query the on-chain `GasPriceOracle` contract and call the `getL1Fee(txBytes)` method to obtain an estimated value. To do so, you must provide the fully constructed, unsigned, and RLP-encoded transaction bytes as the input parameter in order to receive an L1 Fee estimate. {% hint style="info" %} Note that the value returned by this method is still denominated in ETH. To calculate the actual L1 Fee in Mantle’s native token (MNT), you must multiply it by the `TokenRatio`, which can also be retrieved from the `GasPriceOracle` contract. {% endhint %} Therefore: ```rust L1 Fee = getL1Fee(txBytes) * TokenRatio ``` ### Operator Fee #### Design Rationale and Mechanism The Operator Fee is designed to provide node operators with a sustainable revenue stream. It adopts a hybrid model of “fixed base + dynamic increment”: the fixed component covers baseline service costs, while the dynamic component scales linearly with transaction computational payload (gas used). **Difference between Pre-Arsia and Post-Arsia** <table data-header-hidden><thead><tr><th width="127.70703125"></th><th></th><th></th></tr></thead><tbody><tr><td><br></td><td><strong>Pre-Arsia</strong></td><td><strong>Post-Arsia</strong></td></tr><tr><td><strong>Difference</strong><br></td><td>Operational costs typically lacked an explicit pricing formula and were often implicitly absorbed by othe
프로젝트로 돌아가기