Conceptually, Ethereum Layer 2?

Jerry Qi
9 min readOct 23, 2021

--

As blockchain become more and more popular, the blockchains around the world, especially Ethereum, is experiencing huge internet traffic.

This is similar to how roads are becoming more congested, the interactions on the mainnet Ethereum (Network) is becoming slower and less efficient at the same time.

(Note: Some fundamental knowledge within Blockchains will be needed)

For visuals, Here is in a nutshell what is happening on Ethereum in the transaction spike.

The slower transaction speed was not the problem, the gas cost was. Gas is the currency used to execute computational effort within the Ethereum network. So, each transaction requires an amount of gas, in Eth. Though, part of this is because of the internal system limitations of Ethereum, ~13 tx / second.

Can you imagine if you had to pay around ~44$ in Eth per transaction or smart contract call? Right? That is F*CKING NUTS.

Because of this outrageous network condition for common users, a more scalable solution is needed. and This is where layer 2 comes in.

Layer 2 Intro

Think of an additional network of blockchain, which is way more efficient and less costly than the current Ethereum mainnet itself. The layer 2 network branches off of the mainnet, and you can view it as an island hovering beside the mainnet, with a bridge attached to the mainnet. Mainnet can also be referred to as Layer 1

View going from layer 1 from layer 2 as moving to a new city. Which, migrates all of the local currency from layer 1 to layer 2’s local currency.

View Layer 2 as layer 1’s subcity, it is running more or less under control of layer 1’s facilitation.

Layer 2 Deep_Dive

There are mainly two types of ways that blockchain developers can create a layer 2 blockchain network. The first, an optimistic rollup. The second, a zk rollup. Even though they differ in operation, the central goal is to minimize data manipulation and computation on blockchain. In this piece, the focus will be on optimistic rollups as they more popular and less mathematics.

Focus: Storing O(1) data on mainnet for every O(N) processing offchain

Optimistic Rollups Operation

Because the focus for rollups is to keep little onchain, and move a lot of computation and data off chain, rollups introduce a thirdparty called Sequencers. Say that you submitted a transaction from account 1 to account 2. This request would go straight to the sequencers.

Sequencers

Sequencers are the “main data computers” in the context of the rollup. They would store and execute users’ submitted transactions locally.

However, layer 2 rollups inherently still behave much similarly to the main ethereum mainnet in function of decentralization. So, the sequencers in rollups will still have to periodically submit a batch of transactions, algorithmically computed into a state root onto the layer 1 network as records to keep fraud at bay.

After your transaction has been processed by the sequencer, your transaction, along with other transactions that happen in the same time period, will be compiled into one state root*, very similar to how proof of work networks bundle different transactions into blocks (their hash and id).

Sequencers are network nodes, which can be either the company’s own node or one of the public. For the latter, there will be a need for a trust mechanism, talked about below.

*State roots are sequences that describe the change of status of the blockchain. For example, in the state root batch of transactions, there may be a transaction from account1 to account2, and a transaction from account2 to account3. The State root describes the new state of blockchain after all transactions in batch have been executed. These new states are stored and put on to layer 1 (Talked about later)

Run-Down of operation

After the Sequencers have posted a state root (similar thing to merkle root for each state), the state root is added to the layer 2 chain of state roots.

The optimistic rollup system is set up to be “optimistic” about whatever transaction that is put in by a user. So, whatever transaction it is; either legit, or fraudulent, the sequencer computes the transaction anyway.

However, a blockchain cannot just simply trust that the state root that has been posted is accurate (Not checking would be web2 shit). Optimistic Rollups have this thing called the dispute period, set for each state root (which is the batch of new transactions that are processed by the sequencer).

Lets call the uncomputed batch of transactions which has not yet been compiled into the state root, the state batch.

Dispute Period

Once the state batch containing your transaction is compiled into a state root, and pushed onto the layer 2 state chain. The dispute period for that specific batch has begun.

The dispute period starts right after the sequencer processed state root is submitted to the layer 2 chain.

As the name literal, a dispute period is where the system accepts any request to revert the state because it is fraudulent. These requests are called fraud proofs, a proof that details the transition between a previous state to the new state is invalid.

These fraud proofs will be submitted by different verifiers within the network, users can also become verifier nodes for the network. Then, verifiers are able to submit fraud proofs. However, differing from traditional proof of work mechanisms, the race of computational power is not the focus, but rather, the chain will chose a specific group of verifiers for each batch to create fraud proofs. This mechanism is more similar to proof of stake and other mechanisms of chance. *(See end for more details on the mechanism)

For example, lets say that account1 = 10 DOGE, account2 = 0 DOGE, account3 = 0 DOGE

First, account1 sends account2 all of its 10 DOGE coins. Second, account1 also sends account3 some non-existant 10 DOGE coins. Resulting in the state of

