Layer 2 Solutions
Rollups, state channels, sidechains, and scaling solutions.
Overview
Layer 2 solutions scale Ethereum while inheriting security.
Scaling Approaches
Architecture Diagram
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Layer 2 Solutions ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Optimistic ā Zero-Knowledge ā
ā Rollups ā Rollups ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā State Channels ā Sidechains ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Optimistic Rollups
// Simplified fraud proof
contract OptimisticRollup {
struct StateUpdate {
bytes32 stateRoot;
uint256 blockNumber;
address submitter;
}
uint256 public constant CHALLENGE_PERIOD = 7 days;
function submitState(StateUpdate calldata update) public {
// Store state update
// Start challenge period
}
function challenge(uint256 updateId, bytes calldata proof) public {
// Verify fraud proof
// Revert invalid state
}
}
ZK-Rollups
// Simplified ZK proof verification
contract ZKRollup {
function verifyProof(
uint[2] calldata a,
uint[2][2] calldata b,
uint[2] calldata c,
uint[4] calldata publicInputs
) public view returns (bool) {
// Verify zk-SNARK proof
return verifier.verify(a, b, c, publicInputs);
}
}
State Channels
// Payment channel
contract PaymentChannel {
address public sender;
address public receiver;
uint256 public amount;
uint256 public expiry;
function open(address _receiver, uint256 _amount) public payable {
sender = msg.sender;
receiver = _receiver;
amount = msg.value;
expiry = block.timestamp + 1 hours;
}
function close(bytes calldata signature) public {
require(block.timestamp < expiry);
// Verify signature
// Transfer funds
}
}
Comparison
| Solution | TPS | Security | Cost |
|---|---|---|---|
| Optimistic | 2000+ | Ethereum | Low |
| ZK-Rollup | 3000+ | Ethereum | Medium |
| State Channel | 10000+ | Ethereum | Very Low |
| Sidechain | 1000+ | Own chain | Low |
Practice
Deploy a simple payment channel contract.