Next Article in Journal
Synthetic Aperture Radar Image Despeckling Based on a Deep Learning Network Employing Frequency Domain Decomposition
Previous Article in Journal
GPT-Driven Source-to-Source Transformation for Generating Compilable Parallel CUDA Code for Nussinov’s Algorithm
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Smart Contract Vulnerability Detection Based on Multi-Scale Encoders

School of Computer Science and Engineering, Xi’an Technological University, Xi’an 710021, China
*
Author to whom correspondence should be addressed.
Electronics 2024, 13(3), 489; https://doi.org/10.3390/electronics13030489
Submission received: 29 December 2023 / Revised: 18 January 2024 / Accepted: 22 January 2024 / Published: 24 January 2024

Abstract

:
Vulnerabilities in smart contracts may trigger serious security events, and the detection of smart contract vulnerabilities has become a significant problem. In this paper, to solve the limitations of current deep learning-based vulnerability detection methods in extracting various code critical features, using the multi-scale cascade encoder architecture as the backbone, we propose a novel Multi-Scale Encoder Vulnerability Detection (MEVD) approach to hit well-known high-risk vulnerabilities in smart contracts. Firstly, we use the gating mechanism to design a unique Surface Feature Encoder (SFE) to enrich the semantic information of code features. Then, by combining a Base Transformer Encoder (BTE) and a Detail CNN Encoder (DCE), we introduce a dual-branch encoder to capture the global structure and local detail features of the smart contract code, respectively. Finally, to focus the model’s attention on vulnerability-related characteristics, we employ the Deep Residual Shrinkage Network (DRSN). Experimental results on three types of high-risk vulnerability datasets demonstrate performance compared to state-of-the-art methods, and our method achieves an average detection accuracy of 90%.

1. Introduction

Blockchain is a distributed ledger that records the financial transactions that take place within decentralized networks [1]. With the emergence of Ethereum smart contracts, blockchain has entered the era of programmable finance [2]. In recent years, blockchain technology has surpassed its original scope in finance and achieved success in a variety of industries and sectors. For instance, within the energy sector, blockchain is transforming conventional approaches to energy management and distribution [3]. In the field of agriculture, blockchain technology offers novel solutions for ensuring data integrity and traceability in supply chains, thereby enhancing food safety and traceability of agricultural products [4]. In healthcare, it is contributing to better patient care and efficient medical record management by securely storing and sharing patient data [5]. Furthermore, in the field of e-government, blockchain serves as a means to improve the transparency and efficiency of public services, which leads to a more effective and secure management of these services [6]. The success of blockchain technology is closely linked to smart contracts, which were initially proposed for the dissemination, validation, and enforcement of contracts in an informational manner [7]. Compared to traditional contracts, smart contracts enabled users to codify their agreements and trust relations by providing automated transactions without the supervision of a central authority [8].
With the widespread application of smart contracts in finance, industry, commerce, and other fields, the security of smart contracts is becoming increasingly important [9]. If there are vulnerabilities in the smart contract, attackers can exploit these smart contract vulnerabilities to maliciously penetrate blockchain networks and steal tens of millions of dollars in cryptocurrency. This not only has implications for the reliability of the blockchain system, but also serious for the interests of smart contract holders. There is a typical event that an attacker exploited a reentrancy vulnerability to successfully abscond with millions of Ether called the DAO attack [10]. This event seriously undermined the credibility of the blockchain system. Events based on smart contract vulnerability attacks are still occurring continuously [11]. Undoubtedly, these attacks highlight the urgent need for smart contract vulnerability detection. By detecting potential vulnerabilities in a smart contract, the security and stability of the blockchain system can be effectively improved [12]. Therefore, how to design efficient vulnerability detection models is an important problem and challenge that needs to be solved.
Traditional methods to detect vulnerabilities in smart contracts suffer from the problem of path explosion, which leads to a large increase in the execution time and memory overhead. Moreover, these methods cannot effectively parse complex data structures of program, which may result in higher false positive and false negative rates. In recent years, researchers have used deep learning techniques to improve the accuracy of detecting vulnerabilities in smart contracts [13]. By segmenting the source code slice of smart contracts into code snippets and using the BLSTM model, Qian et al. designed ReChecker to detect reentrancy vulnerabilities [14]. However, the defined slice criteria are not comprehensive, and the generated code snippets may implicitly ignore critical segments. In addition, for longer code snippets, BLSTM may not efficiently capture global semantic information [15], and bring about high false positives. Based on Convolutional Neural Network (CNN) and Bidirectional Gated Recurrent Unit (BiGRU) network models, Zhang et al. devised a CBGRU hybrid deep learning model to detect vulnerabilities [16]. However, due to CNN’s inability to fully extract local syntax and semantic detail features and BiGRU’s limited perception of global structural features, the detection results can lead to false negatives. To detect reentrancy vulnerabilities, Wu et al. proposed a peculiar approach for extracting critical data flow graphs from the smart contract code [17]. However, this method cannot detect other types of vulnerabilities and has a lack of generality.
To overcome the above shortcomings, we proposed a novel Multi-Scale Encoder Vulnerability Detection (MEVD) approach. Firstly, due to excessive semantic information that is irrelevant to vulnerability features in the set of the original ones [18], it may affect the correlation of the global semantic information and the coherence of the contextual structure. To address this problem, we have designed a Surface Feature Encoder (SFE) based on the gating mechanism. The unique mechanism can control the flow of critical semantic information, suppress noise data, and enhance the global semantic information of the features. Second, by combining a Base Transformer Encoder (BTE) based on Transformer blocks and Detail CNN Encoder (DCE), we devise a dual-branch structured encoder to comprehensively explore vulnerability patterns from global structure and local detail features, where the BTE is used to extract long-range dependencies and global structural features in the code and the DCE focuses more on the analysis and exploration of the syntax and semantics within the code to extract local detail features. Third, to improve the quality of the code vector representation, we introduce Deep Residual Shrinkage Networks (DRSNs) to resist the noise generated by vulnerability-unrelated variables. Using deep learning to automatically determine the threshold, the model can focus more on the vulnerability-related characteristics. Due to the large amount of irrelevant information may exist in the set of contract codes [19], in the data preprocessing phase, we intend to use the Vulnerability Syntax-driven Slice (VSS) to eliminate redundant information. VSS provides a more comprehensive set of slice criteria for identifying different vulnerability characteristics, which can maintain data dependency and control relevance of code statements. We conducted extensive experiments on three different types of vulnerability datasets: reentrancy, timestamp dependency, and infinite loop vulnerabilities. The experimental results show that our approach outperforms state-of-the-art methods in terms of detection performance. The major contributions of this paper are as follows:
  • We present a vulnerability syntax-driven slice method, which can simplify the contract code by removing statements unrelated to vulnerability characteristics and preserving the data and controls dependencies in statements.
  • We propose a novel MEVD approach to detect vulnerabilities in smart contracts. The global structure and local detail features are captured by multi-scale encoders, respectively to compensate for the lack of feature extraction capability of a single model.
  • We have compared MEVD with state-of-the-art vulnerability detection methods. Experimental results show that the proposed MEVD outperforms existing methods for detecting reentrancy, timestamp dependency, and infinite loop vulnerabilities.
