A Layer 2, also referred to as L2, refers to a secondary framework or protocol that is built on top of an existing blockchain system. The main goal of these protocols is to solve the transaction speed and scaling difficulties that are being faced by the major cryptocurrency networks.
Lightning Network is a layer 2 solution designed to address the issue of scalability on the Bitcoin blockchain, using multiple payment channels. The transaction throughput for the bitcoin blockchain can only accommodate seven transactions per second, meaning any number exceeding the transaction limit is likely to cause congestion on the network, delaying the time it takes to process each transaction and leading to higher gas costs.
Rollups are designed to scale on Ethereum and other EVM-compatible chains. Yet, they inherit the security infrastructure of the main network or layer 1, leaving no room for vulnerability.
Zero-knowledge rollups are smart contracts that collate several transactions off-chain, creating a cryptographic proof, called a SNARK (Succinct Non-interactive Argument of Knowledge) which is submitted to the Layer 1. This cryptographic proof is also known as validity proof. Layer 1 (Ethereum) helps maintain the state of all transfers on the ZK smart contract, making it easier for a block to be validated since only the validity proof is required and not the entire transaction data.
Optimistic rollups run side by side with the main chain. However, Optimistic rollups assume that a transaction is valid by default, after which they propose the new state to the mainnet.
While assuming that a transaction is correct could save the computational power that mainnet miners would otherwise require to verify the transaction status. This could pose great risks, such as the tendency to submit a fraudulent transaction on layer 1. Optimistic rollups avoid this and other risks by introducing what is known as fraudproof.