Layer 1
Layer 1 Blockchain is a name that is used to describe the main blockchain network protocol such as Ethereum and Bitcoin. Layer 1 is a main network or blockchain that Layer 2 is built on top of to improve the scalability of Layer 1 or the main chain.
Layer 2
Layer 2 is a secondary protocol that is built on top of an existing blockchain system. Many major cryptocurrencies networks such as Ethereum and bitcoin face slow transaction speeds and scaling difficulties. They are not fast able to perform hundreds or thousands of transactions per second. layer 2 offers much better transaction speed and fees.
Layer 2 protocols are specifically designed for underlying blockchain to improve the transactions throughput. Operations on layer 2 can be performed independently of layer 1. This is why sometimes we can call them off-chain solutions.
Layer 1 can provide security because of a blockchain.
Layer 2 can provide the speed.
Since layer 2 transactions are happening on a completely different chain, a connection is open from time to time to move these transactions to the main blockchain network. This connection is called bridge. So, a major consideration for the layer 2 solutions is how transactions are validated and confirmed before being sent to the main chain.
Layer 2 Scaling Solutions
There are two main topics where scaling solutions differ from each other transaction execution and data availability.
Transaction execution deals with where the transactions are run, how they run, What are the transaction environments, what the security and decentralization environments are, and more.
Data availability means whether the Layer 2 solutions transactions data will be available on Layer 1 or not.
1. State Channels
State channels are used when two or more users want to do many transactions in a trusted manner without paying gas every single time.
For example: Let's say Nancy and Laura want to play a tic tac toe game on the blockchain, with betting.
Now both of them want to put 20 ETH to play a game. and both of them trust other. We can design a smart contract such that each move is recorded on the blockchain and at the end of the game, Nancy or Laura receive their winnings. But this will be a very expensive game. because each move cost some gas fees. This can be solved with the help of state channels.
Rather than creating a smart contract to support tic tac toe move by move, we can create a smart contract that allows us to open and close a state channel. When the state channel is opened, it will have the game's default start state, and Nancy and Laura can make moves on it without paying gas fees because the open state channel is off-chain. The main chain channel will not be updated with every move. When the channel is closed, the game end state is written to the main chain with the game's winnings. As a result, rather than writing every move to the blockchain, only the beginning and end of the game are written to the blockchain.
The blockchain methodology is still used by state channels, such as by making each state update cryptographically safe.
Other Advantages of state channels include potential gains in speed and lower gas fees. Because the beginning and end of the game are written on the main chain, but the states in between are not, it is possible to have more privacy. The state channels are only Between Nancy and Laura, but because each move is not published to the blockchain, each move is not public.
But one limitation of the state channels is that we assume that the participants of the state channel trust each other to perform these transactions off-chain. Because both Nancy and Laura had to deposit 20 ETH to open the channel. Until the state is closed, the money is locked into the smart contract. However, if Nancy goes offline during her move, Laura never sees her money again. As a result, if Laura does not trust Nancy, a state channel is not the best approach because both of them have the ability to lock up the smart contract.
2. Side Chains
A side chain is an independent EVM-compatible blockchain that runs in parallel with the main blockchain and has a channel to Layer 1. A side chain has its own validators and consensus method for adding blocks. The side chain accumulates transactions quickly and cheaply and summarises them to the main chain via a bridge.
Because side chains are based on EVM, they have all of the benefits of an EVM, such as the ability to write smart contracts in solidity and interact with the chain via web3 APIs.
The disadvantage of side chains is that they can become more centralized .
3. Rollups
Rollups are solutions that execute transactions on Layer 2 but post transaction data to Layer 1, in a summarized way. They free up more space on-chain by moving computation off-chain. The availability of on-chain data is critical because it allows Ethereum to double-check the integrity of roll-up transactions.
The transaction data that rollups post on the main chain can be verified as correct or incorrect, and rollup execution does not need to take place in a trustful environment.
Optimistic Rollups
Batches of transaction data are posted to the main chain in optimistic rollups and are by default believed to be genuine, although they can be subject to challenge by other users.
Anyone can challenge them by submitting a claim, also known as fraud-proof, to demonstrate that a batch committed to the chain contained invalid state transitions. if the found proof is found to be valid, these invalid transitions will be reversed. if no one challenges the transactions will e committed to the main chain. To allow users enough time to challenge transactions, there is a long delay between when a transaction is posted and when it is committed on the main chain, typically a few days or can be up to one week. we can withdraw funds to the main chain during this time.
There are 3 main players or people in optimistic rollups:-
- asserter - the proposer who attempts to post proof of transaction validity on the main chain.
- challenger - a user attempting to prove that the proof posted by the asserter is fraudulent.
verifier - a smart contract on the main chain that verifies and validates the proof.
ZK Rollups
Zero Knowledge is a technique that enables one party the prover--to convince another--the verifier-- that a particular assertion is true while the prover avoids disclosing any more information beyond the fact the statement is true.
There are no individuals performing the verification in this rollup. Instead, anyone wishing to add a fresh batch of rolled-up transactions to the main chain must first create a zero-knowledge proof for it. The smart contract that manages to add transactions to the main chain can automatically verify this. Because of this, ZK Rollups differ from Optimistic Rollups in that every proof put on the main chain is confirmed at the time of publishing and there is no challenger role.
4. Plasma
Plasma is a layer 2 application framework for building scalable applications.
off-chain solutions, state commitments, and main chain entry and exit are the building blocks of plasma. A plasma chain is a separate blockchain that is linked to the main Ethereum chain. Plasma chains, like optimistic rollups, use various fraud proofs to settle disputes. Plasma chains like side chains, have their own consensus algorithm and create blocks of transactions. A compressed representation of each block is committed to an Ethereum smart contract at regular intervals.
Plasma chains only communicate with the main chain to commit their state or allow entry or exit. Because most plasma implementations are a separate blockchain, it must allow for entry and exit from the main chain, which is facilitated by smart contracts. Actually one of the major disadvantages of plasma networks is that it is more difficult to transfer assets from them to the main chain.
Validators is also used in Plasma implementations to monitor the network and ensure security. When funds are withdrawn, there is also a waiting period to allow for challenges. The benefits of plasma are higher throughput and lower cost per transaction. it's ideal for transactions between two users. The disadvantage of plasma is that it does not support computation as complex as the main chain.
Validium
Validium functions similarly to ZK rollups, with the exception that data is stored outside of the main chain. Due to the fact that transaction data is not published on the main chain, users must rely on an operator to make data available when it is required. This is typically accomplished through a committee of well-known entities whose business reputation is built on being reliable data providers. If a Layer 2 node operator stops service withdrawal requests, this committee will make its copy of the data available to the public. Validium is a type of data-availability situation and does not concern itself with how transactions are carried out.
Volition
Volition chains are the direct descendants of Rollups and Validium data-availability approaches. They essentially enable a hybrid data-availability scenario in which users can choose what they want on the main chain and what they do not want on the main chain. similar to Validiums, this is just a data-availability situation and does not concern itself with how the transactions are executed.