# Arbitrum 阅读笔记 **Published by:** [luxebeng](https://paragraph.com/@luxebeng/) **Published on:** 2022-07-06 **URL:** https://paragraph.com/@luxebeng/arbitrum ## Content 背景为什么要ArbitrumArbitrum is an L2 scaling solution for Ethereum, offering a unique combination of benefits:Trustless security: security rooted in Ethereum, with any one party able to ensure correct Layer 2 resultsCompatibility with Ethereum: able to run unmodified EVM contracts and unmodified Ethereum transactionsScalability: moving contracts’ computation and storage off of the main Ethereum chain, allowing much higher throughputMinimum cost: designed and engineered to minimize the L1 gas footprint of the system, minimizing per-transaction cost.Some other Layer 2 systems provide some of these features, but to our knowledge no other system offers the same combination of features at the same cost.Optimistic RollupArbitrum is an optimistic rollup. Let’s unpack that term. Rollup Arbitrum is a rollup, which means that the inputs to the chain -- the messages that are put into the inbox -- are all recorded on the Ethereum chain as call-data. Because of this, everyone has the information they would need to determine the current correct state of the chain -- they have the full history of the inbox, and the results are uniquely determined by the inbox history, so they can reconstruct the state of the chain based only on public information, if needed. This also allows anyone to be a full participant in the Arbitrum protocol, to run an Arbitrum node or participate as a validator. Nothing about the history or state of the chain is a secret. Optimistic Arbitrum is optimistic, which means that Arbitrum advances the state of its chain by letting any party (a “validator”) post a rollup block that that party claims is correct, and then giving everyone else a chance to challenge that claim. If the challenge period (roughly a week) passes and nobody has challenged the claimed rollup block, Arbitrum confirms the rollup block as correct. If somebody challenges the claim during the challenge period, then Arbitrum uses an efficient dispute resolution protocol (detailed below) to identify which party is lying. The liar will forfeit a deposit, and the truth-teller will take part of that deposit as a reward for their efforts (some of the deposit is burned, guaranteeing that the liar is punished even if there's some collusion going on). Because a party who tries to cheat will lose a deposit, attempts to cheat should be very rare, and the normal case will be a single party posting a correct rollup block, and nobody challenging it.Interactive Proving & Re-executingWe believe strongly that interactive proving is the superior approach, for the following reasons. More efficient in the optimistic case: Because interactive proving can resolve disputes that are larger than one transaction, it can allow a rollup block to contain only a single claim about the end state of the chain after all of the execution covered by the block. By contrast, re-execution requires posting a state claim for each transaction within the rollup block. With hundred or thousands of transactions per rollup block, this is a substantial difference in L1 footprint -- and L1 footprint is the main component of cost. More efficient in the pessimistic case: In case of a dispute, interactive proving requires the L1 referee contract only to check that Alice and Bob's actions "have the right shape", for example, that Alice has divided her N-step claim into two claims half as large. (The referee doesn't need to evaluate the correctness of Alice's claims--Bob does that, off-chain.) Only one instruction needs to be reexecuted. By contrast, reexecution requires the L1 referee to emulate the execution of an entire transaction. Much higher per-tx gas limit: Interactive proving can escape from Ethereum's tight per-transaction gas limit; a transaction that requires so much gas it couldn't even fit into an Ethereum block is possible on Arbitrum. The gas limit isn't infinite, for obvious reasons, but it can be much larger than on Ethereum. As far as Ethereum is concerned, the only downside of a gas-heavy Arbitrum transaction is that it may require an interactive fraud proof with slightly more steps (and only if indeed it is fraudulent). By contrast, re-execution must impose a lower gas limit than Ethereum, because it must be possible to emulate execution of the transaction (which is more expensive than executing it directly) within a single Ethereum transaction. No limit on contract size: Interactive proving does not need to create an Ethereum contract for each L2 contract, so it does not need contracts to fit within Ethereum's contract size limit. As far as Arbitrum's dispute contracts are concerned, deploying a contract on L2 is just another bit of computation like any other. By contrast, re-execution approaches must impose a lower contract size limit than Ethereum, because they need to be able to instrument a contract in order to emulate its execution, and the resulting instrumented code must fit into a single Ethereum contract. More implementation flexibility: Interactive proving allows more flexibility in implementation, for example the ability to add instructions that don't exist in EVM. All that is necessary is the ability to verify a one-step proof on Ethereum. By contrast, re-execution approaches are tethered to limitations of the EVM.Arbitrum架构下图是Arbitrum的基本框图On the bottom right is good old Ethereum. Arbitrum builds on Ethereum and inherits its security from Ethereum. On top of Ethereum is the EthBridge, a set of Ethereum contracts that manage an Arbitrum chain. The EthBridge referees the Arbitrum rollup protocol, which ensures that the layers above it operate correctly. The EthBridge also maintains the chain’s inbox and outbox, allowing people and contracts to send transaction messages to the chain, and to observe and use the outputs of those transactions. Users, L1 Ethereum contracts, and Arbitrum nodes make calls to the EthBridge contracts to interact with the Arbitrum chain. The horizontal layer boundary above the EthBridge is labeled AVM Architecture, because what the EthBridge provides to the layer above it is an Arbitrum Virtual Machine, which can execute a computer program that reads inputs and produces outputs. This is the most important interface in Arbitrum, because it divides Layer 1 from Layer 2--it divides the Layer 1 components that provide the inbox/execution/outbox abstraction from the Layer 2 components that use that abstraction. The next layer up is ArbOS. This is a software program, written by Offchain Labs, that runs on the Arbitrum Virtual Machine, and serves as a record-keeper, traffic cop, and enforcer for the execution of smart contracts on the Arbitrum chain. It’s called ArbOS because it plays a role like a (lightweight version of) the operating system on a laptop or phone--it’s the program that starts up first and that manages the execution of all other code on the chain. Importantly, ArbOS runs entirely at Layer 2, off of the Ethereum chain, so it can take advantage of the scalability and low cost of Layer 2 computation. The horizontal layer boundary above ArbOS is called EVM compatibility because ArbOS provides an Ethereum Virtual Machine compatible execution environment for smart contracts. That is, you can send ArbOS the EVM code for a contract, in the same way you would send that contract to Ethereum, and ArbOS will load the contract and enable it to service transactions, just like on Ethereum. ArbOS takes care of the details of compatibility, so the smart contract programmer can just write their code like they would on Ethereum (or often, just take existing Ethereum contracts and redeploy them). At the top of the stack--the upper right portion of the diagram--are EVM contracts. which have been deployed to the Arbitrum chain by developers, and which execute transactions that are submitted to the chain.The EthBridgeInbox contractOutbox contractRollup contractChallenge contractArbitrum Rollup ProtocolChallengesValidatorsArbitrum Virtual MachineAbove or Below the Line? We often say that the key dividing line in the Arbitrum architecture is the AVM interface which divides Layer 1 from Layer 2. It can be useful to think about whether a particular activity is below the line or above the line. Below the line functions are concerned with ensuring that the AVM, and therefore the chain, executes correctly. Above the line functions assume that the AVM will execute correctly, and focus on interacting with the software running at Layer 2. As an example, Arbitrum validators operate below the line, because they participate in the rollup protocol, which is managed below-the-line by the EthBridge, to ensure that correct execution of the AVM is confirmed. On the other hand, Arbitrum full nodes operate above the line, because they run a copy of the AVM locally, and assume that below-the-line mechanisms will ensure that the same result that they compute locally will eventually be confirmed by below-the-line mechanisms that they don’t monitor. Most users, most of the time, will be thinking in above the line terms. They will be interacting with an Arbitrum chain as just another chain, without worrying about the below-the-line details that ensure that the chain won’t go wrong. Differences between AVM and EVM:Execution vs. proving The logical separation of execution from proving allows execution speed to be optimized more aggressively in the common case where proving turns out not to be needed.Requirements from ArbOSSupporting MerkleizationCodepoints: Optimizing code for provingCreating code at runtimeGetting messages from the InboxProducing outputsArbGas and gas trackingError handlingArbOSEVM CompatibilityThe account table Translating EVM code to run on AVM There are three main differences between EVM execution on Arbitrum compared to Ethereum. First, the two EVM instructions DIFFICULTY and COINBASE, which don’t make sense on an L2 chain, return fixed constant values. Second, the EVM instruction BLOCKHASH returns a pseudorandom value that is a digest of the chain’s history, but not the same hash value that Ethereum would return at the same block number. Third, Arbitrum uses the ArbGas system so everything related to gas is denominated in ArbGas, including the gas costs of operations, and the results of gas-related instructions like GASLIMIT and GASPRICE.Full NodesArbitrum full nodes operate "above the line", meaning that they don’t worry about the rollup protocol but simply treat their Arbitrum chain as a machine consuming inputs to produce outputs. Full nodes typically use both compression and batching when submitting transactions. Batching transactions: full node as an aggregator Compressing transactions Aggregator costs and feesSequencer ModeThe sequencer is a specially designated full node, which is given limited power to control the ordering of transactions. This allows the sequencer to guarantee the results of user transactions immediately. Instant confirmation Without a sequencer, a node can predict what the results of a client transaction will be, but the node can't be sure, because it can't know or control how the transactions it submits will be ordered in the inbox, relative to transactions submitted by other nodes. The sequencer is given more control over ordering, so it has the power to assign its clients' transactions a position in the inbox queue, thereby ensuring that it can determine the results of client transactions immediately. The sequencer's power to reorder has limits (see below for details) but it does have more power than anyone else to influence transaction ordering. Inboxes, fast and slow If the sequencer is well-behaved... If the sequencer is malicious... Decentralized fair sequencingBridgingGas and FeesFeesFees are charged for four resources that a transaction can use:L2 tx: a base fee for each L2 transaction, to cover the cost of servicing a transactionL1 calldata: a fee per units of L1 calldata directly attributable to the transaction (as on Ethereum, each non-zero byte of calldata is 16 units, and each zero byte of calldata is 4 units)computation: a fee per unit of ArbGas used by the transactionstorage: a fee per location of EVM contract storage, based change in EVM storage usage due to the transactionEach of these four resources has a price, which may vary over time. The resource prices, which are denominated in wei, are set as follows: Prices for L2 tx and L1 calldataThe base price of an L2 transaction is set by each aggregator, using an Arbitrum precompile, subject to a system-wide maximum.The base price of a unit of L1 calldata is just the estimated L1 gas price.Price for storage Transactions are charged a storage fee for allocating an EVM storage cell. Each storage allocation costs 2000 times the estimated L1 gas price. This means that storage costs about 10% as much as it does on the L1 chain. Price for ArbGas ArbGas pricing depends on a minimum price, and a congestion pricing mechanism. The minimum ArbGas price is set equal to the estimated L1 gas price divided by 100. The price of ArbGas will never go lower than this. The price will rise above the minimum if the chain is starting to get congested. At the beginning of each block, is multiplied by a factor between 7/8 and 9/8, depending on how busy the chain seems to be. The automatic adjustment mechanism depends on an “ArbGas pool” that is tracked by ArbOS. The ArbGas pool has a maximum capacity that is equal to 12 minutes of full-speed computation at the chain’s speed limit. ArbGas used by transactions is subtracted from the gas pool, and at the beginning of each new Ethereum block, ArbGas is added to the pool corresponding to full-speed execution for the number of timestamp seconds since the last block (subject to the maximum pool capacity). After adding the new gas to the pool, if the new gas pool size is G, the current ArbGas price is multiplied by (16200S - G) / (14400S) where S is the ArbGas speed limit of the chain. This quantity will be 7/8 when G = 720S (the maximum gas pool size) and it will be 9/8 when G = 0.参考文档Inside Arbitrum Understanding Arbitrum: 2-Dimensional Fees ## Publication Information - [luxebeng](https://paragraph.com/@luxebeng/): Publication homepage - [All Posts](https://paragraph.com/@luxebeng/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@luxebeng): Subscribe to updates