This paper is organized as follows. First, in Section 2, we discuss the background knowledge of smart contract vulnerabilities. Next, in Section 3, we introduce the related work. In Section 4, we provide a detailed explanation of our proposed method. Section 5 presents our experimental results. Finally, we conclude the paper by discussing future directions in Section 6.

2. Background

In this section, we introduce background about the smart contract and common vulnerabilities in the smart contract.

2.1. Smart Contract Basics

Smart Contracts: Smart contracts are typically written in the Solidity programming language. When smart contracts are deployed on the blockchain, transactions can be executed automatically and irreversibly. Smart contracts ensure the security and reliability of transactions without the need for third party verification and execution. This effectively reduces transaction costs and risks.
Fallback Function: In a smart contract, when an unmatched function is called by an external user, the fallback function is automatically executed to handle unknown transactions or calls [20]. It can be used to automatically receive transfers of Ether or other digital assets when performing fund transfer operations, enabling smart contracts to accept funds and execute related business logic.

2.2. Smart Contract Vulnerabilities

Vulnerabilities in smart contracts exist at three levels: Solidity language, EVM virtual machine, and blockchain [20]. For example, at the Solidity language level, types of vulnerabilities include reentrancy, integer overflow, and underflow. Types of vulnerabilities include short address attack and storage overlap attack at the EVM virtual machine level. At the blockchain level, types of vulnerabilities include timestamp dependency, transaction order dependency, etc. Our work is mainly focused on reentrancy, timestamp dependency, and infinite loop vulnerabilities. By checking 40,932 Ethereum smart contracts, Liu et al. discover that out of 307,396 functions, approximately 5013 functions may lead to reentrancy vulnerabilities, and about 4833 functions may result in timestamp dependency vulnerabilities [21]. In addition, around 56,800 functions contain for or while loop statements, which can lead to infinite loop vulnerabilities. These scenes have led us to investigate on these three types of vulnerabilities.
Reentrancy: The reentrancy vulnerability is a commonly exploited vulnerability in blockchain networks. With the well-known DAO attack incident being an attack that exploited this vulnerability, attackers can make a program execute malicious code designed by repeating a transaction until the victim’s account balance is 0 or gas is exhausted [13], thus causing huge financial losses. This allows attackers to illegally acquire a significant amount of funds within the contract.
Timestamp Dependency: As the system determines the timestamp during the mining process, it allows for a deviation of 900 s so that the miners can control the timestamp to a certain extent [22]. However, malicious miners can set arbitrary values for timestamps within a short time frame (<900 s). Additionally, they can gain foreknowledge of the timestamp of the next block, and thus manipulate the smart contract to gain illegal profits.
Infinite Loop: An infinite loop vulnerability is where the code within a contract function contains an iterative or looping structure (such as a for loop, while loop, etc.) but lacks a termination condition or the termination condition cannot be met, resulting in the loop not being able to terminate normally [21]. This can trap a smart contract in an infinite loop state, consuming the contract’s computational resources and potentially causing the contract to fail to execute.
The damage caused by these three vulnerabilities is very serious, and the logic of the contract code becomes more complex due to the numerous call relationships between contracts. Additionally, they are not easily discovered by developers. Therefore, detection of these three vulnerabilities is essential.

3. Related Work

In this section, we will discuss the current smart contract vulnerability detection methods, including traditional detection methods and deep learning-based methods. Then, we will introduce some deep learning models.
Traditional Detection Methods: Traditional methods for detecting vulnerabilities in smart contracts primarily include methods such as symbolic execution, formal verification [23], and fuzzing [13]. Oyente leverages the static symbolic execution technique to detect potential vulnerabilities in smart contracts [24]. Mythril combines static symbolic execution, taint analysis, and control flow checking to further improve the accuracy of vulnerability detection [25]. Slither can detect vulnerabilities by transforming contract code into an intermediate representation [26]. ContractFuzzer is the first vulnerability detection framework to apply fuzz testing techniques to smart contracts [22].
Deep Learning Detection Methods: In recent years, the deep learning technology has achieved remarkable success in various fields. Currently, there are a number of deep learning methods for vulnerability detection. ReChecker [14] employs code slicing of smart contract source code and uses a BLSTM-ATT sequence model to detect reentrancy vulnerabilities. To fully capture key statements associated with the vulnerability, Yu et al. had made improvements to the slicing technique by introducing the concept of Vulnerability Candidate Slices (VCSs), which feed into various temporal neural network models for vulnerability detection [27]. Cai et al. constructed a novel contract graph, incorporating Abstract Syntax Trees (ASTs), Control Flow Graphs (CFGs), and Program Dependency Graphs (PDGs) and employed graph neural network models for vulnerability detection [15]. Liu et al. introduced a new method for representing code graphs, AME, which classifies nodes in the graph into core and normal nodes, then extracts deep graph features and fuses global graph features with local expert patterns to improve accuracy [28]. VulnSense combines three types of features from smart contracts and uses a multi-modal learning approach for a comprehensive vulnerability detection method [29].
Our proposed MEVD approach is based on multi-scale encoders. Compared with ReChecker’s single feature extraction, MEVD can extract the semantic and syntactic features of the code more comprehensively, effectively combining global structures with local details. In addition, compared with the VCS method proposed by Yu et al., we have introduced the VSS, which contains more comprehensive vulnerability slicing criteria. The VSS can take into consideration the characteristics of different types of vulnerabilities in depth, and the extracted code snippets contain richer semantic information, which effectively reduces false positives caused by insufficient crucial information in the vulnerability code snippets. Finally, MEVD has demonstrated excellent detection performance compared to current state-of-the-art methods through extensive experimental validation.
Deep Learning Models: In recent years, many outstanding network models have emerged, such as Long Short-Term Memory (LSTM [30]), Graph Convolutional Networks (GCNs [31]), and CNNs. These models have achieved significant success in their respective domains. In addition to these basic models, more complex model structures have emerged in recent years, such as the Transformer model [32]. The core components of the Transformer model are encoders and decoders that use self-attention mechanisms to establish global correlations within input sequences, thereby better capturing contextual structural information. The Transformer has made significant breakthroughs in natural language processing, particularly machine translation. By refining the Transformer’s encoder and decoder modules, Restormer can better capture interactions between distant pixels [33]. RepVGG introduces a multi-branch structure to extract richer features [34]. DRSN is a network structure to improve the feature learning capability for highly noisy vibration signal analysis, enabling more accurate fault diagnosis [35]. CDDFuse designs a novel autoencoder to address the problem of multi-modal image fusion [36].
In the field of smart contract vulnerability detection, we have summarized traditional methods (such as symbolic execution, formal verification, and fuzz testing) and deep learning methods (such as ReChecker and AME). Traditional methods emphasize static symbolic execution techniques, while deep learning methods include various models such as BLSTM-ATT, graph neural networks, and self-attention mechanisms. Finally, we introduce outstanding deep learning models, such as LSTM, Transformer, and Restormer, which have made significant progress in various domains. These methods play an important role in enhancing the security of smart contracts.

