Optimism 技術文書
У Optimism нет традиционного вайтпейпера. Будучи оптимистичным роллапом Layer 2 для Ethereum, его устройство и спецификации задокументированы в технической документации, спецификации OP Stack и исследовательских публикациях, а не в едином формальном академическом документе.
Abstract
Abstract
The paper addresses the problem of scalability in decentralized blockchains by analyzing the trade-off between transaction throughput and hardware requirements to run a node. Rollups, i.e. technologies for on-chain verification of blocks executed off-chain, are presented in the form of fault or validity proofs. We compare Optimistic Rollups and Validity Rollups with respect to withdrawal time, transaction costs, optimization techniques, and compatibility with the Ethereum ecosystem. Our analysis reveals that Optimism Bedrock currently has a gas compression rate of approximately 20:1, while StarkNet achieves a storage write cost compression rate of around 24:1. We also discuss techniques to further optimize these rates, such as the use of cache contracts and Bloom filters. Ultimately, our conclusions highlight the trade-offs between complexity and agility in the choice between Optimistic and Validity Rollups. Keywords Blockchain, Scalability, Rollup 1. Introduction Blockchain technology has gained significant attention due to its potential to revolutionize various industries. However, scalability remains a major challenge, as most blockchains face a trade-off between scalability, decentralization, and security, commonly referred to as the Scalability Trilemma [1, 2]. To increase the throughput of a blockchain, a trivial solution is to increase its block size. In the context of Ethereum, this means increasing the maximum amount of gas a block can hold. As each full node must validate every transaction of every block, as the throughput increases, the hardware requirements also increase, leading to a greater centralization of the network. Some blockchains, such as Bitcoin and Ethereum, optimize their design to maximize their architectural decentralization, while others, such as the Binance Smart Chain and Solana, are designed to be as fast and cheap as possible. Decentralized networks artificially limit the throughput of the blockchain to lower the hardware requirements to participate in the network. Over the years, attempts have been made to find a solution to the Trilemma, such as state channels [3] and Plasma [4, 5]. These solutions have the characteristic of moving some activity off-chain, linking on-chain activity to off-chain activity using smart contracts, and verifying DLT 2023: 5th Distributed Ledger Technology Workshop, May 25-26, 2023, Bologna, Italy $ [email protected] (L. Donno) https://lucadonnoh.github.io/ (L. Donno) 0000-0001-9221-3529 (L. Donno) © 2023 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings http://ceur-ws.org ISSN 1613-0073 CEUR Workshop Proceedings (CEUR-WS.org) on-chain what is happening off-chain. However, both Plasma and state channels are limited in their support of general smart contracts. Rollups are blockchains (called Layer 2 or L2) that publish their blocks on another blockchain (Layer 1 or L1) and therefore inherit its consensus, data availability and security properties. They, unlike other solutions, support arbitrary computation. Rollups have three main components: • Sequencers: nodes that receive Rollup transactions from users and combine them into a block that is sent to Layer 1. The block consists of at least the state root (e.g. a Merkle root) and the data needed to reconstruct and validate the state. The Layer 1 defines the...
概要
この論文では、トランザクション スループットとノードを実行するためのハードウェア要件との間のトレードオフを分析することで、分散型 blockchain のスケーラビリティの問題に対処しています。ロールアップ、つまりオフチェーンで実行されるブロックをオンチェーンで検証するテクノロジーは、障害証明または有効性証明の形式で提供されます。出金時間、取引コスト、最適化手法、Ethereum エコシステムとの互換性に関して、オプティミスティック ロールアップと有効性ロールアップを比較します。私たちの分析により、Optimism Bedrock の現在のガス圧縮率は約 20:1 であるのに対し、StarkNet は約 24:1 のストレージ書き込みコスト圧縮率を達成していることがわかりました。また、キャッシュ コントラクトやブルーム フィルターの使用など、これらのレートをさらに最適化する手法についても説明します。最終的に、私たちの結論は、楽観的ロールアップと妥当性ロールアップの選択における複雑さと機敏性の間のトレードオフを浮き彫りにします。キーワード ブロックチェーン、スケーラビリティ、ロールアップ 1. はじめに ブロックチェーン技術は、さまざまな業界に革命を起こす可能性があるため、大きな注目を集めています。ただし、ほとんどの blockchain は、一般にスケーラビリティのトリレンマと呼ばれる、スケーラビリティ、分散化、セキュリティの間のトレードオフに直面しているため、スケーラビリティは依然として大きな課題です。 blockchain のスループットを向上させる簡単な解決策は、ブロック サイズを増やすことです。 Ethereum のコンテキストでは、これはブロックが保持できるガスの最大量を増やすことを意味します。各フルノードはすべてのブロックのすべてのトランザクションを検証する必要があるため、スループットが増加するにつれてハードウェア要件も増加し、ネットワークの集中化が進みます。 Bitcoin や Ethereum などの一部の blockchain は、アーキテクチャの分散化を最大化するために設計を最適化しますが、Binance Smart Chain や Solana などの他のものは、可能な限り高速かつ安価になるように設計されています。分散型ネットワークは、blockchain のスループットを人為的に制限して、ネットワークに参加するためのハードウェア要件を下げます。長年にわたり、状態チャネル [3] やプラズマ [4、5] など、トリレンマの解決策を見つける試みが行われてきました。これらのソリューションには、一部のアクティビティをオフチェーンに移動し、smart contracts を使用してオンチェーンのアクティビティをオフチェーンのアクティビティにリンクし、DLT 2023 を検証するという特徴があります: 第 5 回分散台帳技術ワークショップ、2023 年 5 月 25 ~ 26 日、イタリア、ボローニャ $ [email protected] (L. Donno) https://lucadonnoh.github.io/ (L. Donno) 0000-0001-9221-3529 (L. Donno) © 2023 この論文の著作権は著者にあります。クリエイティブ コモンズ ライセンス表示 4.0 インターナショナル (CC BY 4.0) に基づいて使用が許可されています。 CEUR ワークショップ議事録 http://ceur-ws.org ISSN 1613-0073 CEUR ワークショップ議事録 (CEUR-WS.org) オンチェーンとオフチェーンで何が起こっているか。ただし、プラズマ チャネルと状態チャネルの両方は、一般的な smart contract のサポートに制限があります。ロールアップは、ブロックを別の blockchain (Layer 1 または L1) に公開する blockchain (Layer 2 または L2 と呼ばれます) であり、そのため、そのコンセンサス、データの可用性、およびセキュリティのプロパティを継承します。他のソリューションとは異なり、これらは任意の計算をサポートします。ロールアップには 3 つの主なコンポーネントがあります。 • シーケンサー: ユーザーからロールアップ トランザクションを受け取り、それらを Layer 1 に送信されるブロックに結合するノード。ブロックは、少なくとも状態ルート (マークル ルートなど) と、状態を再構築して検証するために必要なデータで構成されます。 Layer 1 は...を定義します。
Introduction
Introduction
- Introduction Blockchain technology has gained significant attention due to its potential to revolutionize various industries. However, scalability remains a major challenge, as most blockchains face a trade-off between scalability, decentralization, and security, commonly referred to as the Scalability Trilemma [1, 2]. To increase the throughput of a blockchain, a trivial solution is to increase its block size. In the context of Ethereum, this means increasing the maximum amount of gas a block can hold. As each full node must validate every transaction of every block, as the throughput increases, the hardware requirements also increase, leading to a greater centralization of the network. Some blockchains, such as Bitcoin and Ethereum, optimize their design to maximize their architectural decentralization, while others, such as the Binance Smart Chain and Solana, are designed to be as fast and cheap as possible. Decentralized networks artificially limit the throughput of the blockchain to lower the hardware requirements to participate in the network. Over the years, attempts have been made to find a solution to the Trilemma, such as state channels [3] and Plasma [4, 5]. These solutions have the characteristic of moving some activity off-chain, linking on-chain activity to off-chain activity using smart contracts, and verifying DLT 2023: 5th Distributed Ledger Technology Workshop, May 25-26, 2023, Bologna, Italy $ [email protected] (L. Donno) https://lucadonnoh.github.io/ (L. Donno) 0000-0001-9221-3529 (L. Donno) © 2023 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings http://ceur-ws.org ISSN 1613-0073 CEUR Workshop Proceedings (CEUR-WS.org)
on-chain what is happening off-chain. However, both Plasma and state channels are limited in their support of general smart contracts. Rollups are blockchains (called Layer 2 or L2) that publish their blocks on another blockchain (Layer 1 or L1) and therefore inherit its consensus, data availability and security properties. They, unlike other solutions, support arbitrary computation. Rollups have three main components: • Sequencers: nodes that receive Rollup transactions from users and combine them into a block that is sent to Layer 1. The block consists of at least the state root (e.g. a Merkle root) and the data needed to reconstruct and validate the state. The Layer 1 defines the canonical blockchain of the L2 by establishing the ordering of the published data. • Rollup full nodes: nodes that obtain, process and validate Rollup blocks from Layer 1 by verifying that the root is correct. If a block contains invalid transactions it is then discarded, which prevents Sequencers from creating valid blocks that include invalid transactions. • Rollup light nodes: nodes that obtain Rollup blocks from Layer 1 but do not compute the new state themselves. They verify that the new state root is valid using techniques such as fault or validity proofs. Rollups achieve scalability by decreasing the amortized cost of transactions as the number of users increases. This is because the cost of ensuring blockchain validity grows sub-linearly with respect to the cost of verifying transactions individually. Rollups differ according to the mechanism by which they ensure the validity of transaction execution at light nodes: in Optimistic Rollups it is ensured by an economic model and by fault proofs, while in Validity Rollups it is cryptographically ensured using validity proofs. Light nodes can be implemented as smart contracts on Layer 1. They accept the root of the new state and verify validity or fault proofs: these Rollup are therefore called Smart Contract Rollups. If light nodes are independent, they are called Sovereign Rollups [6]. The advantage of using a Smart Contract Rollup is to be able to build a trust-minimized bridge between the two blockchains: since the validity of the L2 state is proven to L1, a system of transactions from L2 to L1 can be implemented, allowing withdrawals. The disadvantage is that the cost of the transactions depends on the cost of verifying the state on L1: if the base layer is saturated by other activities, the cost of transactions on the Rollup also increases. The data and consensus layers are the ones that determine the security of the system as they define the ordering of transactions, prevent attacks and make data available to prove state validity. Paper contribution In this paper, we study Optimistic and Validity Rollups, two innovative solutions to the Scalability Trilemma, with a focus on notable implementations, such as Optimism Bedrock and StarkNet. Our contributions include a comprehensive comparison of these solutions, an analysis of withdrawal times, and a discussion of a possible attack on Optimism Bedrock. Additionally, we calculate their gas compression ratios, provide application-specific optimizations, and present the advantages and disadvantages of moving away from the Ethereum Virtual Machine (EVM).
Paper structure The paper is organized as follows. In section 2 Optimistic Rollups are introduced by analyzing Optimism Bedrock. In section 3 Validity Rollups are introduced by analyzing StarkNet. In section 4 we compare the two solutions. Finally, in section 5 we draw some conclusions.
導入
- はじめに ブロックチェーン技術は革命を起こす可能性があるため大きな注目を集めています さまざまな業界。ただし、ほとんどの blockchain が直面しているように、スケーラビリティは依然として大きな課題です。 スケーラビリティ、分散化、セキュリティの間のトレードオフ。一般に スケーラビリティのトリレンマ [1、2]。 blockchain のスループットを向上させるための簡単な解決策は次のとおりです。 ブロックサイズを大きくします。 Ethereum のコンテキストでは、これは最大値を増やすことを意味します。 ブロックが保持できるガスの量。各フルノードはすべてのトランザクションを検証する必要があるため、 ブロックのスループットが増加すると、ハードウェア要件も増加し、 ネットワークの一元化。 Bitcoin や Ethereum などの一部の blockchain は、 アーキテクチャの分散化を最大限に高めるように設計されている一方で、Binance Smart などの他の製品は Chain と Solana は、できるだけ速く、そして安価になるように設計されています。分散型ネットワーク blockchain のスループットを人為的に制限して、ハードウェア要件を下げる ネットワークに参加します。 長年にわたり、トリレンマの解決策を見つける試みがなされてきました。 チャネル [3] およびプラズマ [4、5]。これらのソリューションには、何らかのアクティビティを移動するという特徴があります。 オフチェーン、smart contracts を使用してオンチェーン アクティビティをオフチェーン アクティビティにリンクし、検証する DLT 2023: 第 5 回分散台帳テクノロジー ワークショップ、2023 年 5 月 25 ~ 26 日、イタリア、ボローニャ $ [email protected] (L. ドノ) https://lucadonnoh.github.io/ (L. ドノ) 0000-0001-9221-3529 (L. ドンノ) © 2023 この論文の著作権は著者にあります。クリエイティブ コモンズ ライセンス表示 4.0 インターナショナル (CC BY 4.0) に基づいて使用が許可されています。 クール ワークショップ 議事録 http://ceur-ws.org ISSN 1613-0073 CEUR ワークショップ議事録 (CEUR-WS.org)オフチェーンで起こっていることをオンチェーンで。ただし、プラズマ チャネルと状態チャネルの両方が制限されています。 一般的な smart contract のサポート。 ロールアップは、別の blockchain でブロックを公開する blockchain (Layer 2 または L2 と呼ばれます) です。 (Layer 1 または L1) なので、そのコンセンサス、データの可用性、およびセキュリティのプロパティを継承します。彼らは、 他のソリューションとは異なり、任意の計算をサポートします。ロールアップには 3 つの主要なコンポーネントがあります。 • シーケンサー: ユーザーからロールアップ トランザクションを受け取り、それらを結合してトランザクションを作成するノード。 Layer 1 に送信されるブロック。ブロックは少なくとも状態ルート (マークルなど) で構成されます。 root) と、状態を再構築して検証するために必要なデータ。 Layer 1 は、 公開されたデータの順序を確立することにより、L2 の正規 blockchain を取得します。 • ロールアップフルノード: レイヤーからロールアップブロックを取得、処理、検証するノード 1 ルートが正しいことを確認します。ブロックに無効なトランザクションが含まれている場合、 破棄され、シーケンサーが無効なブロックを含む有効なブロックを作成できなくなります。 取引。 • ロールアップ ライト ノード: Layer 1 からロールアップ ブロックを取得しますが、計算は行わないノード 新しい状態そのもの。彼らは、新しい状態のルートが有効であることを技術を使用して検証します。 欠陥証明や有効性証明など。 ロールアップは、トランザクションの償却コストを数値として削減することでスケーラビリティを実現します。 ユーザー数が増加します。これは、blockchain の有効性を確保するコストが非線形的に増加するためです。 取引を個別に検証するコストに関して。ロールアップは次のように異なります。 ライトノードでのトランザクション実行の正当性を保証するメカニズム: 楽観的なロールアップは、有効期間中、経済モデルとフォールトプルーフによって保証されます。 ロールアップは、有効性証明を使用して暗号的に保証されます。 ライト ノードは、Layer 1 上の smart contract として実装できます。彼らはその根を受け入れます 新しい状態を確認し、有効性または障害の証明を検証します。したがって、これらのロールアップはスマート コントラクトと呼ばれます。 ロールアップ。ライト ノードが独立している場合、それらはソブリン ロールアップ [6] と呼ばれます。の利点 スマート コントラクト ロールアップを使用すると、両者の間に信頼を最小限に抑えたブリッジを構築できるようになります。 blockchains: L2 状態の正当性が L1 に証明されたため、L1 からのトランザクションのシステムが L2からL1まで実装可能で引き出しも可能です。デメリットとしては、費用がかかることです トランザクションは、L1 の状態を検証するコストに依存します。ベース層が飽和している場合、 他のアクティビティに伴い、ロールアップのトランザクションのコストも増加します。 データ層とコンセンサス層は、システムのセキュリティを決定するものです。 トランザクションの順序を定義し、攻撃を防ぎ、状態を証明するためにデータを利用できるようにします。 有効性。 論文寄稿 このペーパーでは、2 つの革新的なオプティミスティック ロールアップと妥当性ロールアップについて研究します。 Optimism Bedrock や StarkNet などの注目すべき実装に焦点を当てた、スケーラビリティのトリレンマに対するソリューション。私たちの貢献には、これらの包括的な比較が含まれます 解決策、引き出し時間の分析、Optimism に対する攻撃の可能性についての議論 岩盤。さらに、ガス圧縮比を計算し、アプリケーション固有の最適化を提供し、Ethereum からの移行の長所と短所を示します。 仮想マシン (EVM)。
紙の構造 論文は以下のように構成されている。セクション 2 では、楽観的なロールアップについて説明します。 Optimism 岩盤を分析することで導入されました。セクション 3 では、有効性ロールアップが導入されています。 StarkNet を分析しています。セクション 4 では、2 つのソリューションを比較します。最後に、セクション 5 で描画します。 いくつかの結論。
Optimistic Rollups
Optimistic Rollups
- Optimistic Rollups The idea of accepting optimistically the output of blocks without verifying their execution is already present in the Bitcoin whitepaper [7], discussing light nodes. These nodes only follow the header chain by verifying the consensus rule, making them vulnerable to accept blocks containing invalid transactions in the event of a 51% attack. Nakamoto proposes to solve this problem by using an “alert" system to warn light nodes that a block contains invalid transactions. This mechanism is first implemented by Al-Bassam, Sonnino and Buterin [8] in which a fault proof system based on error correction codes [9] is used. In order to enable the creation of fault proofs, it is necessary that the data from all blocks, including invalid blocks, is available to the network: this is the Data Availability Problem, which is solved using a probabilistic data sampling mechanism. The first Optimistic Rollup design was presented by John Adler and Mikerah Quintyne-Collins in 2019 [10], in which blocks are published on another blockchain that defines their consensus on ordering. 2.1. Optimism Bedrock Bedrock [11] is the latest version of Optimism, a Smart Contract Rollup. The previous version, the Optimistic Virtual Machine (OVM) required an ad hoc compiler to compile Solidity into its own bytecode: in contrast, Bedrock is fully equivalent to the EVM in that the execution engine follows the Ethereum Yellow Paper specification [12]. 2.1.1. Deposits Users can deposit transactions through a contract on Ethereum, the Optimism Portal, by calling the depositTransaction function. When a transaction is executed, a TransactionDeposited event is emitted, which each node in the Rollup listens for to process deposits. A deposited transaction is a L2 transaction that is derived from L1. If the caller of the function is a contract, the address is transformed by adding a constant value to it: this prevents attacks in which a contract on L1 has the same address as a contract on L2 but a different code. The inclusion on L2 of a deposited transaction is ensured by specification within a sequencing window. Deposited transactions are a new EIP-2718 compatible transaction type [13] with prefix 0x7E, where the rlp-encoded fields are: • bytes32 sourceHash: hash that uniquely identifies the source of the transaction. • address from: the address of the sender. • address to: the receiver address, or the zero address if the deposited transaction is a contract creation.
• uint256 mint: the value to be created on L2. • uint256 value: the value to be sent to the recipient. • bytes data: the input data. • bytes gasLimit: the gas limit of the transaction. The sourceHash is computed as the keccak256 hash of the L1 block hash and the L1 log index, uniquely identifying an event in a block. Since deposited transactions are initiated on L1 but executed on L2, the system needs a mechanism to pay on L1 for the gas spent on L2. One solution is to send ETH through the Portal, but this implies that every caller (even indirect callers) must be marked as payable, and this is not possible for many existing projects. The alternative is to burn the corresponding gas on L1. The gas 𝑔allocated to deposited transaction is called guaranteed gas. The L2 gas price on L1 is not automatically synchronized but is estimated using a mechanism similar to EIP-1559 [14]. The maximum amount of gas guaranteed per Ethereum block is 8 million, with a target of 2 million. The quantity 𝑐of ETH required to pay for gas on L2 is 𝑐= 𝑔𝑏L2 where 𝑏L2 is the basefee on L2. The contract on L1 burns an amount of gas equal to 𝑐/𝑏L2. The gas spent to call depositTransaction is reimbursed on L2: if this amount is greater than the guaranteed gas, no gas is burned. The first transaction of a rollup block is a L1 attributes deposited transaction, used to register on a L2 predeploy the attributes of Ethereum blocks. The attributes that the predeploy gives access to are the block number, the timestamp, the basefee, the block hash and the sequence number, which is the block number of L2 relative to the associated L1 block (also called epoch); this number is reset when a new epoch starts. 2.1.2. Sequencing The Rollup nodes derive the Optimism chain entirely from Ethereum. This chain is extended each time new transactions are published on L1, and its blocks are reorganized each time Ethereum blocks are reorganized. The Rollup blockchain is divided into epochs. For each 𝑛 block number of Ethereum, there is a corresponding 𝑛epoch. Each epoch contains at least one block, and each block in an epoch contains a L1 attributes deposited transaction. The first block in an epoch contains all transactions deposited through the Portal. Layer 2 blocks may also contained sequenced transactions, i.e. transactions sent directly to the Sequencer. The Sequencer accepts transactions from users and builds blocks. For each block, it constructs a batch to be published on Ethereum. Several batches can be published in a compressed manner, taking the name channel. A channel can be divided into several frames, in case it is too large for a single transaction. A channel is defined as the compression with ZLIB [15] of rlp-encoded batches. The fields of a batch are the epoch number, the epoch hash, the parent hash, the timestamp and the transaction list. A sequencing window, identified by an epoch, contains a fixed number 𝑤of consecutive L1 blocks that a derivation step takes as input to construct a variable number of L2 blocks. For epoch 𝑛, the sequencing window 𝑛includes the blocks [𝑛, 𝑛+𝑤). This implies that the ordering of L2 transactions and blocks within a sequencing window is not fixed until the window ends. A rollup transaction is called safe if the batch containing it has been confirmed on L1. Frames
are read from L1 blocks to reconstruct batches. The current implementation does not allow the decompression of a channel to begin until all corresponding frames have been received. Invalid batches are ignored. Individual block transactions are obtained from the batches, which are used by the execution engine to apply state transitions and obtain the Rollup state. 2.1.3. Withdrawals In order to process withdrawals, an L2-to-L1 messaging system is implemented. Ethereum needs to know the state of L2 in order to accept withdrawals, and this is done by publishing on the L2 Output Oracle smart contract on L1 the state root of each L2 block. These roots are optimistically accepted as valid (or finalized) if no fault proof is performed during the dispute period. Only addresses designated as Proposers can publish output roots. The validity of output roots is incentivized by having Proposers deposit a stake that is slashed if they are shown to have proposed an invalid root. Transactions are initiated by calling the function initiateWithdrawal on a predeploy on L2 and then finalized on L1 by calling the function finalizeWithdrawalTransaction on the previously mentioned Optimism Portal. The output root corresponding to the L2 block is obtained from the L2 Output Oracle; it is verified that it is finalized, i.e. that the dispute period has passed; it is verified that the Output Root Proof matches the Oracle Proof; it is verified that the hash of the withdrawal is included in it using a Withdrawal Proof; that the withdrawal has not already been finalized; and then the call to the target address is executed, with the specified gas limit, amount of Ether and data. 2.1.4. Cannon: the fault proof system If a Rollup Full Node, by locally executing batches and deposited transactions, discovers that the Layer 2 state does not match the state root published on-chain by a Proposer, it can execute a fault proof on L1 to prove that the result of the block transition is incorrect. Because of the overhead, processing an entire Rollup block on L1 is too expensive. The solution implemented by Bedrock is to execute on-chain only the first instruction of disagreement of minigeth, compiling it into a MIPS architecture that is executed on an on-chain interpreter and published on L1. minigeth is a simplified version of geth 1 in which the consensus, RPC and database have been removed. To find the first instruction of disagreement, an interactive binary search is conducted between the one who initiated the fault proof and the one who published the output root. When the proof starts, both parties publish the root of the MIPS memory state halfway through the execution of the block on the Challenge contract: if the hash matches it means that both parties agree on the first half of the execution thus publishing the root of half of the second half, otherwise the half of the first half is published and so on. Doing so achieves the first instruction of disagreement in a logarithmic number of steps compared to the original execution. If one of the two stops interacting, at the end of the dispute period the other participant automatically wins. To process the instruction, the MIPS interpreter needs access to its memory: since the root is available, the necessary memory cells can be published by proving their inclusion. To access the state of the EVM, use is made of the Preimage Oracle: given the hash of a block it returns 1https://geth.ethereum.org/docs
the block header, from which one can get the hash of the previous block and go back in the chain, or get the hash of the state and logs from which one can get the preimage. The oracle is implemented by minigeth and replaces the database. Queries are made to other nodes to obtain the preimages.
楽観的なロールアップ
- 楽観的なロールアップ ブロックの実行を検証せずに、ブロックの出力を楽観的に受け入れるというアイデアは次のとおりです。 ライト ノードについて説明している Bitcoin ホワイトペーパー [7] にすでに記載されています。これらのノードは後続するだけです コンセンサス ルールを検証してヘッダー チェーンをブロックし、ブロックを受け入れやすくする 51% 攻撃が発生した場合に無効なトランザクションが含まれる。ナカモトはこれを解決することを提案します 「アラート」システムを使用して、ブロックに無効なトランザクションが含まれていることをライトノードに警告することで、この問題を解決します。 このメカニズムは、Al-Bassam、Sonnino、Buterin [8] によって最初に実装されました。 誤り訂正符号[9]に基づく証明システムが使用されます。の作成を可能にするために、 フォールトプルーフのためには、無効なブロックを含むすべてのブロックのデータが利用可能である必要があります。 ネットワーク: これはデータ可用性問題であり、確率的データを使用して解決されます。 サンプリング機構。最初のオプティミスティック ロールアップ デザインは、ジョン アドラーと 2019 年 [10] の Mikerah Quintyne-Collins、ブロックは別の blockchain で公開されています それが注文に関する彼らの合意を定義します。 2.1. Optimism 岩盤 Bedrock [11] は、スマート コントラクト ロールアップである Optimism の最新バージョンです。以前のバージョンでは、 Optimistic Virtual Machine (OVM) では、Solidity をコンパイルするためにアドホック コンパイラーが必要でした。 独自のバイトコード: 対照的に、Bedrock は実行エンジンという点で EVM と完全に同等です。 Ethereum イエロー ペーパー仕様 [12] に従います。 2.1.1.預金 ユーザーは、depositTransaction 関数を呼び出すことで、Ethereum、Optimism ポータル上のコントラクトを通じてトランザクションをデポジットできます。 トランザクションが実行されると、 TransactionDeposited イベントが発行され、ロールアップ内の各ノードが処理をリッスンします。 預金。入金されたトランザクションは、L1 から派生した L2 トランザクションです。の発信者が 関数がコントラクトである場合、アドレスはそれに定数値を追加することによって変換されます。これにより、 L1 のコントラクトが L2 のコントラクトと同じアドレスを持つが、コードが異なる攻撃。 入金されたトランザクションが L2 に含まれることは、シーケンス内の仕様によって保証されます。 窓。 入金されたトランザクションは、プレフィックス 0x7E を持つ新しい EIP-2718 互換トランザクション タイプ [13] です。 ここで、rlp エンコードされたフィールドは次のとおりです。 • bytes32 sourceHash: トランザクションのソースを一意に識別する hash。 • address from: 送信者のアドレス。 • address to: 受信者のアドレス、または入金されたトランザクションが 契約書の作成。• uint256 mint: L2 で作成される値。 • uint256 値: 受信者に送信される値。 • バイトデータ: 入力データ。 • バイトの GasLimit: トランザクションのガス制限。 sourceHash は、L1 ブロック hash および L1 ログの keccak256 hash として計算されます。 インデックス。ブロック内のイベントを一意に識別します。 入金されたトランザクションは L1 で開始されますが、L2 で実行されるため、システムには L2 で消費されたガスの対価を L1 で支払うメカニズム。解決策の 1 つは、ポータル経由で ETH を送信することです。 しかしこれは、すべての呼び出し元 (間接的な呼び出し元も含む) が支払い可能としてマークされなければならないことを意味します。 多くの既存プロジェクトでは不可能です。別の方法は、L1 で対応するガスを燃焼させることです。 入金されたトランザクションに割り当てられるガス𝑔を保証ガスと呼びます。 L2ガスの価格は L1 は自動的には同期されませんが、EIP-1559 と同様のメカニズムを使用して推定されます。 [14]。 Ethereum ブロックごとに保証されるガスの最大量は 800 万であり、目標は 200万の。 L2 でガスの支払いに必要な ETH の量 𝑐 は 𝑐= 𝑔𝑏L2 です。ここで、𝑏L2 は L2 の基本料金。 L1 のコントラクトでは、𝑐/𝑏L2 に等しい量のガスが燃焼します。通話に費やしたガソリン デポジットトランザクションは L2 で払い戻されます。この金額が保証されたガスより大きい場合、 ガスは燃焼しません。 rollup ブロックの最初のトランザクションは、L1 属性が登録されたトランザクションであり、登録に使用されます。 L2 では、Ethereum ブロックの属性を事前展開します。事前デプロイによって与えられる属性 アクセスできるのは、ブロック番号、タイムスタンプ、基本料金、ブロック hash、およびシーケンスです。 番号。これは、関連する L1 ブロックに対する相対的な L2 のブロック番号 (エポックとも呼ばれます)。 この番号は、新しいエポックが開始されるとリセットされます。 2.1.2.シーケンス ロールアップ ノードは、Optimism チェーンを完全に Ethereum から派生させます。このチェーンは延長されます 新しいトランザクションが L1 で公開されるたびに、そのブロックはそのたびに再編成されます Ethereum ブロックが再編成されます。ロールアップ blockchain はエポックに分割されています。 𝑛ごとに ブロック番号 Ethereum には、対応する 𝑛エポックがあります。各エポックには少なくとも 1 つが含まれます ブロックであり、エポック内の各ブロックには、L1 属性がデポジットされたトランザクションが含まれます。最初のブロック エポックには、ポータルを通じて入金されたすべてのトランザクションが含まれます。 Layer 2 ブロックは、 シーケンスされたトランザクション、つまりシーケンサーに直接送信されるトランザクションが含まれていました。 シーケンサーはユーザーからトランザクションを受け入れ、ブロックを構築します。ブロックごとに、 Ethereum に公開されるバッチ。複数のバッチを圧縮して公開できます。 名前チャンネルを取得します。チャネルが大きすぎる場合に備えて、チャネルを複数のフレームに分割できます。 単一のトランザクション。チャネルは、rlp エンコードされた ZLIB [15] による圧縮として定義されます。 バッチ。バッチのフィールドは、エポック番号、エポック hash、親 hash、 タイムスタンプとトランザクションリスト。 エポックによって識別されるシーケンス ウィンドウには、連続する L1 の固定数 𝑤 が含まれます。 導出ステップが可変数の L2 ブロックを構築するために入力として受け取るブロック。のために エポック 𝑛 では、シーケンス ウィンドウ 𝑛 にはブロック [𝑛, 𝑛+𝑤) が含まれます。これは、順序付けが シーケンス ウィンドウ内の L2 トランザクションとブロックの数は、ウィンドウが終了するまで修正されません。 rollup トランザクションは、それを含むバッチが L1 で確認された場合、安全であると呼ばれます。フレームバッチを再構築するために L1 ブロックから読み取られます。現在の実装では許可されていません 対応するすべてのフレームが受信されるまで、チャネルの圧縮解除が開始されます。無効です バッチは無視されます。個々のブロック トランザクションはバッチから取得されます。 状態遷移を適用し、ロールアップ状態を取得するために実行エンジンによって使用されます。 2.1.3.出金 出金を処理するために、L2-to-L1 メッセージング システムが実装されています。 Ethereum 出金を受け入れるためには L2 の状態を知る必要があり、これはパブリッシングによって行われます。 L2 の出力 Oracle smart contract L1 の各 L2 ブロックのステート ルート。これらの根 実行中にフォールトプルーフが実行されなければ、有効(または確定)として楽観的に受け入れられます。 争議期間。プロポーザとして指定されたアドレスのみが出力ルートを公開できます。有効性 提案者に賭け金を預けてもらうことで、出力ルートの割合が奨励されます。 無効なルートを提案したことが示されています。トランザクションは関数を呼び出すことで開始されます L2 での事前デプロイでのInitialWithdrawal と、関数の呼び出しによる L1 での終了 前述の Optimism ポータルでのfinalizeWithdrawalTransaction。 L2 ブロックに対応する出力ルートは、L2 Output Oracle から取得されます。それはです それが最終決定されたこと、つまり紛争期間が経過したことを確認しました。出力が検証される Root Proof は Oracle Proof と一致します。出金のhashが含まれていることを確認します その中で引き出し証明を使用します。撤退がまだ完了していないこと。そして、 指定されたガス制限、イーサの量、およびデータを使用して、ターゲット アドレスへの呼び出しが実行されます。 2.1.4.大砲: 故障防止システム ロールアップ フル ノードがバッチとデポジットされたトランザクションをローカルで実行することによって、次のことを発見した場合 Layer 2 状態は、プロポーザーによってオンチェーンで公開された状態ルートと一致しないため、実行できます ブロック遷移の結果が正しくないことを証明するための L1 のフォールトプルーフ。のせいで オーバーヘッドのため、L1 でロールアップ ブロック全体を処理するのにコストがかかりすぎます。実装されたソリューション Bedrock によると、minigeth の不一致の最初の命令のみがオンチェーンで実行されます。 それを MIPS アーキテクチャにコンパイルし、オンチェーン インタプリタ上で実行して公開します。 L1で。 minigeth は、コンセンサス、RPC、およびデータベースを備えた geth 1 の簡易バージョンです。 は削除されています。 不一致の最初の命令を見つけるために、対話型バイナリ検索が次の間で実行されます。 フォールトプルーフを開始した者と出力ルートを公開した者です。証明のとき が開始されると、両方の当事者が実行の途中で MIPS メモリ状態のルートを公開します。 チャレンジ契約のブロック: hash が一致する場合、両当事者が 実行の前半は、後半の半分のルートを公開し、それ以外の場合は半分を公開します。 前半部分などを公開します。そうすることで、意見の不一致の最初の指示が達成されます 元の実行と比較して、対数的なステップ数で実行されます。 2台のうちどちらかが止まったら 対話すると、紛争期間の終了時に他の参加者が自動的に勝ちます。 命令を処理するには、MIPS インタプリタはそのメモリにアクセスする必要があります。 必要なメモリセルが利用可能であれば、そのメモリセルが含まれていることを証明することで公開できます。アクセスするには EVM の状態では、Preimage Oracle が使用されます。返されるブロックの hash が与えられると、 1https://geth.ethereum.org/docs
ブロックヘッダー。そこから前のブロックの hash を取得して、そのブロックに戻ることができます。 チェーンするか、プリイメージを取得できる状態とログの hash を取得します。 oracle minigeth によって実装され、データベースを置き換えます。他のノードに対してクエリが実行され、 プリイメージを取得します。
Validity Rollups
Validity Rollups
- Validity Rollups The goal of a Validity Rollup is to cryptographically prove the validity of the state transition given the sequence of transactions with a short proof that can be verified sub-linearly compared to the time of the original computations. These kind of certificates are called computational integrity proofs and are practically implemented with SNARKs (Succint Non-interactive ARgument of Knowledge), which use arithmetic circuits as their computational model. Different SNARK implementations differ in proving time, verification time, the need of a trusted setup and quantum resistance [16, 17]. STARKs (Scalable Transparent ARgument of Knowledge) [18] are a type of SNARKs that does not require a trusted setup and are quantum resistant, while giving up some efficiency on proving and verification compared to other solutions. 3.1. StarkNet StarkNet is a Smart Contract Validity Rollup developed by StarkWare that uses the STARK proof system to validate its state to Ethereum. To facilitate the construction of validity proofs, a virtual machine different than the EVM is used, whose high-level language is Cairo. 3.1.1. Deposits Users can deposit transactions via a contract on Ethereum by calling the sendMessageToL2 function. The message is recorded by computing its hash and increasing a counter. Sequencers listen for the LogMessageToL2 event and encode the information in a StarkNet transaction that calls a function of a contract that has the l1_handler decorator. At the end of execution, when the proof of state transition is produced, the consumption of the message is attached to it and it is deleted by decreasing its counter. The inclusion of deposited transactions is not required by the StarkNet specification, so a gas market is needed to incentivize Sequencers to publish them on L2. In the current version, because the Sequencer is centralized and managed by StarkWare, the cost of deposited transactions is only determined by the cost of executing the deposit. This cost is paid by sending ETH to sendMessageToL2. These Ethers remain locked on L1 and are transferred to the Sequencer on L1, when the deposited transaction is included in a state transition. The amount of ETH sent, if the deposited transaction is included, is fully spent, regardless of the amount of gas consumed on L2. StarkNet does not have a system that makes L1 block attributes available automatically. Alternatively, Fossil is a protocol developed by Oiler Network 2 that allows, given a hash of a block, any information to be obtained from Ethereum by publishing preimages. 2https://www.oiler.network/
3.1.2. Sequencing The current state of StarkNet can be derived entirely from Ethereum. Any state difference between transitions is published on L1 as calldata. Differences are published for each contract and are saved as uint256[] with the following encoding: • Number of field concerning contract deployments. • For each published contract: – The address of the published contract. – The hash of the published contract. – The number of arguments of the contract constructor. – The list of constructor arguments • Number of contract whose storage has been modified. • For each contract that has been modified: – The address of the modified contract. – The number of storage updates. – The key-value pairs of the storage addresses with the new values. The state differences are published in order, so it is sufficient to read them sequentially to reconstruct the state. 3.1.3. Withdrawals To send a message from L2 to L1, the syscall send_message_to_L1 is used. The message is published to L1 by increasing its hash counter along with the proof and finalized by calling the function consumeMessageFromL2 on the StarkGate smart contract on L1, which decrements the counter. Anyone can finalize any withdrawal. 3.1.4. Validity proofs The Cairo Virtual Machine [19] is designed to facilitate the construction of STARK proofs. The Cairo language allows the computation to be described with a high-level programming language, and not directly as a circuit. This is accomplished by a system of polynomial equations 3 representing a single computation: the FDE cycle of a von Neumann architecture. The number of constraints is thus fixed and independent of the type of computation, allowing for only one Verifier program for every program whose computation needs to be proved. StarkNet aggregates multiple transactions into a single STARK proof using a shared prover named SHARP. The proofs are sent to a smart contract on Ethereum, which verifies their validity and updates the Merkle root corresponding to the new state. The sub-linear cost of verifying a validity proof allows its cost to be amortized over multiple transactions. 3called Algebraic Intermediate Representation (AIR)
有効性ロールアップ
- 有効性ロールアップ Validity Rollup の目的は、状態遷移の有効性を暗号的に証明することです。 準線形的に比較できる検証可能な短い証明を伴うトランザクションのシーケンスが与えられたとします。 元の計算の時点まで。 この種の証明書は計算整合性証明と呼ばれ、実際には算術演算を使用する SNARK (Succint Non-interactive ARgument of Knowledge) で実装されます。 回路を計算モデルとして使用します。 SNARK 実装が異なれば証明時間も異なります。 検証時間、信頼できるセットアップの必要性、および量子耐性 [16、17]。 STARK (スケーラブル) 透明な知識引数) [18] は、信頼できる認証を必要としない SNARK の一種です。 証明と検証の効率をある程度犠牲にする一方で、量子耐性を備えています。 他のソリューションと比較して。 3.1. StarkNet StarkNet は、Starkware によって開発された、STARK を使用するスマート コントラクト有効性ロールアップです。 Ethereum までの状態を検証する証明システム。有効性証明の構築を容易にするために、 EVM とは異なる仮想マシンが使用されており、その高級言語は Cairo です。 3.1.1.預金 ユーザーは、sendMessageToL2 を呼び出すことで、Ethereum のコントラクトを介してトランザクションを入金できます。 機能。メッセージは、hash を計算し、カウンターを増やすことによって記録されます。シーケンサー LogMessageToL2 イベントをリッスンし、StarkNet トランザクションで情報をエンコードします。 l1_handler デコレータを持つコントラクトの関数を呼び出します。実行の最後に、 状態遷移の証明が生成されると、メッセージの消費がそれに添付されます そしてカウンターを減らすことで削除されます。 StarkNet 仕様では、入金されたトランザクションを含めることは必須ではないため、 シーケンサーが L2 で公開するよう奨励するには、市場が必要です。現在のバージョンでは、 シーケンサーは StarkWare によって集中管理され、入金されたトランザクションのコストは はデポジットの実行コストによってのみ決定されます。この費用はETHを送金することで支払われます。 L2 にメッセージを送信します。これらのイーサは L1 でロックされたままになり、L1 でシーケンサに転送されます。 L1、入金されたトランザクションが状態遷移に含まれる場合。送金されたETHの量(場合) ガスの消費量に関係なく、入金されたトランザクションは含まれており、全額使用されます。 L2で。 StarkNet には、L1 ブロック属性を自動的に使用可能にするシステムがありません。 また、Fossil は、Oiler Network 2 によって開発されたプロトコルであり、hash を指定すると、 ブロック、プレイメージを公開することによって Ethereum から取得される情報。 2https://www.oiler.network/3.1.2.シーケンス StarkNet の現在の状態は、すべて Ethereum から派生できます。あらゆる状態の違い トランジション間はコールデータとして L1 に公開されます。差異は契約ごとに公開されます 次のエンコードを使用して uint256[] として保存されます。 • 契約展開に関するフィールドの数。 • 公開された各契約について: – 公開された契約書の住所。 – 公開された契約の hash。 – コントラクト コンストラクターの引数の数。 – コンストラクター引数のリスト • ストレージが変更された契約の数。 • 変更された各契約について: – 変更された契約の住所。 – ストレージ更新の数。 – 新しい値を含むストレージ アドレスのキーと値のペア。 状態の違いは順番に公開されているため、順番に読んでいけば十分です。 状態を再構築します。 3.1.3.出金 L2 から L1 にメッセージを送信するには、syscall send_message_to_L1 を使用します。メッセージは 証明とともに hash カウンタを増やすことで L1 に公開され、 L1 の StarkGate smart contract の関数 ConsumerMessageFromL2 (デクリメント) カウンター。誰でも出金を完了できます。 3.1.4.有効性の証明 Cairo 仮想マシン [19] は、STARK 証明の構築を容易にするように設計されています。 Cairo 言語を使用すると、高レベルのプログラミングで計算を記述することができます。 言語であり、直接回路としてではありません。これは多項方程式系によって実現されます。 図3は、単一の計算、すなわちフォン・ノイマン・アーキテクチャのFDEサイクルを表す。番号 したがって、制約の数は固定され、計算の種類に依存せず、1 つだけが許可されます。 計算を証明する必要があるすべてのプログラムの検証プログラム。 StarkNet は、共有証明者を使用して複数のトランザクションを単一の STARK 証明に集約します シャープという名前。証明は Ethereum の smart contract に送信され、その有効性が検証されます。 そして、新しい状態に対応するマークル ルートを更新します。検証にかかるサブリニアコスト 有効性の証明により、そのコストを複数のトランザクションにわたって償却することができます。 3代数中間表現 (AIR) と呼ばれる
Comparison
Comparison
- Comparison 4.1. Withdrawal time The most important aspect that distinguishes Optimistic Rollups from Validity Rollups is the time that elapses between the initialization of a withdrawal and its finalization. In both cases, withdrawals are initialized on L2 and finalized on L1. On StarkNet, finalization is possible as soon as the validity proof of the new state root is accepted on Ethereum: theoretically, it is possible to withdraw funds in the first block of L1 following initialization. In practice, the frequency of sending validity proofs on Ethereum is a trade-off between the speed of block finalization and proof aggregation. Currently StarkNet provides validity proofs for verification every 10 hours 4, but it is intended to be decreased as transaction activity increases. On Optimism Bedrock it is possible to finalize a withdrawal only at the end of the dispute period (currently 7 days), after which a root is automatically considered valid. The length of this period is mainly determined by the fact that fault proofs can be censored on Ethereum until its end. The success probability of this type of attack decreases exponentially as time increases: E[subtracted value] = 𝑉𝑝𝑛 where 𝑛is the number of blocks in an interval, 𝑉is the amount of funds that can be subtracted by publishing an invalid root, and 𝑝is the probability of successfully performing a censorship attack in a single block. Suppose that this probability is 99%, that the value locked in the Rollup is one million Ether, and that the blocks in an interval are 1800 (6 hours of blocks with a 12 seconds interval): the expected value is about 0.01391 Ether. The system is made secure by asking Proposers to stake a much larger amount of Ether than the expected value. Winzer et al. showed how to carry out a censorship attack using a simple smart contract that ensures that certain areas of memory in the state do not change [20]. Modeling the attack as a Markov game, the paper shows that censoring is the dominant strategy for a rational block producer if they receive more compensation than including the transaction that changes the memory. The 𝑝value discussed above can be viewed as the percentage of rational block producers in the network, where “rational” does not take into account possibly penalizing externalities, such as less trust in the blockchain that decreases its cryptocurrency value. The following code presents a smart contract that can be used to perform a censorship attack on Bedrock. The attack exploits the incentives of block producers by offering them a bribe to censor the transactions that would modify specific parts of the state. The contract’s main function, claimBribe, allows block producers to claim the bribe if they successfully censor the targeted transaction by checking that the invalid output root is not touched. function claimBribe(bytes memory storageProof) external { require(!claimed[block.number], "bribe already claimed"); OutputProposal memory current = storageOracle.getStorage(L2_ORACLE, block.number, SLOT, storageProof); require(invalidOutputRoot == current.outputRoot, "attack failed"); claimed[block.number] = true; (bool sent, ) = block.coinbase.call{value: bribeAmount}(""); 4https://etherscan.io/address/0xc662c410c0ecf747543f5ba90660f6abebd9c8c4
require(sent, "failed to send ether"); } Listing 1: Example of a contract that incentivizes a censorship attack on Bedrock. The length of the dispute period must also take into account the fact that the fault proof is an interactive proof and therefore enough time must be provided for participants to interact and that any interaction could be censored. If the last move occurs at a time very close to the end of the dispute period, the cost of censoring is significantly less. Although censoring is the dominant strategy, the likelihood of success is lower because censoring nodes are vulnerable to Denial of Service attacks: an attacker can generate very complex transactions that end with the publication of a fault proof at no cost, as no fees would be paid. In extreme cases, a long dispute period allows coordination in the event of a successful censorship attack to organize a fork and exclude the attacking block producers. Another possible attack consists in publishing more state root proposals than disputants can verify, which can be avoided using a frequency limit. 4.1.1. Fast optimistic withdrawals Since the validity of an Optimistic Rollup can be verified at any time by any Full Node, a trusted oracle can be used to know on L1 whether the withdrawal can be finalized safely. This mechanism was first proposed by Maker [21]: an oracle verifies the withdrawal, publishes the result on L1 on which an interest-bearing loan is assigned to the user, which is automatically closed at the end of 7 days, i.e. when the withdrawal can actually be finalized. This solution introduces a trust assumption, but in the case of Maker it is minimized since the oracle operator is managed by the same organization that assumes the risk by providing the loan. 4.2. Transaction costs The cost of L2 transactions is mostly determined by the interaction with the L1. In both solutions the computational cost of transactions is very cheap as it is executed entirely off-chain. Optimism publishes L2 transactions calldata as calldata and rarely (or never) executes fault proofs, therefore calldata is the most expensive resource. On January 12, 2022 a Bedrock network has been launched on the Ethereum’s Goerli testnet. A gas compression rate can be calculated by tracking the amount of gas used on Bedrock in a certain period and by comparing it to the amount of gas spent on L1 for the corresponding blocks. Using this method a gas compression rate of ∼20 : 1 is found, but this figure may differ with real activity on mainnet. StarkNet publishes on Ethereum every change in L2 state as calldata, therefore storage is the most expensive resource. Since the network does not use the EVM, the transaction cost compression cannot be trivially estimated. By assuming the cost of execution and calldata to be negligible, it is possible to calculate the compression ratio of storage writes compared to L1. Assuming no contract is deployed and 10 cells not previously accessed on StarkNet are modified, a storage write cost compression rate of ∼24 : 1 is found. If a cell is overwritten 𝑛times between data publications, the cost of each write will be 1/𝑛compared to the cost of a single write, since only the last one is published. The cost can be further minimized by
compressing frequently used values. The cost of validity proof verification is divided among the transactions it refers to: for example, StarkNet block 4779 contains 200 transactions and its validity proof consumes 267830 units of gas, or 1339.15 gas for each transaction. 4.2.1. Optimizing calldata: cache contract Presented below is a smart contract that implements an address cache for frequently used addresses by taking advantage of the fact that storage and execution are much less expensive resources, along with a Friends contract that demonstrates its use. The latter keeps track of the “friends” of an address that can be registered by calling the addFriend function. If an address has already been used at least once, it can be added by calling the addFriendWithCache function: the cache indices are 4-byte integers while the addresses are represented by 20 bytes, so there is a 5:1 saving on the function argument. The same logic can be used for other data types such as integers or more generally bytes. contract AddressCache { mapping(address => uint32) public address2key; address[] public key2address; function cacheWrite(address _address) internal returns (uint32) { require(key2address.length < type(uint32).max, "AddressCache: cache is full"); require(address2key[_address] == 0, "AddressCache: address already cached"); // keys must start from 1 because 0 means "not found" uint32 key = uint32(key2address.length + 1); address2key[_address] = key; key2address.push(_address); return key; } function cacheRead(uint32 _key) public view returns (address) { require(_key <= key2address.length && _key > 0, "AddressCache: key not found"); return key2address[_key - 1]; } } Listing 2: Address cache contract. contract Friends is AddressCache { mapping(address => address[]) public friends; function addFriend(address _friend) public { friends[msg.sender].push(_friend); cacheWrite(_friend); } function addFriendWithCache(uint32 _friendKey) public { friends[msg.sender].push(cacheRead(_friendKey)); } function getFriends() public view returns (address[] memory) { return friends[msg.sender];
} } Listing 3: Example of a contract that inherits the address cache. The contract supports in cache about 4 billion (232) addresses, and adding one byte gives about 1 trillion (240). 4.2.2. Optimizing storage: Bloom’s filters On StarkNet there are several techniques for minimizing storage usage. If it is not necessary to guarantee the availability of the original data then it is sufficient to save on-chain its hash: this is the mechanism used to save data for an ERC-721 (NFT) [22], i.e., an IPFS link that resolves the hash of the data if available. For data that is stored multiple times, it is possible to use a look-up table similar to the caching system introduced for Optimism, requiring all values to be saved at least once. For some applications, saving all the values can be avoided by using a Bloom filter [23, 24, 25], i.e., a probabilistic data structure that allows one to know with certainty whether an element does not belong to a set but admits a small but non-negligible probability of false positives. A Bloom filter is initialized as an array of 𝑚bits at zero. To add an element, 𝑘hash functions with a uniform random distribution are used, each one mapping to a bit of the array that is set to 1. To check whether an element belongs to the set we run the 𝑘hash functions and verify that the 𝑘bits are set to 1. In a simple Bloom’s filter there is no way to distinguish whether an element actually belongs to the set or is a false positive, a probability that grows as the number of entries increases. After inserting 𝑛elements: P[false positive] = (︃ 1 − [︂ 1 −1 𝑚 ]︂𝑘𝑛)︃𝑘 ≈ (︁ 1 −𝑒−𝑘𝑛/𝑚)︁𝑘 assuming independence of the probability of each bit set. If 𝑛elements (of arbitrary size!) are expected to be included and the probability of a false positive tolerated is 𝑝, the size of the array can be calculated as: 𝑚= −𝑛ln 𝑝 (ln 2)2 While the optimal number of hash functions is: 𝑘= 𝑚 𝑛ln 2 If we assume to insert 1000 elements with a tolerance of 1%, the size of the array is 9585 bits with 𝑘= 6, while for a tolerance of 0.1% it becomes 14377 bits with 𝑘= 9. If a million elements are expected to be inserted, the size of the array becomes about 1170 kB for 1% and 1775 kB for 0.1%, with the same values of 𝑘, since it depends only on 𝑝[26]. In a game where players must not be assigned to an opponent they have already challenged, instead of saving in storage for each player the list of past opponents one can use a Bloom filter. The risk of not challenging some players is often acceptable, and the filter can be reset periodically.
4.3. Ethereum compatibility The main advantage of being compatible with EVM and Ethereum is the reuse of all the available tools. Ethereum smart contracts can be published on Optimism without any modification nor new audits. Wallets remain compatible, development and static analysis tools, general analysis tools, indexing tools and oracles. Ethereum and Solidity have a long history of well-studied vulnerabilities, such as reentrancy attacks, overflows and underflows, flash loans, and oracle manipulations. Because of this, Optimism was able to capture a large amount of value in a short time. Choosing to adopt a different virtual machine implies having to rebuild an entire ecosystem, with the advantage of a greater implementation freedom. StarkNet natively implements account abstraction, which is a mechanism whereby each account is a smart contract that can implement arbitrary logic as long as it complies with an interface (hence the term abstraction): this allows the use of different digital signature schemes, the ability to change the private key using the same address, or use a multisig. The Ethereum community proposed the introduction of this mechanism with EIP-2938 in 2020, but the proposal has remained stale for more than a year as other updates have been given more priority [27]. Another important benefit gained from compatibility is the reuse of existing clients: Optimism uses a version of geth for its own node with only ∼800 lines of difference, which has been developed, tested, and maintained since 2014. Having a robust client is crucial as it defines what is accepted as valid or not in the network. A bug in the implementation of the fault proof system could cause an incorrect proof to be accepted as correct or a correct proof for an invalid block to be accepted as incorrect, compromising the system. The likelihood of this type of attack can be limited with a wider client diversity: Optimism can reuse in addition to geth the other Ethereum clients already maintained, and development of another Erigon-based client is already underway. In 2016 a problem in the memory management of geth was exploited for a DoS attack and the first line of defense was to recommend the use of Parity, the second most used client at the time 5. StarkNet faces the same problem with validity proofs, but the clients have to be written from scratch and the proof system is much more complex, and consequently it is also much more complex to ensure correctness.
比較
- 比較 4.1.出金時間 楽観的ロールアップと妥当性ロールアップを区別する最も重要な側面は、 出金の開始から完了までに経過する時間。どちらの場合も、 出金は L2 で初期化され、L1 で完了します。 StarkNet では、次のようにファイナライズが可能です 新しい状態ルートの有効性証明が Ethereum で受け入れられ次第、理論的には次のようになります。 初期化後の L1 の最初のブロックで資金を引き出すことが可能です。実際には、 Ethereum で有効性証明を送信する頻度は、ブロックの速度とのトレードオフです ファイナライゼーションと証明の集約。現在、StarkNet は検証のための有効性証明を提供しています 10 時間ごと 4 ですが、トランザクション アクティビティが増加するにつれて減少することが意図されています。 Optimism Bedrock では、紛争の終了時にのみ撤回を完了することができます。 期間 (現在は 7 日) が経過すると、ルートは自動的に有効とみなされます。長さ この期間は主に、Ethereum に欠陥証明が検閲されるまでの期間によって決定されます。 その終わり。このタイプの攻撃の成功確率は、時間の経過とともに指数関数的に減少します。 E[減算値] = 𝑉𝑝𝑛 ここで、𝑛は間隔内のブロック数、𝑉は差し引くことができる資金の量です 無効なルートを公開することによって、𝑝は検閲が正常に実行される確率です 単一ブロックで攻撃します。この確率が 99% で、値がロールアップにロックされていると仮定します。 は 100 万イーサ、間隔内のブロックは 1800 (12 個のブロックで 6 時間) 秒間隔): 期待値は約 0.01391 Ether です。システムの安全性は次のとおりです。 提案者に、期待値よりもはるかに大量のイーサをステーキングするよう求めます。 ウィンザーら。単純な smart contract を使用して検閲攻撃を実行する方法を示しました。 これにより、状態内のメモリの特定の領域が [20] 変更されないことが保証されます。攻撃のモデル化 この論文は、マルコフゲームとして、検閲が合理的なアプローチの支配的な戦略であることを示しています。 変更を伴うトランザクションを含めるよりも多くの報酬を受け取った場合、プロデューサーをブロックする 記憶。上で説明した 𝑝 値は、有理ブロックのパーセンテージとして見ることができます。 ネットワーク内のプロデューサー。「合理的」とは、ペナルティを与える可能性を考慮していない blockchain に対する信頼が低下し、暗号通貨の価値が低下するなどの外部性。 次のコードは、検閲攻撃の実行に使用できる smart contract を示しています。 岩盤の上。この攻撃は、ブロックプロデューサーに賄賂を提供することで、ブロックプロデューサーのインセンティブを悪用します。 州の特定の部分を変更する取引を検閲するため。契約の主な内容 関数、claimBribe を使用すると、ブロックプロデューサーが検閲に成功した場合に賄賂を請求できるようになります。 無効な出力ルートが触れられていないことを確認して、ターゲットのトランザクションを処理します。 functionclaimBribe(バイトメモリ storageProof) 外部 { require(!claimed[block.number], "賄賂はすでに請求されています"); OutputProposal メモリの現在 = storageOracle.getStorage(L2_ORACLE, block.number, SLOT, ストレージプルーフ); require(invalidOutputRoot == current.outputRoot, "攻撃は失敗しました"); 主張[ブロック番号] = true; (ブール送信、 ) = block.coinbase.call{値: 賄賂金額}(""); 4https://etherscan.io/address/0xc662c410c0ecf747543f5ba90660f6abebd9c8c4require(sent, "イーサの送信に失敗しました"); } リスト 1: Bedrock に対する検閲攻撃を奨励する契約の例。 紛争期間の長さには、過失の証明が不十分であるという事実も考慮する必要があります。 インタラクティブな証明であるため、参加者が対話するのに十分な時間を提供する必要があります そして、あらゆるやり取りが検閲される可能性があるということです。最後の移動が直前に行われた場合、 紛争期間が終了すると、検閲のコストは大幅に減少します。検閲はあるものの、 ドミナント戦略では、検閲ノードが次の攻撃に対して脆弱であるため、成功の可能性は低くなります。 サービス拒否攻撃: 攻撃者は、次のような非常に複雑なトランザクションを生成する可能性があります。 手数料は支払われないため、欠陥証明の発行は無料で行われます。 極端な場合には、紛争期間が長ければ、解決に成功した場合の調整が可能になります。 フォークを組織し、攻撃しているブロックプロデューサーを排除するための検閲攻撃。もう一つ 攻撃の可能性としては、議論者が検証できる以上に多くのステートルート提案を公開することが挙げられます。 これは周波数制限を使用することで回避できます。 4.1.1.素早い楽観的な出金 オプティミスティック ロールアップの有効性はフル ノードでいつでも検証できるため、 信頼できる oracle を使用すると、出金が安全に完了できるかどうかを L1 で知ることができます。これ このメカニズムは Maker [21] によって最初に提案されました。oracle は引き出しを検証し、 ユーザーに有利子ローンが割り当てられる L1 の結果。これは自動的に実行されます。 7 日間の終わり、つまり実際に出金が完了した時点で締め切りとなります。この解決策 信頼の仮定が導入されていますが、Maker の場合、oracle 演算子があるため最小化されています。 は、融資を提供することでリスクを引き受けるのと同じ組織によって管理されます。 4.2.取引コスト L2 トランザクションのコストは、主に L1 との対話によって決まります。どちらのソリューションでも トランザクションは完全にオフチェーンで実行されるため、トランザクションの計算コストは非常に安価です。 Optimism は、L2 トランザクションの呼び出しデータを呼び出しデータとして公開し、フォルトをほとんど (またはまったく) 実行しません。 したがって、calldata は最も高価なリソースです。 2022 年 1 月 12 日、Bedrock ネットワーク Ethereum の Goerli テストネットで開始されました。ガスの圧縮率を計算できます 一定期間に岩盤上で使用されたガスの量を追跡し、それを過去のガスの量と比較することによって、 対応するブロックの L1 で費やされるガスの量。この方法を使用してガス圧縮 〜20 : 1 の割合が見つかりますが、この数値はメインネット上の実際のアクティビティとは異なる可能性があります。 StarkNet は、L2 状態のすべての変更を呼び出しデータとして Ethereum に公開するため、ストレージは 最も高価なリソース。ネットワークは EVM を使用しないため、トランザクション コストは 圧縮率を自明に見積もることはできません。実行コストと呼び出しデータを想定すると、 無視できるほど、ストレージ書き込みの圧縮率を計算することができます。 L1。コントラクトが展開されておらず、StarkNet で以前にアクセスされていない 10 個のセルが存在すると仮定します。 変更すると、ストレージ書き込みコスト圧縮率は約 24:1 であることがわかります。セルが上書きされた場合 データ公開間の𝑛回、各書き込みのコストは、以前のコストと比較して 1/𝑛 になります。 最後の書き込みのみが公開されるため、1 回の書き込みで済みます。コストをさらに抑えることができるのは、頻繁に使用される値を圧縮します。有効性証明検証の費用は次のとおりに分割されます。 参照するトランザクション: たとえば、StarkNet ブロック 4779 には 200 個のトランザクションが含まれており、その 有効性証明には 267830 ユニットのガス、つまりトランザクションごとに 1339.15 ガスが消費されます。 4.2.1.コールデータの最適化: キャッシュ コントラクト 以下に示すのは、頻繁に使用されるアドレス キャッシュを実装する smart contract です。 ストレージと実行のコストがはるかに低いという事実を利用して対処します リソースとその使用法を示す Friends 契約。後者は、 addFriend関数を呼び出すことで登録できるアドレスの「友達」。住所の場合 すでに少なくとも 1 回使用されている場合は、addFriendWithCache を呼び出すことで追加できます。 機能: キャッシュ インデックスは 4 バイトの整数ですが、アドレスは 20 バイトで表されます。 したがって、関数の引数は 5:1 で節約されます。同じロジックを他のデータにも使用できます 整数やより一般的にはバイトなどの型。 コントラクト AddressCache { マッピング(アドレス => uint32) パブリックアドレス2キー; アドレス[]公開鍵2アドレス; 関数cacheWrite(address _address)内部戻り値(uint32) { require(key2address.length < type(uint32).max, "AddressCache: キャッシュがいっぱいです"); require(address2key[_address] == 0, "AddressCache: アドレスはすでにキャッシュされています"); // 0 は「見つからない」ことを意味するため、キーは 1 から開始する必要があります uint32 キー = uint32(key2address.length + 1); address2key[_address] = キー; key2address.push(_address); リターンキー; } 関数cacheRead(uint32 _key)パブリックビューは(アドレス)を返します{ require(_key <= key2address.length && _key > 0, "アドレスキャッシュ: キーが見つかりません"); キー 2 アドレスを返します [_key - 1]; } } リスト 2: アドレス キャッシュ コントラクト。 コントラクトフレンドはAddressCache { マッピング(アドレス => アドレス[]) 公開友達; 関数 addFriend(アドレス _friend) public { friends[msg.sender].push(_friend); キャッシュ書き込み(_friend); } 関数 addFriendWithCache(uint32 _friendKey) public { friends[msg.sender].push(cacheRead(_friendKey)); } function getFriends() public view returns (address[]memory) { 友達を返す[msg.sender];} } リスト 3: アドレス キャッシュを継承するコントラクトの例。 この契約はキャッシュ内で約 40 億 (232) のアドレスをサポートしており、1 バイトを追加すると次のようになります。 約1兆(240)個。 4.2.2.ストレージの最適化: Bloom のフィルター StarkNet には、ストレージの使用量を最小限に抑えるための手法がいくつかあります。必要がない場合は、 元のデータの可用性を保証する場合は、その hash をオンチェーンに保存するだけで十分です。 ERC-721 (NFT) [22] のデータを保存するために使用されるメカニズムです。つまり、 利用可能な場合はデータの hash。複数回保存されたデータの場合は、ルックアップを使用できます。 Optimism に導入されたキャッシュ システムに似たテーブル。すべての値を次の場所に保存する必要があります。 少なくとも一度は。一部のアプリケーションでは、ブルーム フィルターを使用することですべての値の保存を回避できます。 [23, 24, 25]、つまり、次のことを確実に知ることができる確率的データ構造。 要素はセットに属していませんが、小さいながらも無視できない false の確率を許容します。 ポジティブ。 ブルーム フィルターは、ゼロの 𝑚 ビットの配列として初期化されます。要素を追加するには、𝑘hash 関数を使用します 一様なランダム分布を持つものが使用され、それぞれが設定された配列のビットにマッピングされます。 要素がセットに属しているかどうかを確認するには、𝑘hash 関数を実行して検証します。 単純なブルームフィルターでは、𝑘ビットが1に設定されているかどうかを区別する方法はありません。 要素が実際にセットに属しているか、偽陽性であるか、その確率は数に応じて増加します。 エントリ数が増加します。 𝑛要素を挿入した後: P[偽陽性] = (︃ 1 − [︂ 1 −1 𝑚 ]︂𝑘𝑛)︃𝑘 ≈ (︁ 1 −𝑒−𝑘𝑛/𝑚)︁𝑘 各ビットセットの確率が独立していると仮定します。 𝑛要素 (任意のサイズ!) が が含まれることが期待され、許容される偽陽性の確率は配列のサイズ 𝑝 です。 は次のように計算できます。 𝑚= −𝑛ln 𝑝 (ln 2)2 hash 関数の最適な数は次のとおりです。 𝑘= 𝑚 𝑛ln 2 許容誤差 1% で 1000 個の要素を挿入すると仮定すると、配列のサイズは 9585 ビットになります。 𝑘= 6 の場合、0.1% の許容誤差の場合、𝑘= 9 では 14377 ビットになります。要素が 100 万個の場合 が挿入されることが予想される場合、配列のサイズは 1% の場合は約 1170 KB、1% の場合は 1775 KB になります。 𝑝[26] のみに依存するため、𝑘 の値が同じ場合は 0.1%。 すでに挑戦した相手にプレイヤーを割り当ててはいけないゲームでは、 各プレイヤーの過去の対戦相手のリストをストレージに保存する代わりに、ブルームを使用できます。 フィルター。一部のプレイヤーに挑戦しないリスクは多くの場合許容され、フィルターはリセットできます。 定期的に。4.3. Ethereum 互換性 EVM および Ethereum と互換性があることの主な利点は、利用可能なすべてのコンポーネントを再利用できることです。 ツール。 Ethereum smart contract は、変更を加えずに Optimism で公開できます。 新しい監査。ウォレットの互換性維持、開発および静的分析ツール、一般的な分析 ツール、インデックス作成ツール、oracle。 Ethereum と Solidity には、十分に研究されてきた長い歴史があります。 再入攻撃、オーバーフローとアンダーフロー、フラッシュ ローン、oracle などの脆弱性 操作。このため、Optimism は短期間で大量の価値を獲得することができました。 時間。 別の仮想マシンを採用するという選択は、エコシステム全体を再構築する必要があることを意味します。 実装の自由度が高まるという利点があります。 StarkNet アカウントをネイティブに実装します 抽象化。各アカウントを smart contract として実装できるメカニズムです。 インターフェイスに準拠している限り、任意のロジック (したがって抽象化という用語が使われます): これにより、 さまざまなデジタル署名スキームの使用、秘密キーを使用して秘密キーを変更する機能 同じアドレスを使用するか、マルチシグを使用します。 Ethereum コミュニティがこれの導入を提案しました 2020 年に EIP-2938 のメカニズムが確立されましたが、この提案は 1 年以上古いままでした。 他の更新には、[27] の方が優先されます。 互換性から得られるもう 1 つの重要な利点は、既存のクライアントの再利用です: Optimism は、わずか約 800 行の違いがある独自のノードに geth のバージョンを使用します。 2014 年以来、開発、テスト、保守が行われています。堅牢なクライアントを持つことが重要です。 ネットワーク内で何が有効か無効として受け入れられるか。フォールトプルーフの実装におけるバグ システムにより、間違った証明が正しい証明として受け入れられたり、無効な証明が正しい証明として受け入れられたりする可能性があります。 ブロックが不正なものとして受け入れられ、システムが危険にさらされる可能性があります。このタイプの可能性は より幅広いクライアントの多様性により攻撃を制限できます: Optimism は取得に加えて再利用できます。 他の Ethereum クライアントはすでに保守されており、別の Erigon ベースのクライアントの開発が行われています。 すでに進行中です。 2016 年に、geth のメモリ管理の問題が悪用されました。 DoS 攻撃と防御の第一線は、2 番目に多いパリティの使用を推奨することでした。 当時使用されていたクライアント 5. StarkNet は有効性証明に関して同じ問題に直面していますが、クライアントは スクラッチから作成する必要があり、証明システムははるかに複雑になり、その結果、 また、正確性を保証するのははるかに複雑です。
Conclusion
Conclusion
- Conclusion Rollups are the most promising solution available today to solve the scalability problem in decentralized blockchains, paving the way for the era of modular blockchains as opposed to monolithic blockchains. The choice of developing either an Optimistic Rollup or a Validity Rollup is mainly shown as a trade-off between complexity and agility. StarkNet has numerous advantages such as fast withdrawals, structural inability to have invalid state transitions, lower transaction cost at the expense of a longer development period and incompatibility with EVM, while Optimism has leveraged the network economy to quickly gain a major share of the market. Optimism Bedrock, however, possesses a modular design that allows it to become a Validity 5https://blog.ethereum.org/2016/09/22/ethereum-network-currently-undergoing-dos-attack
Rollup in the future: Cannon currently uses minigeth compiled to MIPS for its fault proof system, but the same architecture can be used to obtain a circuit and produce validity proofs. Compiling a complex machine such as the EVM for a microarchitecture results in a simpler circuit that does not need to be modified and re-verified in case of upgrades. RISC Zero is a verifiable microarchitecture with STARK proofs already in development based on RISC-V that can be used for this purpose as an alternative to MIPS [28]. One aspect that should not be underestimated is the complexity in understanding how the technology works. A strength of traditional blockchains is to be able to verify the state of the blockchain without trusting any third party entity. However, in the case of StarkNet, it is necessary to trust the implementation when it is not possible to verify the various components based on cryptography and advanced mathematics. This may initially create friction for the adoption of the technology, but as the tools and the usage of integrity proofs advance even outside the blockchain field this problem will be hopefully solved.
結論
- 結論 ロールアップは、スケーラビリティの問題を解決するために現在利用できる最も有望なソリューションです。 分散型 blockchain は、モジュール型 blockchain の時代への道を開きます。 モノリシックblockchain。 主に、楽観的ロールアップまたは妥当性ロールアップのどちらを開発するかの選択が示されています。 複雑さと機敏性の間のトレードオフとして。 StarkNet には、高速などの多くの利点があります。 引き出し、無効な状態遷移が構造的に不可能であること、取引コストが低いこと 開発期間が長くなり、EVM との互換性がないため、Optimism は ネットワーク経済を活用して、市場で急速に大きなシェアを獲得しました。 Optimism ただし、Bedrock は、Validity になることを可能にするモジュラー設計を備えています。 5https://blog.ethereum.org/2016/09/22/ethereum-network-currently-undergoing-dos-attack
将来のロールアップ: Cannon は現在、フォールトプルーフのために MIPS にコンパイルされた minigeth を使用しています システムですが、同じアーキテクチャを使用して回路を取得し、有効性証明を作成することができます。 EVM などの複雑なマシンをマイクロアーキテクチャ用にコンパイルすると、より単純になります。 アップグレードの場合に回路を変更したり再検証したりする必要がありません。 RISCゼロは、 RISC-V に基づいてすでに開発中の STARK 証明を備えた検証可能なマイクロアーキテクチャ MIPS [28] の代わりに、この目的に使用できます。 過小評価すべきではない側面の 1 つは、どのようにして、 テクノロジーは機能します。従来の blockchain の強みは、状態を確認できることです。 第三者エンティティを信頼せずに blockchain を実行します。ただし、StarkNet の場合は、 さまざまなコンポーネントを検証できない場合に実装を信頼する必要がある 暗号化と高度な数学に基づいています。これにより、最初は摩擦が生じる可能性があります。 テクノロジーの導入は進んでいますが、完全性証明のツールと使用法が進歩するにつれて、 blockchain フィールドの外では、この問題は解決されることが期待されます。