Try   HackMD

How fees work on Base / Optimism

References: https://community.optimism.io/docs/developers/build/transaction-fees/

Overview

Unlike L1 (Ethereum) transactions fees which will burn the base fee, pass priority fee to miners, distribute a block reward, Base (or the op stack) L2s have a different fee calculation mechanism.

Sender

On a high level, for a given transaction, it will be charged

  • L2 execution fee => which is the same mechanism as L1
    • if it is a EIP-1559 tx, then will be charged for BaseFee + PriorityFee
    • if it is a legacy tx, then it will be charged for Gas Fee
  • L1 data fee => used to cover the L1 “security” cost from the batch submission mechanism
    • The fee is shown on the transaction receipt, not directly on the transaction itself.

The combination of L1 fee + L2 fee equals the total amount of fees that a transaction pays.

Fee Distribution

For fee distributions, the biggest difference from L1 mechanism is that Base

  1. does not burn fees, all the fees will be distributed to smart contracts that the system own, so essentially every gas spent on our chain is allocated to us. The fee will be distributed to 3 pre-deployed contracts
    • BaseFeeVault => gets base fees (gas_used * gas_price) paid by transaction
    • SequencerFeeVault => gets priority fees (gas_used * max_priority_fee_per_gas) paid by transaction
    • L1FeeVault => gets L1 data fees paid by transaction
  2. no block rewards, since native currency is ETH, distributing block rewards equals print money out of thin air.

Details

System transactions

Base do not charge any fees for system transactions as they are either paid on L1 (Deposited Transaction) or they are auto generated system transactions which is purely read from L1 (L1 Attributes Deposited transaction)

Normal transactions

For legacy transactions of type 0, the total transaction fee equals

  • l2_execution_fee = gas_price * gas_used
  • l1_data_fee = l1_gas_price * (tx_data_gas + fixed_overhead) * dynamic_overhead
    • l1_gas_price, fixed_overhead, dynamic_overhead are set in gas oracle contract
    • currently fixed_overhead = 2100, dynamic_overhead = 1

Dynamic Fee Adjustment

Base will dynamically adjust fees based on demand. There are 2 parts of fee adjustments:

L1 data fee

As a rollup, base needs to periodically commit its data (transaction batches) and state root to L1 for various purposes. In order to cover that cost, L1 data fee configuration values are managed by the SystemConfig contract on L2 and are updated by the derivation process for each L1 block.

L2 execution fee

The fee adjustment mechanism is exactly like L1. For example, it follows EIP-1559 standard for EIP-1559 transactions, All you need to know about EIP-1559 provides a very good explanation of how it works.