Nowadays, more and more applications are developed for running on a distributed ledger technology, namely dApps. The business logic of dApps is usually implemented within smart contracts developed through Solidity, a programming language for writing smart contracts on different blockchain platforms, including the popular Ethereum. In Ethereum, the smart contracts run on the machines of miners and the gas corresponds to the execution fee compensating such computing resources. However, the deployment and execution costs of a smart contract depend on the implementation choices done by developers. Unappropriated design choices could lead to higher gas consumption than necessary. In this paper, we (i) identify a set of 19 Solidity code smells affecting the deployment and transaction costs of a smart contract, and (ii) assess the relevance of such smells through a survey involving 34 participants. On top of these smells, we propose GasMet, a suite of metrics for statically evaluating the code quality of a smart contract from the gas consumption perspective. An experiment involving 2,186 smart contracts demonstrates that the proposed metrics have direct associations with deployment costs. The metrics in our suite can be used for more easily identifying source code segments that need optimizations.
翻译:目前,在分布式分类账技术(即dApps)上,开发了越来越多的应用软件,用于使用分布式分类账技术(即dApps)。dApps的商业逻辑通常是在通过Solidiity开发的智能合同中实施,Solidiity是一种用于在不同块链平台(包括受欢迎的Ethereum)上撰写智能合同的编程语言。在Etheum,在矿工机器和天然气上运行的智能合同与补偿这种计算资源的执行费相对应。然而,智能合同的部署和执行费用取决于开发商所作的实施选择。不适当的设计选择可能导致天然气消耗量超过必要。在本文中,我们(一)确定了一套19套Solidiity代码的气味影响智能合同的部署和交易成本,以及(二)通过涉及34名参与者的调查评估这种气味的相关性。除了这些气味外,我们提议从天然气消费角度对智能合同的代码质量进行静态评估的一套指标。涉及2,186个智能合同的实验表明拟议指标与部署成本有直接关联。我们套套装中的指标可用于更方便地确定需要优化的源代码部分。