What if you could speed up blockchain transactions without losing trust or security?
Rollups (Optimistic vs ZK) in Blockchain / Solidity - When to Use Which
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have a busy highway where every car represents a transaction on a blockchain. Without any special system, all cars must drive on the main road, causing traffic jams and slow travel.
Handling every transaction directly on the main blockchain is slow and expensive. It's like forcing all cars to use the same crowded road, leading to delays and high costs. This makes scaling difficult and frustrating for users.
Rollups bundle many transactions off the main chain and then submit a summary back. Optimistic rollups assume transactions are valid unless challenged, while ZK rollups use proofs to instantly verify correctness. Both reduce traffic on the main road, speeding up processing and lowering fees.
function processTransaction(tx) {
validateOnMainChain(tx);
recordOnMainChain(tx);
}function submitBatch(transactions) {
const rollupProof = generateProof(transactions);
submitToMainChain(rollupProof);
}Rollups unlock fast, cheap, and secure blockchain transactions by moving most work off-chain while keeping trust strong.
Think of a busy online game where thousands of players trade items. Rollups let these trades happen quickly without clogging the main blockchain, so players enjoy smooth gameplay and low fees.
Manual transaction processing on main chains is slow and costly.
Rollups bundle transactions to reduce load and speed up processing.
Optimistic and ZK rollups use different trust methods to keep data secure and efficient.
Practice
What is the main difference between Optimistic Rollups and ZK Rollups?
Solution
Step 1: Understand Optimistic Rollups behavior
Optimistic Rollups trust transactions are valid initially and allow a challenge period to dispute invalid ones.Step 2: Understand ZK Rollups behavior
ZK Rollups generate cryptographic proofs that transactions are valid immediately, so no waiting period is needed.Final Answer:
Optimistic Rollups assume transactions are valid until challenged; ZK Rollups use proofs to verify immediately. -> Option AQuick Check:
Trust first vs proof first [OK]
- Confusing which rollup uses proofs immediately
- Thinking both rollups have the same waiting period
- Assuming ZK Rollups do not move work off-chain
Which of the following is the correct syntax to describe a ZK Rollup in a blockchain smart contract comment?
// This rollup uses ______ to verify transactions instantlySolution
Step 1: Identify ZK Rollup verification method
ZK Rollups use zero-knowledge proofs to verify transactions instantly.Step 2: Match the correct phrase in the comment
The comment should mention "zero-knowledge proofs" to describe ZK Rollups.Final Answer:
zero-knowledge proofs -> Option DQuick Check:
ZK Rollups = zero-knowledge proofs [OK]
- Choosing 'waiting period' which applies to Optimistic Rollups
- Confusing optimistic assumptions with ZK proofs
- Selecting manual challenges which are for Optimistic Rollups
Consider this pseudocode for an Optimistic Rollup transaction verification:
function verifyTransaction(tx) {
assume tx is valid
wait 7 days for challenge
if no challenge then finalize tx
else revert tx
}What will happen if a fraudulent transaction is submitted and no one challenges it?
Solution
Step 1: Analyze the verification logic
The function assumes transactions are valid and waits 7 days for any challenge.Step 2: Consider no challenge scenario
If no challenge occurs within 7 days, the transaction is finalized regardless of validity.Final Answer:
The fraudulent transaction will be finalized after 7 days. -> Option CQuick Check:
Optimistic waits then finalizes if no challenge [OK]
- Thinking fraudulent tx is rejected immediately
- Assuming zero-knowledge proofs are used here
- Believing finalization is instant without waiting
Identify the bug in this ZK Rollup pseudocode snippet:
function verifyZKProof(proof) {
if (proof.isValid) {
finalizeTransaction()
} else {
wait 7 days for challenge
}
}What is the main issue?
Solution
Step 1: Understand ZK Rollup verification
ZK Rollups use immediate proof verification and do not require waiting periods.Step 2: Analyze the code logic
The code incorrectly waits 7 days if proof is invalid, which contradicts ZK Rollup design.Final Answer:
ZK Rollups should not wait for challenges; proof validity is immediate. -> Option BQuick Check:
ZK Rollups = instant proof, no wait [OK]
- Thinking waiting is needed for ZK Rollups
- Misreading proof validity condition
- Assuming finalizeTransaction requires delay
You want to design a rollup system that minimizes user waiting time but can handle complex computations off-chain. Which rollup type should you choose and why?
Solution
Step 1: Identify rollup goals
The goal is to minimize waiting time and handle complex off-chain computations.Step 2: Compare rollup features
ZK Rollups provide immediate validity proofs, enabling faster finality without waiting periods, suitable for complex computations.Final Answer:
ZK Rollup, because it provides immediate proof and faster finality. -> Option AQuick Check:
Minimize wait + complex work = ZK Rollup [OK]
- Choosing Optimistic Rollup for instant finality incorrectly
- Confusing which rollup uses zero-knowledge proofs
- Thinking ZK Rollups wait for challenges