{account1: 0 //Dogeaccount2: 10 //Dogeaccount3: 10 //Doge}

This isn’t right! As accounts 1, 2 and 3’s doge coins in total was only 10, there cannot be the 20 DOGE coins in the new state. This is an example of a double spending problem, where account1’s initial 10 DOGE coins are spent “twice”.

This is an example of an invalid new state, and the fraud proof submitted to the layer 2 would indicate the the impossibility of how account3 obtained 10 DOGE coins.

Well, now that legitimate fraud proof is submitted, what does the system do now to resolve such invalidity of state? It is done through a tracking deletion process.

Resolution of Fraud

Though Layer 2 is similar to that of an detached city, it is still internally connected to the Layer 1 (Ethereum) ecosystem to unmodifiable records of the layer 2 states, preventing fraud.

Think of it like this, Layer 1 and Layer 2 both have the chain of blocks in the above image. However, the blocks for layer 2 are referred to as states.

Layer 1 blockchain blocks are permanent once published, so, view Layer 1 blockchain as the irreversible final essay writeups. However, with layer 2, each individual state is different drafts for different essays. The Dispute period would then be the time that each individual essay draft accepts different critique, Fraud proofs, determining if the essay draft is trash and deleting it. After the time for critique ends, if the essay is not deleted, the finalized essay draft is then pushed onto Layer 1, no changes after that.

Only after states are pushed onto the layer 1 chain, wallet balances, smart contract statuses and other blockchain integrations will update.

If verifier submits a fraud proof to the sequencer telling it that one of the Layer 2 states in the dispute period is not legit. A deletion sequence occurs.

The deletion sequence involves first locating the specific state on the Layer 2 chain which is proved to be fraudulent by the fraud proof (In Example: State 2). Then, if it is the last state, the state will be directly deleted, any pending transaction in the state is gone, reversing to the state before. But if the fraudulent state is not the latest state draft, all of the states branching off of the state is deleted including the first fraudulent state.

Layer 2 then reverts to the latest state (State 1 on Layer 2), that hasn’t been deleted. The system then starts building a new state from State 1 (State 2 v2).

There is one crucial assumption with this system: We are assuming the very honesty and only good actors within the layer 2 verifiers and sequencers. What if they are not all “good” actors who did all of that honest processing?

Incentives

In this system there are two main aspects that incentivizes good honest actions of sequencers and verifiers.

→ Photo by Matthew Ansley on Unsplash

Many different layer 2 algorithms will require an application process when regular network nodes want to become sequencers (EVM Helpers). This application process will involve numerous considerations such as the node’s tech specs, however, the most crucial aspect is the Fidelity Bond that is mandatory.

The Fidelity Bond is a deposit of an amount Ether onto the blockchain, by a node, in order to become a sequencer for the network.

This fidelity bond will be kept on the blockchain as long as the node is still a sequencer. Why? If a state produced by a sequencer is proved to be in-valid, the deposited bond by that specific sequencer is given to the verifier or node who submitted the fraud proof. Boom! Incentive for verifiers to detect more fraud, and incentive for sequencer to do less fraud.

Modern applications

From Coin98

Modern blockchain applications usually will tinker the Fidelity Bond amount and the length of the Dispute period, also, the work protocol.

Fidelity Bonds Modification

Changing the number of tokens required for nodes to deposit on the main chain to become a node impacts the Verifier Incentive. As verifiers will get more rewards when found fraud.

Dispute Period Modification

Changing this variable will impact the user experience. Remember, dispute period is the confirmation period of the transaction (period before permanent record). During the dispute period, the transaction technically is unverified and unsettled for both parties. So, a shorter dispute period creates a speedy user experience, while a longer dispute period makes layer 2 more secure.

Protocol Modification

Similar to any layer 1 blockchains, layer 2s can also modify their system decision making in different ways. For example, deviating from what I said above about PoS in L2, L2s can also have PoW type structures to create incentive (though not environmentally friendly). Depending on the goals of the layer 2, incentives and fraud proofs can be setup in varieties of ways (even PoA).

Conclusion

Hey! Thanks for reading this article, I experimented a bit more with “free form” diagram drawings :).

I think that layer 2 is a very interesting optimization strategy for the scaling of blockchain, and will likely become common place in short time in combination with Ethereum 2 launch. To learn more about Ethereum 2 expansions, this is the beacon chain.

A little TLDR

  • Gas, and transaction limits, miner limits are the causes for Ethereum’s congestion.
  • Using Optimistic Rollups, we solve this by implementing an additional blockchain.
  • Optimistic Rollups feature a memory pool of states similar to blocks, verifiers similar to that of miners, and sequencers to process transactions and smart contracts
  • Layer 2 records txs in batches, called states
  • Verifiers have the dispute period to submit Fraud proofs (state invalid proofs) for these states
  • If state is found to be fraud, it and the states after it are reverted
  • Modern applications modify dispute period and fidelity bond (deposit for becoming sequencer) in order to customize UX

Thanks again, See you in the next one 👋

--

--