arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.07589cs.SE
收藏

复制粘贴?识别多链复用合约中的EVM不等价代码异味

Copy-and-Paste? Identifying EVM-Inequivalent Code Smells in Multi-chain Reuse Contracts

Zexu Wang, Jiachi Chen, Tao Zhang, Yu Zhang, Weizhe Zhang, Yuming Feng, Zibin Zheng

AI总结:

本文首次实证研究多链复用合约中的EVM不等价代码异味,定义六类异味并开发EquivGuard工具,通过静态污点分析和符号执行实现自动检测,在六大区块链90余万份合约中发现平均17.70%的异味出现率,警示开发者避免复制粘贴式复用。

摘要:

随着Solidity合约在以太坊上的发展,越来越多的开发者将它们复用到其他兼容区块链上。然而,开发者可能忽视区块链系统设计之间的差异,例如Gas机制和共识协议,导致相同的合约在不同区块链上无法实现与以太坊上一致的执行。这种不一致揭示了复用合约中的设计缺陷,暴露出阻碍代码复用性的代码异味,我们将这种不一致定义为EVM不等价代码异味。在本文中,我们开展了首个实证研究,以揭示EVM不等价代码异味的成因和特征。为确保识别出的异味反映开发者的真实关切,我们收集并分析了与EVM兼容区块链(如币安智能链(BSC)和Polygon)上复用合约相关的1,379份安全审计报告和326条Stack Overflow帖子。通过开放式卡片分类法,我们定义了六类EVM不等价代码异味。为实现自动化检测,我们开发了一款名为EquivGuard的工具。该工具采用静态污点分析来识别不同模式中的关键路径,并使用符号执行来验证路径可达性。我们对六大主流区块链上的905,948份合约进行分析,结果表明EVM不等价代码异味广泛存在,平均出现率为17.70%。虽然带有代码异味的合约不一定会导致经济损失和攻击,但它们的高出现率和显著的资产管理规模凸显了复用这些有异味的以太坊合约的潜在威胁。因此,建议开发者放弃复制粘贴式编程实践,并在复用以太坊合约之前检测EVM不等价代码异味。

英文摘要:

As the development of Solidity contracts on Ethereum, more developers are reusing them on other compatible blockchains. However, developers may overlook the differences between the designs of the blockchain system, such as the Gas Mechanism and Consensus Protocol, leading to the same contracts on different blockchains not being able to achieve consistent execution as on Ethereum. This inconsistency reveals design flaws in reused contracts, exposing code smells that hinder code reusability, and we define this inconsistency as EVM-Inequivalent Code Smells. In this paper, we conducted the first empirical study to reveal the causes and characteristics of EVM-Inequivalent Code Smells. To ensure the identified smells reflect real developer concerns, we collected and analyzed 1,379 security audit reports and 326 Stack Overflow posts related to reused contracts on EVM-compatible blockchains, such as Binance Smart Chain (BSC) and Polygon. Using the open card sorting method, we defined six types of EVM-Inequivalent Code Smells. For automated detection, we developed a tool named EquivGuard. It employs static taint analysis to identify key paths from different patterns and uses symbolic execution to verify path reachability. Our analysis of 905,948 contracts across six major blockchains shows that EVM-Inequivalent Code Smells are widespread, with an average prevalence of 17.70%. While contracts with code smells do not necessarily lead to financial loss and attacks, their high prevalence and significant asset management underscore the potential threats of reusing these smelly Ethereum contracts. Thus, developers are advised to abandon Copy-and-Paste programming practices and detect EVM-Inequivalent Code Smells before reusing Ethereum contracts.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