The Gas Burn Identity: Early Detection of Gas-Intensive Functions and Patterns in Smart Contracts
In the Ethereum blockchain, gas refers to the transaction fee required to execute operations on the network, and one major challenge in developing smart contracts is to optimize their gas consumption. Due to the immutability of blockchain, applying such optimizations before smart contract deployment is highly beneficial. To assist developers in identifying gas-intensive code sections before deployment, this paper first proposes a machine learning-based approach using static features to automatically detect smart contract functions with high execution costs. To construct the truth set, we leverage Etherscan and mine the execution costs of functions implemented in a collection of real smart contracts running on the Ethereum blockchain. Experiments on 4,356 functions from 1,769 different smart contracts show that the method achieves high precision and recall, making it a viable solution for pinpointing code blocks that need optimization during development. Additionally, by inspecting cases where similar smart contract functions exhibit divergent gas consumption, we identify six architectural design patterns that are statistically linked to higher gas usage. These patterns provide concrete, actionable hotspots for developers.