Abstract
Ethereum is a blockchain network that allows developers to create smart contracts and programs that run on the blockchain. Smart contracts contain logic to transfer assets based on pre-defined conditions. With over 100,000 new smart contracts being deployed every day, the potential for coding errors is high, making the contracts vulnerable to exploits. A key limitation is that once deployed, smart contracts are immutable and cannot be updated, even if flaws are found. This inflexibility puts funds at risk of theft and loss. The rapid pace of deployment outpaces security audits, increasing vulnerabilities that put users’ cryptocurrency at risk. To reduce the risk caused by smart contract vulnerabilities, we applied deep learning techniques. To develop a deep learning model capable of detecting vulnerabilities, we first created a dataset by replaying real transactions on the Ethereum Mainnet, collecting opcode sequences from real Ethereum contracts, and labeling them using the SODA plugin. We pre-processed this opcode data by removing duplicates, normalizing sequence lengths, simplifying opcodes into representative groups, and converting sequences into numerical vectors to ultimately obtain an optimal representation of the data. We then trained and evaluated three different neural network architectures on this dataset. Our best-performing model achieved an average accuracy of 88% in detecting seven types of vulnerabilities. Further analysis showed that the model was effective at identifying potential problems in smart contracts, which was an important capability for securing funds and executing logic in live contracts.
Similar content being viewed by others
Data availibility
The datasets generated or analyzed during this study are available from the corresponding author on reasonable request.
References
Zhang S, Wang G, Bhuiyan MZA, Liu Q (2018) A dual privacy preserving scheme in continuous location-based services. IEEE Internet Things J 5(5):4191–4200
Peng T, Zhong W, Wang G, Zhang S, Luo E, Wang T (2023) Spatiotemporal-aware privacy-preserving task matching in mobile crowdsensing. IEEE Internet Things J
Zhang S, Choo K-KR, Liu Q, Wang G (2018) Enhancing privacy through uniform grid and caching in location-based services. Futur Gener Comput Syst 86:881–892
Nakamoto S, Bitcoin A (2008) A peer-to-peer electronic cash system 4(2):15. Bitcoin. https://bitcoin.org/bitcoin.pdf
Szabo N (1996) Smart contracts: building blocks for digital markets. EXTROPY: The Journal of Transhumanist Thought(16) 18(2):28
Suvitha M, Subha R (2021) A survey on smart contract platforms and features. In 2021 7th International Conference on Advanced Computing and Communication Systems (ICACCS), vol.1. IEEE, pp 1536–1539
Buterin V etal (2014) A next-generation smart contract and decentralized application platform, white paper 3(37):1–2
Zhang S, Mao X, Choo K-KR, Peng T, Wang G (2020) A trajectory privacy-preserving scheme based on a dual-k mechanism for continuous location-based services. Inform Sci 527:406–419
Liu Q, Hou P, Wang G, Peng T, Zhang S (2019) Intelligent route planning on large road networks with efficiency and privacy. J Parallel Distrib Comput 133:93–106
Zhang S, Wang Y, Luo E, Liu Q, Gu K, Wang G (2023) A traceable and revocable decentralized multi-authority privacy protection scheme for social metaverse. J Syst Archit 140:102899
Yaga D, Mell P, Roby N, Scarfone K (2019) Blockchain technology overview, arXiv preprint arXiv:1906.11078
Sapna, Prashar D (2021) Analysis on blockchain vulnerabilities & attacks on wallet. In 2021 3rd International Conference on Advances in Computing, Communication Control and Networking, pp 1515–1521
Lu N, Wang B, Zhang Y, Shi W, Esposito C (2021) Neucheck: A more practical ethereum smart contract security analysis tool. Softw Prac Exp 51(10):2065–2084
Sun J, Huang S, Zheng C, Wang T, Zong C, Hui Z (2022) Mutation testing for integer overflow in ethereum smart contracts. Tsinghua Sci Technol 27(1):27–40
Lu J, Wu S, Cheng H, Song B, Xiang Z (2021) Smart contract for electricity transactions and charge settlements using blockchain. Appl Stoch Model Bus Ind 37(3):442–453
Permenev A, Dimitrov D, Tsankov P, Drachsler-Cohen D, Vechev M (2020) Verx: Safety verification of smart contracts. In 2020 IEEE symposium on security and privacy (SP). IEEE, pp 1661–1677
Brent L, Jurisevic A, Kong M, Liu E, Gauthier F, Gramoli V, Holz R, Scholz B (2018) Vandal: A scalable security analysis framework for smart contracts. arXiv preprint arXiv:1809.03981
Nikolic I, Kolluri A, Sergey I, Saxena P, Hobor A (2018) Finding the greedy, prodigal, and suicidal contracts at scale. In Proceedings of the 34th Annual Computer Security Applications Conference, pp 653–663
Lai E, Luo W (2020) Static analysis of integer overflow of smart contracts in ethereum. In Proceedings of the 2020 4th International Conference on Cryptography, Security and Privacy, p 110–115
Chen X, Hao Z, Li L, Cui L, Zhu Y, Ding Z, Liu Y (2022) Cruparamer: Learning on parameter-augmented api sequences for malware detection. IEEE Trans Inf Forensics Secur 17:788–803
Ivanov N, Li C, Yan Q, Sun Z, Cao Z, Luo X (2023) Security threat mitigation for smart contracts: A comprehensive survey. ACM Comput Surv
Xu Z, Li C, Han H, Dong X, Zheng Z, Wang H, Zhang J, Chen X, Kochan O (2023) W2V-SA: A deep neural network-based approach to smart contract vulnerability detection. In Proceedings of the 7th International Conference on Computational Linguistics and Intelligent Systems, pp 249–262
Qian P, Liu Z, He Q, Zimmermann R, Wang X (2020) Towards automated reentrancy detection for smart contracts based on sequential models. IEEE Access 8:19685–19695
Kalra S, Goel S, Dhawan M, Sharma S (2018) ZEUS: analyzing safety of smart contracts. In 25th Annual Network and Distributed System Security Symposium, pp 18–21
Brent L, Grech N, Lagouvardos S, Scholz B, Smaragdakis Y (2020) Ethainter: A smart contract security analyzer for composite vulnerabilities. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation, p 454–469
Tikhomirov S, Voskresenskaya E, Ivanitskiy I, Takhaviev R, Marchenko E, Alexandrov Y (2018) Smartcheck: Static analysis of ethereum smart contracts. In 1st IEEE/ACM International Workshop on Emerging Trends in Software Engineering for Blockchain, pp 9–16
Momeni P, Wang Y, Samavi R (2019) Machine learning model for smart contracts security analysis. In 2019 17th International Conference on Privacy, Security and Trust (PST), pp 1–6
Xu Y, Hu G, You L, Cao C (2021) A novel machine learning-based analysis model for smart contract vulnerability. Secur Commun Netw 2021:1–12
Liao J, Tsai T, He C, Tien C (2019) Soliaudit: Smart contract vulnerability assessment based on machine learning and fuzz testing, in 2019 Sixth International Conference on Internet of Things: Systems, Management and Security (IOTSMS). IEEE, pp 458–465
Su L, Shen X, Du X, Liao X, Wang X, Xing L, Liu B (2021) Evil under the sun: Understanding and discovering attacks on ethereum decentralized applications, in 30th USENIX Security Symposium, pp 1307–1324
Chen T, Li Z, Zhu Y, Chen J, Luo X, Lui JC, Lin X, Zhang X (2020) Understanding ethereum via graph analysis. ACM Trans Internet Technol 20(2):181–1832
Jiang B, Liu Y, Chan WK (2018) Contractfuzzer: fuzzing smart contracts for vulnerability detection. In Proceedings of the 33rd ACM/IEEE International Conference on Automated Software Engineering, pp 259–269
Ji S, Wu J, Qiu J, Dong J (2023) Effuzz: Efficient fuzzing by directed search for smart contracts. Inf Softw Technol 159:107213
Tsankov P, Dan AM, Drachsler-Cohen D, Gervais A, Bünzli F, Vechev MT (2018) Securify: Practical security analysis of smart contracts. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security, pp 67–82
Li X, Xing X, Wang G, Li P, Liu X (2022) Detecting unknown vulnerabilities in smart contracts with binary classification model using machine learning. In Inernational Conference on Ubiquitous Security, pp 179–192
Sun T, Yu W (2020) A formal verification framework for security issues of blockchain smart contracts. Electronics 9(2):255
Garfatta I,Klai K,Gaaloul W, Graiet M (2021) A survey on formal verification for solidity smart contracts. In Proceedings of the 2021 Australasian Computer Science Week Multiconference, pp 1–10
Han N, Li X, Wang G, Shi Z, Guan Y (2020) Formal verification of atomicity requirements for smart contracts. In Programming Languages and Systems - 18th Asian Symposium, pp 44–64
Park D, Zhang Y, Rosu G (2020) End-to-end formal verification of ethereum 2.0 deposit smart contract. In Computer Aided Verification - 32nd International Conference, pp. 151–164
Yang Z, Lei H, Qian W (2020) A hybrid formal verification system in coq for ensuring the reliability and security of ethereum-based service smart contracts. IEEE Access 8:21411–21436
Bai X, Cheng Z, Duan Z, Hu K (2018) Formal modeling and verification of smart contracts. In Proceedings of the 2018 7th international conference on software and computer applications, pp 322–326
Amani S, Bégel M, Bortin M, Staples M (2018) Towards verifying ethereum smart contract bytecode in isabelle/hol. In Proceedings of the 7th ACM SIGPLAN international conference on certified programs and proofs, pp 66–77
Duan Y, Zhao X, Pan Y, Li S, Li M, Xu F, Zhang M (2022) Towards automated safety vetting of smart contracts in decentralized applications, in Proceedings of the 2022 ACM SIGSAC Conference on Computer and Communications Security, pp 921–935
Zhu J, Xing X, Wang G, Li P (2023) Opcode sequences-based smart contract vulnerabilities detection using deep learning. In accepted by the 22nd IEEE International Conference on Trust, Security and Privacy in Computing and Communications (TrustCom 2023)
Torres CF, Iannillo AK, Gervais A, State R (2021) The eye of horus: Spotting and analyzing attacks on ethereum smart contracts. In Financial Cryptography and Data Security - 25th International Conference, pp 33–52
Chen J, Xia X, Lo D, Grundy J, Luo X, Chen T (2022) Defectchecker: Automated smart contract defect detection by analyzing EVM bytecode. IEEE Trans Softw Eng 48(7):2189–2207
Qian P, He J, Lu L, Wu S, Lu Z, Wu L, Zhou Y, He Q (2023) Demystifying random number in ethereum smart contract: Taxonomy, vulnerability identification, and attack detection. IEEE Trans Softw Eng 49(7):3793–3810
Liao Z, Song S, Zhu H, Luo X, He Z, Jiang R, Chen T, Chen J, Zhang T, Zhang X (2023) Large-scale empirical study of inline assembly on 7.6 million ethereum smart contracts. IEEE Trans Softw Eng 49(2):777–801
Kina-Kina KM, Cutipa-Arias HE, Shiguihara-Juárez P (2019) A comparison of performance between fully and partially decentralized applications. In 2019 IEEE XXVI International Conference on Electronics, Electrical Engineering and Computing (INTERCON), pp 1–4
Zhang M, Zhang X, Zhang Y, Lin Z (2020) TXSPECTOR: uncovering attacks in ethereum from transactions, in 29th USENIX Security Symposium, pp 2775–2792
Ivanov N, Yan Q, Kompalli A (2023) Txt: Real-time transaction encapsulation for ethereum smart contracts. IEEE Trans Inf Forensics Secur 18:1141–1155
Wang G, Li P, Li X, Xing X, Peng T, Chen S, Liu X (2022) Generating opcode sequences by replaying ethereum transaction data. China Patent Application, Application Number: 202211531992.1
Wood G (2024) Ethereum: A secure decentralised generalised transaction ledger paris version. https://ethereum.github.io/yellowpaper/paper.pdf. Accessed: March 2024
Hochreiter S, Schmidhuber J (1997) Long short-term memory. Neural Comput 9(8):1735–1780
Wang Z, Zhou C, Liu Y, Huang K, Yang C (2023) Cluster-based industrial kpis forecasting considering the periodicity and holiday effect using LSTM network and MSVR. Adv Eng Inform 56:101916
Chen T, Cao R, Li T, Luo X, Gu G, Zhang Y, Liao Z, Zhu H, Chen G, He Z, Tang Y, Lin X, Zhang X (2020) SODA: A generic online detection framework for smart contracts. In 27th Annual Network and Distributed System Security Symposium, pp 1–17
Graves A, Mohamed A-R, Hinton G (2013) Speech recognition with deep recurrent neural networks. In 2013 IEEE international conference on acoustics, speech and signal processing, pp 6645–6649
Tatsunami Y, Taki M (2022) Sequencer: Deep lstm for image classification. Adv Neural Inform Process Syst 35:38204–38217
Ren M, Yin Z, Ma F, Xu Z, Jiang Y, Sun C, Li H, Cai Y (2021) Empirical evaluation of smart contract testing: What is the best choice? In Proceedings of the 30th ACM SIGSOFT International Symposium on Software Testing and Analysis, pp 566–579
Feist J, Grieco G, Groce A (2019) Slither: a static analysis framework for smart contracts. In 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB). IEEE, pp 8–15
Mueller B (2017) A framework for bug hunting on the ethereum blockchain. ConsenSys/mythril
Luu L, Chu D-H, Olickel H, Saxena P, Hobor A (2016) Making smart contracts smarter. In Proceedings of the 2016 ACM SIGSAC conference on computer and communications security, pp 254–269
Funding
This work was supported in part by the National Natural Science Foundation of China under Grant 62372121, and in part by the National Key Research and Development Program of China (2020YFB1005804).
Author information
Authors and Affiliations
Contributions
Peiqiang Li: Conceptualization, Methodology, Software, Investigation, Formal Analysis, Writing; Guojun Wang: Conceptualization, Funding Acquisition, Resources, Supervision, Review; Xiaofei Xing: Supervision, Review; Jinyao Zhu: Conceptualization, Methodology, Review & Editing; Wanyi Gu: Visualization, Investigation; Guangxin Zhai: Visualization, Investigation.
Corresponding author
Ethics declarations
Ethics approval
Not applicable.
Consent to publish
All authors have read and understood the publishing policy, and agree to submit this manuscript in accordance with this policy.
Conflict of interest
We declare that we have no financial and personal relationships with other people or organizations that can inappropriately influence our work, and there is no professional or other personal interest of any nature or kind in any product, service, or company that could be construed as influencing the position presented in, or the review of, the manuscript entitled.
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.
About this article
Cite this article
Li, P., Wang, G., Xing, X. et al. A smart contract vulnerability detection method based on deep learning with opcode sequences. Peer-to-Peer Netw. Appl. 17, 3222–3238 (2024). https://doi.org/10.1007/s12083-024-01750-7
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s12083-024-01750-7