MoleEdu Web3 Series Public Course Review: Ethereum and Layer2 Notes
Author: Moledao
The Web3 series course co-hosted by Moledao and OGBC officially started on January 16, 2023! The first week is Infrastructure Week, covering blockchain basics, Ethereum, Layer2, Layer0, and storage.
Today, let's review the "Ethereum and Layer2" course by mentor Neil Han on January 18, 2023! The course recording has been uploaded to Moledao's Bilibili:
Week 1: Infrastructure Week | Ethereum and Layer2
Now, let's learn from the notes of the "Ethereum and Layer2" course!
Mentor Introduction
Neil HAN, Founder & CEO of Reddio, was the third employee at Twilio in the Asia-Pacific region, leading the team to achieve a 30-fold revenue growth in four years. He was also the first overseas commercialization employee at PingCAP/TiDB and served as GM for the Asia-Pacific and European regions.
Mentor Neil left his position at the end of 2021 to establish Reddio, a Web3 infrastructure company headquartered in Singapore, providing PaaS services to global developers to solve Ethereum scalability issues, allowing them to put assets on-chain with higher concurrency, lower Gas Fees, and greater security. Reddio is the first Infra company in the Asia-Pacific region invested by Paradigm.
Mentor Neil is also an angel investor, focusing on investments in U.S. SaaS companies, and is an angel investor in companies such as growrk.com, getbean.com, mynurse.ai, and mileauto.com.
Learning Outcomes
In this class, Mentor Neil explained Ethereum and its limitations, sidechains, Layer2 scalability solutions, the trilemma of Layer2, and the evolution of the tech stack.
01 Ethereum and Its Limitations
Why Ethereum? Even in 2022, when the situation was not particularly good, Ethereum's dominant position in the entire ecosystem remained unchanged. Moreover, most of the major NFT transactions in 2022 occurred on Ethereum. Ethereum is a must-see chain for entering the blockchain industry. However, Ethereum has two significant limitations that restrict its development:
First: Every operation on Ethereum incurs a Gas Fee, and the Gas Fees are quite high.
In the image above, GAS is the unit of measurement. During the transfer process, 21,000 GAS will be generated. The price of GAS will fluctuate within a range depending on whether the transaction initiator needs the transaction to be processed quickly. Taking one GAS as 100 GWEI as an example. GWEI is a unit of measurement equal to 10 to the power of -9 ETH. Therefore, in the transfer process shown in the image, the Gas Fee is 0.0021 ETH. Assuming the price of ETH is $1800, this transfer costs $3.78.
Note: This Gas Fee is not constant. If a transaction initiator is very eager for confirmation, the Gas Fee will increase. This is due to the miners' bidding mechanism, where whoever offers a higher Gas Fee will be selected first. Therefore, eager transaction initiators will offer a higher Gas Fee. In 2021, there was a case where the highest Gas Fee reached $150 for an NFT transaction, which is an exaggerated amount. If all transactions were this expensive, the entire on-chain transaction system would be nearly unusable.
Second: Scalability
From the image above, we can see that Ethereum's TPS is about 20 transactions per second. However, compared to VISA's 24,000 TPS, it is still too low.
Due to these limitations, centralized exchanges can only handle transactions in a centralized manner. Regarding this, Mentor Duke provided a detailed introduction in the blockchain basics course. However, this approach contradicts the principles of Web3 and has led to malicious events like the FTX collapse.
Ethereum is certainly aware of this issue, as shown in Ethereum's product roadmap. Last year, Ethereum transitioned from POW to POS, primarily to address power consumption issues, eliminating the need for miners. This change significantly saved resources, reducing 99% of the electricity consumption in the entire Ethereum ecosystem. However, it did not effectively improve TPS or significantly lower Gas Fees. Therefore, for now, these two limitations have not seen significant improvement. Future Data Sharding can address these two issues better, but until then, Ethereum alone cannot resolve them.
02 Blockchain Expansion
Based on the above two limitations, various attempts have been made in the industry regarding blockchain scalability, and the above lists various different solutions. Below, we will focus on Ethereum's scalability.
2.1 Sidechains
A representative example of a sidechain is Polygon's PoS chain. What it does is: since Ethereum's Gas Fees are high and its processing capacity is limited, a new chain is established where all nodes, consensus, and security are controlled by the chain itself. If assets on Ethereum want to be transferred to the sidechain, the assets must first be locked in a Polygon wallet on Ethereum, and then corresponding tokens are generated on the sidechain to the corresponding wallet. The process of retrieving tokens from the sidechain is similar.
In this solution, the sidechain must prove that the funds indeed exist, utilizing a proof mechanism called Merkle Proof.
2.1.1 Merkle Proof
Merkle Proof consists of a data block, a Merkle Root, and a "branch" composed of all Hashes from the data block to the root path. The reader of the proof can verify the Hash of the given data block (at least for the current branch) and the consistency of the Hashes of all nodes on the path to the Root, ultimately verifying whether the given data block is indeed a node in the tree. This method is widely used in blockchain.
2.1.2 Advantages and Disadvantages
The benefits of the sidechain solution include:
- Because it is relatively centralized, high-performance machines can be used to increase transaction throughput.
- Transaction fees are controlled by the sidechain, so the transaction Gas Fees are relatively low.
- The privacy of transactions can be guaranteed. Since the data is controlled by the sidechain, some methods can be used to hide the data. Therefore, some enterprises may choose sidechains as their on-chain solution.
However, the disadvantages are also prominent:
- The biggest issue is security, as the entire security is centrally controlled by a third party. For example, the security of Polygon PoS is controlled by Polygon.
- Cross-chain bridges are verified by relatively few nodes, making them vulnerable to hacker attacks, and there have been countless hacking incidents in history.
Mentor Neil does not consider sidechains to be Layer2 because their security does not rely on Ethereum but rather on the sidechain's own security. Only by inheriting Ethereum's security can Layer2 be called Layer2.
03 Layer2 Scalability Solutions
All Layer2 scalability solutions aim to perform most transactions off-chain on Layer2, requiring only the entire transaction state to be placed on Layer1 for confirmation. This optimizes the performance of Layer1.
3.1 State Channel
State Channel is a relatively early Layer2 scalability solution, and the method is quite straightforward. We can see in the upper half of the image that Player1 and Player2 may engage in many transactions. However, for Layer1, the process is not important; the final result is what matters. Before these two individuals engage in transactions, both must log in using their private keys, and then they can open this State Channel. When the channel is opened, both individuals must be online until all transactions are completed and the channel is closed. Thus, only the start and end states of the transaction are recorded on Layer1, saving a significant amount of computational resources.
However, the drawbacks of State Channel include:
- Both parties must log in using their private keys. The private keys being exposed on-chain may be attacked.
- Both parties must remain logged in; otherwise, the channel will automatically close.
- The assets for the transaction must be locked at the start of the transaction, so they cannot be used for other purposes during the transaction.
- Smart contracts cannot be executed.
However, this model is more suitable for chains like Bitcoin, which do not have contract functionality. Payment Channels are used in Bitcoin's scalability and are the basic principle behind the lightning network.
3.2 Layer2 Architecture
In mainstream Layer2 solutions, data can be stored on-chain or off-chain. Proofs can also be divided into two types: validity proofs and fraud proofs. This leads to different solutions.
3.3 Fraud Proof
After the verifier downloads transaction data from the Layer1 contract, they can locally reconstruct the (Layer2 state) Merkle tree. The verifier can confirm whether there is fraudulent behavior by comparing the local Merkle root (state root) with the contract's Merkle root. If fraud is detected, the verifier needs to provide a Merkle proof to the Layer1 contract, which is the green part in the image, to initiate a challenge.
3.4 Plasma Solution
Plasma is a Layer2 solution whose basic principle is to process operations through corresponding smart contracts and then place transactions on a child chain via operators. Different child chains handle different tasks. This allows many operations to be placed on different child chains. To ensure security, when a user wants to transfer assets from the child chain to Layer1, Plasma reserves 7 to 14 days for fraud-proof nodes to challenge.
The benefits of this solution include:
- Assets can be transferred to anyone.
- Security is guaranteed by the main chain.
The drawbacks are:
- Withdrawal operations require 7-14 days of review, during which time is reserved for fraud-proof nodes to verify.
- Cannot run arbitrary smart contracts, as the smart contracts are fixed and cannot be changed from the beginning.
- Only Merkle roots are recorded on the main chain, so security may be somewhat compromised.
3.5 Rollups Solution
Implementation of Rollups
First, a contract must be written on Layer1, with the purpose of generating a Merkle root for all operations to be packaged on Layer2 and placing this Merkle root state on Layer1. Once the packaged operations change, this Merkle root will change, requiring the state to be updated through the contract on Layer1. If issues arise with the operations, there are two ways to prove whether the operations are valid. All Rollups operations are implemented based on the above logic.
Main Factions
For the validity proof of transactions on Layer2, there are currently two main factions: Optimistic Rollups and zkRollup. Currently, Optimism has the largest locked value globally. However, it has a significant issue; because it uses fraud proof, assets cannot be withdrawn quickly. zk-Rollup is a better solution, but its deployable contract solutions are not yet fully mature.
If Optimism wants to withdraw, it needs to download all the data involved in the transaction, run the Merkle tree, and then verify the fraud proof, which is very time-consuming. Moreover, there is a paradox in the mechanism: if the nodes running the fraud proof do not detect fraud, they earn nothing. However, if there is fraud, the chain will become very slow.
Arbitrum made a small improvement by not requiring all transaction-related data to be downloaded; it uses a binary method, only needing to prove the validity of specific nodes' results. However, it still takes a lot of time on fraud proof.
3.5.1 zk-Rollup
A very important concept in zk-Rollup is zero-knowledge proof. We can understand it simply using the example of a restaurant receipt.
Most people do not care about the specific items on a restaurant receipt; generally, customers just add up the costs of each dish and compare it with the total on the receipt to verify. Therefore, it is possible to prove the validity of a transaction without knowing the details. This is just a very relatable analogy for zero-knowledge proof; the specific principles can be studied further.
Thus, in zk-Rollup, the proof speed is very fast, taking only a few hundred milliseconds for real-time verification, and it takes only a few minutes to confirm on Layer1. This innovative solution is favored by many, including Vitalik Buterin. This solution can greatly improve the efficiency of Layer1. For example, StarkEx can increase the NFT storage capacity of a Layer1 block from 150 to 1.8 million, making it almost free to issue NFTs on Layer2.
Validium Solution
Some relatively fixed operations, such as NFT transfers, are converted into standard contracts. These operations are then proven on Layer1 using zero-knowledge proof. Since data stored on Layer1 is always limited by Ethereum's TPS, storing some data off-chain or on Layer2 is a better solution. Although this comes with some compromise on security, it is a better solution for projects that do not have high security requirements.
zkRollup Solution
zkRollup places all the off-chain stored calldata of Validium on Layer1, while transactions are placed on Layer2, and these operations are proven on Layer1 using zero-knowledge proof.
Volition Solution
Volition integrates the off-chain solution of Validium with the on-chain solution of zk-Rollup. Users can choose freely.
StarkEx Project
This is currently the most mature zkRollup/Validium solution.
Its Validium processing capacity can reach 9,000 transactions per second, while zk-Rollup's processing capacity can reach 2,000 transactions per second. In April 2022, StarkEx processed four million transactions in one day, setting the record for the highest daily transaction volume on-chain.
3.5.2 zk-Rollup and zKEVM
The biggest limitation of StarkEx is that it cannot write contracts. The following projects have added contract functionality. The more green boxes in the image, the better the compatibility with EVM. Currently, these solutions are not yet at the stage of large-scale production use; the closest is StarkNet, while other projects may take several years to approach maturity.
While EVM compatibility can help many engineers who have already written EVM contracts to migrate easily, the more compatible with EVM, the more performance is compromised, as detailed in the following chart. For zkRollup that is fully compatible with EVM, its performance ceiling is Ethereum's limit. However, zkRollup solutions designed based on the principles of zkRollup, although they cannot be well compatible with EVM, have enormous potential.
3.5.3 Comparison of Optimistic Rollup and zk-Rollup
04 The Trilemma of Layer2
The trilemma of Layer2 is different from Ethereum's trilemma. Below are projects and chains that balance two characteristics.
- Performance
- Composability: whether contracts can be written.
- Decentralization
Project teams can choose corresponding solutions based on their focus. For example, for Web3 applications or games, where logic and transactions are relatively fixed, StarkEx appears to be a better choice. For DeFi projects that have higher contract requirements, if performance is a concern, Polygon PoS may be a better choice. For scenarios that require high decentralization but do not mind longer withdrawal times, Optimistic Rollup may be a more suitable solution.
05 Evolution of the Tech Stack
With the support of zkRollup, we see significant changes in the tech stack of decentralized solutions. Taking the representative decentralized exchange dYdX as an example, users match buy and sell orders on a relatively centralized server, while all transactions occur in zk-Rollup. Users use custodial wallets, meaning the assets still belong to the users and can be withdrawn at any time.
Below is Reddio's tech stack. We serve developers through familiar programming languages, APIs, and SDKs, allowing developers to quickly deploy ERC20 and NFTs to Ethereum and Layer2 zkRollup, enabling them to use our products and Layer2 solutions with very high concurrency (up to 10K TPS) and stability. We also convert the proprietary chain language of Layer2 into commonly used APIs and SDKs for developers, greatly reducing the time developers need to integrate Layer2 and Ethereum. Thus, even if it is not an EVM-compatible zkRollup, developers can quickly use it. If you are interested in Reddio's solutions, feel free to visit www.reddio.com for a free test.
With the improvement of zkRollup, we will see more fully decentralized on-chain DeFi, Web3 Apps, and games being deployed and thriving, which will significantly change the landscape of Web3 and provide unprecedented opportunities for more entrepreneurs. We look forward to building such a future together.
06 Acknowledgments
Thanks to the following organizations for their support of this public welfare course!
Sponsor Support:
One Global Blockchain Centre (OGBC)
https://www.ogbc.com/
OGBC is a leading incubator for Web 3.0, collaborating with emerging cryptocurrency startups to build the infrastructure of the future. By leveraging OGBC's expertise, network, and resources in the cryptocurrency field, companies and projects can maximize their potential and strive to develop innovative and valuable solutions for the growing user base of the blockchain industry.
Other Partner Support:
07 About Moledao
MoleDAO is a blockchain developer community for all blockchain enthusiasts to learn about the latest developments in blockchain and grow with the help of experienced blockchain pioneers and innovators, contributing more innovative ideas to build the Web 3 ecosystem.
We aim to bring blockchain concepts to everyone and develop the blockchain ecosystem by building a community for blockchain enthusiasts to communicate, providing support for blockchain projects, hosting global hackathon series, helping match project talents, and offering project sponsorship and guidance.
Our vision is to become a well-curated one-stop blockchain ecosystem. Whether you are a blockchain enthusiast, developer, institution, or investor, you can find your suitable position at Moledao.
For more content, please check: Who is Moledao? What are we doing? What can you gain here?