Explain in detail how the Layer 2 extension solution Optimism works
Tokenview
2022-11-18 03:05
本文约4698字,阅读全文需要约19分钟
Optimism's design has a number of significant advantages over other, more complex L2 structures.

Optimism is a fast, stable, scalable and low-cost Ethereum Layer 2 blockchain. This means it runs on top of the Ethereum blockchain (Layer 1) to help alleviate congestion, which in turn reduces transaction costs and processing times. As a minimal extension of existing Ethereum software, Optimism's EVM-equivalent architecture can extend Ethereum applications. If it works on Ethereum, it also works on Optimism at a fraction of the cost of Ethereum.

secondary title

Optimism design philosophy

simplicity

Optimism aims to keep the feature set as simple as possible for it. Ideally, Optimism should consist of the minimum number of moving parts required for a secure, scalable and flexible L2 system. This simplicity gives Optimism's design a number of significant advantages over other, more complex L2 structures.

Simplicity reduces engineering overhead, which in turn means more time can be spent on new functionality rather than recreating existing functionality. Optimism prefers to use existing battle-tested Ethereum code and infrastructure wherever possible. The clearest example of this philosophy in practice is the choice to use Geth as Optimism's client software. When dealing with critical infrastructure, simplicity is also security. A simple protocol means less code to write and therefore less potential for bugs. A clean and minimal code base is also easier for external contributors and auditors to access. All of these help to maximize the security and correctness of the Optimism protocol.

Simplicity is also important to Optimism's long-term vision. By limiting the amount of code written on top of Ethereum tools, the majority of time can be spent directly on existing codebases. Optimism can also directly benefit Ethereum and vice versa. This will only become more apparent as the Optimism protocol solidifies and existing resources can be redirected to core Ethereum infrastructure.

Practicality

sustainability

sustainability

Application developers need to ensure that the platforms they build will not only work but also be competitive over a long period of time. Optimism's design process is built around the idea of ​​long-term sustainability, rather than taking shortcuts to achieve scalability. At the end of the day, a scalable system is meaningless without the ecosystem that sustains it.

optimism

secondary title

Optimistic Rollups

Optimism adopts optimistic Rollups technology, which can "aggregate" a large amount of transaction data into a batch of data on Ethereum, so that only one transaction fee is charged. In this way, transactions are processed faster and cheaper, while relying on the security of Ethereum. We will briefly explain how Optimistic Rollups work at a high level. We'll then explain why Optimism was built as Optimistic Rollups, and why we think it's the best choice for a system that addresses all of our design goals.

Optimism is an "Optimistic Rollup", which is basically just a fancy way of describing a blockchain that relies on the security of another "parent" blockchain. Specifically, Optimistic Rollups utilize the consensus mechanism of its parent chain (such as PoW or PoS), rather than providing its own. In Optimism's usage, this parent blockchain is Ethereum.

block storage

All Optimism blocks are stored in a special smart contract on Ethereum called the CanonicalTransactionChain (or CTC for short). Optimism blocks are kept in an append-only list within the CTC. This append-only list forms the Optimism blockchain.

CanonicalTransactionChain contains some code to ensure that the existing block list cannot be modified by new Ethereum transactions. However, this guarantee would be broken if the ethereum blockchain itself were to reorganize and change the order of past ethereum transactions. The Optimism mainnet is configured to be resistant to block reorganizations for up to 50 Ethereum blocks. If Ethereum undergoes a larger reorganization than this, Optimism will reorganize as well.

Of course, not undergoing such major block reorganizations is a key security goal of Ethereum. Therefore, as long as Ethereum's consensus mechanism is secure, large-scale block reorganizations can be avoided. It is through this relationship (at least in part) that Optimism derives its security from Ethereum.

block production

Optimism block production is primarily managed by a single party, called a sequencer, which helps the network by providing the following services:

  • Provides instant transaction confirmations and status updates.

  • Build and execute L2 blocks.

  • Submit user transactions to L1.

The sequencer has no mempool, and transactions are accepted or rejected immediately in the order they are received. When a user sends their transaction to the sequencer, it checks that the transaction is valid (i.e. paid enough fees), and then applies the transaction to its local state as a pending block. These pending blocks are periodically submitted in bulk to Ethereum for finalization. This batching process significantly reduces overall transaction fees by spreading the fixed cost across all transactions within a given batch. The sequencer also applies some basic compression techniques to minimize the amount of data posted to Ethereum.

