# ZK Rollup
A **ZK Rollup** is a Layer 2 scaling solution that batches thousands of transactions into a single cryptographic proof (not one proof per transaction!). This proof is computed off-chain and provides cryptographic assurance of state changes. More precisely, the proof guarantees that there exists a series of transactions, correctly signed by the respective owners, that update the account balances accurately and transition the old Merkle root to the new one.
**Scalability**
- Only **one** succinct proof is submitted to the blockchain, reducing on-chain data load.
- Transaction data is processed **off-chain**, significantly enhancing throughput.
## Definitions
**Accounts and States**
Accounts can either be user accounts or smart contract accounts. Each account typically includes: **balance**, the amount of tokens (e.g., ETH, native tokens) associated with the account.
Accounts are stored in a Merkle tree, where each account corresponds to a leaf. The **state** of all accounts is represented by the Merkle root.
Example of states (and accounts):
- Pre-State: The state of all accounts before processing a batch of transactions.

- Post-State: The updated state of all accounts after processing the batch (using the example batch shown in the batch definition)

**Transactions**
Transactions are cryptographically signed instructions from accounts. The simplest transaction is a token transfer between accounts. For example:
- Alice -> Bob: 20 tokens
- Alice -> Charlie: 10 tokens
- Bob -> Charlie: 10 tokens
**Batch**
A batch is a collection of transactions grouped together for efficient processing and state updates in the zkRollup.

**Proof**
A proof ensures the correctness of off-chain computations. This cryptographic proof verifies that the state update resulting from a batch of transactions are valid without requiring the Layer 1 chain to re-execute them.
## Architecture
**On-Chain Components**
- Verifier Contract: Verifies the zk-proof, ensuring the correctness of state updates.
- Main Contract: Stores rollup blocks, tracks deposits, and monitors state updates.
On-chain data includes:
- A **compressed representation of the batch** (e.g., calldata), allowing anyone to reconstruct the rollup’s state independently.
- The corresponding validity **proof** that verifies the batch.
- The **new state root** after applying the batch of transactions.
**Off-Chain Components**
Transactions are executed off-chain:
- **User Actions**: Users sign transactions and submit them to the Layer 2 operator (or sequencer).
- **Batch Aggregation**: The operator aggregates transactions into batches, compresses them into calldata, and submits the calldata to Layer 1
- **State Root Updates**: After processing the transactions, the operator computes the new state root and submits it to the on-chain contract.
- **Proof Generation**: The operator computes a zk-proof verifying the correctness of off-chain state update. Once this proof is verified by the verifier contract, the new state root becomes the zkRollup’s canonical state root.
### Proof Generation
The proving circuit computes the validity proof by iterating over each transaction and performing the following steps:
- State Update for the Sender's Account:
- Verifies that the sender's account exists in the current state tree using the provided Merkle proof.
- Reduces the sender's balance and increases their nonce.
- Hashes the updated account data and recomputes the Merkle proof to derive an updated state root.
- State Update for the Receiver's Account:
- Checks if the receiver's account exists in the updated state tree using the Merkle proof.
- Increases the receiver's balance.
- Re-hashes the account data and recomputes the Merkle proof to derive a new state root.
After processing all transactions in the batch, the last computed Merkle root becomes the new canonical state root for the zkRollup.
<!--
:::info
Underlying proof system:
zkSync (PLONK), StarkWare (zk-STARKs), and Aztec (zk-SNARKs).
:::
-->
## References
- [An Incomplete Guide to Rollups](https://vitalik.eth.limo/general/2021/01/05/rollup.html)
- [Ethereum zk-Rollups](https://ethereum.org/en/developers/docs/scaling/zk-rollups/)