We use cookies to improve your experience with our site.

Indexed in:

SCIE, EI, Scopus, INSPEC, DBLP, CSCD, etc.

Submission System
(Author / Reviewer / Editor)
Que-Ping Kong, Zi-Yan Wang, Yuan Huang, Xiang-Ping Chen, Xiao-Cong Zhou, Zi-Bin Zheng, Gang Huang. Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts[J]. Journal of Computer Science and Technology, 2022, 37(1): 67-82. DOI: 10.1007/s11390-021-1674-4
Citation: Que-Ping Kong, Zi-Yan Wang, Yuan Huang, Xiang-Ping Chen, Xiao-Cong Zhou, Zi-Bin Zheng, Gang Huang. Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts[J]. Journal of Computer Science and Technology, 2022, 37(1): 67-82. DOI: 10.1007/s11390-021-1674-4

Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts

Funds: This work was supported by the Key-Area Research and Development Program of Guangdong Province of China under Grant No.2020B010164002, and the National Natural Science Foundation of China under Grant No.62032025.
More Information
  • Author Bio:

    Xiang-Ping Chen is an associate professor at the Sun Yat-sen University, Guangzhou. She got her Ph.D. degree in computer software and theory from the Peking University, Beijing, in 2010. Her research interests include software engineering and mining software repositories.

  • Corresponding author:

    Xiang-Ping Chen E-mail: chenxp8@mail.sysu.edu.cn

  • Received Date: June 01, 2021
  • Revised Date: October 31, 2021
  • Accepted Date: December 02, 2021
  • Published Date: January 27, 2022
  • 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.
  • [1]
    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. DOI: 10.1016/j.future.2019.12.019.
    [2]
    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. DOI: 10.1109/OJCS.2020.2990458.
    [3]
    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. DOI: 10.1007/978-3-030-53288-8-10.
    [4]
    Nagele J, Schett M A. Blockchain superoptimizer. arXiv:2005.05912, 2020. https://arxiv.org/abs/2005.05912, May 2021.
    [5]
    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. DOI: 10.1145/3183399.3183420.
    [6]
    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. DOI: 10.1109/TETC.2020.2979019.
    [7]
    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. DOI: 10.1007/s10664-019-09796-5.
    [8]
    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. DOI: 10.1145/3377811.3380364.
    [9]
    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. DOI: 10.1109/TSE.2020.2989002.
    [10]
    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. DOI: 10.1145/3238147.3238177.
    [11]
    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. DOI: 10.1145/3276486.
    [12]
    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. DOI: 10.1145/3183440.3183495.
    [13]
    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. DOI: 10.1109/ASE.2019.00136.
    [14]
    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. DOI: 10.1109/SANER.2019.8668020.
    [15]
    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. DOI: 10.1109/ICSE.2019.00120.
    [16]
    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. DOI: 10.1109/SANER.2017.7884650.
    [17]
    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. DOI: 10.1145/3194113.3194115.
    [18]
    Zhang P, Xiao F, Luo X. SolidityCheck: Quickly detecting smart contract problems through regular s. arXiv:1911.09425, 2019. https://arxiv.org/abs/1911.09425, Nov. 2021.
    [19]
    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. DOI: 10.1109/ACCESS.2021.3057565.
    [20]
    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. DOI: 10.1109/ICSE.2019.00032.
    [21]
    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. DOI: 10.1109/ICSE.2019.00028.
    [22]
    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. DOI: 10.1007/s10664-019-09703-y.
    [23]
    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. DOI: 10.1145/3318464.3389754.
  • Related Articles

    [1]Xiang-Jun Liu, Ping Yu, Xiao-Xing Ma. An Empirical Study on Automated Test Generation Tools for Java: Effectiveness and Challenges[J]. Journal of Computer Science and Technology, 2024, 39(3): 715-736. DOI: 10.1007/s11390-023-1935-5
    [2]Wen-Jie Li, Jun Ma, Yan-Yan Jiang, Chang Xu, Xiao-Xing Ma. Understanding and Detecting Inefficient Image Displaying Issues in Android Apps[J]. Journal of Computer Science and Technology, 2024, 39(2): 434-459. DOI: 10.1007/s11390-022-1670-3
    [3]Yi-Xuan Tang, Zhi-Lei Ren, He Jiang, Xiao-Chen Li, Wei-Qiang Kong. An Empirical Comparison Between Tutorials and Crowd Documentation of Application Programming Interface[J]. Journal of Computer Science and Technology, 2021, 36(4): 856-876. DOI: 10.1007/s11390-020-0042-0
    [4]Yong-Hao Wu, Zheng Li, Yong Liu, Xiang Chen. FATOC: Bug Isolation Based Multi-Fault Localization by Using OPTICS Clustering[J]. Journal of Computer Science and Technology, 2020, 35(5): 979-998. DOI: 10.1007/s11390-020-0549-4
    [5]Mohammed Alqmase, Mohammad Alshayeb, Lahouari Ghouti. Threshold Extraction Framework for Software Metrics[J]. Journal of Computer Science and Technology, 2019, 34(5): 1063-1078. DOI: 10.1007/s11390-019-1960-6
    [6]Xiang Chen, Dun Zhang, Zhan-Qi Cui, Qing Gu, Xiao-Lin Ju. DP-Share: Privacy-Preserving Software Defect Prediction Model Sharing Through Differential Privacy[J]. Journal of Computer Science and Technology, 2019, 34(5): 1020-1038. DOI: 10.1007/s11390-019-1958-0
    [7]Xin-Li Yang, David Lo, Xin Xia, Zhi-Yuan Wan, Jian-Ling Sun. What Security Questions Do Developers Ask? A Large-Scale Study of Stack Overflow Posts[J]. Journal of Computer Science and Technology, 2016, 31(5): 910-924. DOI: 10.1007/s11390-016-1672-0
    [8]Thomas Weise, Raymond Chiong, Ke Tang. Evolutionary Optimization: Pitfalls and Booby Traps[J]. Journal of Computer Science and Technology, 2012, 27(5): 907-936. DOI: 10.1007/s11390-012-1274-4
    [9]Giuseppe Lami, Robert W. Ferguson. An Empirical Study on the Impact of Automation on the Requirements Analysis Process[J]. Journal of Computer Science and Technology, 2007, 22(3): 338-347.
    [10]Li Tianzhu. A Study of Optimization and Rule/Goal Graph for a Logical Query[J]. Journal of Computer Science and Technology, 1992, 7(4): 356-362.
  • Others

  • Cited by

    Periodical cited type(17)

    1. Xiangping Chen, Ziang Qian, Peiyong Liao, et al. Characterizing Smart Contract Evolution. ACM Transactions on Software Engineering and Methodology, 2025. DOI:10.1145/3719004
    2. Jinan Jiang, Zihao Li, Haoran Qin, et al. Unearthing Gas-Wasting Code Smells in Smart Contracts With Large Language Models. IEEE Transactions on Software Engineering, 2025, 51(4): 879. DOI:10.1109/TSE.2024.3491578
    3. Elvira Albert, Jesús Correas, Pablo Gordillo, et al. Harnessing heap analysis for the synthesis of superoptimized bytecode. Journal of Systems and Software, 2025, 221: 112284. DOI:10.1016/j.jss.2024.112284
    4. Xiaocong Zhou, Quanqi Wang, Yifan Liu, et al. Are the smart contracts on Q&A site reliable?. Software: Practice and Experience, 2025, 55(1): 29. DOI:10.1002/spe.3361
    5. Yuan Huang, Rong Wang, Xiangping Chen, et al. Ethereum Transaction Replay Platform Based on State-Wise Account Input Data. IEEE Transactions on Services Computing, 2024, 17(5): 2404. DOI:10.1109/TSC.2024.3390433
    6. Xiaohong Shi, Ziyan Wang, Runlu Zhong, et al. GethReplayer: a smart contract testing method based on transaction replay. International Journal of Web Information Systems, 2024, 20(4): 358. DOI:10.1108/IJWIS-08-2023-0138
    7. Elvira Albert, Maria Garcia de la Banda, Alejandro Hernández-Cerezo, et al. SuperStack: Superoptimization of Stack-Bytecode via Greedy, Constraint-Based, and SAT Techniques. Proceedings of the ACM on Programming Languages, 2024, 8(PLDI): 1437. DOI:10.1145/3656435
    8. Manfred Baldauf, Erik Sonnleitner, Marc Kurz. Exemplary Ethereum Development Strategies Regarding Security and Gas-Saving. Electronics, 2023, 13(1): 117. DOI:10.3390/electronics13010117
    9. Chuan Chen, Lei Zhang, Yihao Li, et al. When Digital Economy Meets Web3.0: Applications and Challenges. IEEE Open Journal of the Computer Society, 2022, 3: 233. DOI:10.1109/OJCS.2022.3217565
    10. Yuan Huang, Xiaoyuan Wu, Quanqi Wang, et al. The Sword of Damocles: Upgradeable Smart Contract in Ethereum. Proceedings of the 32nd IEEE/ACM International Conference on Program Comprehension, DOI:10.1145/3643916.3644426
    11. Yunqi Liu, Wei Song. FunRedisp: A Function Redispatch Tool to Reduce Invocation Gas Fees in Solidity Smart Contracts. Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis, DOI:10.1145/3650212.3685312
    12. Jasvinder Kaur, Deepakshi Dabas. New Approaches for Multidimensional Signal Processing. Smart Innovation, Systems and Technologies, DOI:10.1007/978-981-19-7842-5_16
    13. Yuan Huang, Rong Wang, Xiangping Chen, et al. GOV: A Verification Method for Smart Contract Gas-Optimization. 2022 IEEE 22nd International Conference on Software Quality, Reliability and Security (QRS), DOI:10.1109/QRS57517.2022.00055
    14. Xiaolin Liu, Adel Belkhiri, Mónica Jin, et al. ContractViz: Extending Eclipse Trace Compass for Smart Contract Transaction Analysis. 2025 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), DOI:10.1109/SANER64311.2025.00084
    15. Yunqi Liu, Wei Song. FunRedisp: Reordering Function Dispatch in Smart Contract to Reduce Invocation Gas Fees. Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis, DOI:10.1145/3650212.3652146
    16. Chuan Chen, Lei Zhang, Yihao Li, et al. From Blockchain to Web3 & Metaverse. DOI:10.1007/978-981-99-3648-9_6
    17. Soroush Farokhnia, Amir Kafshdar Goharshady. Reducing the Gas Usage of Ethereum Smart Contracts without a Sidechain. 2023 IEEE International Conference on Blockchain and Cryptocurrency (ICBC), DOI:10.1109/ICBC56567.2023.10174876

    Other cited types(0)

Catalog

    Article views (141) PDF downloads (0) Cited by(17)
    Related

    /

    DownLoad:  Full-Size Img  PowerPoint
    Return
    Return