4. Method

In this section, we introduce a novel method for slicing smart contract code and present the design of the MEVD framework.

4.1. Overview

As shown in Figure 1, the MEVD proposed in this paper consists of three phases: data preprocessing phase, model training phase, and vulnerability detection phase. Firstly, in the data preprocessing phase, we remove redundant information from the smart contract code, such as blank lines, comments, and non-ASCII characters. Then, to simplify the contract, the source code is sliced into VSS and uniform naming rules for normalization. Next, we use the Word2Vec word embedding technique [37] to convert code slices into vector forms suitable for input to the model in the model training phase. The model consists of multi-scale encoders that are used to enrich the semantic information of the feature vectors and capture global structural and local detail features that are used to improve the performance of vulnerability detection. Finally, in the vulnerability detection phase, to obtain a vector containing global structure and local detail features, the two feature vectors processed by the multiple encoders are fed into a fusion layer. These feature vectors are then fed into a fully connected layer and a SoftMax activation function is used to output vulnerability detection probabilities.

4.2. Data Preprocessing

4.2.1. Code Slice Criteria

It has been discovered that there are a number of code statements in the contract source code that are unrelated to vulnerabilities [38]. These irrelevant code statements can have an impact on vulnerability detection performance. Therefore, it is important to extract key code statements accurately. However, existing methods for the definition of slice criteria have certain limitations when dealing with smart contract code, which can result in the loss of implicit information about vulnerabilities. Therefore, as shown in Table 1, we propose an entirely new set of slice criteria that covers three types of vulnerabilities.
Taking the reentrancy vulnerability as an example, we have defined several slice criteria. Firstly, code statements that include call.value () and fallback () are considered to be critical code statements that are susceptible to reentrancy vulnerabilities, because they allow smart contracts to undergo state transitions as they interact with other contracts. This state transition could result in the contract continuing to execute after an external call, which may result in potential vulnerabilities. In addition, fund transfer functions that include call.value calls require special attention. These functions are widely used in the transfer and invocation processes of smart contracts and serve as conditions for launching reentrancy attacks. Then, we have also focused on variables related to user balances, as these variables are equally important in fund transfers. Similarly, we have also defined slice criteria for the other two types of vulnerabilities. This novel set of slice criteria enables more comprehensive vulnerability-related information to be captured within the contract code, avoiding the omission of critical implicit details.

4.2.2. Code Slice Generation

To address the impact of redundant information in smart contract source code on the accuracy of vulnerability detection, we have proposed a novel vulnerability syntax-driven slice method, as shown in Figure 2.
Taking a smart contract containing call.value () as an example, in step 2, we first remove comments, non-ASCII characters, and blank lines from the smart contract. Removing this irrelevant information does not affect the results. Next, in step 3, based on the vulnerability type associated with the code, we identify the key statements of the code according to the slice criteria in Table 1. For example, the ninth line of code contains the keyword call.value (), and the sixth line operates on the user’s balance. Therefore, we consider these to be key sensitive statements. The code statements relevant to the key statements are then extracted and organized into code snippets by analyzing the control and data dependencies between statements and variables. Then, in order to normalize the code snippets and avoid the potential impact of different naming rules, in step 4, we map user-defined variables to symbolic names (e.g., “VAR1”, “VAR2”) and user-defined functions to symbolic names (e.g., “FUN1”, “FUN2”). This is the final generated VSS. Finally, to convert code snippets into a format that can be accepted by neural networks, we use Word2Vec technology to convert code snippets into vector representations.

4.3. MEVD Model

In this section, we will introduce the model structure of MEVD. The MEVD model consists of three modules: the surface feature encoder, the dual-branch Transformer-CNN encoder, and the deep residual shrinkage network.

4.3.1. Surface Feature Encoder

We used the Word2Vec algorithm, which can convert tokens to vectors, but by converting code directly to vectors as input, semantic features within the code may be ignored. To solve this problem, we designed SFE, which can enhance the relevance of global semantics within the features and suppress the influence of irrelevant information, thus preserving richer syntactic and semantic information. The detailed design of the SFE module is shown in Figure 3.
SFE leverages three design strategies to enhance semantic features: a gating mechanism, dilated convolutions, and depth-wise convolutions. Gating mechanisms are typically used to control the flow of information by enhancing attention to critical information. Specifically, the gating mechanism is formulated as the element-wise product of two parallel paths of linear transformation layers. One path is activated by the non-linear activation function GELU, while the other path applies the reverse operation to the vector. The outputs of these two paths are then subjected to element-wise multiplication, allowing for information from one path to modulate the strength of the other, thereby enhancing focus on important semantic details and reducing the impact of irrelevant variables. On the other hand, the SFE employs dilated convolutions and depth-wise convolutions. Dilated convolutions extend the receptive field to cover a wider range of input information, helping to capture different scales and structural features within the code. Meanwhile, depth-wise convolutions focus on the local context and detailed information in the input data. They efficiently capture local interdependencies between different channels in the input data, helping the SFE to enrich the semantic information within the features. Given the input vector (feature matrix) X R L × D , L represents the length of the token sequence and D represents the dimension of the token embedding. The SFE equation is as follows:
G a t i n g ( X ) = ϕ ( W d e 1 W d i 1 ( X ) ) R e v e r s e ( W d e 2 W d i 2 ( X ) )
X ^ = L N Gating X + X
where W d i ( ) is the 3 × 3 dilated convolution, W d e ( ) is the 3 × 3 depth-wise convolution, ⊙ denotes element-wise multiplication, ϕ represents the GELU non-linearity, and LN is the layer normalization. Reverse denotes the reversal of rows in a feature matrix, e.g., swapping the first row with the last. In summary, the design of the SFE allows each level to be concerned with details that are complementary to other levels, focusing on enriching features with code semantic context information.

