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
| Word | What it means |
|---|---|
| Main chain | the chain every node checks, also called L1 |
| Rollup | a system that runs transactions off the main chain and posts them on it |
| Execution | running each transaction to work out the new state |
| Batch | many transactions posted together |
| Posted data | the batch written on the main chain so anybody can read it |
| State root | one 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
docker exec jupyter python3 steps/costs.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: what the lab printed
| Measure | Each transfer on L1 | One rollup batch |
|---|---|---|
| Transfers L1 runs | 1000 | 0 |
| Data L1 stores | every transfer | 10524 bytes and one root |
| Bytes per transfer | not measured | 10.5 |
| Transfers that fit one blob | not used | about 12454 |
The cells students fill in are left blank in this preview.
Try it: the bytes a batch posts
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
docker exec jupyter ls stepsShown here, not run. Press Start lab to type it into your own lab’s terminal.