Defining Smart Contract Defects on Ethereum

Jiachi Chen, Xin Xia, David Lo, John C. Grundy, Xiapu Luo, Ting Chen

TL;DR

This paper addresses the critical need for robust smart contracts on Ethereum by empirically defining and categorizing 20 common contract defects across security, availability, performance, maintainability, and reusability. The research provides a valuable dataset and survey-backed insights into the prevalence and impact of these defects, aiming to guide developers and researchers in building more secure and reliable decentralized applications.

What Problem Does This Paper Address?

Smart contracts, the backbone of many blockchain applications, are immutable once deployed. This means bugs or design flaws can't be easily fixed, making it crucial to ensure they are bug-free before deployment. However, the unique characteristics of blockchains, like the gas system and decentralization, introduce specific types of errors (defects) not found in traditional software. Existing research often focuses narrowly on security vulnerabilities, neglecting other crucial aspects like availability, performance, maintainability, and reusability. This paper aims to fill this gap by providing a comprehensive, empirically-derived classification of smart contract defects on the Ethereum platform.

Methods

The researchers employed a multi-pronged approach:

  1. Data Collection: They scraped 17,128 posts from Ethereum StackExchange, a popular Q&A site for developers, and collected real-world smart contracts from the Ethereum blockchain.
  2. Defect Identification: Using keyword filtering and manual analysis of StackExchange posts, they identified recurring issues and themes. This was followed by "open card sorting" to categorize and define 16 initial contract defects.
  3. Code-Based Defect Definition: By manually analyzing real-world smart contract code, they identified an additional 4 defects, bringing the total to 20.
  4. Practitioner Validation: An online survey was conducted with 138 respondents from 32 countries to gauge their perception of the identified defects' harmfulness and importance.
  5. Distribution and Impact Analysis: The researchers manually labeled 587 smart contracts to determine the prevalence of each defect and then categorized the impact of these defects into five levels.

Datasets

  • Ethereum StackExchange Posts: 17,128 posts were crawled and analyzed to identify defect patterns.
  • Real-World Smart Contracts: A dataset of 587 smart contracts was manually labeled to identify the presence of the defined defects. This dataset is publicly released.

Key Insights and Ideas

  • Beyond Security: The research highlights that smart contract defects extend far beyond just security vulnerabilities, impacting availability, performance, maintainability, and reusability, all of which are critical for long-term project success.
  • Ubiquity of Defects: The findings reveal that smart contracts are riddled with defects; over 99% of the analyzed contracts contained at least one defect from the "trivial" impact levels (IP4/IP5), suggesting a widespread lack of attention to non-critical aspects like code reuse and maintainability.
  • Practitioner Perception vs. Reality: While practitioners rated most defects highly, there's a disconnect between their perception of importance and the actual impact of some defects (e.g., "Unspecified Compiler Version" and "Missing Interrupter" were perceived as less important but were very common).
  • Impact Levels Matter: The paper introduces a useful framework for understanding the severity of defects, categorizing them into critical, major, and trivial impacts, which can help prioritize fixes.
  • Common Defects: "Unspecified Compiler Version" and "Missing Interrupter" were found to be the most prevalent defects in the dataset.

Key Results

  • 20 Contract Defects Defined: The paper defines 20 distinct contract defects, categorized into five aspects: security, availability, performance, maintainability, and reusability.
  • High Defect Prevalence: 99.82% of the 587 analyzed smart contracts contained at least one defect with an impact level of 4 or 5 (trivial problems like low readability or code reuse difficulty). Only 7.33% contained defects leading to critical unwanted behaviors.
  • Practitioner Validation: The survey of 138 developers indicated that the defined defects are indeed harmful, and their removal would improve contract quality and robustness, with an average importance score of 4.22 out of 5.
  • Impact Classification: Five impact levels were defined, ranging from critical (IP1) to trivial (IP5), with defects like "Unchecked External Calls" and "Reentrancy" falling into higher impact categories.

Limitations and Future Work

  • Keyword Limitations: The initial defect identification relied on keyword filtering of StackExchange posts, which might have missed some defects.
  • Dataset Size: While 587 contracts were analyzed, the authors acknowledge that the dataset size is limited, and the prevalence of certain defects might be underestimated.
  • Manual Labeling: The manual labeling of contracts, while performed by experienced individuals, is still subject to human error and potential misinterpretations.
  • Future Work: The authors suggest developing automated tools for contract defect detection, extending the defect list and dataset as new features are added to Solidity and more posts become available, and further investigating the reasons behind practitioners' perceptions of defect importance. They also propose applying their methodology to other blockchain platforms.

Summary updated

BibTeX
@article{chen2019defining,
  author = {Jiachi Chen and Xin Xia and David Lo and John C. Grundy and Xiapu Luo and Ting Chen},
  title = {{Defining Smart Contract Defects on Ethereum}},
  journal = {IEEE Trans. Software Eng.},
  year = {2019},
  url = {https://openreview.net/forum?id=VUi3bu8wW-e},
}
Figure