4.3.2. Dual-Branch Encoder

The dual-branch encoder consists of two parallel encoders: the base Transformer encoder and the detail CNN encoder. These two modules are used to further extract vector features after the SFE. The BTE is used to effectively capture global structural information, allowing it to capture dependencies between code statements and contextual logical structural features. The DCE, on the other hand, focuses on exposing crucial latent features within the code, while preserving more syntactic and semantic details. This dual-branch design strategy allows the model to simultaneously consider global structure and fine-grained features, leading to a more comprehensive understanding of smart contract code and significantly improving the accuracy and performance of vulnerability detection.
  • Base Transformer Encoder (BTE)
The BTE consists of multiple self-attention layers, with each self-attention layer containing multi-head self-attention and feedforward networks. It uses the multi-head self-attention feature of the Transformer encoder to capture contextual information and long-range dependencies within code sequences, thereby extracting richer global structural features. The multi-head self-attention mechanism serves as the core of BTE, allowing it to establish correlations between different positions in the input sequence and effectively capture contextual information. The structure of the BTE is shown in Figure 4.
BTE achieves parallel computation of multiple attentional heads, which allows the model to simultaneously focus on information from different positions within the input sequence. It then combines the outputs of the different heads using weighted fusion to obtain a more comprehensive feature representation. The calculation process of the BTE encoder is as follows:
X p o s = P o s i t i o n a l _ E n c o d i n g   ( X )
Q = Linear   X p o s = X p o s W Q
K = Linear   X p o s = X p o s W K
V = Linear   X p o s = X p o s W V
X attention = S e l f _ Attention Q , K , V
Here, X p o s   is obtained using positional encoding operations, Q represents the query vector, K represents the key vector, and V represents the value vector. Each vector undergoes a linear transformation, with W Q , W K , and W V representing the weight matrices for these transformations. Finally, X attention is obtained by Equation (7):
X attention1 = X p o s + X attention
X attention2 = LayerNorm X attention1
X output = A c t i v a t e ( L i n e a r ( L i n e a r ( X attention2 ) ) )
X output1 = X attention2 + X output
X output2 =   LayerNorm   X output1
Then, the X attention2 is obtained by residual connection and layer normalization. Finally, X attention2 is processed through a feedforward neural network and residual connection to obtain X output2 feature vectors with global structure and semantic information. This design enables the model to better understand the overall structure and global semantic relationships of smart contract code and effectively handle complex smart contracts.
b.
Detail CNN Encoder (DCE)
BTE focuses primarily on capturing global semantic information and structural features, while DCE complements BTE by focusing on extracting more intricate and complex features. DCE has the ability to delve deep into the latent syntactic, semantic, and local features of the code, further enriching the feature representation of the code vectors. DCE consists of a multi-branch convolutional structure as shown in Figure 5, consisting of three branches: a 3 × 3 dilated convolution layer with Batch Normalization (BN), a 1 × 1 dilated convolution layer with BN, and an independent BN layer. Dilated convolution allows different dilation rates to be set, providing a larger receptive field without increasing the number of parameters. This helps the model to better understand the structure and relationships within the code, thus capturing more intricate details. In addition, the different kernel sizes in these convolutions allow the DCE to capture information at different scales. Finally, by fusing outputs from different branches, it integrates information from different scales and levels of detail. This helps to improve the model’s perception of fine-grained details and to combine features from different hierarchical levels for a better understanding of the detailed features of the code.
In this research, we utilize symbols to represent key concepts. W ( 3 ) R 3 × 3 represents the convolution kernel for a 3 × 3 dilated convolution layer, while W ( 1 ) R 1 × 1 represents the convolution kernel for a 1 × 1 dilated convolution layer. Additionally, we use μ ( ) , σ ( ) , γ ( ) , and β ( ) to respectively denote the accumulated mean, standard deviation, learned scaling factor, and bias for each branch in the BN layer. We have also defined symbolic representations for the input and output. X ( 1 ) represents the input, and X ( 2 ) represents the output. The DCE equation is as follows:
X ( 2 ) = bn ( X ( 1 ) W ( 3 ) , μ ( 3 ) , σ ( 3 ) , γ ( 3 ) , β ( 3 ) ) + bn ( X ( 1 ) W ( 1 ) , μ ( 1 ) , σ ( 1 ) , γ ( 1 ) , β ( 1 ) ) + bn ( X ( 1 ) , μ ( 0 ) , σ ( 0 ) , γ ( 0 ) , β ( 0 ) )
In summary, the use of DCE enhances the model’s ability to perceive and capture these intricate and complex features, thereby helping the model to better distinguish between vulnerable code and normal code.

4.3.3. Deep Residual Shrinkage Network

The DRSN module integrates soft thresholding and deep learning, introducing a method for adaptive thresholding [35]. Through DRSN, the model can effectively reduce irrelevant information during feature learning. The calculation of the soft threshold is as follows:
y = x τ x > τ 0 τ x τ x + τ x < τ
The soft thresholding calculation is shown in Figure 6b, where x represents the input features, y represents the output features, and τ is the threshold, which is a positive parameter. As can be seen from Equation (14), the essence of soft thresholding is to discard features with smaller absolute values and shrink features with larger absolute values, thereby reducing information unrelated to the current task.
The structure of DRSN is shown in Figure 6c. First, the input vector passes two convolution layers, each accompanied by normalization layers and Relu activation functions. The output of the convolution layer is a matrix and is denoted as X R T × K , where T is the number of token sets, and K is the number of convolution kernels. The resulting matrix undergoes an absolute value operation, followed by global average pooling to generate a one-dimensional vector, denoted as X a v g R K :
X a v g = 1 T i = 1 T X i
where X i denotes the absolute value of the i t h row feature in X . Subsequently, X a v g is fed through a fully connected layer, followed by batch normalization, a Relu activation function, and a second fully connected layer. Furthermore, a sigmoid activation function is used to scale the threshold parameter for each channel in the range (0, 1), resulting in the scaling parameter s c R K , and the threshold τ R K can be calculated using Equation (17):
s c = 1 1 + e Z
τ = s c X a v g
After DRSN processing, this results in eliminating residual redundant information and ensuring that the feature vectors retain only crucial information related to the vulnerability characteristics. Additionally, this helps to improve the performance of the model, enabling it to better distinguish between vulnerable and non-vulnerable samples, thereby increasing the accuracy and effectiveness of vulnerability detection.

4.4. Vulnerability Detection

