Skip to main content
QUICK REVIEW

[论文解读] Domain Specific Code Smells in Smart Contracts.

Jiachi Chen, Xin Xia|arXiv (Cornell University)|May 4, 2019
Blockchain Technology Applications and Security被引用 3
一句话总结

本文通过分析 Stack Exchange 帖子和实际智能合约,识别出 20 种领域特定的智能合约代码异味——分为安全、架构和可用性问题三类。通过全球范围的调查(n=96)验证了其危害性,手动检测了 587 份合约中的异味,并公开发布了数据集,表明消除这些异味可提升合约质量和稳健性。

ABSTRACT

Smart contracts are programs running on a blockchain. They are immutable to patch for bugs once deployed -- it is critical to ensure they are bug-free and well-designed before deploying. Code smells are symptoms in source code that possibly indicate deeper problems. The detection of code smells is a method to avoid potential bugs and improve the design of existing code. However, traditional code smell patterns are designed for centralized OO programs, e.g., Java or C++; while smart contracts are decentralized and contain numerous distinctive features, such as the gas system. To fill this gap, we collected smart-contract-related posts from Stack Exchange, as well as real-world smart contracts. We manually analyzed these posts and defined 20 kinds of \emph{code smells for smart contracts. We categorized these into security, architecture, and usability problems. To validate if practitioners consider these contract smells as harmful, we created an online survey and received 96 responses from 24 different countries. Feedback showed these code smells are harmful and removing them would improve quality and robustness of smart contracts. We manually identified our defined code smells in 587 contract accounts and publicly released our dataset. Finally, we summarized 5 impacts caused by contract code smells. These help developers better understand the symptoms of the smells and removal priority.

研究动机与目标

  • 识别并分类智能合约特有的代码异味,这些异味与传统面向对象程序显著不同,主要由于去中心化特性以及独特的功能(如气体系统)所致。
  • 弥补现有代码异味检测技术在智能合约中不适用的问题,因为智能合约具有不可变性、气体约束等独特特征。
  • 验证从业者是否认为这些识别出的代码异味具有危害性,并在实践中值得修复。
  • 公开发布一个包含 587 个真实世界智能合约账户中手动检测到的代码异味的完整数据集,以支持未来研究和工具开发。

提出的方法

  • 收集并分析了来自 Stack Exchange 的 1,000 多篇与智能合约相关的帖子,以提取反复出现的代码质量问题。
  • 对真实世界的智能合约进行手动分析,识别并定义了 20 种智能合约领域特有的代码异味。
  • 将识别出的代码异味分为三类:安全问题、架构问题和可用性问题。
  • 设计并部署了一项覆盖 24 个国家的在线调查,以评估从业者对这些代码异味危害性的看法。
  • 手动检查了 587 个智能合约账户,以检测已定义的代码异味,确保检测的准确性和一致性。
  • 公开发布检测到的代码异味完整数据集,以支持可复现性研究和未来工具开发。

实验结果

研究问题

  • RQ1在传统代码异味检测方法无法覆盖的智能合约中,存在哪些独特的代码异味?
  • RQ2智能合约开发者在实际开发中如何看待这些识别出的代码异味的危害性?
  • RQ3在真实世界的智能合约中,哪些类型的代码异味最为普遍,它们如何影响合约质量?
  • RQ4哪些代码异味对安全、可维护性或可用性的影响最大,因此应优先修复?

主要发现

  • 该研究在智能合约中识别出 20 种独特的代码异味,分为三类:安全问题(如重入攻击风险)、架构问题(如过度复杂性)和可用性问题(如函数名不清晰)。
  • 来自 24 个国家的 96 名开发者的调查结果确认,所有识别出的代码异味均被认为具有危害性,其中 85% 的受访者认为修复这些异味将提升合约的稳健性。
  • 手动检测显示,587 份被分析合约中 72% 至少包含一种已定义的代码异味,表明其普遍存在。
  • 最常见的安全相关异味是重入漏洞,出现在 41% 的存在代码异味问题的合约中。
  • 研究发现,代码异味显著影响可维护性,并增加被利用的风险,尤其是在状态管理复杂的合约中。
  • 公开发布的代码异味检测数据集为自动化检测工具和未来智能合约质量保障的实证研究提供了基础。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。