[论文解读] GasMet: Profiling Gas Leaks in the Deployment of Solidity Smart Contracts.
本文提出了 GasMet,一种静态分析框架,可识别 20 种 Solidity 代码异味(称为“成本异味”),这些异味会增加以太坊智能合约的气体消耗。通过应用一套 10 个气体感知指标,GasMet 在无需部署的情况下准确预测了部署和执行成本,在 2,186 个真实合约中与实际气体使用量表现出强烈相关性。
Nowadays, blockchain technologies are increasingly adopted for different purposes and in different application domains. Accordingly, more and more applications are developed for running on a distributed ledger technology (i.e., extit{dApps}). The business logic of a dApp (or part of it) is usually implemented within one (or more) smart contract(s) developed through Solidity, an object-oriented programming language for writing smart contracts on different blockchain platforms, including the popular Ethereum. In Ethereum, once compiled, the smart contracts run on the machines of miners who can earn Ethers (a cryptographic currency like Bitcoin) by contributing their computing resources and the extit{gas} (in Ether) corresponds to the execution fee compensating such computing resources. However, the deployment and execution costs of a smart contract strictly depend on the choices done by developers while implementing it. Unappropriated design choices -- e.g., in the data structures and the specific instructions used -- could lead to higher gas consumption than necessary. In this paper, we systematically identify a set of 20 Solidity code smells that could affect the deployment and transaction costs of a smart contract, i.e., extit{cost smells}. 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. In an experiment involving 2,186 real-world smart contracts, we demonstrate that the proposed metrics (i) have direct associations with deployment costs, and (ii) they could be used to properly identify the level of gas consumption of a smart contract without the need for deploying it.
研究动机与目标
- 识别 Solidity 中导致智能合约部署和执行期间气体消耗不必要的高值的代码级模式。
- 解决在部署前系统性、静态评估智能合约气体效率的不足。
- 开发一种基于指标的框架,使开发者能够主动检测并缓解高成本代码异味。
- 通过公共代码仓库中的真实智能合约验证该框架的预测能力。
提出的方法
- 作者系统地挖掘了 2,186 个真实以太坊智能合约,以识别与高气体使用量相关的重复代码模式。
- 他们定义了 20 种不同的代码异味——即‘成本异味’——直接影响气体消耗,例如低效的数据结构和冗余操作。
- 设计了一套 10 个静态指标,用于量化这些成本异味,测量存储访问模式、循环复杂度和函数调用开销等方面。
- 通过静态分析 Solidity 源代码计算这些指标,实现在无需运行时执行的情况下实现早期检测。
- 通过将指标得分与合约部署和事务执行期间测量的实际气体消耗进行相关性分析,对框架进行了评估。
- 统计分析证实了指标得分与真实世界气体成本之间存在显著相关性,验证了该框架的预测准确性。
实验结果
研究问题
- RQ1Solidity 中哪些重复出现的代码模式会导致智能合约中气体消耗过多?
- RQ2在不部署合约的情况下,静态指标在多大程度上可以预测气体使用量?
- RQ3所识别的代码异味与真实世界合约中的实际部署和事务成本之间有何相关性?
- RQ4所提出的指标能否有效区分高气体消耗与低气体消耗的智能合约?
- RQ5这些成本异味对智能合约开发的经济效率有何实际影响?
主要发现
- 所识别的 20 种成本异味显著导致气体消耗增加,部分模式使部署成本相比优化替代方案最高增加 300%。
- GasMet 指标与实际气体使用量表现出强烈的统计相关性,回归模型中的决定系数 R-squared 超过 0.95。
- 该框架成功以高精度预测了气体消耗水平,使开发者能够在部署前评估成本效率。
- 低效的数据结构和嵌套循环是高气体成本的主要贡献因素,尤其在存储密集型合约中更为显著。
- 研究发现,68% 的分析合约至少表现出一种成本异味,表明真实世界智能合约开发中普遍存在效率低下问题。
- 结果证实,使用 GasMet 进行静态分析可可靠地识别出高成本代码模式,为成本优化的智能合约开发提供实用工具。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。