A layer 2 blockchain
A layer 2 blockchain is an independent, overlaying blockchain network that exists on top of an existing layer 1 blockchain network. The layer 2 network uses the same functions, principles, and rules as a layer 1 network but usually focuses on a specific component of the blockchain network, such as scaling transactions.
The blockchain trilemma is a problem that has been haunting blockchain since the invention of the technology, which consists of three conflicting blockchain components: decentralization, security, and scalability. The trilemma states that only two of these components can be fully implemented by a single layer, where the remaining component of the three is a tradeoff the network must face. Because of the generally accepted importance of a base layer to prioritize decentralization and security, these two components are what layer 1 networks within multi-layer architectures try to achieve. As a result, layer 2 networks will attempt to scale the network.
Scalability issues became of high interest with rising gas fees on Ethereum, making the network practically unusable for the average user. This led to the creation of the first set of layer 2 networks that compute higher volumes of transactions in a much shorter time frame, thus increasing the throughput and overall speed of EVM-based transactions. All while still inheriting the security and decentralized nature of the Ethereum (layer 1) base layer.
Layer 1 is secured by network maintainers who participate in consensus and guarantee state verification, and Layer 2 will conduct higher transaction throughput The transactions on layer 1 (meaning that all transactions must adhere to the rules of Layer 1 to be accepted).
Optimistic roll-ups and ZK (zero-knowledge) roll-ups
The most frequently used types of layer 2 solutions are optimistic roll-ups and zk (zero-knowledge) roll-ups. Both rollup transactions in a similar fashion, where optimistic rollups assume transactions are valid, and zk-rollups rely on the verification of state transitions through proofs.
How do roll-ups work?
Imagine a very long scroll, and every transaction is written as 1 row (in layer 1 it would need a whole sheet of paper). After a certain number of transactions (much bigger, from tens to thousands or even more than on layer 1), the scroll is rolled and then placed on a layer 1 block (in the same box that only 1/10 to 1/1000s of the transactions would fit if they were not recorded in a rollup first).
Difference between optimistic and zk rollup's
The main differences between optimistic and zk rollup's are in how the validation or invalidation of a broadcasted rollup happens. In an optimistic rollup, the actors are assumed to behave in good faith, so all the published transactions to layer 1 will be considered valid until proven corrupted. If there is any suspicion, a fraud-proof mechanism will take place. If the suspicion is confirmed, the transaction is eliminated, the state of the blockchain is reversed, and another transaction rollup with [assumed] uncorrupted transactions is published.
The ZK stands for Zero-Knowledge, meaning that the layer 1 does not need to know what is inside the rollup to introduce a new block, because a validity proof is provided by the zk layer. The validity proof is a cryptographic hash that proves that the content of the transaction is legit and the new state of layer 1 will be correct.
In conclusion, layer 2 blockchains utilize either rollup solutions to scale blockchain networks by creating and computing big batches of transactions and then executing them off chain. The transactions are broadcasted to layer 1 blockchains for verification, thus inheriting the security and decentralization of layer 1.