The Three Paths for Smart Contract Scalability

tl;dr;

  • A smart contract blockchain can scale with hardware, with an optimistic rollup or a zk-rollup
  • Solana’s hardware scaling solution suffers from lack of decentralization and sync issues
  • Optimistic rollups (Optimism) rely on off-chain verifiers and has a 6 days finality on L1
  • zk-rollups (StarkNet) submits and verifies validity proofs on-chain increasing security but also data usage of L1
  • Optimistic rollups are cheaper but zk-rollups are more secure

Introduction

In 2021 we saw the emergence of multiple Ethereum competitors that wanted to capture a share of the market frustrated by the extremely high fees required to pay in order to use the blockchain. This frustration was compounded by the realization that the long awaited upgrade to Ethereum 2.0 wouldn’t solve the problem of high fees as it would focus exclusively on reducing the network’s energy consumption by switching its consensus algorithm from proof-of-work (PoW) to proof-of-stake (PoS).

Once the transition to PoS is completed, a regular home computer (with enough ETH staked) will be able to create blocks on Ethereum. This is in sharp contrast to the expensive and energy hungry mining rigs that create blocks. Given how close we finally are to the transition to PoS, I’ll base my comparison with other blockchains assuming that Ethereum is already a PoS blockchain.

Ethereum's block creation
Ethereum’s block production after the merge

Because the “merge”, as the transition to PoS is known, is not going to solve scalability, three approaches are being experimented in parallel: scaling with hardware, optimistic rollups and zk-rollups.

Scaling with Hardware

To my knowledge, all the “Ethereum killers” (Solana, Avalanche, Cardano, etc.) are also PoS systems that make a different set of tradeoffs in order to achieve a higher number of transactions per second (TPS) than Ethereum. A common tradeoff for the sake of speed, is to increase the hardware requirements for the nodes on the network. With more powerful hardware it is possible to bundle more transactions per block and to create blocks at a faster rate, thus achieving higher TPS. This is in particular Solana’s approach.

Solana's block creation
Solana’s hardware scaling approach

Increasing TPS with hardware can have on paper impressive results both in terms of network performance and reduced gas fees but it comes with great risks. High performance machines are much more expensive to procure and operate than the regular PCs or laptops required to run an Ethereum PoS. This reduces the amount of people who are able to operate a node and by extension impacts the decentralization of the network. 

But perhaps the biggest problem of increasing the size and frequency of block production is network synchronization. This problem has become so bad on Solana that the network has stopped working for days and the whole network has to be manually restarted. Scaling with hardware is now proven to be the incorrect approach for a blockchain, something that Bitcoiners have known since the block size wars.

Scaling with Layers

On Ethereum, an alternative approach to scalability using compression layers (also known as “layer 2”, “L2” or “rollups”) has been in the works for quite some. Instead of modifying Ethereum itself to make it more performant, a compression layer could be placed on top of it so most of the work is done off-chain and only some data about the layer is registered on Ethereum as a single transaction. Using a single Ethereum transaction to settle multiple L2 transactions has the economic benefit of a significant reduction of the average gas fees paid by users of the compression layer.

On a rollup system, transactions are processed and bundled into blocks by a “Sequencer” and just enough data to allow full nodes to reconstruct the current state of the layer is sent to Ethereum (also known as the “layer 1” or “L1”) for storage. Rollups don’t have a consensus protocol, they instead use a smart contract on L1 to keep track of their block ordering and emulate having a blockchain of their own.

Rollup storing data on Ethereum
Rollup storing data on Ethereum

Note: The diagram above is an over simplification of what happens in reality. In reality, to settle a layer 2 block, more than one L1 block (i.e. more than one transaction) might be needed given that Ethereum imposes a limit on how much data can be stored per block. As a result, it’s unlikely to have a 1 to 1 mapping between L2 and L1 blocks and “finality” (certainty about the state transition) on L2 will take longer than L1. Keep this in mind when analyzing the diagrams for optimistic and zk-rollup shown below.

With rollups the Ethereum ecosystem is able to achieve an increase in TPS without requiring changes to the hardware specification of the Ethereum nodes. This is possible because L1 nodes are not required to execute and validate L2 transactions, they are only required to store data about L2 transactions and the order of its blocks (the emulated blockchain). Rollup nodes are able to synchronize with the latest state of the system by scanning the Ethereum blockchain and processing only the transaction posted by the Sequencer on L1.

