The Gas Burn Identity: Early Detection of Gas-Intensive Functions and Patterns in Smart Contracts
Ermanno Francesco Sannini, Andrea Di Sorbo, Corrado Aaron Visaggio, Gerardo Canfora · 2026
Context: Smart contracts are self-executing digital contracts used to automate and enforce the terms of an agreement running on a blockchain, which provides a transparent and immutable ledger for recording transactions. One major challenge in developing smart contracts is to optimize their gas consumption. However, during the design and implementation phases of a smart contract, developers do not have any reasonable guidelines or tools to predict how the adopted choices may influence execution costs.Objective: This paper aims to help developers claim about gas savings while designing and implementing smart contracts by identifying, before deployment, the code portions to focus their optimization efforts.Method: We propose a machine learning-based approach to automatically identify smart contract functions with high execution costs based on static features available at implementation time. To construct the truth set, we leverage Etherscan and mine the execution costs of functions implemented in real smart contracts running on Ethereum. By inspecting cases where diverging gas consumption occurs for similar code chunks, we also identify six design patterns that directly impact the execution costs of smart contract functions.Results: Experiments on 4,356 functions from 1,769 smart contracts demonstrate that the proposed approach achieves high precision and recall, representing a viable solution to ease the early identification of code blocks requiring optimization. For each identified pattern, we also show that a statistically significant association exists between the occurrence of the design pattern and functions with higher execution costs.Conclusion: While our proposed approach is useful for spotting expensive functions early in the development lifecycle, unveiling gas-intensive design patterns can aid developers during the crucial design phase of smart contracts to make more informed decisions considering execution costs