# Vulnerability Detection and Classification of Ethereum Smart Contracts Using Deep Learning
## 3 Methodology
### Multi-Label Classification  
In this task, only the ScrawID dataset, which contains 8933 smart contracts, is used, and all these contracts are labeled as containing one or more vulnerabilities. The dataset includes 8 of the vulnerabilities that were explained earlier in Section 2. They are ARTHM, DOS, RENT, TimeM, TimeO, UE, LE, and TX-Origin. Figure 12 shows a sample of the Dataset used. After excluding 190 specific null byte codes from the dataset, the number of bytecodes becomes 8933. As a result, the distribution of vulnerabilities in the database will be changed. The \"ARITHM\" vulnerability frequency becomes 8568, while \"RENT\" is present in 5037 smart contracts. The remaining vulnerability frequencies are 2176, 1673, 1247, 1052, 1033, and 232, respectively, for \"TimeM\", \"LE\", \"DOS\", \"TimeO\", \"UE\" and \"TX-Origin\", as shown in Figure 13.  
Figure 11: KNN Model’s workflow. Figure 12: Sample of Multi-Dataset used. Figure 13: Distribution of the labels after removing the specified bytecodes. As shown in Figure 13, the distribution of classes in the multi-dataset is unbalanced, as there is an apparent disparity in the frequencies of smart contracts within each class. This is why it was necessary to use one of the methods of balancing datasets in deep learning. In this work, we defined a \"balance\" function to balance the dataset by sampling groups of under-represented classes. One sampling strategy used for imbalanced datasets is adding more examples from the minority class (oversampling) [57]. It was done by collecting all the labels in one list to facilitate processing and simplify the balancing process so that each unique set of labels is treated as one class [57]. Then, the maximum number of occurrences of any set of labels is determined, to use this value to determine the target size for oversampling [57]. Based on these occurrences, it replicates the under-represented classes over each set that share the same set of labels. For each set, it samples the tuples (with replacement) until the set size matches the target size. Balancing through resampling strategies ensures that all unique sets of labels are represented equally in the training set, which helps improve the performance and fairness of machine learning models trained on this data [57]. The multi-label classification process was carried out using three different approaches to obtain the best results:  
1. Approach 1: Multi-label classification using all the labels contained in the dataset. This method was carried out by using the eight vulnerabilities: ARTHM, DOS, RENT, TimeM, TimeO, UE, LE, and TX-Origin. 2. Approach 2: Multi-label classification with the deletion of labels with few repetitions. Four of the vulnerabilities 'DOS, TimeO, UE and TX-Origin' were deleted and replaced with one class under the name 'Others'. 3. Approach 3: Multi-label classification with the deletion of low-accuracy labels. Four of the vulnerabilities 'UE, LE, DOS and ARTHM' were deleted and replaced with one class under the name 'Others'. This makes the dataset used in this approach more balanced and, hence, gives better accuracy. Multi-Label Classification with Deep Learning Algorithms Using the Three Different Approaches  
Different algorithms for multi-label classification are applied to RGB and Gray-Scale images resulting from conversion of the dataset. The three approaches described earlier were also applied in each algorithm, to ensure the best results. The same process for preparing the dataset and selecting the hyperparameters is followed as in the case of binary classification, except that we changed the batch size to 64. The dataset was also augmented to improve and generalize the results. In addition, the structure of the model on which the images were trained is the same as in the binary classification shown in Figures 7-11, with the three approaches explained earlier being applied to each algorithm to study the extent of the impact of these structures in the different approaches used.