How to Implement an Optimistic Rollup Step by Step
An optimistic rollup moves transactions off chain and posts results to layer 1, assuming they are valid unless challenged. Here is how to build one, step by step.
On this page
Short answer
An optimistic rollup is a layer-2 chain that executes transactions off the main chain and posts the data to layer 1, assuming the transactions are valid unless someone proves otherwise during a challenge window. To implement one, you pick a rollup stack, deploy the bridge and rollup contracts on layer 1, run a sequencer and a batcher, test on a testnet, then open deposits and withdrawals with monitoring in place.
What is an optimistic rollup?
An optimistic rollup is a layer-2 blockchain that runs transactions off the main chain and posts the resulting data back to layer 1. The name comes from its key idea: the rollup assumes transactions are valid, and only checks them if someone challenges them.
That assumption is what makes the design fast and cheap. Instead of proving every transaction correct in advance, the rollup posts a summary of the new state to layer 1 and waits. If nobody objects during the challenge window, the state is accepted as final.
The challenge window is usually around seven days on the large optimistic rollups. During that time anyone can submit a fraud proof showing that a state update was wrong. If the proof holds, the bad update is reversed and the party that posted it loses its bond.
Optimistic rollups inherit security from the layer-1 chain because the data is posted there. Anyone can rebuild the rollup state from the layer-1 data, so the rollup cannot hide what it did.
What do you need before you start?
Before you start, you need to know the parts of a rollup and which of them you will run yourself. A rollup is not one program; it is several services working together.
| Part | What it does | Who runs it |
|---|---|---|
| Bridge contracts | Hold deposits and handle withdrawals on layer 1 | Deployed on layer 1 |
| Sequencer | Orders transactions and builds blocks | Usually the rollup team at first |
| Batcher | Posts transaction data to layer 1 | Usually the rollup team |
| Proposer | Posts state roots to layer 1 | Usually the rollup team |
| Challenger | Checks state roots and submits fraud proofs | Anyone, including the team |
| Node software | Lets users sync and check the chain | Anyone who runs a node |
You also need a decision on the stack. The two common paths are the OP Stack, used by Optimism-based chains, and Arbitrum Orbit, used by Arbitrum-based chains. Both give you the contracts and node software; the difference is in the tooling and the community around each.
Finally, you need a testnet plan and a budget for layer-1 fees. Posting data to layer 1 is the main running cost, so estimate it before you promise a launch date.
How do you implement an optimistic rollup?
You implement an optimistic rollup by choosing a stack, configuring the chain, deploying the contracts, running the services, testing on a testnet, and then launching with monitoring in place.
- Choose the stack. Pick the OP Stack or Arbitrum Orbit based on the tooling your team knows and the ecosystem you want to join.
- Configure the chain. Set the chain ID, block time, gas limits and fee rules, and decide who runs the sequencer at launch.
- Deploy the bridge and rollup contracts. Deploy them on layer 1 and check that deposits, withdrawals and state roots work on a testnet first.
- Run the sequencer and batcher. Bring up the services that order transactions and post data to layer 1, with backups for each.
- Run a challenger. Watch the state roots your proposer posts and be ready to submit a fraud proof if one is wrong.
- Test on a public testnet. Invite users to break deposits, withdrawals and the bridge before real funds are involved.
- Launch with limits. Open deposits with a cap, watch the system for a few weeks, then raise the cap.
Do not skip the challenger step. A rollup with no one watching the state roots is trusting its own proposer, which removes the point of the design.
For a sense of what the build costs, optimistic rollup cost breaks down the main cost drivers.
How do fraud proofs and the challenge window work?
Fraud proofs work by letting anyone replay a disputed transaction on layer 1 and show that the rollup's claimed result was wrong. The layer-1 contract runs the check, so the dispute is settled by code, not by voting.
The challenge window is the time during which a fraud proof can be submitted. On the large optimistic rollups it is usually around seven days. That means a withdrawal from the rollup to layer 1 takes about seven days to finalise, because the bridge must wait out the window.
That wait is the main user-facing cost of the design. Deposits into the rollup are fast, because layer 1 only needs to record them. Withdrawals are slow, because the bridge cannot release funds until no one can challenge the state any more.
Teams sometimes shorten the wait with liquidity providers, who pay the user immediately and wait out the window themselves for a fee. That is a service built on top of the rollup, not a change to the challenge window itself.
Example (hypothetical): a game studio launches a rollup
Example (hypothetical): a game studio launches an optimistic rollup for its game. On a busy day, 10,000 players each make 20 in-game transactions, which is 200,000 transactions a day.
The sequencer groups those transactions into batches of 1,000. That means 200,000 divided by 1,000 gives 200 batches a day, and each batch is posted to layer 1 as one piece of data. Posting 200 batches costs far less than posting 200,000 separate transactions.
Withdrawals work differently. A player who sells an item and withdraws the proceeds must wait out the challenge window of about seven days before the bridge releases the funds on layer 1.
The studio plans for that wait in its support pages, so players are not surprised. The rollup gives the game cheap transactions, and the seven-day wait is the price of the fraud-proof design.
What are the common mistakes?
The most common mistakes in an optimistic rollup build come from treating the rollup like a standalone chain. It is not; it depends on layer 1 for security and for withdrawals.
- No challenger running. If nobody watches the state roots, a bad update can pass unchallenged.
- Centralised sequencer with no plan. A single sequencer is normal at launch, but there should be a written plan for what happens if it stops.
- Hiding the withdrawal wait. Users who learn about the seven-day window after withdrawing will complain, so state it up front.
- Underestimating layer-1 data costs. Posting data is the main running cost, and it rises with usage.
- Launching without a cap. Opening deposits without a limit means a bug can put large sums at risk on day one.
- Skipping the bridge audit. The bridge holds the funds, so it deserves the same review as the rollup itself.
To compare this design with the other rollup type before committing, read ZK rollup vs optimistic rollup.
How do you keep a rollup running safely?
You keep a rollup running safely by watching the services, the state roots and the bridge, and by having a tested plan for upgrades and outages.
Monitoring should cover the sequencer, the batcher and the proposer. If the batcher stops posting, the rollup stops settling, so alert on that first. If the proposer posts a state root that does not match the data, the challenger must catch it inside the window.
Upgrades need care because the bridge contracts hold user funds. Any upgrade should be tested on a testnet, reviewed, and announced in advance, with a pause mechanism in case something goes wrong.
Data availability is the last piece. If the data posted to layer 1 stops being available, users cannot rebuild the state or exit. Check that the data is actually on layer 1, not only that the proposer claims it is.
Teams that want an outside review of the design can start with blockchain development before committing to a stack.
Key takeaways
- An optimistic rollup assumes transactions are valid and relies on fraud proofs to catch errors
- The challenge window is usually around seven days, which is why withdrawals are slow
- You need a stack, bridge contracts, a sequencer, a batcher and a challenger
- Posting data to layer 1 is the main running cost and it grows with usage
- Launch with a deposit cap and a challenger running from day one
Frequently asked questions
How long do optimistic rollup withdrawals take?
Withdrawals usually take about seven days, because the bridge must wait out the challenge window before releasing funds on layer 1. Deposits are fast, since layer 1 only needs to record them. Liquidity providers can pay users sooner for a fee.
What is the difference between an optimistic rollup and a ZK rollup?
An optimistic rollup assumes transactions are valid and uses fraud proofs to catch errors, while a ZK rollup proves each batch is correct with a validity proof before it is accepted. Optimistic rollups are simpler to build; ZK rollups finalise withdrawals faster.
Do I need to write my own rollup code?
No. The OP Stack and Arbitrum Orbit provide the contracts and node software, so most teams configure and deploy rather than writing a rollup from scratch. The work is in configuration, testing, operations and the bridge.
What does the sequencer do?
The sequencer orders transactions and builds blocks for the rollup. It is usually run by the rollup team at launch, which is why a plan for decentralising it or handling its failure matters.
Can anyone challenge a bad state update?
Yes. Anyone can submit a fraud proof during the challenge window by replaying the disputed transaction on layer 1. If the proof holds, the bad update is reversed and the party that posted it loses its bond.
Is an optimistic rollup safe for real funds?
It is as safe as its bridge, its challenger and its data posting. A rollup with an audited bridge, a running challenger and data posted to layer 1 inherits the security of the base chain. A rollup missing any of those three is not ready for real funds.