Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction Finality Explainer #987

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a6ac1ab
Initial commit
krofax Oct 14, 2024
0b36071
updated docs
krofax Oct 14, 2024
10bac65
updated the docs and added image
krofax Oct 14, 2024
2063c26
updated the docs
krofax Oct 14, 2024
880a3eb
fix lint issues
krofax Oct 14, 2024
7cbd715
updated finality docs
krofax Oct 23, 2024
f35ba6c
fix linting errors
krofax Oct 23, 2024
0b66134
fix conflict
krofax Oct 23, 2024
e87c41b
updated few grammar errors
krofax Oct 23, 2024
d1003e6
updated the tones
krofax Oct 23, 2024
5d50382
updated some concepts
krofax Oct 23, 2024
96d6722
removed duplications
krofax Oct 23, 2024
565bc82
Updated structure
krofax Oct 23, 2024
1a136d6
resolved suggestions
krofax Oct 23, 2024
16f6052
fix lint errors
krofax Oct 23, 2024
0139df2
Update pages/stack/transactions/_meta.json
krofax Oct 24, 2024
186d941
Update pages/stack/transactions/_meta.json
krofax Oct 24, 2024
4eced45
Update pages/stack/transactions/_meta.json
krofax Oct 24, 2024
062aa1a
Update pages/stack/transactions/_meta.json
krofax Oct 24, 2024
fc42888
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
c1ebce7
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
2b3e7ed
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
965f8b9
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
8cf8f59
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
60e3688
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
a19a677
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
6340edd
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
ce345b5
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
1d70689
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
b9acf97
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
f6f4a38
resolved comments
krofax Oct 24, 2024
376a990
fix conflict
krofax Oct 24, 2024
867fb4c
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
8a9ecd0
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
b2cac6a
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
f5929b5
updated content
krofax Oct 24, 2024
d27bae6
updated the docs
krofax Oct 24, 2024
b71df34
removed wrong word
krofax Oct 24, 2024
aacd64f
resolved comments
krofax Oct 24, 2024
71ea8fc
Used sentence case in meta json file
krofax Oct 24, 2024
d7bec26
Update pages/stack/transactions/transaction-finality.mdx
sbvegan Oct 24, 2024
04bb7e9
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 24, 2024
e755619
Update pages/stack/transactions/transaction-finality.mdx
krofax Oct 30, 2024
f9a4bb0
updated text
krofax Oct 30, 2024
4513c5c
fix merge conflict
krofax Oct 30, 2024
99abedd
fix merge conflcits
krofax Oct 30, 2024
8c54927
feat: miscellanous improvements to finality doc
smartcontracts Nov 1, 2024
eda6ab7
Removed passive tones, and rephrased contents
krofax Nov 6, 2024
4c88d3a
replaced image with a mermaid diagram
krofax Nov 6, 2024
241c587
update meta.json
krofax Nov 6, 2024
1a13d97
Fix merge conflict
krofax Nov 6, 2024
c8c3d52
updated meta.json
krofax Nov 6, 2024
76396df
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 7, 2024
47ad29d
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 7, 2024
71774a7
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 7, 2024
816ac38
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 7, 2024
45a3248
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 7, 2024
1186141
remove todo
krofax Nov 7, 2024
4460b89
Update pages/stack/transactions/transaction-finality.mdx
krofax Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/stack/protocol/rollup/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"deposit-flow": "Deposit Flow",
"transaction-flow": "Transaction Flow",
"withdrawal-flow": "Withdrawal Flow",
"transaction-finality": "Transaction Finality ",
"forced-transaction": "Forced Transaction"
}
135 changes: 135 additions & 0 deletions pages/stack/protocol/rollup/finality.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
title: Transaction Finality
lang: en-US
description: Learn about finality in OP Stack and the steps to achieve transaction settlement.
---

import Image from 'next/image'
import { Callout } from 'nextra/components'

# OP Stack rollups

OP Stack rollup is an extension of the consensus mechanism in Ethereum, where instead of running an entirely separate consensus protocol, we piggyback off Ethereum's consensus. This way, OP Stack rollup can take advantage of Ethereum's ordering mechanism and finalize its own blocks without needing to create a new consensus layer.

## State Machines and Transaction Processing

State machines, such as the EVM, rely on input lists (transactions) to evolve from one state to another. The list and its order are vital because incorrect ordering can lead to an invalid state.

For example, if a user tries to send 1 ETH to two different parties at the same time, only one transaction can be valid. The order determines which transaction succeeds, making ordering an essential aspect of consensus.

## Commutative vs non-Commutative operations

Commutative operations allow input order to change without affecting the outcome. However, non-commutative operations (like sending funds) require strict ordering. Hence, the list's availability and ordering are fundamental to ensuring the integrity of the system.

## Consensus and Ordering

Consensus determines the valid chain or list of transactions. In OP Stack, Ethereum's consensus (via Proof of Stake) is used to achieve transaction ordering and finality.

## Why piggybacking on Ethereum?

By publishing rollup blocks on Ethereum, OP Stack effectively outsource it's consensus mechanism. Instead of running a separate consensus protocol, they rely on Ethereum's ordering and finality guarantees.
krofax marked this conversation as resolved.
Show resolved Hide resolved

Key benefits of this approach include:

