Security Analysis of Smart Contract Migration from Ethereum to Arbitrum
Abstract
:1. Introduction
- We identify security risks related to the runtime environment of smart contracts, highlight the importance of understanding the underlying differences between the source and target blockchains during smart contract migration for vulnerability identification.
- Through a multifaceted analysis of differences, we delved into the key distinctions between Ethereum and Arbitrum. Our research revealed several unique aspects, including Arbitrum cross-chain messaging, block properties, contract address alias, and gas fees.
- Through multiple case studies, we summarize the potential risks that may arise during the migration of smart contracts from Ethereum to Arbitrum. These include outdated off-chain data obtained by the inactive sequencer, logic errors based on time, the failed permission checks, and DOS attacks.
- To address these issues, we provide relevant mitigation strategies, which are valuable for users and developers with smart contract migration needs. It is worth mentioning that this paper is the first in-depth research on the secure migration of smart contracts from Ethereum to Arbitrum.
2. Background
2.1. Ethereum
2.2. Arbitrum
2.3. The Migration of Smart Contracts from L1 to L2
2.3.1. Smart Contract Migration Process
- Data recovery: The first step in smart contract migration is data recovery. In this step, we need to read data from specific blocks on the source blockchain for migration and use corresponding methods to recover the data based on the contract’s data structure—for example, by calling the appropriate getter() function to retrieve public variables from the contract, relying on events, or using the getStorageAt() function to calculate the memory offset of private variables and retrieve their values from contract storage. However, please note that in order to increase the transparency of the migration and prevent attackers from exploiting users who are unaware of the migration, it is recommended to pause the contract’s operation during the data recovery process.
- Writing data to new contract: During smart contract migration, once the data to be migrated has been collected, the next step is to deploy and initialize the new contract on the target blockchain for migration. For simple variables, their values can be set through the contract’s constructor() function. If the amount of data being migrated is large, the migration needs to be split into multiple transactions. For example, for ERC20 token contracts, the contract needs to be deployed on the target blockchain and the initial parameters set in the initial state. Then, users initiate transfer transactions in the old contract, and the new contract receives and records these transfer operations, moving the token balances from the old contract to the new one.
2.3.2. Differences between L1 and L2
- Smart contract development language: There are many programming languages for smart contract development, including Solidity [10], Vyper [17], Cairo [18], and more. Solidity is widely used for smart contract development on Ethereum and has a large developer community. Vyper is also an officially supported language for Ethereum. Most L2 blockchains also support Solidity, such as Arbitrum and Optimism [19]. Some L2 blockchains have their own smart contract development languages, such as Cairo for smart contracts on StarkNet [20]. Cairo is a low-level intermediate language used to describe the computation and state transition logic of StarkNet.
- Smart contract runtime environment: On Ethereum, the runtime environment for smart contracts based on Solidity and Vyper is the EVM. Many L2 solutions provide runtime environments for smart contracts that are EVM compatible, but the differences between them should not be overlooked. For example, Arbitrum’s smart contracts [21] runtime environment simulates EVM execution through its custom Arbitrum Virtual Machine (AVM) or the WebAssembly-based ArbOS program. These execution environments aim to provide an execution environment that closely resembles the EVM. The operating environment for Polygon zkEVM [22] is the zkEVM developed by Polygon. Differences between Polygon zkEVM and EVM mainly include opcodes, precompiled contracts, and so on [23].
2.4. Vulnerabilities in Smart Contracts
3. Related Work
4. Methodology
4.1. Data Collection
- Collection of relevant literature: During the process of collecting relevant literature, we used keywords such as “Smart Contract”, “Migration”, and “Security” to conduct literature searches on Google Scholar. We found that the amount of relevant literature in the field of smart contract security migration is limited, which may be due to its relatively new and technologically complex nature. There are two papers [29,30] that focus on discussing migration mechanisms by designing toolkits and middleware to facilitate the migration of smart contracts or applications. However, they do not provide explanations and verifications regarding the security of migrating smart contracts and applications.
- Collection of official online resources: Although the amount of literature specifically focused on smart contract migration is limited, we made efforts to gather a large amount of official online resources to supplement the literature. These resources have been extremely helpful for our research. Since our focus is on smart contract migration from Ethereum to Arbitrum, we relied on the official websites of Ethereum and Arbitrum for data collection [34,35,36,37,38,39,40]. In particular, we found numerous relevant online resources on Arbitrum website, highlighting the differences between Arbitrum and Ethereum. Additionally, we collected data from the official websites of OpenZeppelin [41], Chainlink [42], and Solidity [10].
- Collection of smart contract source code: We collected cases of smart contract vulnerabilities from audit reports found on the official websites, including Code4rena [43], Cyfrin [44], Halborn [45], OpenZeppelin [41], and so on, encompassing a total of 36 types of smart contracts. We also referred to swcregistry (classification of smart contract vulnerability types), Ethereum Smart Contract Best Practices–Attacks, and the UNISWAP project. Table 1 displays some of our data sources.
4.2. Data Organization
4.3. Case Study
- Analyze the underlying differences and characteristics between Ethereum and Arbitrum.
- Based on the differences between Ethereum and Arbitrum’s foundations, examine the smart contract source code to understand the contract’s inheritance relationships, function call relationships, and various variables.
- Combine automated vulnerability detection tools with manual auditing and conduct group discussions on the audit results.
- Synthesize case studies and foundational differences to summarize the potential security risks in smart contracts migrating from Ethereum to Arbitrum.
4.4. Expert Participation
5. Findings
5.1. Arbitrum Cross-Chain Messaging
5.1.1. Sequencer in L2-to-L1 Message
- Incorrect transaction execution: If a contract relies on real-time off-chain data for executing transfers or other fund-related operations, delayed data can cause transaction execution delays or errors. This can lead to funds being transferred incorrectly or transactions not being executed as expected.
- Asymmetric transaction conditions: Delayed off-chain data may cause information asymmetry between smart contracts and external data sources, potentially leading to missed opportunities or unfair transaction conditions. This can result in certain participants obtaining unfair advantages, leading to financial losses for other participants.
- Inaccurate prices or market data: If a smart contract relies on timely prices or market data for executing trades or making decisions, delayed or inaccurate data can lead to transactions being executed at inappropriate prices or market conditions, resulting in financial losses.
5.1.2. L1-to-L2 Messaging through Retryable Tickets
- Submission process on L1.
- 2.
- Redeem process on L2.
- When calling the createRetryableTicket() function on L1, if the funds fail the verification check, the transaction will be reverted, resulting in the loss of gas fees without any refund.
- After the automatic redemption fails on L2, a manual redeem operation is required. This may cause:
- If the ticket fails to redeem automatically and is temporarily stored in the buffer, it will be saved for seven days. If the ticket fails to redeem or the fee is not paid to continue the storage after the expiration, the carried messages and value (excluding the managed callvalue) may be lost and cannot be recovered.
5.2. Block Properties
- Inconsistent block number logic: Due to the different mechanism for updating L1 block numbers in Arbitrum compared to Ethereum, smart contracts may not be able to make accurate logical judgments based on block numbers. For example, if a contract relies on the state or events of a specific block, inconsistent results may occur on Arbitrum.
- Inconsistent timestamp logic: Since the timestamp obtained in Arbitrum is recorded by the sequencer and not the timestamp of the current block, smart contracts may not be able to make accurate logical judgments based on timestamp. For example, if a contract needs to perform certain operations or restrictions based on the current time, inconsistent results may occur on Arbitrum.
- Duplicate timestamp issue: It is possible for Arbitrum to have the same timestamp in different blocks, which can prevent contracts from accurately differentiating between timestamps of different blocks. This can impact time-related contract logic, such as restricting certain operations to be executed only once within a specific time period.
5.3. Contract Address Alias
- Failed permission checks: If a contract on Arbitrum performs permission checks by comparing “msg.sender” with an expected address and does not take into account the alias address from L1-to-L2 messages, permission checks may fail. This means that unauthorized addresses may be granted access to the contract, resulting in potential security vulnerabilities.
- Inability to modify contract owner: In some cases, a contract may need to modify its owner address. However, if the contract’s owner address is obtained through L1-to-L2 messages and developers do not handle the alias correctly, the contract may be unable to modify its owner. This can limit the contract’s functionality and flexibility, as it may not be able to update its logic or configuration.
- Potential contract impersonation risks: If a contract on Arbitrum uses “msg.sender” for contract impersonation risk checks and does not consider the alias address, there may be a risk of contract impersonation. This means that one contract can impersonate another and perform unauthorized operations, potentially resulting in financial losses or other adverse effects.
5.4. Gas Fees
- Large-scale small-value transaction attacks: Due to the lower gas fees, attackers may exploit Arbitrum to launch attacks involving a large number of small-value transactions. Such attacks can cause network congestion, transaction delays, and resource waste, negatively impacting the network’s normal operation and user experience.
- Resource exhaustion: Large-scale small-value transaction attacks can deplete network resources, including computational and storage resources. This can result in increased transaction processing times, transaction failures, or DOS issues, affecting users’ normal transaction activities.
- Exploitation of malicious contracts: Attackers may create malicious smart contracts to exploit the low gas fees and execute a large number of transactions for certain purposes, such as market manipulation, fraudulent activities, or other improper behaviors. This can cause significant losses and inconvenience to users and the ecosystem.
5.5. Summary of Issues
5.5.1. Outdated Off-Chain Data Obtained by the Inactive Sequencer
5.5.2. Logic Errors Based on Time
5.5.3. The Permission Check Failed
5.5.4. DOS Attack
6. Risk Avoidance Methods
6.1. Outdated Off-Chain Data Obtained by the Inactive Sequencer
6.2. Logic Errors Based on Time
6.3. The Permission Check Failed
6.4. DOS Attack
7. Limitations
7.1. Data Collection
7.2. Selection of Research Objects
7.3. Migration Risks
8. Conclusions and Future Work
Supplementary Materials
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Fynn, E.; Bessani, A.; Pedone, F. Smart contracts on the move. In Proceedings of the 2020 50th Annual IEEE/IFIP International Conference on Dependable Systems and Networks (DSN), Valencia, Spain, 29 June–2 July 2020; pp. 233–244. [Google Scholar]
- Hafid, A.; Hafid, A.S.; Samih, M. Scaling blockchains: A comprehensive survey. IEEE Access 2020, 8, 125244–125262. [Google Scholar] [CrossRef]
- Khan, S.; Amin, M.B.; Azar, A.T.; Aslam, S. Towards interoperable blockchains: A survey on the role of smart contracts in blockchain interoperability. IEEE Access 2021, 9, 116672–116691. [Google Scholar] [CrossRef]
- Ethereum. Welcome to Ethereum. 2023. Available online: https://ethereum.org/ (accessed on 1 September 2023).
- Arbitrum. Take It to the Next Layer with Nitro: Making Ethereum More Inclusive and Sustainable. 2023. Available online: https://arbitrum.io/ (accessed on 1 September 2023).
- Neiheiser, R.; Inácio, G.; Rech, L.; Montez, C.; Matos, M.; Rodrigues, L. Practical limitations of ethereum’s layer-2. IEEE Access 2023, 11, 8651–8662. [Google Scholar] [CrossRef]
- Rosca, I.; Butnaru, A.-I.; Simion, E. Security of ethereum layer 2s. Cryptology ePrint Archive. 2023. Available online: https://eprint.iacr.org/2023/124 (accessed on 26 September 2023).
- CoinMarketCap. Today’s Cryptocurrency Prices by Market Cap. 2023. Available online: https://coinmarketcap.com/ (accessed on 3 September 2023).
- Zou, W.; Lo, D.; Kochhar, P.S.; Le, X.B.D.; Xia, X.; Feng, Y.; Chen, Z.; Xu, B. Smart contract development: Challenges and opportunities. IEEE Trans. Softw. Eng. 2019, 47, 2084–2106. [Google Scholar] [CrossRef]
- Solidity. 2023. Available online: https://soliditylang.org/ (accessed on 1 September 2023).
- Ethereum. Ethereum Virtual Machine (EVM). 2023. Available online: https://ethereum.org/en/developers/docs/evm/ (accessed on 1 September 2023).
- Ethereum. Gas and Fees. 2023. Available online: https://ethereum.org/en/developers/docs/gas/ (accessed on 2 September 2023).
- Kalodner, H.; Goldfeder, S.; Chen, X.; Weinberg, S.M.; Felten, E.W. Arbitrum: Scalable, private smart contracts. In Proceedings of the 27th USENIX Security Symposium (USENIX Security 18), Baltimore, MD, USA, 15–17 August 2018; pp. 1353–1370. [Google Scholar]
- Arbitrum. Arbitrum Portal. 2023. Available online: https://portal.arbitrum.io/?chains=arbitrum-one (accessed on 3 September 2023).
- CoinGecko. Top Layer 2 Chains by Total Value Locked (TVL). 2023. Available online: https://www.coingecko.com/en/chains/layer-2 (accessed on 3 September 2023).
- Watters, C. Digital Gold or Digital Security? Unravelling the Legal Fabric of Decentralised Digital Assets. Commodities 2023, 2, 355–366. [Google Scholar] [CrossRef]
- Vyper. What is Vyper? 2023. Available online: https://docs.vyperlang.org/en/stable/ (accessed on 10 September 2023).
- Cairo. The Cairo Programming Language. 2023. Available online: https://book.cairo-lang.org/zh-cn/index.html (accessed on 4 September 2023).
- Optimism. Ethereum, Scaled. 2023. Available online: https://www.optimism.io/ (accessed on 4 September 2023).
- Starknet. Welcome to Starknet. 2023. Available online: https://www.starknet.io/en (accessed on 4 September 2023).
- Arbitrum. Wen Why Nitro? 2023. Available online: https://docs.arbitrum.io/why-nitro (accessed on 4 September 2023).
- Polygon. Bring Ethereum to Everyone. 2023. Available online: https://polygon.technology/polygon-zkevm (accessed on 4 September 2023).
- Polygon. Differences Between EVM and zkEVM. 2023. Available online: https://wiki.polygon.technology/docs/zkevm/protocol/evm-diff/ (accessed on 5 September 2023).
- Musson, M. CryptoTanks: Tank NFTs Smart Contract Migration. 2023. Available online: https://medium.com/@cryptotanksio/cryptotanks-tank-nfts-smart-contract-migration-60ace6c93663 (accessed on 15 September 2023).
- BasketCoin. Migration to Binance Smart Chain (BSC). 2021. Available online: https://medium.com/@basketcoin/migration-to-binance-smart-chain-bsc-e42dd66cfe97 (accessed on 15 September 2023).
- Sandbox, T. The Sandbox is Deploying on Polygon. 2022. Available online: https://medium.com/sandbox-game/the-sandbox-is-deploying-on-polygon-c44e026afeb2 (accessed on 15 September 2023).
- OpenBlox. Migration Guide: How to Move Your Blox from Ethereum to Arbitrum. 2022. Available online: https://medium.com/openblox/migration-guide-how-to-move-your-blox-from-ethereum-to-arbitrum-b736970830a3 (accessed on 15 September 2023).
- Fix the Cross Chain Messaging Bridge on Arbitrum. 2022. Available online: https://gov.uniswap.org/t/temperature-check-fix-the-cross-chain-messaging-bridge-on-arbitrum/18073 (accessed on 16 September 2023).
- Westerkamp, M. Verifiable smart contract portability. In Proceedings of the 2019 IEEE International Conference on Blockchain and Cryptocurrency (ICBC), Seoul, Republic of Korea, 14–17 May 2019; pp. 1–9. [Google Scholar]
- Shudo, K.; Kanda, R.; Saito, K. Towards application portability on blockchains. In Proceedings of the 2018 1st IEEE International Conference on Hot Information-Centric Networking (HotICN), Shenzhen, China, 15–17 August 2018; pp. 51–55. [Google Scholar]
- Papaioannou, D.; Sutton, A.; Booth, A. Systematic Approaches to a Successful Literature Review; Sage Publishing: Thousand Oaks, CA, USA, 2016; pp. 1–336. [Google Scholar]
- Granello, D.H.; Wheaton, J.E. Online data collection: Strategies for research. J. Couns. Dev. 2004, 82, 387–393. [Google Scholar] [CrossRef]
- Rashid, Y.; Rashid, A.; Warraich, M.A.; Sabir, S.S.; Waseem, A. Case study method: A step-by-step guide for business researchers. Int. J. Qual. Methods 2019, 18, 1609406919862424. [Google Scholar] [CrossRef]
- Arbitrum. Arbitrum Address Aliasing. 2023. Available online: https://docs.arbitrum.io/arbos/l1-to-l2-messaging#address-aliasing (accessed on 10 October 2023).
- Arbitrum. L2 to l1 Messaging. 2023. Available online: https://docs.arbitrum.io/arbos/l2-to-l1-messaging (accessed on 10 October 2023).
- Arbitrum. Arbos. 2023. Available online: https://docs.arbitrum.io/arbos/ (accessed on 10 October 2023).
- Arbitrum. Arbos Gas. 2023. Available online: https://docs.arbitrum.io/arbos/gas (accessed on 10 October 2023).
- Arbitrum. Arbos l1 Pricing. 2023. Available online: https://docs.arbitrum.io/arbos/l1-pricing (accessed on 10 October 2023).
- Arbitrum. The Sequencer. 2023. Available online: https://docs.arbitrum.io/how-arbitrum-works/sequencer (accessed on 10 October 2023).
- Arbitrum. Transaction Lifecycle in Arbitrum. 2023. Available online: https://docs.arbitrum.io/tx-lifecycle (accessed on 10 October 2023).
- OpenZeppelin. Securely Code, Deploy and Operate Your Smart Contracts. 2023. Available online: https://www.openzeppelin.com/ (accessed on 16 October 2023).
- Chainlink. Connecting the World to Blockchains. 2023. Available online: https://chain.link/ (accessed on 16 October 2023).
- Code4rena. Secure Your Smart Contracts. 2023. Available online: https://code4rena.com/ (accessed on 16 October 2023).
- Cyfrin. World-Class Smart Contract Auditing and Web3 Education 2023. Available online: https://www.cyfrin.io/ (accessed on 16 October 2023).
- Halborn. Elite Blockchain Security Solutions. 2023. Available online: https://www.halborn.com/ (accessed on 20 October 2023).
- Arbitrum. A Gentle Introduction to Arbitrum. 2023. Available online: https://docs.arbitrum.io/intro/ (accessed on 10 October 2023).
- Ethereum. Learn Hub. 2023. Available online: https://ethereum.org/en/learn/ (accessed on 20 October 2023).
- ChainLink. Chainlink—l2-Sequencer-Feeds. Available online: https://docs.chain.link/data-feeds/l2-sequencer-feeds (accessed on 20 October 2023).
- Evert0x. Glporacle. 2023. Available online: https://github.com/sherlock-audit/2023-01-sentiment/blob/main/oracle/src/gmx/GLPOracle.sol (accessed on 20 October 2023).
- R0ohafza. Glporacle.t.sol. 2023. Available online: https://github.com/sentimentxyz/oracle/blob/815233add2d23a7e2a2c5136504537b234a65c47/src/tests/GLPOracle.t.sol (accessed on 22 October 2023).
- R0ohafza. Glporacleupdate.sol. 2023. Available online: https://github.com/sentimentxyz/oracle/blob/main/src/gmx/GLPOracle.sol (accessed on 22 October 2023).
- TriHaz. Trading.sol. 2022. Available online: https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L857-L868 (accessed on 22 October 2023).
- Tintinweb. Marginfactory.sol. 2022. Available online: https://github.com/tintinweb/smart-contract-sanctuary-arbitrum/blob/662d22a0f98c6a0c8ef23e43ac6d6a3eac5968da/contracts (accessed on 22 October 2023).
- Uniswap. Uniswapv3factory. 2021. Available online: https://arbiscan.io/address/0x1f98431c8ad98523631ae4a59f267346ea31f984#code (accessed on 25 October 2023).
- DavidBDiligence. Dos. 2022. Available online: https://github.com/Consensys/smart-contract-best-practices/blob/master/docs/attacks/denial-of-service.md (accessed on 25 October 2023).
- Sherlock Admin. Pool. 2023. Available online: https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L216-L263 (accessed on 25 October 2023).
- Karasev, O.; Mukanina, E. Expert assessment method in foresight studies. Stat. Econ. 2019, 16, 4–13. [Google Scholar] [CrossRef]
- Tantikul, P.; Ngamsuriyaroj, S. Exploring vulnerabilities in solidity smart contract. In Proceedings of the 6th International Conference on Information Systems Security and Privacy (ICISSP 2020), Valletta, Malta, 25–27 February 2020; pp. 317–324. [Google Scholar]
Data Platforms | Reference |
---|---|
Google Scholar | [29,30] |
Online Resources | [34,35,36,37,38,39,40,46,47,48] |
Smart Contract Vulnerability Cases | [49,50,51,52,53,54,55,56] |
Wall Clock Time | L1 block.number | L2 block.number |
---|---|---|
12:00:00 a.m. | 1000 | 1000 |
12:00:15 a.m. | 1001 | 1000 |
12:00:30 a.m. | 1002 | 1000 |
12:00:45 a.m. | 1003 | 1000 |
12:01:00 a.m. | 1004 | 1004 |
12:01:15 a.m. | 1005 | 1005 |
Tx Example | Arbitrum One | Ethereum | Pct Saved | Amount Saved |
---|---|---|---|---|
Aave Deposit | USD 0.15 | $4.02 | 96% | USD 3.87 |
EOA Transfer | USD 0.09 | $0.65 | 87% | USD 0.57 |
Opensea NFT Sale | USD 0.20 | $5.55 | 96% | USD 5.35 |
SushiSwap Swap | USD 0.08 | $2.53 | 97% | USD 2.45 |
Uniswap Swap | USD 0.08 | $3.97 | 98% | USD 3.89 |
Yearn Deposit | USD 0.05 | $3.63 | 99% | USD 3.58 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Tang, X.; Shi, L. Security Analysis of Smart Contract Migration from Ethereum to Arbitrum. Blockchains 2024, 2, 424-444. https://doi.org/10.3390/blockchains2040018
Tang X, Shi L. Security Analysis of Smart Contract Migration from Ethereum to Arbitrum. Blockchains. 2024; 2(4):424-444. https://doi.org/10.3390/blockchains2040018
Chicago/Turabian StyleTang, Xueyan, and Lingzhi Shi. 2024. "Security Analysis of Smart Contract Migration from Ethereum to Arbitrum" Blockchains 2, no. 4: 424-444. https://doi.org/10.3390/blockchains2040018
APA StyleTang, X., & Shi, L. (2024). Security Analysis of Smart Contract Migration from Ethereum to Arbitrum. Blockchains, 2(4), 424-444. https://doi.org/10.3390/blockchains2040018