What are the differences between OP Stack and Ethereum mainnet

avatar
Bitpush
02-24
This article is machine translated
Show original

Text / OP Stack; translation / Jinse Finance xiaozou

On February 23, 2023, Coinbase announced the launch of the Base testnet based on OP Stack. At the same time, the Optimism Collective ( the DAO that manages Optimism) announced that it will be upgraded to the Optimism Superchain.

But both the Base test network and the Optimism super chain are based on the OP Stack. So what are the differences between OP Stack and the Ethereum mainnet?

The current OP Stack version is Bedrock, and the OP Stack official website document details the differences between Bedrock and the Ethereum mainnet. Jinse Finance xiaozou translated this document:

It is worth noting that there are various minor differences between the behavior of Optimism and Ethereum. You should be aware of these differences when building applications on Optimism or OP Stack code bases.

Opcode (operation code) differences

fIIcmPIBtQW7ISAspTieKEPR5oBLyuoystKBwX0a.png

`tx.origin == msg.sender`

On Ethereum L1, tx.origin is equal to msg.sender only when the smart contract is called directly from an external account (EOA). However, on Optimism, tx.origin is the origin on Optimism, which may also be an EOA. However, for a message from L1, it is possible for a message from a smart contract on L1 to appear on L2, when tx.origin == msg.origin. This is unlikely to make a noticeable difference since L1 smart contracts cannot directly manipulate L2 state. However, there may also be edge cases that we have not considered.

Get L1 information

If you need the equivalent of the latest L1 block, you can get it from the L1Block contract. The pre-deployed contract is at address 0×42000000000000000000000000000000000000000015. You can get these parameters using getter functions:

  • number: The latest L1 block number known to L2.

  • timestamp: The timestamp of the latest L1 block.

  • basefee: The base fee for the latest L1 block.

  • hash: The hash value of the latest L1 block.

  • sequenceNumber: The number of L2 blocks in the epoch (when there is a new L1 block, the epoch changes accordingly).

Address Aliasing (Address Aliasing)

With the behavior of the CREATE opcode, users can create a contract on L1 and L2 that shares the same address but has different bytecodes. This can break trust assumptions, as one contract may be trusted while another contract may not be trusted (see below). To avoid this problem, the behavior of the ORIGIN and CALLER opcodes (tx.origin and msg.sender) is slightly different between L1 and L2.

The value of tx.origin is determined as follows:

a2nUP2BDa7ZvlI9xmrRSDWMnSPeYHFX4biVBfw8j.png

The top-level (first contract called) msg.sender value is always equal to tx.origin. Therefore, if the tx.origin value is affected by the rules defined above, the top-level value of msg.sender will also be affected.

Note that in general, tx.origin should not be used for authentication. However, this is a different issue than address aliasing, since address aliasing also affects msg.sender.

Why is address aliasing a problem?

The problem with two identical source addresses (L1 contract and L2 contract) is that we are extending trust based on addresses. It is possible that we want to trust one of the contracts but not the other.

(1) Helena Hacker forked Uniswap to create her own exchange (on L2), called Hackswap.

Note: There are actually multiple contracts on Uniswap, so this description is a simplification.

(2) Helena Hacker provides liquidity for Hackswap, which seems to provide profitable arbitrage opportunities. For example, you can spend 1 DAI to buy 1.1 USDT. Both coins are worth $1.

(3) Nimrod Naive knows that if something seems too good to be true, it probably is. However, he checked the bytecode of the Hackswap contract and verified that it was identical to Uniswap. He takes this to mean that the contract can be trusted to behave exactly like Uniswap.

(4) Nimrod approved the 1000 DAI transaction of the Hackswap contract. Nimrod wanted to call the swap function on Hackswap and received nearly 1100 USDT.

(5) Before Nimrod's swap transaction was sent to the blockchain, Helena Hacker sent a transaction from the L1 contract with the same Hackswap address. The transaction transferred 1000 DAI from Nimrod's address to Helena Hacker's address. If this transaction comes from the same address as Hackswap on L2, it will be able to transfer the 1000 DAI, because Nimrod has approved the token swap on Hackswap in the previous step.

Despite Nimrod's naivety, he is protected because Optimism modifies the transaction's tx.origin (which is also the original msg.sender). The transaction came from a different address, one that was not approved.

Note: It is easy to create two different contracts with the same address on different chains. But it's nearly impossible to create two different contracts with the same specified amount, so Helena Hacker can't do that.

block

There are several differences in the way blocks are generated between L1 Ethereum and Optimism Bedrock.

F2eX7BgTXwxFwF3gFCOzU1upDPEBNwVuhqtKmNe5.png

(1) This is the ideal state. If any blocks are missed, it may be an integer multiple, such as 24 seconds, 36 seconds, etc.

Note: L1 Ethereum parameter values are taken from ethereum.org. The Optimism Bedrock value is taken from the Optimism parameter.

network norms

JSON-RPC differences

The OP Stack codebase uses the same JSON-RPC API as Ethereum. Some additional OP Stack-specific methods are introduced.

Whether to support Pre-EIP-155

Pre-EIP-155 transactions do not have a chain ID, which means transactions on one Ethereum blockchain can be replayed on other Ethereum blockchains. This is a security risk, so OP Stack does not support Pre-EIP-155 transactions by default.

transaction cost

By default, transaction costs on the OP Stack chain include L2 execution fees and L1 data fees.

Source
Disclaimer: The content above is only the author's opinion which does not represent any position of Followin, and is not intended as, and shall not be understood or construed as, investment advice from Followin.
Like
Add to Favorites
Comments