Abstract
Ethereum blockchain is a new internetware with tens of millions of smart contracts running on it. Different from general programs, smart contracts are decentralized, tamper-resistant and permanently running. Moreover, to avoid resource abuse, Ethereum charges users for deploying and invoking smart contracts according to the size of contract and the operations executed by contracts. It is necessary to optimize smart contracts to save money. However, since developers are not familiar with the operating environment of smart contracts (i.e., Ethereum virtual machine) or do not pay attention to resource consumption during development, there are many optimization opportunities for smart contracts. To fill this gap, this paper defines six gas-inefficient patterns from more than 25 000 posts and proposes an optimization approach at the source code level to let users know clearly where the contract is optimized. To evaluate the prevalence and economic benefits of gas-inefficient patterns, this paper conducts an empirical study on more than 160 000 real smart contracts. The promising experimental results demonstrate that 52.75% of contracts contain at least one gas-inefficient pattern proposed in this paper. If these patterns are removed from the contract, at least $0.30 can be saved per contract.
Similar content being viewed by others
Explore related subjects
Discover the latest articles, news and stories from top researchers in related subjects.References
Zheng Z, Xie S, Dai H N, Chen W, Chen X, Weng J, Imran M. An overview on smart contracts: Challenges, advances and platforms. Future Generation Computer Systems, 2020, 105: 475-491. https://doi.org/10.1016/j.future.2019.12.019.
Zheng P, Zheng Z, Wu J, Dai H N. XBlock-ETH: Extracting and exploring blockchain data from Ethereum. IEEE Open Journal of the Computer Society, 2020, 1: 95-106. https://doi.org/10.1109/OJCS.2020.2990458.
Albert E, Gordillo P, Rubio A, Schett M A. Synthesis of super-optimized smart contracts using Max-SMT. In Proc. the 32nd International Conference on Computer Aided Verification, Jul. 2020, pp.177-200. https://doi.org/10.1007/978-3-030-53288-8_10.
Nagele J, Schett M A. Blockchain superoptimizer. arXiv:2005.05912, 2020. https://arxiv.org/abs/2005.05912, May 2021.
Chen T, Li Z, Zhou H, Chen J, Luo X, Li X, Zhang X. Towards saving money in using smart contracts. In Proc. the 40th IEEE/ACM International Conference on Software Engineering: New Ideas and Emerging Technologies Results, May 27-Jun. 3, 2018, pp.81-84. https://doi.org/10.1145/3183399.3183420.
Chen T, Feng Y, Li Z, Zhou H, Luo X, Li X, Xiao X, Chen J, Zhang X. GasChecker: Scalable analysis for discovering gas-inefficient smart contracts. IEEE Transactions on Emerging Topics in Computing, 2020, 9(3): 1433-1448. https://doi.org/10.1109/TETC.2020.2979019.
Oliva G A, Hassan A E, Jiang Z M. An exploratory study of smart contracts in the Ethereum blockchain platform. Empirical Software Engineering, 2020, 25(3): 1864-1904. https://doi.org/10.1007/s10664-019-09796-5.
Durieux T, Ferreira J F, Abreu R, Cruz P. Empirical review of automated analysis tools on 47,587 Ethereum smart contracts. In Proc. the 42nd IEEE/ACM International Conference on Software Engineering, Oct. 2020, pp.530-541. https://doi.org/10.1145/3377811.3380364.
Chen J, Xia X, Lo D, Grundy J, Luo X, Chen T. Defining smart contract defects on Ethereum. IEEE Transactions on Software Engineering, 2022, 48(1): 327-345. https://doi.org/10.1109/TSE.2020.2989002.
Jiang B, Liu Y, Chan W. ContractFuzzer: Fuzzing smart contracts for vulnerability detection. In Proc. the 33rd IEEE/ACM International Conference on Automated Software Engineering, Sept. 2018, pp.259-269. https://doi.org/10.1145/3238147.3238177.
Grech N, Kong M, Jurisevic A, Brent L, Scholz B, Smaragdakis Y. MadMax: Surviving out-of-gas conditions in Ethereum smart contracts. Proceedings of the ACM on Programming Languages, 2018, 2(OOPSLA): Article No. 116. https://doi.org/10.1145/3276486.
Liu C, Liu H, Cao Z, Chen Z, Chen B, Roscoe B. ReGuard: Finding reentrancy bugs in smart contracts. In Proc. the 40th IEEE/ACM International Conference on Software Engineering: Companion, May 27-June 3, 2018, pp.65-68. https://doi.org/10.1145/3183440.3183495.
Li Z, Wu H, Xu J, Wang X, Zhang L, Chen Z. MuSC: A tool for mutation testing of Ethereum smart contract. In Proc. the 34th IEEE/ACM International Conference on Automated Software Engineering, Nov. 2019, pp.1198-1201. https://doi.org/10.1109/ASE.2019.00136.
Wang X, Wu H, Sun W, Zhao Y. Towards generating cost-effective test-suite for Ethereum smart contract. In Proc. the 26th IEEE International Conference on Software Analysis, Evolution and Reengineering, Feb. 2019, pp.549-553. https://doi.org/10.1109/SANER.2019.8668020.
Grech N, Brent L, Scholz B, Smaragdakis Y. Gigahorse: Thorough, declarative decompilation of smart contracts. In Proc. the 41st IEEE/ACM International Conference on Software Engineering, May 2019, pp.1176-1186. https://doi.org/10.1109/ICSE.2019.00120.
Chen T, Li X, Luo X, Zhang X. Under-optimized smart contracts devour your money. In Proc. the 24th IEEE International Conference on Software Analysis, Evolution and Reengineering, Feb. 2017, pp.442-446. https://doi.org/10.1109/SANER.2017.7884650.
Tikhomirov S, Voskresenskaya E, Ivanitskiy I, Takhaviev R, Marchenko E, Alexandrov Y. SmartCheck: Static analysis of Ethereum smart contracts. In Proc. the 1st International Workshop on Emerging Trends in Software Engineering for Blockchain, May 27-June 3, 2018, pp.9-16. https://doi.org/10.1145/3194113.3194115.
Zhang P, Xiao F, Luo X. SolidityCheck: Quickly detecting smart contract problems through regular expressions. arXiv:1911.09425, 2019. https://arxiv.org/abs/1911.09425, Nov. 2021.
Correas J, Gordillo P, Román-Díez G. Static profiling and optimization of Ethereum smart contracts using resource analysis. IEEE Access, 2021, 9: 25495-25507. https://doi.org/10.1109/ACCESS.2021.3057565.
Li Z, Chen T H, Yang J, Shang W. DLFinder: Characterizing and detecting duplicate logging code smells. In Proc. the 41st IEEE/ACM International Conference on Software Engineering, May 2019, pp.152-163. https://doi.org/10.1109/ICSE.2019.00032.
Vassallo C, Proksch S, Gall H C, Di Penta M. Automated reporting of anti-patterns and decay in continuous integration. In Proc. the 41st IEEE/ACM International Conference on Software Engineering, May 2019, pp.105-115. https://doi.org/10.1109/ICSE.2019.00028.
Afjehei S S, Chen T H, Tsantalis N. iPerfDetector: Characterizing and detecting performance antipatterns in iOS applications. Empirical Software Engineering, 2019, 24(6): 3484-3513. https://doi.org/10.1007/s10664-019-09703-y.
Dintyala P, Narechania A, Arulraj J. SQLCheck: Automated detection and diagnosis of SQL anti-patterns. In Proc. the 2020 ACM SIGMOD International Conference on Management of Data, Jun. 2020, pp.2331-2345. https://doi.org/10.1145/3318464.3389754.
Author information
Authors and Affiliations
Corresponding author
Supplementary Information
ESM 1
(PDF 155 kb)
Rights and permissions
About this article
Cite this article
Kong, QP., Wang, ZY., Huang, Y. et al. Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts. J. Comput. Sci. Technol. 37, 67–82 (2022). https://doi.org/10.1007/s11390-021-1674-4
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11390-021-1674-4