The execution of smart contracts on Ethereum, a public blockchain system, incurs a fee called gas fee for its computation and data-store consumption. When programmers develop smart contracts (e.g., in the Solidity programming language), they could unknowingly write code snippets that unnecessarily cause more gas fees. These issues, or what we call gas wastes, could lead to significant monetary waste for users. Yet, there have been no systematic examination of them or effective tools for detecting them. This paper takes the initiative in helping Ethereum users reduce their gas fees in two important steps: we conduct the first empirical study on gas wastes in popular smart contracts written in Solidity by understanding their root causes and fixing strategies; we then develop a static tool, PeCatch, to effectively detect gas wastes with simple fixes in Solidity programs based on our study findings. Overall, we make seven insights and four suggestions from our gas-waste study, which could foster future tool development, language improvement, and programmer awareness, and develop eight gas-waste checkers, which pinpoint 383 previously unknown gas wastes from famous Solidity libraries.
翻译:在以太坊这一公共区块链系统上执行智能合约会产生计算和数据存储消耗的费用,即Gas费。当程序员开发智能合约(例如使用Solidity编程语言)时,他们可能无意中编写出导致额外Gas费消耗的代码片段。这些问题——我们称之为Gas浪费——可能给用户带来显著的经济损失。然而,目前尚无针对此类问题的系统性研究或有效的检测工具。本文通过两个重要步骤开创性地帮助以太坊用户降低Gas费用:首先,我们通过理解Gas浪费的根本原因和修复策略,对用Solidity编写的热门智能合约中存在的Gas浪费进行了首次实证研究;其次,基于研究结果,我们开发了一个静态工具PeCatch,能够有效检测Solidity程序中可通过简单修复解决的Gas浪费。总体而言,我们从Gas浪费研究中提炼出七项重要发现和四项建议,这有助于推动未来工具开发、语言改进以及程序员意识提升,并开发了八个Gas浪费检测器,从知名Solidity库中精准识别出383个此前未知的Gas浪费案例。