In the model training phase, we obtain two feature vectors: one from the BTE, denoted as vector B and another from the DCE, denoted as vector D. These two vectors are individually subjected to soft thresholding processing through DRSN, resulting in processed feature vectors B and D . To concatenate these two vectors, we flatten these two vectors as 1D vectors and we concatenate them to B D , which is then fed into a fully connected layer and a Relu activation function for non-linear transformation. Finally, the transformed vector is fed into a SoftMax layer to determine whether the code snippet contains vulnerabilities. The equations are as follows:
B D = concat F l a t t e n ( B ) , F l a t t e n ( D )
y ^ c = s o f t m a x ( F C ( B D ) )
Here, y ^ c represents the predicted probability, FC represents the fully connected layer, concat signifies vector concatenation operation, and s o f t m a x denotes the SoftMax function, used to transform real-valued vectors into probability vectors, indicating the probabilities of each category in a classification problem.
The MEVD model proposed in this paper is a framework that integrates several different functional encoders. In addition, we introduce a novel code-slicing method for data preprocessing. Through an extensive series of experiments, the method proposed in this paper demonstrates outstanding performance in the smart contract vulnerability detection. In the following sections, we present the experimental results to comprehensively substantiate the effectiveness of our proposed approach.

5. Experiments

In this section, we introduced the datasets and configuration parameters used in the experiments. We provided a detailed description of the experimental procedures and presented the experimental results. To evaluate the performance of our proposed method, we answered the following questions:
  • RQ1: Can the proposed method effectively detect reentrancy, infinite loop, and timestamp dependency vulnerabilities? How does its accuracy, precision, recall, and F1-score compare to state-of-the-art vulnerability detection methods?
To answer this question, we compared state-of-the-art detection tools. Through these comparisons, we were able to assess the performance of our approach within the existing technology.
  • RQ2: Is the proposed code slicing method helpful for vulnerability detection?
To answer this question, we divided the dataset into two parts: the original dataset and the Vulnerability Syntax-Driven Slice (VSS) dataset. We conducted experiments using these two datasets as model inputs and compared their performance separately.
  • RQ3: What is the impact of the different components designed in the model on detection performance?
To answer this question, we conducted experiments to compare the performance of models with different combinations of components in terms of metrics such as accuracy, precision, recall, and F1-score.

5.1. Datasets

Our research dataset covers three types of vulnerabilities: reentrancy vulnerabilities, timestamp dependency vulnerabilities, and infinite loop vulnerabilities. The primary sources of these datasets include: (i) The SmartBugs Wild dataset consists of 47,398 Solidity language files containing a total of approximately 203,716 contracts with known vulnerabilities [39]. (ii) The ESC (Ethereum Smart Contracts) dataset consists of 307,396 smart contract functions extracted from 40,932 smart contracts. (iii) In addition, we use the datasets published by Qian et al. [40].

5.2. Experimental Settings

All experiments were performed on a computer equipped with 32 GB RAM and a GPU at 1080Ti. We implemented our method using the Keras and TensorFlow frameworks. In our experiment, 80% of the contracts form the training set, and the remaining 20% form the test set. The parameters used in the model are detailed in Table 2.

5.3. Evaluation Metrics

To measure the performance of our approach, we use the following four widely used evaluation metrics:
A c c u r a c y : It represents the proportion of correctly predicted samples out of the total number of samples and measures the overall accuracy of the model’s predictions.
A c c u r a c y = T P + T N T P + F P + T N + F N
P r e c i s i o n : It represents the proportion of true positives among those predicted to be positive by the model and measures the accuracy of the model in predicting positive samples.
P r e c i s i o n = T P T P + F P
R e c a l l : It represents the proportion of true positives among the actual positive samples and measures the ability of the model to detect positive samples.
R e c a l l = T P T P + F N
F 1 S c o r e : This is a composite score that combines precision and recall to assess the overall performance of the model.
F 1 S c o r e = 2 P r e c i s o n R e c a l l P r e c i s o n + R e c a l l

5.4. Results Analysis

Result for Answering RQ1: To evaluate the performance of MEVD in detecting these three types of vulnerabilities, we compared it with deep learning-based approaches (ReChecker [14], DR-GCN [40], TMP [40], CGE [21]). In Table 3, we show the comparison with state-of-the-art deep learning-based methods. These comparisons allow us to assess the performance of our proposed MEVD in vulnerability detection.
Based on the results presented in Table 3 and Figure 7, we can compare the performance of different models in terms of detection. The following conclusions can be drawn from these data: Firstly, the ReChecker model shows relatively poor detection performance compared to the other models, particularly in the context of identifying infinite loop vulnerabilities, where its accuracy is only 68.79%. However, when we use the MEVD model for detection, the accuracy improves significantly by 18.15%. It is worth noting that our approach not only outperforms in detecting infinite loop vulnerabilities, but also provides satisfactory performance improvements in other metrics. For example, in detecting timestamp dependency vulnerabilities, the accuracy of the MEVD model is 3.09% higher than that of the graph neural network-based CGE. In addition, the MEVD model achieves an accuracy of 92.13% for the detection of reentrancy vulnerabilities, which is well above the performance of other methods.
By comparing the experimental results, we come to a clear conclusion: the MEVD shows outstanding performance in different types of vulnerability detection. The MEVD shows significant performance advantages over state-of-the-art deep learning-based detection approaches.
Result for Answering RQ2: To evaluate the effectiveness of our proposed code slicing method, we divided the dataset into two parts: the unprocessed original dataset and the VSS dataset (VSS + Dataset). We then performed experiments on these two datasets separately, as shown in Table 4. This approach allows us to evaluate the impact of code slicing on model performance.
By analyzing the results in Table 4, we observe that running experiments on the sliced dataset, as opposed to the unprocessed dataset, significantly improves the performance of the models. For example, in the case of reentrancy vulnerability detection, experiments conducted on the sliced dataset yielded an accuracy of 92.13%, which is a significant improvement of 5.81% compared to the unprocessed dataset. At the same time, in the detection of vulnerabilities related to timestamps, the F1-score reaches 91.04%, which represents an improvement of 4.8%. By comparing the experimental results, we arrive at a definitive conclusion: The slice criteria defined by our approach are significant in covering crucial statements within the contract code. Furthermore, by extracting sliced code using control flow and data flow methods, we can expose critical code structure information and deepen the relationships between semantics. This helps models learn vulnerability patterns more effectively.
Result for Answering RQ3: In order to evaluate the effectiveness of different modules in the MEVD, we performed substitution experiments between modules. Specifically, we performed the following experiments individually: (1). Removal of the SFE module only, known as the MEVD-S model. (2). Replacement of the Transformer-CNN dual-branch encoder module with a CNN model, called the MEVD-T model. (3). Removal of the DRSN module only, called the MEVD-D model. Table 5 shows the experimental results for these different modules. By comparing these results, we can determine the impact of the different modules on the model performance.
From an analysis of the experimental results in Table 5, we obtain a clear conclusion: when various modules are removed, the experimental performance of all models generally experience a decrease. Particularly noteworthy is the MEVD-T model, which shows a significant decrease in F1-score of 8.29% compared to the MEVD model for timestamp dependency vulnerability detection. In the case of reentrancy vulnerability detection, the accuracy of the MEVD-T model is only 84.31%, a decrease of 7.82% compared to the MEVD model, with other evaluation metrics also falling short of the MEVD model. This phenomenon is due to the limitation of the CNN models in adequately capturing the code relationships, thus failing to extract vulnerability features effectively. In contrast, our constructed Transformer CNN dual-branch encoder module comprehensively extracts the code global structure and fine-grained syntax semantic features, and fuses them into multi-scale feature vectors. This enables the model to learn vulnerability patterns, significantly improving detection performance. Further analysis of the MEVD-S and MEVD-D experimental results shows that the SFE and DRSN modules enhance semantic contextual details and effectively eliminate redundant information from feature vectors. For example, in the detection of reentrancy vulnerabilities, the SFE module improves accuracy by 3.42%, this improvement is attributed to SFE’s unique gating mechanism, which allows it to learn bidirectional semantic features from the code. By controlling the transmission of important semantic information, SFE increases the focus on critical semantic details. In addition, unlike traditional convolutional layers, SFE uses dilated convolutional layers for feature extraction, which can flexibly adjust dilation rates to capture a wider range of contextual semantic information, ensuring the integrity of the code’s semantics.
While the DRSN module improves the F1-score by 3.91% in the infinite loop vulnerability, this improvement is attributed to DRSN’s unique adaptive soft threshold setting strategy. This adaptability allows the model to flexibly capture vulnerability features at different positions in the code structure, enabling the network model to better adapt and learn different vulnerability patterns. By reducing information unrelated to the current task, DRSN effectively reduces the impact of features irrelevant to vulnerabilities on the model, resulting in improved vulnerability detection performance.

