Journal of Computer Science and Technology ›› 2022, Vol. 37 ›› Issue (1): 67-82.doi: 10.1007/s11390-021-1674-4

Special Issue: Software Systems

• Special Section on Software Systems 2021 • Previous Articles     Next Articles

Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts

Que-Ping Kong1 (孔雀屏), Member, CCF, Zi-Yan Wang1 (王子彦), Member, CCF, Yuan Huang2 (黄袁), Member, CCF, Xiang-Ping Chen3,* (陈湘萍), Member, CCF, IEEE, Xiao-Cong Zhou1 (周晓聪), Member, CCF, Zi-Bin Zheng1 (郑子彬), Senior Member, CCF, ACM, IEEE, and Gang Huang4 (黄罡), Distinguished Member, CCF, Member, ACM, IEEE        

  1. 1School of Computer Science and Engineering, Sun Yat-sen University, Guangzhou 510006, China
    2School of Software Engineering, Sun Yat-sen University, Zhuhai 519082, China
    3Guangdong Key Laboratory for Big Data Analysis and Simulation of Public Opinion, School of Communication and Design, Sun Yat-sen University, Guangzhou 510006, China
    4Peking University Shenzhen Graduate School, Shenzhen 518000, China
  • Received:2021-06-02 Revised:2021-11-01 Accepted:2021-12-03 Online:2022-01-28 Published:2022-01-28
  • Contact: Xiang-Ping Chen E-mail:chenxp8@mail.sysu.edu.cn
  • About author: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.
  • Supported by:
    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.

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.

Key words: smart contract; anti-pattern; detection; optimization; empirical study;

