Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Why rollups exist

After this lesson: I can explain what a rollup runs off the main chain and what it posts on it.

60 min lesson2 commandsRollup lab: batches, fraud proofs, data availability and exits in Python

A chain where everybody repeats everything

On a public chain, every node runs every transaction again to check it. That is what makes the chain trustworthy, and also what makes it slow.

Most activity on large chains now happens on rollups instead. Today you see what a rollup moves off the chain and what it must leave on it.

By the end of this lesson

Note

I can explain what a rollup runs off the main chain and what it posts on it.

Key words

WordWhat it means
Main chainthe chain every node checks, also called L1
Rollupa system that runs transactions off the main chain and posts them on it
Executionrunning each transaction to work out the new state
Batchmany transactions posted together
Posted datathe batch written on the main chain so anybody can read it
State rootone hash that stands for every balance

The cells students fill in are left blank in this preview.

A rollup splits the work in two

A rollup takes the slow part, execution, off the main chain. A computer run by the rollup applies the transactions and works out the new balances.

The main chain keeps the part that needs trust. It stores the batch as posted data, so anybody can read it, and the new state root. While nobody objects, it runs none of the transactions itself.

Compare the work for 1000 transfers

Command
docker exec jupyter python3 steps/costs.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: what the lab printed

MeasureEach transfer on L1One rollup batch
Transfers L1 runs10000
Data L1 storesevery transfer10524 bytes and one root
Bytes per transfernot measured10.5
Transfers that fit one blobnot usedabout 12454

The cells students fill in are left blank in this preview.

Try it: the bytes a batch posts

Code: python
transfers = [("ana", "ben", 5), ("ben", "chen", 3), ("chen", "ana", 2)]

lines = []
for sender, receiver, amount in transfers:
    lines.append(sender + ">" + receiver + ":" + str(amount))
data = "\n".join(lines)

print(data)
print("bytes:", len(data))
print("bytes per transfer:", round(len(data) / len(transfers), 1))
# Add ("dev", "ana", 40) to the list and run again. How many bytes does it add?

What the main chain still guarantees

Three things stay on the main chain. The data is published, so anybody can rebuild the balances. The state root is fixed, so nobody can quietly change history. And the main chain settles any dispute about a batch.

Rollups differ in how a wrong root is stopped. An optimistic rollup lets anybody challenge it. A validity rollup posts a proof with every batch.

A common mistake

Warning

Many people think a rollup is just a separate chain. A separate chain has its own checkers who decide its state. A rollup's state follows from data and rules on the main chain, so anybody can rebuild it from the main chain alone.

List the scripts in the lab

Command
docker exec jupyter ls steps

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

About this lab and its source: Rollup lab: batches, fraud proofs, data availability and exits in Python

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.