Unearthing Gas-Wasting Code Smells in Smart Contracts with Large Language Models

  • Jinan Jiang
  • , Zihao Li
  • , Haoran Qin
  • , Muhui Jiang
  • , Xiapu Luo
  • , Xiaoming Wu
  • , Haoyu Wang
  • , Yutian Tang
  • , Chenxiong Qian
  • , Ting Chen

Research output: Journal article publicationJournal articleAcademic researchpeer-review

Abstract

Smart contracts are automated programs stored on a blockchain, featuring unique attributes such as permissionlessness, trustlessness, immutability, and transparency. These properties underpin an array of unprecedented decentralized services. Compiled into bytecodes, Ethereum smart contracts are executed within the Ethereum Virtual Machine (EVM). Ethereum's distinct gas mechanism assigns a price to each bytecode execution, incentivizing resource-efficient computing. However, a disconnect exists between conventional coding practices and the less intuitive gas consumption computation mechanism, resulting in inadvertent gas wastage. Gas-wasting code smells at the source code level have been studied in various related works; however, the task of manually identifying such code smells by reading through codes and reasoning about them is both time-consuming and economically inefficient. In this work, we propose to leverage Large Language Models (LLMs), which have seen a surge in popularity recently, to facilitate undertaking the labor-intensive part of the code-smell-finding pipeline. In particular, we focus on Solidity, the predominant programming language for Ethereum smart contracts. Overall, we identified 26 gas-wasting code smells, out of which 13 were not presented in previous papers. On average, applying these code smells led to a reduction of approximately 10.534% in deployment costs and 21.528% in message call costs across our test codes. We further make a report on each of the identified code smells with associated example contracts sourced from either previous literature or recently deployed contracts.
Original languageEnglish
Pages (from-to)879 - 903
Number of pages25
JournalIEEE Transactions on Software Engineering
Volume51
Issue number4
Publication statusPublished - Apr 2025

Keywords

  • Artificial Intelligence
  • language models
  • patterns
  • program analysis
  • smart contracts

ASJC Scopus subject areas

  • Software

Fingerprint

Dive into the research topics of 'Unearthing Gas-Wasting Code Smells in Smart Contracts with Large Language Models'. Together they form a unique fingerprint.

Cite this