[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.
[1] Peng-Fei Sun, Ya-Wen Ouyang, Ding-Jie Song, and Xin-Yu Dai. Self-Supervised Task Augmentation for Few-Shot Intent Detection [J]. Journal of Computer Science and Technology, 2022, 37(3): 527-538.
[2] Xin Feng, Hao-Ming Wu, Yi-Hao Yin, and Li-Bin Lan. CGTracker: Center Graph Network for One-Stage Multi-Pedestrian-Object Detection and Tracking [J]. Journal of Computer Science and Technology, 2022, 37(3): 626-640.
[3] Yan Tao, Yi-Teng Zhang, and Xue-Jin Chen. Element-Arrangement Context Network for Facade Parsing [J]. Journal of Computer Science and Technology, 2022, 37(3): 652-665.
[4] Jun Ma, Qing-Wei Sun, Chang Xu, and Xian-Ping Tao. GridDroid---An Effective and Efficient Approach for Android Repackaging Detection Based on Runtime Graphical User Interface [J]. Journal of Computer Science and Technology, 2022, 37(1): 147-181.
[5] Ze-Lin Zhao, Di Huang, and Xiao-Xing Ma. TOAST: Automated Testing of Object Transformers in Dynamic Software Updates [J]. Journal of Computer Science and Technology, 2022, 37(1): 50-66.
[6] Gen Zhang, Peng-Fei Wang, Tai Yue, Xu Zhou, Kai Lu. MEBS: Uncovering Memory Life-Cycle Bugs in Operating System Kernels [J]. Journal of Computer Science and Technology, 2021, 36(6): 1248-1268.
[7] Ling-Yun Situ, Zhi-Qiang Zuo, Le Guan, Lin-Zhang Wang, Xuan-Dong Li, Jin Shi, Peng Liu. Vulnerable Region-Aware Greybox Fuzzing [J]. Journal of Computer Science and Technology, 2021, 36(5): 1212-1228.
[8] Yu-Wei Wu, Qing-Gang Wang, Long Zheng, Xiao-Fei Liao, Hai Jin, Wen-Bin Jiang, Ran Zheng, Kan Hu. FDGLib: A Communication Library for Efficient Large-Scale Graph Processing in FPGA-Accelerated Data Centers [J]. Journal of Computer Science and Technology, 2021, 36(5): 1051-1070.
[9] Xiao-Jing Zha, Yin-Shui Xia, Shang-Luan Xie, Zhu-Fei Chu. Defect-Tolerant Mapping of CMOL Circuit Targeting Delay Optimization [J]. Journal of Computer Science and Technology, 2021, 36(5): 1118-1132.
[10] Hui-Ming Tian, Zhu-Fei Chu. Inversion Optimization Strategy Based on Primitives with Complement Attributes [J]. Journal of Computer Science and Technology, 2021, 36(5): 1145-1154.
[11] Dong-Hui Yang, Zhen-Yu Li, Xiao-Hui Wang, Kavé Salamatian, Gao-Gang Xie. Exploiting the Community Structure of Fraudulent Keywords for Fraud Detection in Web Search [J]. Journal of Computer Science and Technology, 2021, 36(5): 1167-1183.
[12] 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.
[13] Wen-Jun Yang, Bei-Ji Zou, Kai-Wen Li, Shu Liu. A Character Flow Framework for Multi-Oriented Scene Text Detection [J]. Journal of Computer Science and Technology, 2021, 36(3): 465-477.
[14] Yu-Jie Yuan, Yukun Lai, Tong Wu, Lin Gao, Li-Gang Liu. A Revisit of Shape Editing Techniques: From the Geometric to the Neural Viewpoint [J]. Journal of Computer Science and Technology, 2021, 36(3): 520-554.
[15] Jun Gao, Paul Liu, Guang-Di Liu, Le Zhang. Robust Needle Localization and Enhancement Algorithm for Ultrasound by Deep Learning and Beam Steering Methods [J]. Journal of Computer Science and Technology, 2021, 36(2): 334-346.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
[1] Zhou Di;. A Recovery Technique for Distributed Communicating Process Systems[J]. , 1986, 1(2): 34 -43 .
[2] Chen Zhaoxiong; Gao Qingshi;. A Substitution Based Model for the Implementation of PROLOG——The Design and Implementation of LPROLOG[J]. , 1986, 1(4): 17 -26 .
[3] Tang Tonggao; Zhao Zhaokeng;. Stack Method in Program Semantics[J]. , 1987, 2(1): 51 -63 .
[4] Bao Feng;. On the Condition for FSM Being a Scrambler[J]. , 1988, 3(1): 70 -74 .
[5] Chen Qiming;. Extending the Object-Oriented Paradigm for Supporting Complex Objects[J]. , 1988, 3(2): 113 -130 .
[6] Fan Zhihua;. Vectorization for Loops with Three-Forked Jumps[J]. , 1988, 3(3): 186 -202 .
[7] Wang Nengbin; Liu Xiaoqing; Liu Guangfu;. A Software Tool for Constructing Traditional Chinese Medical Expert Systems[J]. , 1988, 3(3): 214 -220 .
[8] Hong Jiarong; Carl Uhrik;. The ALFALFA Entomology Pest Identification System[J]. , 1988, 3(4): 251 -262 .
[9] Xue Xing; Sun Zhongxiu; Zhou Jianqiang; Xu Xihao;. A Message-Based Distributed Kernel for a Full Heterogeneous Environment[J]. , 1990, 5(1): 47 -56 .
[10] Xu Jie; Li Qingnan; Huang Shize; Xu Jiangfeng;. DFTSNA:A Distributed Fault-Tolerant Shipboard System[J]. , 1990, 5(2): 109 -116 .

ISSN 1000-9000(Print)

         1860-4749(Online)
CN 11-2296/TP

Home
Editorial Board
Author Guidelines
Subscription
Journal of Computer Science and Technology
Institute of Computing Technology, Chinese Academy of Sciences
P.O. Box 2704, Beijing 100190 P.R. China
Tel.:86-10-62610746
E-mail: jcst@ict.ac.cn
 
  Copyright ©2015 JCST, All Rights Reserved