A centralization problem is presented here. If the Sequencer is centralized and the Ethereum blockchain is not validating its transactions, what’s keeping the Sequencer honest? Depending on how a rollup handles this problem it can be classified as an “optimistic rollup” or a “zero knowledge rollup” (zk-rollup).

Optimistic Rollups

Optimistic rollups (Arbitrum, Optimism, etc.) rely on game theory to keep the system honest by rewarding off-chain computers to validate every L2 transaction and submit a fraud proof to Ethereum in case a malicious transaction is found. If the fraud proof is found to be correct, the contested L2 block that included the malicious transaction is invalidated and the Sequencer is economically penalized at the same time that the off-chain computer who found the inconsistency and submitted the fraud proof (the “verifier”) gets economically rewarded.

Fraud proof verification on Optimism (optimistic rollup)
Fraud proof verification on Optimism (optimistic rollup)

If the number of honest verifiers is too small (or just one) the network could be compromised by hackers performing DDoS attacks on those machines to prevent them from communicating with the Ethereum network for long enough so their malicious transactions are included in the blockchain. This is why optimistic rollups provide a one week window since a new block is produced until it is considered “final”, for any verifier to submit a fraud proof. The downside is that any withdrawal from L2 to L1 will take a full week to be processed to prevent a “hit-and-run”.

Other type of rollups address this problem using advanced cryptography known as zero knowledge proofs that submit a cryptographic proof of the validity of all the transactions on an L2 block on-chain for Ethereum nodes to corroborate instead of relying on off-chain Verifiers.

Zero Knowledge Rollups

Zk-rollups are very similar to optimistic rollup except for how they manage to keep the Sequencer honest. On a zk-rollup when the Sequencer proposes a new block a cryptographic proof is also created off-chain by a Prover. This proof is submitted to L1, along with the rest of the data needed for the rollup, so every Ethereum node can validate the integrity of the computation performed by the Sequencer using a Verifier smart contract available on L1.

This change increases the security of the network as L2 blocks can be instantly verified by Ethereum without having to validate (execute) every single transaction on the block. With zk-rollups there’s no need to have off-chain Verifiers that can be target of attack and blockchain finality is achieved quicker, no need to wait a full week to withdraw funds from L2 to L1.

Note: The actual wait time to withdraw funds is unknown as it fluctuates depending on how busy the L2 system is. Counter intuitively, the wait time decreases as the the number of transactions on L2 increases because the Sequencer waits until having enough transactions on a “pending block” before submitting data to Ethereum to make the process gas efficient (cheap for end users).

StarkNet (zk-rollup) block production and validity proofs
StarkNet (zk-rollup) block production and validity proofs

There are two main trade-offs when comparing zk-rollups to optimistic rollups. The first one is that the average gas cost of an L2 transaction on a zk-rollup is higher than an optimistic rollup because more data has to be stored on L1, mainly the validity proof. The second is that creating smart contracts that are compatible with the creation of a validity proof precluded the use of the Ethereum Virtual Machine (EVM) and Solidity as programming language. In fact, many zk-rollup projects don’t even allow smart contract composability, reducing their use case to specific domains (payments, swaps, etc.).

StarkNet is the only zk-rollup to my knowledge that allows for the creation of composable L2 smart contracts and thus can be considered to be “universal”. The downside is that a completely new programming language was introduced (Cairo) making the learning curve steep. Fortunately a project exists that allows for the transpilation of Solidity code into Cairo, making it easy to deploy dapps already available on Ethereum on this layer 2.

Conclusion

Rollups are a superior approach to scalability than the hardware scaling approach that alternate layer 1s like Solana propose. A rollup can achieve high performance by grouping and processing transactions off-chain while sending enough data back to Ethereum to secure the network. The two main approaches for rollups are optimistic and zero knowledge. Zero knowledge rollups are more secure as they don’t rely on off-chain validators but have a higher average transaction cost.

As rollups start to take off it is possible that Ethereum block space will be used almost entirely to secure these networks instead of serving individual users. The increased demand for storage space on L1 from rollups is driving the Ethereum core team to re-think their research on data availability with sharding. The new sharding approach is known as proto-danksharding and it’s part of the rollup centric vision outlined by Vitalik Buterin.

The future of Ethereum looks bright and StarkNet is the rising star of this new phase. Expect more articles digging deeper into this technology.

Acknowledgements

2 thoughts on “The Three Paths for Smart Contract Scalability”

So, what do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.