* OP Stack inherit Ethereum's security and ordering properties.
krofax marked this conversation as resolved.
Show resolved Hide resolved
* The OP Stack simplifies the design and development process by removing the need for a separate consensus protocol.
* Attack vectors such as double-spends are mitigated by Ethereum's inherent mechanisms.

### Transaction finality states

In OP Stack, transaction finality involves three main stages:

* Unsafe: The L2 sequencer creates a block containing the transaction, but the transaction data will not been posted to L1. It is circulated within the L2 network for speed.
krofax marked this conversation as resolved.
Show resolved Hide resolved

* Safe: The sequencer's batcher posts transaction data to L1. Any L2 node can now derive this transaction.

* Finalized: Transactions is finalized once more than (>65) L1 blocks have passed(approximately 20 minutes), ensuring the L1 data is secure and won't be reorganized.

<Image src="/img/op-stack/protocol/tx-finality.png" alt="Transaction Finality Diagram." width={0} height={0} sizes="100vw" style={{ width: '100%', height: 'auto' }} quality={100} />

## Sequencer Operations

The sequencer (block producer) handles transaction processing through the following steps:

1. Pre-publishing Distribution:
* Sequencer receives transactions from users
* Creates blocks containing these transactions
* Distributes blocks to network nodes before L1 publication
* Nodes mark these blocks as "unsafe"

2. L1 Publication:
* Sequencer publishes blocks to Ethereum
* Blocks become "safe" once included in L1
* Blocks achieve "finalized" status after L1 finalization (approximately 20 minutes)

### Sequencer Trust

The sequencer's role involves certain trust assumptions:

* Can temporarily withhold transactions.
* May attempt to reorder transactions before L1 publication.
* Cannot modify or censor transactions once published to L1.
* Cannot affect finalized transactions.

## Block and transaction validity in the OP Stack

When a block is submitted to Ethereum, it is either valid or invalid. If the block is valid, the state is updated; otherwise, it is discarded. Nodes execute valid blocks and update the rollup state accordingly.

### Reorgs and finality

A block's inclusion in a finalized Ethereum block ensures its finality. If a rollup block is included in a finalized Ethereum block, it cannot be reorged. Therefore, rollup blocks enjoy the same finality guarantees as Ethereum blocks, and this finality is handled by the **OP Stack** architecture.

### Reorg Handling

When L1 reorgs occur:

1. Nodes detect the L1 reorg
2. Affected L2 blocks return to "unsafe" status
3. Sequencer typically republishes the same transactions
4. System returns to consistent state after reprocessing
krofax marked this conversation as resolved.
Show resolved Hide resolved

## The role of the proof system

The proof system, is entirely separate from the core OP Stack protocol. It is an app-level validation system designed to ensure that certain claims about the rollup's state are correct.

### What is a claim?

A claim in the context of rollups built on the OP Stack is a statement that asserts the state of the system at a specific block height. For example, a claim might assert that at block 1,000,000, the state hash is `XYZ`. Other participants can challenge this claim if they believe it to be incorrect.

### Fault proofs and challenges

Challenges revolve around proving whether a given claim is valid. However, the outcome of a challenge does not affect the underlying chain. For example, if a claim about the state of the rollup at a certain block is proven wrong, it only affects the app-level functionality, not the OP Stack protocol.

### Bridge Independence

Important points about bridge systems:

* Bridges are application-level constructs
* They operate independently of the core rollup protocol
* Bridge security doesn't affect L2 transaction validity
* Bridge failures don't cause L2 reorgs or state changes

### Example: Custom bridges in OP Stack

A custom bridge might be developed by a user to allow ERC-20 tokens to move between layers. However, this bridge is app-level and not native to the OP Stack rollup. If there's an issue with the bridge, such as incorrect proof validation, it doesn't affect the rollup itself but impacts the subjective value of the bridged assets.

## 7 days challenge period in OP Stack

The 7 days challenge period exists to give time for challenges to be raised and resolved. While the rollup chain itself finalizes quickly (within 20 minutes), withdrawals from Layer 2 are delayed to allow for fault-proof validation. This ensures that malicious activity can be detected and challenged before it affects the system.
krofax marked this conversation as resolved.
Show resolved Hide resolved

### Why 7 days?

The 7 day period is a reasonable time frame to allow participants to organize a response, potentially even organizing a hard fork on Layer 1 to address severe issues. In the context of the OP Stack, this challenge period also serves as a safeguard for app-level bridges and custom rollup designs that may be built on top of the core protocol.

### Withdrawal Delays vs. Finality

One common misconception is confusing withdrawal delays with transaction finality:

* Transaction finality occurs in approximately 20 minutes
* Withdrawal delays (often 7 days) are separate from transaction finality
* Withdrawal delays are application-level security features
* These delays affect only L1 withdrawals, not L2 transaction finality

## Conclusion

Transaction finality on the OP Stack depends heavily on Ethereum's consensus mechanism. The OP Stack ensures that rollups inherit Ethereum's finality guarantees, while the proof system adds an additional layer of validation for app-level functionality. While finality occurs quickly for rollup blocks, the proof system introduces a delay for withdrawals to ensure the security of bridging mechanisms.
Binary file added public/img/op-stack/protocol/tx-finality.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.