Because the sequencer is given preferential write access to the L2 chain, when it finalizes a new pending block, the sequencer can provide a strong guarantee of what state will be finalized. In other words, know exactly what the impact of the deal is. As a result, the L2 state can be updated very quickly and reliably. The benefits of this include a fast, instant user experience, such as near real-time Uniswap price updates.

Alternatively, users can skip the sequencer entirely and submit their transactions directly to the

CanonicalTransactionChain. This is usually more expensive because the fixed cost of submitting this transaction is paid entirely by the user and is not spread over many different transactions. However, this optional submission method has the advantage of being resistant to censorship by the sequencer. Users can always continue to send transactions on Optimism even if the sequencer is actively vetting them.

In order for users to be able to perform withdrawals in a censorship-resistant manner, the rollup must allow participants to publish transaction results to Ethereum in a trustless manner. Currently, the Optimism Foundation is the only entity capable of publishing transaction results while decentralizing the "result proposal" role. While not unique to Optimism, it pays to be aware of these security properties when using the system. The unlicensed release of results should introduce a proof-of-failure system alongside Cannon's production release.

block execution

Ethereum nodes download blocks from Ethereum's p2p network. Optimism nodes download blocks directly from the append-only block list in the CanonicalTransactionChain contract.

An Optimism node consists of two main components, the Ethereum data indexer and the Optimism client software. The Ethereum Data Indexer, also known as the "Data Transfer Layer" (or DTL), reconstructs the Optimism blockchain from blocks published to the CanonicalTransactionChain contract.

The DTL searches for events emitted by the CanonicalTransactionChain that signal that a new Optimism block has been published. It then examines the transactions that emitted these events, reconstructing the published blocks in the standard Ethereum block format.

The second part of the Optimism node, the Optimism client software, is an almost entirely vanilla version of Geth. This means that Optimism is essentially the same as Ethereum. In particular, Optimism shares the same Ethereum virtual machine, the same account and state structure, and the same gas metering mechanism and fee schedule. We refer to this architecture as "EVM-equivalent", meaning that most Ethereum tools (even the most sophisticated) "just work" with Optimism.

secondary title

Standard bridge between L1 and L2

Optimism is designed to allow users to send arbitrary messages between Optimism and smart contracts on Ethereum. This makes it possible to transfer assets (including ERC20 tokens) between the two networks. The exact mechanism by which this communication occurs depends on the direction in which the message is sent. Optimism uses a standard bridge (StandardBridge) to allow users to deposit assets (ERC20 and ETH) from Ethereum into Optimism, and allow the same assets to be withdrawn from Optimism back to Ethereum.

The standard bridge consists of two main contracts L1StandardBridge (for layer 1) and L2StandardBridge (for layer 2).

Deposits

Deposit to ERC20

ERC20 deposits to L2 can be triggered through the depositERC20 and depositERC20To functions on L1StandardBridge, Standard Token Bridge must be approved to use the amount of tokens you want to deposit, otherwise the deposit will fail.

deposit ETH

The deposit of ETH into L2 can be triggered by the depositETH and depositETHTo functions on L1StandardBridge. It is also possible to send ETH directly to L1StandardBridge. Once the user's deposit is detected and finalized on Optimism, the user's account will receive a corresponding amount of ETH on L2.

Withdrawals

Withdraw ERC20

ERC20 withdrawal can be triggered by the withdraw or withdrawTo function on L2StandardBridge.

Withdraw ETH

Unlike L1, we do not have a separate function on L2 to withdraw ETH. Instead, users can use the withdraw or withdraw to function on L2StandardBridge, and use the address

secondary title

failure proof

In Optimistic Rollup, state commitments are posted to Ethereum without any direct proof of the validity of those commitments. Instead, these commitments are considered pending for a period of time (called the "challenge window"). A proposed state commitment is considered final if it has not been challenged during the challenge window (currently set to 7 days). Once a commitment is considered final, smart contracts on Ethereum can safely accept proofs based on the Optimism state of that commitment.

When state commitments are challenged, they can be invalidated through the "proof-of-failure" (formerly "proof-of-fraud") process. If the commitment is successfully challenged, it is removed from the StateCommitmentChain and eventually replaced by another proposed commitment. It is important to note that a successful challenge does not roll back Optimism itself, only the published commitments about the state of the chain. The order of transactions and the state of Optimism will not change due to a proof-of-failure challenge.

Original link:

Original link:

https://community.optimism.io/docs/how-optimism-works/#moving-from-ethereum-to-optimism

For more blockchain knowledge and dry goods, follow Tokenview.io.

Tokenview
作者文库