6. Conclusions and Future Work

6.1. Conclusions

In this paper, we propose a novel MEVD approach. In contrast to existing approaches, the proposed method can enrich the semantic information of code features, fully extract both global structure and local detail features of smart contract code, and effectively eliminate redundant elements for code features. In addition, we have introduced the concept of VSS, which removes code statements unrelated to vulnerability characteristics, contains rich syntactic and semantic information, and preserves the data and control dependencies in statements. It helps the model focus on the critical characteristics of the vulnerability, and capture more features about the vulnerability. A large number of experiments have shown that MEVD outperforms traditional methods and state-of-the-art deep learning approaches in detecting vulnerabilities in smart contracts.
This paper introduces the MEVD approach, which shows excellent accuracy in detecting vulnerabilities in smart contracts. In the field of blockchain technology, improving the security of smart contracts will increase the reliability and credibility of the blockchain system. In Decentralized Finance (DeFi), reducing financial fraud and losses caused by smart contract vulnerabilities may not only increase the credibility of blockchain financial products, but also attract more traditional financial institutions and investors to the blockchain sector. However, with the continuous development of smart contract platforms and various programming languages, new vulnerabilities may appear, making it difficult for MEVD to effectively detect them. To overcome this challenge, MEVD will need to become more scalable and flexible in the future.

6.2. Future Work

This paper proposes a novel multi-scale encoder approach for vulnerability detection and explores how to address the problem of inadequate code feature extraction ability. Our future work and research will include the following aspects:
  • Construct a unified and standardized dataset of smart contract vulnerabilities. The dataset we are currently using is not comprehensive, as it does not include all types of vulnerabilities and is limited to smart contracts written in Solidity. Therefore, to fully exploit the potential of deep learning, we need to expand our research to include a wider range of programming languages and construct a dataset that covers a variety of vulnerability types.
  • Develop a combined static and dynamic analysis model. Our current deep learning approach is primarily based on the static analysis of source code, which may ignore certain execution paths, leading to false positives. To address this issue, we plan to integrate detection tools at different levels to more effectively identify vulnerabilities in contracts. For example, the combination of deep learning models with dynamic execution techniques will be a valuable direction for research.
  • Construction of an easy-to-use and highly scalable detection tool. Currently, the deployment and use of many vulnerability detection tools require complex environment configurations, which can be a barrier for non-expert users. When deploying MEVD in real-world scenarios, we need to consider issues such as computing resources and system compatibility. In addition, MEVD builds its model primarily on known types of vulnerabilities and may not be able to quickly adapt to newly emerging unknown vulnerabilities. Therefore, the development of a detection tool that is both user-friendly and capable of flexibly addressing new vulnerabilities will be an important part of our future research.

Author Contributions

Conceptualization, L.L. and J.G.; methodology, L.L. and J.G.; software, L.L.; validation, J.L., J.G. and L.L.; formal analysis, L.L.; investigation, J.G.; resources, L.L.; data curation, L.L.; writing—original draft preparation, L.L.; writing—review and editing, J.G. and L.L.; funding acquisition, J.G. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Key Research and Development Project in Shaanxi Province of China (No. 2022GY048) and the Scientific Research Program Funded by the Shaanxi Provincial Education Department (No. 19JC021).

Data Availability Statement

