The Impact of Input Types on Smart Contract Vulnerability Detection Performance Based on Deep Learning: A Preliminary Study
Abstract
:1. Introduction
2. Research Background
2.1. Smart Contract Vulnerabilities
2.2. Types of Input
3. Related Work
4. Methodology: Dataset, Input Preparation, and Classifier Description
4.1. Data Preprocessing
- All Ethereum solidity keywords are gathered, including “bool”, “break”, “return”, “assert”, “event”, etc.
- Eliminate all components of the smart contract that are not related to the vulnerability (such as “pragma solidity 0.5.8”), and eliminates blank lines, comments, and non-ASCII values from the contract.
- Represent variable names as VAR with numbers (such as VAR1, VAR2, …), and function names as FUN with numbers (such as FUN1, FUN2, …).
- Tokenize each smart contract fragment line by line.
- Gather these tokens to create a matrix using the input method.
4.2. Feature Extraction and Classification with CNN
- Convolution Layer 1: We choose to use a one-dimensional convolution layer (Convolution Layer 1). The sizes for Word2Vec, FastText, BoW, and TF-IDF are (300, 100), (300, 100), 37, and 300, respectively.
- MaxPooling 1: Max pooling reduces the spatial dimension of the input data by only preserving the maximum value within each pooling window; hence, it helps in lowering computational complexity and managing overfitting. By offering translation in variance, max pooling lowers the number of parameters in the model and increases its resilience to small changes in the input data.
- Convolution Layer 2: This layer further extracts higher-level features.
- MaxPooling 2: This layer further decreases the dimensions of the feature maps.
- Dropout: This layer facilitates the learning of more robust features during training by arbitrarily setting a portion of the input units to zero. This helps prevent overfitting [27]. By decreasing neuronal co-adaptation and enhancing generalization ability, dropout regularizes the model.
- Flatten: This layer flattens the input into a one-dimensional vector required by dense layers.
- Dense Layer 1: This fully connected layer performs a linear transformation with a rectified linear activation function. From the features that are extracted, it learns complex patterns and representations.
- Dense Layer 2: This fully connected layer performs further recognition of complex patterns in the data.
- Dense Layer 3: This final dense layer computes the probability distributions over the classes by applying the softmax activation function and translates the learned representations to the output classes. The softmax is an activation function typically used for classification. The function turns raw output results into probabilities that reflect the possibility of each class.
4.3. Deep-Learning Library and Parameters
4.4. Smart Contract Dataset
- Re-entrancy: 1224 fragments.
- Timestamp Dependency: 2908 fragments.
- Integer Overflow: 550 fragments.
- Integer Underflow: 4000 fragments.
- CDAV: 2800 fragments.
- Delegate: 980 fragments.
5. Vulnerability Detection Results and Analysis
5.1. Binary Classification
- True Positive (TP): The number of predictions accurately identified as belonging to the positive class.
- True Negative (TN): The number of predictions correctly identified as belonging to the negative class.
- False Positive (FP): The number of predictions wrongly classified as positive.
- False Negative (FN): The number of predictions mistakenly classified as negative.
5.1.1. Word2Vec Performance
5.1.2. FastText Performance
5.1.3. BoW Performance
5.1.4. TF-IDF Performance
5.1.5. Comparing the Impact of the Four Types of Input
5.2. Multiclass Classification
5.3. Comparison with Related Work
6. Limitations of the Current Study
7. Conclusions and Future Work
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Zhao, W. From Traditional Fault Tolerance to Blockchain; John Wiley & Sons: Hoboken, NJ, USA, 2021. [Google Scholar]
- Dhillon, V.; Metcalf, D.; Hooper, M.; Dhillon, V.; Metcalf, D.; Hooper, M. The DAO hacked. In Blockchain Enabled Applications: Understand the Blockchain Ecosystem and How to Make it Work for You; Springer: Berlin/Heidelberg, Germany, 2017; pp. 67–78. [Google Scholar]
- Mehar, M.I.; Shier, C.L.; Giambattista, A.; Gong, E.; Fletcher, G.; Sanayhie, R.; Kim, H.M.; Laskowski, M. Understanding a revolutionary and flawed grand experiment in blockchain: The DAO attack. J. Cases Inf. Technol. (JCIT) 2019, 21, 19–32. [Google Scholar] [CrossRef]
- Devlin, J.; Chang, M.W.; Lee, K.; Toutanova, K. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv 2018, arXiv:1810.04805. [Google Scholar]
- Kushwaha, S.S.; Joshi, S.; Singh, D.; Kaur, M.; Lee, H.N. Systematic review of security vulnerabilities in Ethereum blockchain smart contract. IEEE Access 2022, 10, 6605–6621. [Google Scholar] [CrossRef]
- Mik, E. Smart contracts: Terminology, technical limitations and real world complexity. Law Innov. Technol. 2017, 9, 269–300. [Google Scholar] [CrossRef]
- Liu, C.; Liu, H.; Cao, Z.; Chen, Z.; Chen, B.; Roscoe, B. Reguard: Finding reentrancy bugs in smart contracts. In Proceedings of the 40th International Conference on Software Engineering: Companion Proceeedings, Gothenburg, Sweden, 27 May–3 June 2018; pp. 65–68. [Google Scholar]
- Wöhrer, M.; Zdun, U. Design patterns for smart contracts in the ethereum ecosystem. In Proceedings of the 2018 IEEE International Conference on Internet of Things (iThings) and IEEE Green Computing and Communications (GreenCom) and IEEE Cyber, Physical and Social Computing (CPSCom) and IEEE Smart Data (SmartData), Halifax, NS, Canada, 30 July–3 August 2018; pp. 1513–1520. [Google Scholar]
- Atzei, N.; Bartoletti, M.; Cimoli, T. A survey of attacks on ethereum smart contracts (sok). In Proceedings of the Principles of Security and Trust: 6th International Conference, POST 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, 22–29 April 2017; pp. 164–186. [Google Scholar]
- Gupta, B.C.; Shukla, S.K. A study of inequality in the ethereum smart contract ecosystem. In Proceedings of the 2019 Sixth International Conference on Internet of Things: Systems, Management and Security (IOTSMS), Granada, Spain, 22–25 October 2019; pp. 441–449. [Google Scholar]
- Mikolov, T.; Chen, K.; Corrado, G.; Dean, J. Efficient estimation of word representations in vector space. arXiv 2013, arXiv:1301.3781. [Google Scholar]
- Mnih, A.; Kavukcuoglu, K. Learning word embeddings efficiently with noise-contrastive estimation. Adv. Neural Inf. Process. Syst. 2013, 26. [Google Scholar]
- Le, Q.; Mikolov, T. Distributed representations of sentences and documents. In Proceedings of the International Conference on Machine Learning, PMLR, Beijing, China, 21–26 June 2014; pp. 1188–1196. [Google Scholar]
- Ramos, J. Using tf-idf to determine word relevance in document queries. In Proceedings of the First Instructional Conference on Machine Learning, Citeseer; 2003; Volume 242, pp. 29–480. [Google Scholar]
- Zhao, W. Towards frame-level person identification using Kinect skeleton data with deep learning. In Proceedings of the 2021 IEEE Symposium Series on Computational Intelligence (SSCI), Virtual, 5–7 December 2021; pp. 1–8. [Google Scholar]
- Yu, X.; Zhao, H.; Hou, B.; Ying, Z.; Wu, B. Deescvhunter: A deep learning-based framework for smart contract vulnerability detection. In Proceedings of the 2021 International Joint Conference on Neural Networks (IJCNN), Shenzhen, China, 18–22 July 2021; pp. 1–8. [Google Scholar]
- Zhang, L.; Chen, W.; Wang, W.; Jin, Z.; Zhao, C.; Cai, Z.; Chen, H. CBGRU: A detection method of smart contract vulnerability based on a hybrid model. Sensors 2022, 22, 3577. [Google Scholar] [CrossRef] [PubMed]
- Wu, H.; Zhang, Z.; Wang, S.; Lei, Y.; Lin, B.; Qin, Y.; Zhang, H.; Mao, X. Peculiar: Smart contract vulnerability detection based on crucial data flow graph and pre-training techniques. In Proceedings of the 2021 IEEE 32nd International Symposium on Software Reliability Engineering (ISSRE), Wuhan, China, 25–28 October 2021; pp. 378–389. [Google Scholar]
- Qian, P.; Liu, Z.; He, Q.; Zimmermann, R.; Wang, X. Towards automated reentrancy detection for smart contracts based on sequential models. IEEE Access 2020, 8, 19685–19695. [Google Scholar] [CrossRef]
- Zhuang, Y.; Liu, Z.; Qian, P.; Liu, Q.; Wang, X.; He, Q. Smart contract vulnerability detection using graph neural networks. In Proceedings of the Twenty-Ninth International Conference on International Joint Conferences on Artificial Intelligence, online, 7–15 January 2021; pp. 3283–3290. [Google Scholar]
- Liu, Z.; Qian, P.; Wang, X.; Zhu, L.; He, Q.; Ji, S. Smart contract vulnerability detection: From pure neural network to interpretable graph feature and expert pattern fusion. arXiv 2021, arXiv:2106.09282. [Google Scholar]
- Fan, Y.; Shang, S.; Ding, X. Smart contract vulnerability detection based on dual attention graph convolutional network. In Proceedings of the Collaborative Computing: Networking, Applications and Worksharing: 17th EAI International Conference, CollaborateCom 2021, Virtual Event, 16–18 October 2021; pp. 335–351. [Google Scholar]
- Wu, H.; Dong, H.; He, Y.; Duan, Q. Smart contract vulnerability detection based on hybrid attention mechanism model. Appl. Sci. 2023, 13, 770. [Google Scholar] [CrossRef]
- Zhang, L.; Li, Y.; Jin, T.; Wang, W.; Jin, Z.; Zhao, C.; Cai, Z.; Chen, H. SPCBIG-EC: A robust serial hybrid model for smart contract vulnerability detection. Sensors 2022, 22, 4621. [Google Scholar] [CrossRef] [PubMed]
- Guo, D.; Ren, S.; Lu, S.; Feng, Z.; Tang, D.; Liu, S.; Zhou, L.; Duan, N.; Svyatkovskiy, A.; Fu, S.; et al. Graphcodebert: Pre-training code representations with data flow. arXiv 2020, arXiv:2009.08366. [Google Scholar]
- Hwang, S.J.; Choi, S.H.; Shin, J.; Choi, Y.H. CodeNet: Code-targeted convolutional neural network architecture for smart contract vulnerability detection. IEEE Access 2022, 10, 32595–32607. [Google Scholar] [CrossRef]
- Goodfellow, I.; Bengio, Y.; Courville, A. Deep Learning; MIT Press: Cambridge, MA, USA, 2016. [Google Scholar]
- Abadi, M.; Agarwal, A.; Barham, P.; Brevdo, E.; Chen, Z.; Citro, C.; Corrado, G.S.; Davis, A.; Dean, J.; Devin, M.; et al. Tensorflow: Large-scale machine learning on heterogeneous distributed systems. arXiv 2016, arXiv:1603.04467. [Google Scholar]
- Qiao, S.; Han, N.; Huang, J.; Yue, K.; Mao, R.; Shu, H.; He, Q.; Wu, X. A dynamic convolutional neural network based shared-bike demand forecasting model. ACM Trans. Intell. Syst. Technol. (TIST) 2021, 12, 1–24. [Google Scholar] [CrossRef]
- Durieux, T.; Ferreira, J.F.; Abreu, R.; Cruz, P. Empirical review of automated analysis tools on 47,587 ethereum smart contracts. In Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering, Seoul, Republic of Korea, 27 June–19 July 2020; pp. 530–541. [Google Scholar]
- Durieux, T.; Madeiral, F.; Martinez, M.; Abreu, R. Empirical review of Java program repair tools: A large-scale experiment on 2,141 bugs and 23,551 repair attempts. In Proceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, Tallinn, Estonia, 26–30 August 2019; pp. 302–313. [Google Scholar]
- Chawla, N.V.; Bowyer, K.W.; Hall, L.O.; Kegelmeyer, W.P. SMOTE: Synthetic minority over-sampling technique. J. Artif. Intell. Res. 2002, 16, 321–357. [Google Scholar] [CrossRef]
- Raschka, S.; Mirjalili, V. Python Machine Learning: Machine Learning and Deep Learning with Python, Scikit-Learn, and TensorFlow 2; Packt Publishing Ltd.: Birmingham, UK, 2019. [Google Scholar]
Study | Input Type(s) | Types of Vulnerability Detected |
---|---|---|
DeeSCVHunter [16] | FastText (Word2Vec + Glove) | Re-entrancy and timestamp dependency |
CBGRU [17] | Word2Vec+FastText | Re-entrancy, timestamp dependency, integer overflow/underflow, CDAV, and infinite loop |
Peculiar [18] | Graph | Re-entrancy |
BLSTM-ATT [19] | Sequential | Re-entrancy |
TMP [20] | Graph | Re-entrancy, timestamp dependency, and infinite loop |
AME [21] | Graph | Re-entrancy, timestamp dependency, and infinite loop |
DA-GCN [22] | Graph | Re-entrancy and timestamp dependency |
HAM [23] | Word2Vec | Re-entrancy, timestamp dependency, arithmetic vulnerability, unchecked return value, and Tx.origin |
SPCBIG-EC [24] | Word2Vec | Re-entrancy, timestamp dependency, and infinite loop |
Dataset | Accuracy | Recall | Precision | F1 Score |
---|---|---|---|---|
Delegate | 96.77 | 100.00 | 93.94 | 96.88 |
Integer Overflow | 94.44 | 100.00 | 90.00 | 94.74 |
CDAV | 86.96 | 85.51 | 88.06 | 86.76 |
Integer Underflow | 84.42 | 86.43 | 83.09 | 84.73 |
Re-entrancy | 84.23 | 79.34 | 88.07 | 83.48 |
Timestamp Dependency | 78.20 | 84.78 | 74.92 | 79.55 |
Dataset | Accuracy | Recall | Precision | F1 Score |
---|---|---|---|---|
Delegate | 100.00 | 100.00 | 100.00 | 100.00 |
Integer Overflow | 91.67 | 100.00 | 85.71 | 92.31 |
CDAV | 86.78 | 84.42 | 88.59 | 86.46 |
Integer Underflow | 85.43 | 87.94 | 83.73 | 85.78 |
Re-entrancy | 85.06 | 83.33 | 86.21 | 84.75 |
Timestamp Dependency | 77.16 | 84.78 | 73.57 | 78.78 |
Dataset | Accuracy | Recall | Precision | F1 Score |
---|---|---|---|---|
Delegate | 99.19 | 100.00 | 98.41 | 99.20 |
Integer Overflow | 86.11 | 97.22 | 79.55 | 87.50 |
Re-entrancy | 78.84 | 75.21 | 81.25 | 78.11 |
CDAV | 76.81 | 82.97 | 73.87 | 78.16 |
Timestamp Dependency | 76.47 | 83.04 | 73.39 | 77.92 |
Integer Underflow | 74.37 | 73.12 | 75.00 | 74.05 |
Dataset | Accuracy | Recall | Precision | F1 Score |
---|---|---|---|---|
Delegate | 99.19 | 100.00 | 98.41 | 99.20 |
Re-entrancy | 95.85 | 96.69 | 95.12 | 95.90 |
Integer Underflow | 95.23 | 95.98 | 94.55 | 95.26 |
CDAV | 95.11 | 96.01 | 94.31 | 95.15 |
Integer Overflow | 94.44 | 100.00 | 90.00 | 94.74 |
Timestamp Dependency | 85.29 | 85.81 | 84.93 | 85.37 |
Study | Input | R | T | D | C | IO | IU |
---|---|---|---|---|---|---|---|
DeeSCVHunter [16] | FastText (+W+G) | 86.87 | 79.93 | ||||
CBGRU [17] | Word2Vec+FastText | 90.92 | 93.29 | 90.21 | 86.43 | 85.28 | |
Peculiar [18] | Graph | 92.40 | |||||
AME [21] | Graph | 87.94 | 84.10 | ||||
BLSTM-ATT [19] | Sequential | 89.81 | |||||
TMP [20] | Graph | 78.11 | 79.19 | ||||
DA-GCN [22] | Graph | 85.43 | 84.83 | ||||
SPCBIG-EC [24] | Word2Vec | 96.74 | 91.62 | ||||
HAM [23] | Word2Vec | 94.04 | 87.85 | ||||
This Study | TF-IDF | 95.90 | 85.37 | 99.20 | 95.15 | 94.74 | 95.90 |
Word2Vec | 83.48 | 79.55 | 96.77 | 86.76 | 94.74 | 84.73 | |
FastText | 84.75 | 78.78 | 100.00 | 86.46 | 92.31 | 85.78 | |
BoW | 78.11 | 74.05 | 99.20 | 78.16 | 87.50 | 74.05 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Aldyaflah, I.M.; Zhao, W.; Yang, S.; Luo, X. The Impact of Input Types on Smart Contract Vulnerability Detection Performance Based on Deep Learning: A Preliminary Study. Information 2024, 15, 302. https://doi.org/10.3390/info15060302
Aldyaflah IM, Zhao W, Yang S, Luo X. The Impact of Input Types on Smart Contract Vulnerability Detection Performance Based on Deep Learning: A Preliminary Study. Information. 2024; 15(6):302. https://doi.org/10.3390/info15060302
Chicago/Turabian StyleAldyaflah, Izdehar M., Wenbing Zhao, Shunkun Yang, and Xiong Luo. 2024. "The Impact of Input Types on Smart Contract Vulnerability Detection Performance Based on Deep Learning: A Preliminary Study" Information 15, no. 6: 302. https://doi.org/10.3390/info15060302
APA StyleAldyaflah, I. M., Zhao, W., Yang, S., & Luo, X. (2024). The Impact of Input Types on Smart Contract Vulnerability Detection Performance Based on Deep Learning: A Preliminary Study. Information, 15(6), 302. https://doi.org/10.3390/info15060302