All posts

FuelingGasSpellsonDunepart2

In this post, we continue our research into fee mechanisms we focus on gas fees and incentives mechanisms for Layer 2 blockchain solutions indexed on Dune!

ResearchSeptember 12, 20225 min read
@Alsie L.
Alsie L.Content Marketing Manager at Dune
Fueling Gas Spells on Dune part 2

In this article we're going to teach you everything you need to know about gas fees on Optimism. By the end you'll grasp the mechanism fully, and be able to cast gas spells of your own.

In part 1 of this series we focused on layer one (L1) chains - looking at Ethereum, BNB & Avalanche in turn. Today we're going up a level and looking at layer two (L2), in particular Optimism, and explaining how gas fees work on the network as well as its various incentive mechanisms. Firstly though, let's start with the basics, what is an L2?

Layer 2 (L2) is a collective term for a set of solutions designed to address scalability issues on L1 blockchains like Ethereum. The issues originate from a well-known trade-off between security, decentralization, and performance, often referred to as the blockchain trilemma.

 width=

Source

On the one hand, L1s need to keep a high degree of decentralization and security, which means that individuals should be able to run nodes independently so they can compute and verify the state of the blockchain (low trust, low cost) without relying on trusted third parties. On the other hand, this comes at the cost of performance since individual nodes don’t have access to the infrastructure capable of handling a high throughput of transactions with low latency.

One way to address this problem is to use separate blockchains, L2 solutions, that extend L1 blockchains like Ethereum while inheriting their security guarantees.

In this series we're going to breakdown two different categories of L2s: rollups like Optimism and Arbitrum, and side chains like Polygon and Gnosis chain. In this article though, we're going to look at Optimism in depth.

Firstly though, let's explain what rollups are more generally.

What is a rollup?

Rollups are currently the preferred L2 solution for scaling Ethereum. The overall approach is to bundle (or “roll up”) hundreds of transactions into a single transaction on L1, which distributes the transaction fees across everyone in the rollup, making it cheaper for each user. There are two different approaches to rollups, optimistic and zero-knowledge, that differ primarily on how transaction data is posted to L1.

“Optimistic” rollups like Optimism and Arbitrum propose to introduce a third party, called a sequencer, that is responsible for:

  1. Storing and executing transactions off-chain (i.e., on L2)
  2. Periodically (every 2 to 10 min) posting the (compressed) input data and results from these batches of transactions on-chain (i.e., on L1)
  3. Increasing throughput since transactions are executed off-chain
  4. Reducing gas fees since sequencers only periodically post compressed data for batches of transactions on-chain.
  5. Pre EIP-1159: L1 data fees = Gas units used * Gas price per unit
  6. Post EIP-1159: L1 data fee = Gas units used *(Base fee + Priority Fee)
  7. The fixed overhead cost, which reflects the additional processing required to add another transaction to the larger batch, now set to 2100 gas units
  8. A Dynamic overhead (fee scalar) premium, which serves as a buffer in case L1 prices rapidly increase

Note that all excess funds collected via the fee scalar are redirected towards public goods funded by the citizen’s house, and that it has been set to 1 since April 5th, 2022.

In the end, post EIP-1559, L1 data fees can be computed using this formula:

L1 data fees = (Call Data Gas units used + Fix overhead) * Dynamic Overhead * (L1 Base fee)

Another upgrade we can talk about is one that was implemented by the Optimism team on March 24th, 2022 to reduce the amount of data posted on L1 (Zlib batch compression). Note that it doesn’t affect gas fees calculations per se, but led to a 30-40% transaction fee reduction. To check out its impact, make sure to look at Msilb7 ’s Dune chart here, showing the amount of gas used to post data on L1 before and after the compression upgrade:

 width=

All that’s left to do to get the total transaction fees is adding costs related to transaction execution on Optimism, called L2 execution fees, computed the exact same way as transactions on Ethereum:

‍L2 execution fees = L2 Gas units used * L2 Gas price per unit. L2 execution fees = L2 Gas units used * L2 Gas price per unit. L2 execution fees = L2 Gas units used * L2 Gas price per unit.

In practice, L2 gas prices are very low (set to ~0.001 Gwei as a default), which means fees are actually negligible, but we’ll still include them on our spells and queries for the sake of completeness.

It’s also worth noting that Dune actually makes it easy to compute transactions fees by introducing the l1_fees column, which takes into account all the parameters needed to compute L1 data costs, and includes all changes and upgrades made by the Optimism team to reduce fees overtime:

L1_fees = (Gas units used + Fix overhead)*Dynamic Overhead*Base feeGas units used + Fix overhead)*Dynamic Overhead*Base feeGas units used + Fix overhead) *Dynamic Overhead*Base fee

To compute the total transaction fees, including L1 data fees and L2 execution fees, here’s the code we’ll use on Dune:


SELECT
'optimism' as blockchain,
l1_fee + (l2_txns.gas_used * l2_txns.gas_price) as tx_fees
FROM optimism.transactions l2_txns
To run this query and check out the other columns we’re including in the optimism gas fees spell, you can click here.

If you’ve made it this far, congratulations! You now have all the pieces needed to compute total transaction fees on Optimism, and we can now build the Optimism gas fees spell on Dune!

For convenience, note that we chose to build our spell starting after the Optimism Regenesis that took place on November 11th 2021, and released upgrades to reach full EVM equivalence (see timeline, and check out the Optimism blog post here for more details). But if you’re feeling adventurous and want to complement the Optimism gas fees spell by adding pre-regenesis data, remember that every spell built on Dune is open-source, so just head over to the Spellbook repo and open a PR!

Finally, here are a couple of Dune and non-Dune resources to explore the Optimism ecosystem further:

Mastered gas spells for Optimism? Stay tuned for the next instalment of this series where we're going to teach you all there is to know about gas on Arbitrum......

Related

VIEW ALL

Make real impact with onchain data

JOIN US

Looking to use Dune for your company?