The experimental data used in this study will be posted on the repository (https://github.com/COPELONG/MEVD (accessed on 22 December 2023)).

Acknowledgments

The authors are very grateful to the anonymous reviewers for their constructive comments, which helped to improve the quality of this paper.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Alharby, M.; Moorsel, A.V. Blockchain Based Smart Contracts: A Systematic Mapping Study. In Proceedings of the Fourth International Conference on Computer Science and Information Technology (CSIT-2017), Dubai, United Arab Emirates, 26–27 August 2017; Academy & Industry Research Collaboration Center (AIRCC): Chennai, India, 2017; pp. 125–140. [Google Scholar]
  2. Gupta, R.; Tanwar, S.; Al-Turjman, F.; Italiya, P.; Nauman, A.; Kim, S.W. Smart Contract Privacy Protection Using AI in Cyber-Physical Systems: Tools, Techniques and Challenges. IEEE Access 2020, 8, 24746–24772. [Google Scholar] [CrossRef]
  3. Andoni, M.; Robu, V.; Flynn, D.; Abram, S.; Geach, D.; Jenkins, D.; McCallum, P.; Peacock, A. Blockchain Technology in the Energy Sector: A Systematic Review of Challenges and Opportunities. Renew. Sustain. Energy Rev. 2019, 100, 143–174. [Google Scholar] [CrossRef]
  4. Mirabelli, G.; Solina, V. Blockchain-Based Solutions for Agri-Food Supply Chains: A Survey. Int. J. Simul. Process Model. 2021, 17, 1–15. [Google Scholar] [CrossRef]
  5. Hasselgren, A.; Kralevska, K.; Gligoroski, D.; Pedersen, S.A.; Faxvaag, A. Blockchain in Healthcare and Health Sciences—A Scoping Review. Int. J. Med. Inform. 2020, 134, 104040. [Google Scholar] [CrossRef] [PubMed]
  6. Batubara, F.R. Challenges of Blockchain Technology Adoption for E-Government: A Systematic Literature Review. In Proceedings of the 19th Annual International Conference on Digital Government Research: Governance in the Data Age, Delft, The Netherlands, 30 May–1 June 2018. [Google Scholar]
  7. Wang, S.; Ouyang, L.; Yuan, Y.; Ni, X.; Han, X.; Wang, F.-Y. Blockchain-Enabled Smart Contracts: Architecture, Applications, and Future Trends. IEEE Trans. Syst. Man Cybern. Syst. 2019, 49, 2266–2277. [Google Scholar] [CrossRef]
  8. Khan, S.N.; Loukil, F.; Ghedira-Guegan, C.; Benkhelifa, E.; Bani-Hani, A. Blockchain Smart Contracts: Applications, Challenges, and Future Trends. Peer Peer Netw. Appl. 2021, 14, 2901–2925. [Google Scholar] [CrossRef] [PubMed]
  9. 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]
  10. 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]
  11. Almakhour, M.; Sliman, L.; Samhat, A.E.; Mellouk, A. Verification of Smart Contracts: A Survey. Pervasive Mob. Comput. 2020, 67, 101227. [Google Scholar] [CrossRef]
  12. He, D.; Deng, Z.; Zhang, Y.; Chan, S.; Cheng, Y.; Guizani, N. Smart Contract Vulnerability Analysis and Security Audit. IEEE Netw. 2020, 34, 276–282. [Google Scholar] [CrossRef]
  13. Chu, H.; Zhang, P.; Dong, H.; Xiao, Y.; Ji, S.; Li, W. A Survey on Smart Contract Vulnerabilities: Data Sources, Detection and Repair. Inf. Softw. Technol. 2023, 159, 107221. [Google Scholar] [CrossRef]
  14. 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]
  15. Cai, J.; Li, B.; Zhang, J.; Sun, X.; Chen, B. Combine Sliced Joint Graph with Graph Neural Networks for Smart Contract Vulnerability Detection. J. Syst. Softw. 2023, 195, 111550. [Google Scholar] [CrossRef]
  16. 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]
  17. 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]
  18. Li, M.; Ren, X.; Fu, H.; Li, Z.; Sun, J. ConvMHSA-SCVD: Enhancing Smart Contract Vulnerability Detection through a Knowledge-Driven and Data-Driven Framework. In Proceedings of the 2023 IEEE 34th International Symposium on Software Reliability Engineering (ISSRE), Florence, Italy, 9–12 October 2023; pp. 578–589. [Google Scholar]
  19. Yu, L.; Lu, J.; Liu, X.; Yang, L.; Zhang, F.; Ma, J. PSCVFinder: A Prompt-Tuning Based Framework for Smart Contract Vulnerability Detection. In Proceedings of the 2023 IEEE 34th International Symposium on Software Reliability Engineering (ISSRE), Florence, Italy, 9–12 October 2023; pp. 556–567. [Google Scholar]
  20. 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; Springer: Berlin/Heidelberg, Germany, 2017; pp. 164–186. [Google Scholar]
  21. Liu, Z.; Qian, P.; Wang, X.; Zhuang, Y.; Qiu, L.; Wang, X. Combining Graph Neural Networks with Expert Knowledge for Smart Contract Vulnerability Detection. IEEE Trans. Knowl. Data Eng. 2021, 35, 1296–1310. [Google Scholar] [CrossRef]
  22. Jiang, B.; Liu, Y.; Chan, W.K. Contractfuzzer: Fuzzing Smart Contracts for Vulnerability Detection. In Proceedings of the 33rd ACM/IEEE International Conference on Automated Software Engineering, Montpellier, France, 3–7 September 2018; pp. 259–269. [Google Scholar]
  23. Tsankov, P.; Dan, A.; Drachsler-Cohen, D.; Gervais, A.; Buenzli, F.; Vechev, M. Securify: Practical Security Analysis of Smart Contracts. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security, Toronto, ON, Canada, 15–19 October 2018; pp. 67–82. [Google Scholar]
  24. Luu, L.; Chu, D.-H.; Olickel, H.; Saxena, P.; Hobor, A. Making Smart Contracts Smarter. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security, Vienna, Austria, 24–28 October 2016; pp. 254–269. [Google Scholar]
  25. Prechtel, D.; Groß, T.; Müller, T. Evaluating Spread of ‘Gasless Send’in Ethereum Smart Contracts. In Proceedings of the 2019 10th IFIP International Conference on New Technologies, Mobility and Security (NTMS), Canary Islands, Spain, 24–26 June 2019; pp. 1–6. [Google Scholar]
  26. Feist, J.; Grieco, G.; Groce, A. Slither: A Static Analysis Framework for Smart Contracts. In Proceedings of the 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB), Montreal, QC, Canada, 27 May 2019; pp. 8–15. [Google Scholar]
  27. 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]
  28. 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]
  29. Duy, P.T.; Khoa, N.H.; Quyen, N.H.; Trinh, L.C.; Kien, V.T.; Hoang, T.M.; Pham, V.-H. VulnSense: Efficient Vulnerability Detection in Ethereum Smart Contracts by Multimodal Learning with Graph Neural Network and Language Model. arXiv 2023, arXiv:2309.08474. [Google Scholar]
  30. Sak, H.; Senior, A.W.; Beaufays, F. Long Short-Term Memory Recurrent Neural Network Architectures for Large Scale Acoustic Modeling; Google: Mountain View, CA, USA, 2014; pp. 338–342. [Google Scholar]
  31. Kipf, T.N.; Welling, M. Semi-Supervised Classification with Graph Convolutional Networks. arXiv 2016, arXiv:1609.02907. [Google Scholar]
  32. Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A.N.; Kaiser, L.; Polosukhin, I. Attention Is All You Need. In Advances in Neural Information Processing Systems; MIT Press: Cambridge, MA, USA, 2017; Volume 30. [Google Scholar]
  33. Zamir, S.W.; Arora, A.; Khan, S.; Hayat, M.; Khan, F.S.; Yang, M.-H. Restormer: Efficient Transformer for High-Resolution Image Restoration. In Proceedings of the 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), New Orleans, LA, USA, 18–24 June 2022; pp. 5718–5729. [Google Scholar]
  34. Ding, X.; Zhang, X.; Ma, N.; Han, J.; Ding, G.; Sun, J. RepVGG: Making VGG-Style ConvNets Great Again. In Proceedings of the 2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Nashville, TN, USA, 20–25 June 2021; pp. 13728–13737. [Google Scholar]
  35. Zhao, M.; Zhong, S.; Fu, X.; Tang, B.; Pecht, M. Deep Residual Shrinkage Networks for Fault Diagnosis. IEEE Trans. Ind. Inform. 2019, 16, 4681–4690. [Google Scholar] [CrossRef]
  36. Zhao, Z.; Bai, H.; Zhang, J.; Zhang, Y.; Xu, S.; Lin, Z.; Timofte, R.; Van Gool, L. CDDFuse: Correlation-Driven Dual-Branch Feature Decomposition for Multi-Modality Image Fusion. In Proceedings of the 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Vancouver, BC, Canada, 17–24 June 2023; pp. 5906–5916. [Google Scholar]
  37. Mikolov, T.; Sutskever, I.; Chen, K.; Corrado, G.S.; Dean, J. Distributed Representations of Words and Phrases and Their Compositionality. In Advances in Neural Information Processing Systems; MIT Press: Cambridge, MA, USA, 2013; Volume 26. [Google Scholar]
  38. 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]
  39. 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]
  40. Zhuang, Y.; Liu, Z.; Qian, P.; Liu, Q.; Wang, X.; He, Q. Smart Contract Vulnerability Detection Using Graph Neural Network. In Proceedings of the Twenty-Ninth International Joint Conference on Artificial Intelligence; International Joint Conferences on Artificial Intelligence Organization, Yokohama, Japan, 11–17 July 2020; pp. 3283–3290. [Google Scholar]
