AI Chat Paper
Note: Please note that the following content is generated by AMiner AI. SciOpen does not take any responsibility related to this content.
{{lang === 'zh_CN' ? '文章概述' : 'Summary'}}
{{lang === 'en_US' ? '中' : 'Eng'}}
Chat more with AI
Article Link
Collect
Submit Manuscript
Show Outline
Outline
Show full outline
Hide outline
Outline
Show full outline
Hide outline
Regular Paper

Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts

School of Computer Science and Engineering, Sun Yat-sen University, Guangzhou 510006, China
School of Software Engineering, Sun Yat-sen University, Zhuhai 519082, China
Guangdong Key Laboratory for Big Data Analysis and Simulation of Public Opinion, School of Communication and Design, Sun Yat-sen University Guangzhou 510006, China
Peking University Shenzhen Graduate School, Shenzhen 518000, China
Show Author Information

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 25000 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 160000 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.

Electronic Supplementary Material

Download File(s)
jcst-37-1-67-Highlights.pdf (155.2 KB)

References

[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 expressions. 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.
Journal of Computer Science and Technology
Pages 67-82
Cite this article:
Kong Q-P, Wang Z-Y, Huang Y, et al. Characterizing and Detecting Gas-Inefficient Patterns in Smart Contracts. Journal of Computer Science and Technology, 2022, 37(1): 67-82. https://doi.org/10.1007/s11390-021-1674-4

424

Views

12

Crossref

12

Web of Science

15

Scopus

1

CSCD

Altmetrics

Received: 02 June 2021
Accepted: 03 December 2021
Published: 31 January 2022
©Institute of Computing Technology, Chinese Academy of Sciences 2022
Return