Figure 1. MEVD framework and vulnerability detection process.
Figure 1. MEVD framework and vulnerability detection process.
Electronics 13 00489 g001
Figure 2. The process of generating code slices from the source code and transforming them into vectors, ①: Smart contract source codes, ②: Codes with redundant information removed, ③: Slice code snippet, ④: Normalized Codes.
Figure 2. The process of generating code slices from the source code and transforming them into vectors, ①: Smart contract source codes, ②: Codes with redundant information removed, ③: Slice code snippet, ④: Normalized Codes.
Electronics 13 00489 g002
Figure 3. The architectural framework of SFE.
Figure 3. The architectural framework of SFE.
Electronics 13 00489 g003
Figure 4. The architectural framework of BTE.
Figure 4. The architectural framework of BTE.
Electronics 13 00489 g004
Figure 5. The architectural framework of DCE.
Figure 5. The architectural framework of DCE.
Electronics 13 00489 g005
Figure 6. The architectural framework of DRSN. (a) DRSN processing procedure, (b) Soft thresholding principle, and (c) Detailed implementation of DRSN.
Figure 6. The architectural framework of DRSN. (a) DRSN processing procedure, (b) Soft thresholding principle, and (c) Detailed implementation of DRSN.
Electronics 13 00489 g006
Figure 7. Comparison with existing methods based on deep learning.
Figure 7. Comparison with existing methods based on deep learning.
Electronics 13 00489 g007
Table 1. The different vulnerability slice criteria.
Table 1. The different vulnerability slice criteria.
VulnerabilitySlice Criteria
Reentrancyfallback ()
call.value ()
a function involving call.value
variable: correspond to user balance
Timestamp Dependencyblock.timestamp
block.number
now
Infinite Loopfor
while loop
self-call function
Table 2. Parameters of the MEVD model.
Table 2. Parameters of the MEVD model.
Model ParameterValue
OptimizerAdam
Learning rate[0.0001, 0.005]
Dropout rate0.5
Batch size8
Epochs50
Table 3. Comparison with deep learning-based methods.
Table 3. Comparison with deep learning-based methods.
VulnerabilityMethodAcc (%)Pre (%)Rec (%)F1 (%)
Reentrancy ReChecker74.6569.4776.9375.62
DR-GCN82.5875.3980.8379.57
TMP86.2878.2584.9680.28
CGE88.3284.1586.7785.64
MEVD92.1389.4990.1589.28
Timestamp Dependency ReChecker72.6870.8669.2473.21
DR-GCN80.2176.5478.8679.04
TMP84.3785.2180.7983.08
CGE87.7686.1582.7784.56
MEVD90.8589.1792.9891.04
Infinite LoopReChecker68.7971.6369.4171.33
DR-GCN76.5572.2574.2178.62
TMP80.8678.0584.8681.77
CGE85.8982.6283.1983.25
MEVD86.9484.1585.6386.21
Table 4. Performance comparison of sliced and original data.
Table 4. Performance comparison of sliced and original data.
DatasetAcc (%)Pre (%)Rec (%)F1 (%)
Reentrancy86.3282.9485.6184.49
Timestamp Dependency85.2181.5483.8686.24
Infinite Loop83.0577.6378.6781.09
VSS + Reentrancy92.1389.4990.1589.28
VSS + Timestamp Dependency90.8589.1792.9891.04
VSS + Infinite Loop86.9484.1585.6386.21
Table 5. Model comparison with different components.
Table 5. Model comparison with different components.
MethodVulnerabilityAcc (%)Pre (%)Rec (%)F1 (%)
MEVD-SReentrancy88.7184.4183.5985.94
Timestamp Dependency85.5283.0189.3286.04
Infinite Loop82.1580.3781.8682.18
MEVD-TReentrancy84.3181.9382.2980.07
Timestamp Dependency82.2480.4685.1782.75
Infinite Loop76.1875.4278.2577.92
MEVD-DReentrancy89.3186.2485.1384.27
Timestamp Dependency85.3483.8287.5885.67
Infinite Loop81.2878.3283.5382.30
MEVDReentrancy92.1389.4990.1589.28
Timestamp Dependency90.8589.1792.9891.04
Infinite Loop86.9484.1585.6386.21
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.

Share and Cite

MDPI and ACS Style

Guo, J.; Lu, L.; Li, J. Smart Contract Vulnerability Detection Based on Multi-Scale Encoders. Electronics 2024, 13, 489. https://doi.org/10.3390/electronics13030489

AMA Style

Guo J, Lu L, Li J. Smart Contract Vulnerability Detection Based on Multi-Scale Encoders. Electronics. 2024; 13(3):489. https://doi.org/10.3390/electronics13030489

Chicago/Turabian Style

Guo, Junjun, Long Lu, and Jingkui Li. 2024. "Smart Contract Vulnerability Detection Based on Multi-Scale Encoders" Electronics 13, no. 3: 489. https://doi.org/10.3390/electronics13030489

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop