Next Article in Journal
Research on a Control Strategy for a Split-Phase Three-Level LCL-Type Grid-Connected Inverter
Previous Article in Journal
A Hard Negatives Mining and Enhancing Method for Multi-Modal Contrastive Learning
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

RTMS: A Smart Contract Vulnerability Detection Method Based on Feature Fusion and Vulnerability Correlations

College of Computer Science and Technology, Taiyuan University of Science and Technology, Taiyuan 030024, China
*
Author to whom correspondence should be addressed.
Electronics 2025, 14(4), 768; https://doi.org/10.3390/electronics14040768
Submission received: 27 December 2024 / Revised: 25 January 2025 / Accepted: 8 February 2025 / Published: 16 February 2025

Abstract

:
Smart contracts are at the core of blockchain technology, but the cost of fixing their security vulnerabilities is high, making pre-deployment vulnerability detection crucial. Existing methods rely on fixed rules, which have limitations in accuracy and scalability, and their efficiency decreases with the complexity of the rules. Neural-network-based methods can identify some vulnerabilities but are inefficient in multi-vulnerability scenarios and depend on source code. To address these issues, we propose a multi-vulnerability-based smart contract detection method called RTMS. RTMS takes bytecode as input, disassembles it into opcodes, uses the gas consumed by the contract for data slicing, and extends the length of input opcodes through a layered structure. It employs a weighted binary cross-entropy (BCE) function to handle data imbalance and combines channel-sequence attention mechanisms to extract vulnerability correlation features. By using transfer learning, it reduces training parameters and computational costs. Our RTMS model can detect multiple vulnerabilities simultaneously, enhancing detection accuracy and efficiency. In experiments with 100,000 real contract samples, the model achieved a Jaccard coefficient of 0.9312, a Hamming loss of 0.0211, and an F1 score that improved by about 11 percentage points compared to existing models, demonstrating its superiority and stability.

1. Introduction

Blockchain technology [1] is essentially a distributed shared transaction ledger, and all nodes in the blockchain network maintain the network with the help of consensus protocols [2]. Blockchain technology has characteristics such as decentralization, tamper-proofing, irreversibility, and traceability. This technology is being researched across multiple industries and has a wide range of applications, such as digital identity [3], cross-border banking [4], and insurance [5].
Ethereum [6] is a well-known programmable blockchain platform that allows us to use the Ethereum Virtual Machine to execute code included in smart contracts. The concept of smart contracts was proposed by Szabo [7] as early as 1994, and it was not until the advent of blockchain technology that a reliable execution environment and application foundation were provided. Smart contracts are essentially computer programs running on the blockchain, written in Turing-complete languages, and can be automatically executed within the blockchain network.
In the past, many traditional vulnerability detection techniques have been used to identify vulnerabilities in smart contracts, including formal verification methods [8], symbolic execution methods [9], fuzzing detection methods [10], and intermediate representation methods [11], etc. For more related research, refer to Section 2.2. However, these methods usually rely on rules set by security experts and have a large memory overhead and are time-consuming during detection.
With the rapid development of deep learning and machine learning technologies, they have shown great potential in the field of smart contract vulnerability detection. These advanced algorithms can automatically extract key features from massive data and perform complex detection tasks with high efficiency and accuracy [12]. Li et al. [13] proposed a method that combines opcodes and LSTM networks, which shows certain performance improvements compared to traditional detection methods. Liu et al. [14] proposed a detection method called DL4SC, which combines transformer–encoder and CNN, with an accuracy rate and F1 score of 95.29% and 95.68%, respectively. For more related research, refer to Section 2.3. However, current machine-learning-based smart contract vulnerability detection methods still face some challenges:
  • Training and detection processes typically rely on source code or its decompiled form. However, in reality, the source code of most smart contracts is not publicly available, and what we can mainly obtain is their bytecode. This situation limits the application scope and effectiveness of traditional methods [15].
  • Many existing detection tools can only detect a single type of vulnerability [16]. However, in actual situations, smart contracts often contain multiple vulnerabilities, and detecting these vulnerabilities one by one can significantly increase the time and computational costs of the detection process, thereby affecting detection efficiency.
  • Many existing text-based detection methods lack effective and independent slicing strategies and cannot extract features from multiple scales.
To address the aforementioned issues, we have introduced an innovative detection method called RTMS for identifying multiple smart contract vulnerabilities. Built upon a multi-layered network framework, RTMS is capable of accurately detecting vulnerabilities such as re-entrancy, permission control, integer overflow, and insecure calling by integrating the associated features between vulnerabilities, thereby significantly enhancing detection accuracy. The system excels at managing complex vulnerability scenarios within a unified model framework and simplifies the detection process by optimizing the use of time and computational resources.
The main contributions of this paper can be summarized as follows:
  • Utilizing opcode as input: We have chosen opcode as the input format. Compared to bytecode, opcode offers stronger expressive power and incurs less information loss during the decompilation process. Moreover, compared to Solidity code, opcode is more accessible and facilitates simpler computation of gas values.
  • Proposing a gas-consumption-based slicing method: We have designed a slicing method based on gas consumption. By prioritizing the analysis of the most logically complex opcode segments, this method enhances the efficiency and accuracy of feature extraction.
  • Employing a hierarchical network structure: We have adopted a hierarchical network structure to expand the range of acceptable input lengths and to extract features from multiple dimensions. This significantly improves the efficiency of feature extraction and the generalization capability of the model.
  • Introducing channel–sequence attention mechanisms: By incorporating channel-sequence attention mechanisms, we enable the model to learn correlations between vulnerabilities and refine initial classification results. This approach markedly enhances the performance and accuracy of multi-vulnerability detection.
The rest of this paper is organized as follows: Section 2 introduces background and related work. Section 3 introduces the overall framework, data preprocessing methods, and the issue of data imbalance. Section 4 provides a detailed exposition of the structural principles of each sub-module. Section 5 presents the experimental results. Section 6 provides conclusion and future outlook.

2. Background

2.1. Classification of Smart Contract Vulnerabilities

RTMS is dedicated to the detection of contracts crafted in Solidity, the premier Turing-complete programming language for smart contracts on the Ethereum platform. In an effort to thoroughly uncover latent security threats, a meticulous selection of four prevalent smart contract vulnerabilities has been subjected to rigorous analysis and scrutiny: re-entrancy attacks [17], deficiencies in permission control [18], integer overflow issues [19], and the vulnerabilities of insecure calling protocols [20].
Re-entrancy attacks leverage the contract’s callback functions, enabling repeated function invocations during execution, which can lead to illicit gains for malefactors.
Permission control deficiencies stem from poor management of access privileges, potentially enabling unauthorized interference, manipulation of contract assets, or even theft of funds.
Integer overflow issues, a consequence of improper integer arithmetic within smart contracts, can result in erroneous computations, miscalculation of assets, and exploitation of logical flaws, posing a significant risk to the integrity of blockchain networks.
Vulnerabilities in secure calling protocols emerge during inter-contract function invocations; mismatches in function and parameter types may trigger the default invocation of a contract’s fallback function, presenting a fresh vector for re-entrancy attacks and potentially facilitating the execution of malicious code or the loss of funds.
These four categories of vulnerabilities are not only exceedingly perilous but also emblematic of the broader security challenges within the smart contract ecosystem. Ample samples of these vulnerabilities exist, providing a rich dataset for training purposes and thereby enhancing the precision of detection mechanisms.

2.2. Method of Smart Contract Vulnerability Detection

Smart contracts, as a core component of blockchain technology, are not only crucial for user experience but also profoundly impact the credit system of blockchain smart contracts. With the increasing popularity of smart contract applications, the issue of vulnerability detection has become a focus in the industry.
In the field of traditional software security detection, KEVM [21] serves as a formal analysis framework that constructs an executable formal specification based on EVM bytecode using the K framework. Jiang et al. [22] proposed the first cross-platform smart contract vulnerability detection framework based on Wasm bytecode using symbolic execution techniques, capable of detecting smart contracts in EOSIO and Ethereum. CrossFuzz [23] leverages fuzz testing methods, optimizing the mutation strategy of transaction sequences based on the data flow information between contracts, thereby enhancing the performance of fuzz testing. Contractsentry [24], based on intermediate representation, extracts key information by constructing contract information and intermediate representation, and builds comprehensive vulnerability detection rules, improving the accuracy of detection. However, these methods typically rely on rules set by security experts and have issues such as large memory overhead and long detection times. With the continuous advancement of deep learning technology, its potential in the field of smart contract vulnerability detection is also increasingly being demonstrated.

2.3. Related Work

In the research field where deep learning is applied to vulnerability detection, Qian [25] et al. proposed a method that combines Bi-LSTM with attention mechanisms for executing vulnerability detection tasks, significantly enhancing performance compared to unidirectional LSTM networks. Wu [26] et al. introduced a method that integrates hybrid attention mechanisms with Bi-GRU networks, which uses fewer parameters, simpler structures, and faster training speeds, matching the performance of Bi-LSTM. Both methods highlight the crucial role of bidirectional networks and attention mechanisms in vulnerability detection tasks.
Compared to numerous RNNs and their variants, the transformer–encoder has a distinct advantage in handling long-term dependencies and complex sequential data [27]. For instance, DL4SC [14] utilizes a combination of transformer–encoder and CNN networks to detect security vulnerabilities in smart contracts, further leveraging the potential of multi-attention mechanisms and improving detection performance. However, this method only extracts features from a single level. Guo [28] et al. proposed the multi-scale semantic encoder detection method MEVD, which comprehensively extracts features through local and global dimensions, thereby enhancing detection performance. Nonetheless, this method’s slicing approach to source code input, relying on vulnerability-related functions, is still limited by rules set by humans.
Tong [29] et al. proposed a multi-vulnerability detection method for smart contracts that combines the SecBERT model with WisdomNet, improving model classification accuracy by excluding difficult-to-classify samples. The SecBERT model employs a bidirectional multi-layer transformer–encoder structure, surpassing a single transformer–encoder in semantic understanding capabilities. However, this method only uses a parallel approach when dealing with multiple classification results, not fully considering the interrelationships between vulnerabilities, and feature extraction is conducted through a single channel. The EDSCVD [30] method combines BERT models, Bi-LSTM, and dual-channel CNN modules for feature extraction to obtain more comprehensive information. Despite this, the method does not expand the input scope of the BERT model, leading to some information loss, and the slicing method still relies on predefined vulnerability-related functions.
To address the aforementioned issues, RTMS employs a hierarchical network structure that allows for input expansion while effectively extracting information, using the CodeBERT model to extract sliced semantic features and bidirectional AGM (attention-based gated memory network) to extract global features. The CodeBERT model, compared to the SecBERT model, has a stronger code understanding capability as it was pre-trained with more code data. By utilizing the gas values consumed by instruction execution, the method selects the most logic-rich opcode segments. This method takes opcode as input, effectively solving the problem of insufficient data sources, and opcode, compared to bytecode, has stronger expressiveness. Compared to Solidity code, bytecode retains more information when disassembled into opcode, reducing information loss. RTMS can detect multiple vulnerabilities simultaneously and fully consider the interrelationships between vulnerabilities, significantly improving the overall Jaccard score by correcting initial classification results.

3. Method

3.1. Overview

As shown in Figure 1, RTMS employs a layered architecture, utilizing multiple CodeBERT models in parallel for local feature extraction, which can expand the range of scalable input and then rely on a bidirectional AGM network to achieve feature extraction at the global level. RTMS first standardizes the collected smart contracts, whether in the form of Solidity or bytecode, into opcode form. Compared to decompiling bytecode back into Solidity code, this method not only fully expresses the code logic with a more concise amount of text but also retains the original information of the bytecode to the greatest extent possible. Subsequently, the sequence of opcodes undergoes simplification processing. Considering that the EVM has over 140 instructions, some of which are logically weak and infrequently used, leading to scattered features. By merging these instructions, feature recognition can be enhanced, allowing the CodeBERT model to more effectively understand the semantics of the code. Next, the data are sliced and divided into several pieces according to a length of 512 tokens, which are then placed into containers. The data in the containers are input into the CodeBERT model for feature extraction, and by accumulating the outputs of the last four hidden layers, local feature vectors are obtained. These feature vectors are then input into the DFE module to map to the hidden layers, and finally, a bidirectional AGM network is used to integrate local features, extract global features, and complete preliminary classification. The preliminary classification results are input into the RTBlock module to extract correlations and refine the classification results. By integrating vulnerability correlations, the accuracy and stability of the classification results can be improved.

3.2. Data Preprocessing

The Ethereum smart contract platform has over 140 opcodes, many of which are functionally similar. To enhance the efficiency of feature extraction, these similar opcodes are merged to increase the concentration of features in the opcode sequence. This merging operation helps simplify the model’s input, making it more efficient.
Considering the input limit of the CodeBERT model is 512 tokens, when the opcode sequence exceeds this limit, it is necessary to process the input sequence appropriately. Within the opcode sequence, we observe consecutively repeated opcodes and logically similar opcodes. By merging these into one, we can effectively reduce the length of the sequence to fit the model’s input limit.
However, even after merging, the length of most opcode sequences still exceeds the input range, and a shard selection strategy will be adopted subsequently. Specifically, we combine the gas consumption table from the Ethereum Yellow Paper [31], and by analyzing the gas consumption of each shard during execution, we assess its logical complexity and importance. This method allows us to identify and select the most valuable shards for further processing, ensuring that the model focuses on the parts of the smart contract that are most critical for security and functionality. In this way, while maintaining the model’s input limit, we maximize the capabilities of the CodeBERT model to achieve more accurate and efficient smart contract vulnerability detection.

3.2.1. Opcode Simplification

Use the pyevmasm library to disassemble the collected bytecode into opcodes within the EVM (Ethereum Virtual Machine) and then simplify the opcodes according to the following steps. The effect of the simplification is shown in Figure 2.
  • Replace specific addresses in the opcodes with the symbol “adr”. Since the majority of vulnerabilities are related to code logic rather than specific address values, this transformation turns irrelevant information into relevant information.
  • Merge similar instructions to increase their frequency, which helps concentrate features and mitigates the issue of overly long input data. For example, instructions like PUSH1–PUSH32, where the number following PUSH indicates the byte size of the PUSH, can be unified into a single PUSH instruction. Additionally, instructions that are infrequently used, have low logic, and have similar functionality, such as TIMESTAMP (to obtain the block timestamp), NUMBER (to obtain the block number), and GASLIMIT (to obtain the block’s gas limit), can be merged into a single BLOCK INFO instruction, which means obtaining block information. To facilitate subsequent operations, remove instructions that consume too much or too little gas within the same group and ultimately, select a group with the same gas consumption. The specific merged instructions are shown in Table 1, with all other instructions remaining unchanged.
  • Remove consecutively appearing instructions. There are many instances of the same instruction appearing consecutively in the opcodes. For example, when the ADDRESS instruction (to get the current account address) appears consecutively, it represents only one logic. In such cases, the repeated instructions should be deleted to reduce the weight of that instruction.
Table 1. Opcode simplification table. Created by the authors.
Table 1. Opcode simplification table. Created by the authors.
SimplifiedOriginal
PUSHPUSH1-PUSH32
LOGLOG0-LOG4
DUPDUP1-DUP16
SWAPSWAP1-SWAP16
BlOCK INFOCOINBASE, TIMESTAMP, NUMBER, GASLIMIT
CONTRACT INFOGAS, ADDRESS, BALANCE, GASPRICE
SYSTEM INFOORIGIN, CODESIZE, EXTCODESIZE, RETURNDATASIZE
CALLCALLER, CALLVALUE, CALLDATALOAD, CALLDATASIZE
LTLT, SLT
GTGT, SGT

3.2.2. Opcode Slicing

The CodeBERT model has an upper limit of 512 tokens when processing inputs. After the expansion of the local encoder, RTMS can handle input lengths of n × 512 tokens, where n represents the number of containers. Despite reducing the length through opcode sequence simplification, most opcode samples still exceed the processing limit of the CodeBERT model. To address this issue, RTMS adopts an innovative strategy that differs from simply truncating the opcode sequence. Instead, it implements a gas consumption-based block selection strategy according to the gas values required for each instruction specified in the Ethereum Yellow Paper.
Algorithm 1. Opcode merging and shard selection algorithm.
Algorithm 1: Algorithm for calculating the maximum gas consumption shard. Created by the authors.
Electronics 14 00768 i001
Furthermore, using a gas-consumption-value-based slicing strategy can also reduce the interference of redundant information on vulnerability detection.
Specifically, RTMS first divides the opcode sequence into multiple blocks of length n × 512 tokens to ensure the coherence of code logic. Subsequently, it calculates the gas consumption of each block using the gas consumption table from the Yellow Paper. Among these blocks, the block with the largest gas consumption usually represents the most logically complex part of the contract and is therefore prioritized for further analysis. This gas- consumption-value-based block selection strategy not only improves the efficiency of feature extraction but also ensures that the model focuses on the most critical parts of smart contract security and functionality. For detailed algorithmic procedures, please refer to the pseudocode in Algorithm 1.

3.3. Data Imbalance Problem

In the field of machine learning, particularly in classification tasks, data imbalance is a common issue that refers to the significant difference in the number of data samples across different categories [32]. This disparity can cause models to favor predicting the majority class while neglecting the characteristics and patterns of the minority class, thereby affecting the model’s generalization ability and accuracy. The uneven distribution of sample sizes in the dataset is the main cause of this problem.
To address the data imbalance issue, RTMS employs a strategy that incorporates a weighted binary cross-entropy (BCE) function. The BCE function is one of the widely used loss functions for handling multi-class classification problems. By introducing a weighting mechanism, RTMS assigns different weights to each type of vulnerability based on the number of samples, giving more attention to those with fewer samples. This approach more effectively balances the model’s learning capabilities across different categories.
L x , y = 1 N i = 1 N j = 1 C x i j l o g y i j + 1 x i j l o g 1 y i j
Equation (1) represents the binary cross-entropy (BCE) function, where x i j denotes the true value of the jth label for the ith sample, and y i j denotes the corresponding predicted probability value by the model. N is the number of samples, and C is the number of labels. To tackle the data imbalance problem, higher weights are assigned to the vulnerability types with fewer instances, leading to the proposal of a modified weighted BCE function.
L ω x , y = 1 N i = 1 N j = 1 C ω j x i j l o g y i j + 1 x i j l o g 1 y i j
η j = 1 n j
w j = η j p = 1 C η p
The improved weighted binary cross-entropy (BCE) formula is as follows, where ω j is the weight for the j-th class, calculated based on the proportion of samples in the total dataset. η j represents the base weight for class j, and n j represents the number of samples for class j. Equation (3) can be adjusted based on the number of samples in each class to achieve an effect where the higher the number of samples, the lower the weight value. To ensure that the sum of the elements in the weight matrix is 1, the base weight matrix is normalized, and the result is w j , which is the normalized weight.

3.4. Transfer Learning

In recent years, transfer learning has been widely applied in the field of software engineering, especially in learning semantic features of code. To enhance performance, many studies pre-train models using a large number of source code snippets. Yuan et al. [33] utilized transfer learning techniques to automatically learn features from the multimodality of Solidity source code, which can be extended across platforms. RTMS employs a layered network structure of local-global encoders, which not only extends the input range but also extracts higher-dimensional features. In the local encoder module, to reduce training overhead, RTMS adopts a pre-training approach. First, the CodeBERT model is trained on an opcode dataset for feature extraction, then it is frozen, and multiple instances are connected in parallel to form a local feature encoder. This approach ensures efficient feature extraction while reducing computational costs, allowing for more CodeBERT instances to be connected in parallel under the same hardware conditions, thereby increasing the size of input slices.

4. Structure

4.1. CodeBERT

RoBERTa model [34], as a variant of the BERT model, has been trained on a larger dataset and employs a dynamic masking mechanism that reduces the probability of repeated masking, allowing the model to adapt to different masking strategies and learn richer linguistic representations. In terms of model architecture, RoBERTa maintains the multi-layer bidirectional transformer–encoder structure of the BERT model, where each unit can absorb information from the current token and the tokens on both its left and right sides, rather than simply reversing the text and inputting it again.
CodeBERT [35] is a pre-trained model proposed by Microsoft, based on the RoBERTa model architecture, specifically designed for understanding and generating programming code, as shown in Figure 3. The CodeBERT model further optimizes this foundation, with pre-training specifically tailored to the characteristics of programming languages, making it more effective in handling code-related tasks such as smart contracts. The pre-training of the CodeBERT model includes not only open-source code repositories but also related documentation, enabling the model to capture rich semantic information of code, providing strong support for subsequent feature extraction and vulnerability detection. Compared to RoBERTa, CodeBERT has a significant advantage in capturing semantic information of code as it is pre-trained on a larger scale of code data. The core of the CodeBERT model lies in its ability to deeply understand the complexity of smart contract code, thereby improving the accuracy of classification in vulnerability detection tasks.

4.2. Detail Future Encoder

The DFE (detail future encoder) module, as a crucial component of the RTMS architecture, is depicted in Figure 4. It utilizes a deep separable convolution structure that integrates dilated convolutions, depthwise convolutions, and pointwise convolutions, along with gating mechanisms, to achieve bidirectional extraction and fusion of local semantic features. This module enhances feature representation by adjusting the features of the reverse input based on the forward input and summing them with the original forward input.
The gating mechanism plays a crucial role in the DFE, acting like a valve in neural networks, allowing the network to selectively pass or discard information at each time step, thereby controlling the flow of information and making the network more flexible and dynamic in processing data. In the forward path of the DFE, the GELU (Gaussian error linear unit) activation function is used to activate the output, which is then element-wise multiplied with the output from the reverse path. This adjusts the strength of the reverse path, achieving bidirectional feature fusion.
The introduction of dilated convolutions, by setting different dilation rates, allows a convolution kernel of the same size to have a larger receptive field, effectively capturing structural features of different scales in the code. The combination of depthwise convolutions and pointwise convolutions forms the deep separable convolution structure, where depthwise convolutions are responsible for capturing local features, and pointwise convolutions are responsible for mixing channel information. This structure maintains the effectiveness of feature extraction while reducing computational load. The mathematical expression of DFE is as follows:
X = G E L U P o i n t w i s e D e p t h w i s e D i l a t e d X
X = P o i n t w i s e D e p t h w i s e D i l a t e d R e v e r s e X
G a t e X = X X
X ^ = L N W p G a t e X + X
In the equation, W p · represents the pointwise convolution layer, W e · represents the depthwise convolution layer, W i · represents the dilated convolution layer, X is the input vector, R e v e r s e is the reversed input vector, X ^ is the output vector, denotes element-wise multiplication, and L N stands for the layer normalization layer. Through this structure, the DFE module not only improves the efficiency of feature extraction but also enhances the model’s understanding of code semantics, providing a solid foundation for the high-performance vulnerability detection of the RTMS model. The use of the DFE structure can integrate bidirectional semantic features, mapping the feature vectors extracted by CodeBERT to the hidden layer.

4.3. Attention-Based Gated Memory Network

The AGM module (attention-based gated memory network), as a key component in the RTMS architecture, is designed to capture long-range dependencies across containers and model global information, as shown in Figure 5. This module utilizes a self-attention mechanism to select important information and integrate it into memory, thereby achieving an in-depth understanding and representation of global features within smart contracts.
The self-attention mechanism endows the AGM module with flexibility in processing data. It learns the weights of the occupied elements to identify and emphasize key features. This mechanism not only enhances the model’s sensitivity to local features but also strengthens its grasp of the global context.
The computation process of the AGM module involves a memory vector m and a gating vector g. The memory vector is used to record important information from local representations, while the gating vector controls which information needs to be retained or forgotten during training. The recursive architecture of the AGM module allows it to update the memory content at each time step, reflecting the most recent learning state.
Taking the output of the DFE module as t 1 , t 2 , . . . , t n , which represents the local representation of the ith container. With the aid of the self-attention mechanism, we learn the weights of the occupied elements.
e i = t a n h W e t i + b e
α i = e x p e i j = 1 | D | e x p e j
Where W e and b e represent the weight matrix and bias term of the attention layer, respectively. The final result α i is the attention score for the ith local vector, which is used as a weight.
g i = s i g m o i d W g t i + U g m i 1
m ^ i = t a n h W h t i + g i U h m i 1
m i = 1 α i m i 1 + α i m ^ i
o = m v ; m 1
In which W g , U g , W h , and U h are trainable weight matrices, m ^ i is the candidate state of the current unit, and m i 1 is the output result of the previous unit. The gate g i determines how much of the previous information from the upper layer needs to be activated, α i determines how much of the previous information needs to be retained and how much information from the candidate state needs to be remembered. To fully extract bidirectional global information, two layers of AGM networks are used, one to extract global features in the forward direction and the other in the reverse direction, concatenating the last unit of the forward layer m v with the first unit of the reverse layer m 1 to form the final output o . The sigmoid function is used to generate independent preliminary classification results. This design enables the AGM module to effectively integrate information from different directions, providing the model with a more comprehensive global feature representation.

4.4. RTBlock

RTBlock is an innovative component in the RTMS architecture, as shown in Figure 6, specifically designed to refine initial classification results by integrating vulnerability correlations, thereby enhancing the overall precision and stability of detection. This module combines channel attention and sequence attention mechanisms to learn the complex correlations between vulnerabilities and effectively capture dependent features across channels and sequences.
The channel attention submodule utilizes a multi-layer perceptron (MLP) to amplify cross-dimensional channel-sequence dependencies, while the sequence attention mechanism integrates channel features and promotes efficient information flow through rearrangement between channels, which helps to capture inter-channel vulnerability correlation features. Together, they accomplish the learning of vulnerability correlations. The formula for RTBlock is as follows:
X c h a n n e l = S i g m o i d L i n e a r G E L U L i n e a r X
X s e q u e n c e = t a n h L a y e r C o n v G E L U L a y e r C o n v X X c h a n n e l
X ^ = X + X s e r i a l
Let X be the original classification result, X c h a n n e l be the output of the channel attention module, and X s e q u e n c e be the output of the sequence attention module. The sequence attention submodule uses X X c h a n n e l as input, allowing it to integrate features learned from the previous channel attention layer. The use of the tanh activation function ensures that the output X s e q u e n c e is distributed within the range (−1, 1), which can uniformly adjust the initial classification results X positively or negatively, yielding the final classification sequence X ^ . The design of RTBlock enables the model not only to learn local features but also to optimize global features by considering the correlations between vulnerabilities, thereby achieving higher accuracy and robustness in multi-vulnerability detection tasks.

5. Experiments

5.1. Datasets

The dataset originates from the slither-audited-smart-contracts dataset [36] on Hugging Face, which contains 106,474 bytecodes of smart contracts as well as 32,481 bytecodes of smart contracts crawled from Ethereum. The pyevmasm library is used for disassembly into opcode sequences, and the Slither [37] tool is used for automatic labeling.
To avoid overfitting, the dataset is divided into training, testing, and validation sets in an 8:1:1 ratio. This tool has marked out 38 detailed types of vulnerabilities. To further reduce data imbalance, similar vulnerabilities among the 38 are merged. The final dataset includes vulnerability types such as access control, integer overflow, re-entrancy, and insecure calls. The number of samples in each category of the dataset is shown in Figure 7.

5.2. Experimental Settings

All experiments were conducted on a machine equipped with 48 GB of RAM and two RTX 3080 GPUs with 20 GB of memory each. The methods were implemented using PyTorch. For details on the parameters used, please refer to Table 2.

5.3. Evaluation Metrics

Precision, recall, and F1 score were used as the evaluation criteria. Precision is the proportion of correctly predicted vulnerabilities out of the total number of predicted vulnerabilities. Recall is the proportion of correctly predicted vulnerabilities out of the total number of actual vulnerabilities. The F1 score strikes a balance between the two and is the harmonic mean of precision and recall. The specific calculations are as follows:
P r e c i s i o n = 1 n i = 1 n | X i Y i | | X i |
r e c a l l = 1 n i = 1 n | X i Y i | | Y i |
F 1 = 2 P r e c i s i o n R e c a l l P r e c i s i o n + R e c a l l
Let X i represent the predicted vulnerability sequence for the ith sample and Y i represent the true vulnerability sequence. n is the total number of samples in the dataset. In multi-label classification problems, the focus is on the degree of match between the predicted label set and the true label set [38]. In addition to these, the Jaccard similarity coefficient and Hamming loss are used to evaluate the overall performance of the model’s predictions. The Jaccard similarity coefficient measures the similarity between two sets, defined as the size of the intersection of the two sets divided by the size of their union. Hamming loss measures the proportion of labels that are inconsistent between the predicted labels and the true labels out of the total number of labels. The specific calculation formulas are as follows, using the average of the samples to represent the overall metrics. Both are commonly used evaluation metrics in multi-label classification problems.
J a c c a r d X , Y = X Y X Y
J = 1 n i = 1 n J a c c a r d X i , Y i
h x , y = j = 1 l 1 x j y j
H = 1 n l i = 1 n h i x i , y i
In this context, l represents the number of labels that each sample may have. h denotes the Hamming distance, which is the number of discrepancies between the predicted labels and the actual labels. The Hamming loss is generally the lower, the better.

5.4. Results Analysis

The purpose of all experiments is to input the opcodes to be detected and output a probability sequence indicating the likelihood of the opcodes having four types of vulnerabilities: re-entrancy, permission control, integer overflow, and insecure calling. The threshold is set at 50%. For example, if a segment of opcodes has both re-entrancy and permission control vulnerabilities, the corresponding probabilities for these two vulnerabilities will be greater than 50%, while the probabilities for the other two vulnerabilities will be below 50%.
To highlight the superiority of RTMS in detecting these four types of vulnerabilities, Table 3 presents a performance comparison with other detection methods (Bi-LSTM-ATT [24], Bi-GRU-ATT [25], MEVD [27], EDSCVD [29]) for vulnerability detection tasks. The performance for detecting the four types of vulnerabilities is primarily assessed across three dimensions: precision, recall, and F1 score.
Bi-LSTM-ATT and Bi-GRU-ATT exhibit similar detection performance across various vulnerabilities, while RTMS can achieve an average improvement of about 15 percentage points in terms of precision, recall, and F1 score. Compared to Bi-LSTM-ATT and Bi-GRU-ATT, MEVD, and EDSCVD can achieve an average improvement of about 10 percentage points in precision, recall, and F1 score, indicating that the use of multi-scale feature fusion can effectively enhance the extraction of vulnerability features. Furthermore, RTMS shows a maximum difference of about three percentage points in these three metrics for different vulnerabilities, whereas Bi-LSTM-ATT and Bi-GRU-ATT show a maximum difference of nearly seven percentage points, and MEVD and EDSCVD show a maximum difference of about five percentage points. This suggests that RTMS provides higher accuracy and stability in detecting various vulnerabilities in smart contracts compared to other methods. This is because RTMS can better extract correlations between vulnerabilities and has a smaller performance variation when dealing with different types of vulnerabilities, possessing better generalization ability and stronger detection accuracy.
Table 4 lists the performance differences resulting from different slicing strategies used during the data preprocessing phase, with a focus on overall evaluation metrics. The GSS strategy refers to selecting slices of length n × 512 tokens that have the highest gas consumption. The GASS strategy refers to sequentially selecting n slices of length 512 tokens, ordered from highest to lowest gas consumption. The OT strategy refers to selecting the first n × 512 tokens as slices, with any insufficient portions padded with zeros and any excess directly truncated.
Analyzing the results in Table 4, it can be observed that the use of slicing strategies significantly improves model performance. RTMS-GSS, which uses the GSS strategy, shows an overall improvement of about two percentage points in Jaccard similarity coefficient compared to RTMS-GASS. This indicates that selecting slices of length n × 512 tokens, rather than n slices of length 512 tokens, maintains semantic coherence and extracts more logical features, thereby enhancing the performance of vulnerability detection.
To demonstrate the ability of different deep learning methods to learn vulnerability correlations, Table 5 and Figure 8 present a performance comparison of RTNetBlock layer using fully connected layers, one-dimensional CNNs, bidirectional LSTMs, self-attention mechanisms, and channel-sequence attention. The performance of extracting correlations between vulnerabilities is measured across five dimensions: precision, recall, F1 score, Jaccard coefficient, and Hamming loss.
From the data presented, it is clear that the use of channel–sequence–attention performs the best in terms of network performance, slightly outperforming the Bi-LSTM structure. It not only achieves higher precision, recall, F1 scores, and Jaccard coefficients compared to the other four networks but also has the lowest Hamming loss, indicating the lowest level of inconsistency between predicted labels and true labels. Furthermore, the precision of the channel-sequence attention is slightly greater than its recall rate, suggesting that the model leans towards being conservative in classification, that is, it tends to reduce false positives.
Table 6 presents the results of ablation studies, which demonstrate the necessity of various components by gradually removing key parts of the model. The RTNet layer consists of three RTBlock structures. The TNet is a network model without the shortcut connection structure, composed of three cascaded channel-sequence attention structures. DL-Encoder represents the local-global encoder structure. DL-Encoder-BiLSTM indicates the use of BiLSTM instead of DFE to map features to the hidden layer. CodeBERT refers to the model that does not use the layered architecture and relies solely on the CodeBERT model for classification.
The comparison reveals that when the shortcut connection structure is removed, there is a significant performance drop, especially in recall and F1 score. This indicates that the shortcut connection structure plays a crucial role in enhancing model performance. Conversely, retaining the shortcut connection can effectively improve vulnerability detection, providing the model with better stability and accuracy in detecting smart contract vulnerabilities. With the shortcut connection retained, the RTNet network aims to refine the initial classification results by leveraging correlations. Without the shortcut connection, it implies a secondary classification based on the original classification results. Additionally, compared to using only the DL-encoder, the inclusion of the RTNet structure leads to a slight improvement in all metrics, demonstrating that the RTNet structure helps extract correlations between vulnerabilities, enhancing the model’s overall detection performance. Replacing DFE with BiLSTM results in a slight decrease in overall performance, suggesting that the dual-channel structure in DFE is more effective than bidirectional networks like BiLSTM in mapping features to the hidden layer.

6. Conclusions and Future Work

6.1. Conclusions

RTMS is a multi-vulnerability detection method for smart contracts based on vulnerability correlations. RTMS addresses the issue of input data selection by utilizing the gas values consumed by smart contracts for data preprocessing. We employ a weighted binary cross-entropy (BCE) function to tackle the problem of data imbalance and design a layered structure to expand the length of input slices while enhancing the performance of feature extraction. Furthermore, RTMS combines channel attention and sequence attention mechanisms to learn the correlations between vulnerabilities, thereby improving the precision and stability of classification results.
The experimental results demonstrate that, in the detection of individual vulnerabilities, RTMS achieves F1 scores of 0.9589 for re-entrancy, 0.9153 for permission control, 0.9459 for integer overflow, and 0.9289 for insecure calling. Compared to other detection methods, these scores represent improvements of 8.47%, 9.69%, 9.58%, and 13.16%, respectively. Additionally, RTMS’s overall Jaccard coefficient for multi-vulnerability detection reaches 0.9312, which can be enhanced by 17.71% through the gas-value-based slicing strategy.

6.2. Future Work

Although RTMS has demonstrated superior performance in experiments, there is still room for improvement. Currently, the adjustments made to the CodeBERT model during subsequent training are insufficient, and the dataset we have collected is relatively limited in terms of vulnerability types, encompassing only four specific categories: re-entrancy, permission control, integer overflow, and insecure calling. Future research will focus on optimizing the fine-tuning strategy for the CodeBERT model, collecting more diverse datasets, and combining syntactic features to optimize the information extraction algorithm to enhance the model’s information processing capabilities. We will continue to follow the latest developments in the field of software vulnerability detection and the field of large language models, and we look forward to deeper optimization of the RTMS model.
The application of smart contracts is developing in a more complicated direction. We propose the following recommendations for addressing smart contract security issues and the above shortcomings:
  • Build authoritative datasets. Future efforts should be directed towards gathering datasets that encompass a broader spectrum of vulnerability types. Additionally, it is essential to standardize the format of these datasets, facilitating the data preprocessing work for subsequent researchers. By expanding existing datasets, we can provide richer resources for the training and evaluation of deep learning models, thereby enhancing their performance and reliability.
  • Research vulnerability remediation strategies. Currently, relevant research is still mainly focused on the detection of contract vulnerabilities. In the future, security research can be conducted on vulnerability contracts to help relevant researchers understand the logic behind contract vulnerabilities.
  • Develop integrated static and dynamic analysis models. Focus on addressing the limitations of our current deep learning approach, which relies heavily on static source code analysis and may miss certain execution paths, leading to false positives. Integrate detection tools across different levels to enhance the identification of vulnerabilities in contracts.

Author Contributions

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

Funding

This study is funded by the Natural Science Research Project of the Shanxi Provincial Basic Research Program, China, with the funding number 202403021221141.

Data Availability Statement

The original contributions presented in this study are included in the article. Further inquiries can be directed to the corresponding author.

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 conflicts of interest.

References

  1. Swan, M. Blockchain: Blueprint for a New Economy; O’Reilly Media, Inc.: Sebastopol, CA, USA, 2015. [Google Scholar]
  2. Sankar, L.S.; Sindhu, M.; Sethumadhavan, M. Survey of consensus protocols on blockchain applications. In Proceedings of the 2017 4th International Conference on Advanced Computing and Communication Systems (ICACCS), Coimbatore, India, 6–7 January 2017; IEEE: Piscataway, NJ, USA, 2017; pp. 1–5. [Google Scholar]
  3. Yang, X.; Li, W. A zero-knowledge-proof-based digital identity management scheme in blockchain. Comput. Secur. 2020, 99, 102050. [Google Scholar] [CrossRef]
  4. Rahman, M.S.; Al Omar, A.; Alam Bhuiyan, Z.; Basu, A.; Kiyomoto, S.; Wang, G. Accountable cross-border data sharing using blockchain under relaxed trust assumption. IEEE Trans. Eng. Manag. 2020, 67, 1476–1486. [Google Scholar] [CrossRef]
  5. Wan, Z.; Guan, Z.; Cheng, X. PRIDE: A private and decentralized usage-based insurance using blockchain. 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; IEEE: Piscataway, NJ, USA, 2018; pp. 1349–1354. [Google Scholar]
  6. Buterin, V. A next-generation smart contract and decentralized application platform. White Pap. 2014, 3, 13. [Google Scholar]
  7. Szabo, N. Smart contracts: Building blocks for digital markets. EXTROPY J. Transhumanist Thought 1996, 18, 28. [Google Scholar]
  8. Bhargavan, K.; Delignat-Lavaud, A.; Fournet, C.; Gollamudi, A.; Gonthier, G.; Kobeissi, N.; Kulatova, N.; Rastogi, A.; Sibut-Pinote, T.; Swamy, N.; et al. Formal verification of smart contracts: Short paper. In Proceedings of the 2016 ACM Workshop on Programming Languages and Analysis for Security, Vienna, Austria, 24 October 2016; pp. 91–96. [Google Scholar]
  9. Mossberg, M.; Manzano, F.; Hennenfent, E.; Groce, A.; Grieco, G.; Feist, J.; Brunson, T.; Dinaburg, A. Manticore: A user-friendly symbolic execution framework for binaries and smart contracts. In Proceedings of the 2019 34th IEEE/ACM International Conference on Automated Software Engineering (ASE), San Diego, CA, USA, 11–15 November 2019; IEEE: Piscataway, NJ, USA, 2019; pp. 1186–1189. [Google Scholar]
  10. Takanen, A.; Demott, J.D.; Miller, C.; Kettunen, A. Fuzzing for Software Security Testing and Quality Assurance; Artech House: New York, NY, USA, 2018. [Google Scholar]
  11. Chen, H.; Pendleton, M.; Njilla, L.; Xu, S. A survey on ethereum systems security: Vulnerabilities, attacks, and defenses. ACM Comput. Surv. (CSUR) 2020, 53, 1–43. [Google Scholar] [CrossRef]
  12. Hu, H.; Bai, Q.; Xu, Y. Scsguard: Deep scam detection for ethereum smart contracts. In Proceedings of the IEEE INFOCOM 2022-IEEE Conference on Computer Communications Workshops (INFOCOM WKSHPS), Virtual Conference, 2–5 May 2022; IEEE: Piscataway, NJ, USA, 2022; pp. 1–6. [Google Scholar]
  13. Li, P.; Wang, G.; Xing, X.; Zhu, J.; Gu, W.; Zhai, G. A smart contract vulnerability detection method based on deep learning with opcode sequences. Peer-to-Peer Netw. Appl. 2024, 17, 3222–3238. [Google Scholar] [CrossRef]
  14. Liu, Y.; Wang, C.; Ma, Y. DL4SC: A novel deep learning-based vulnerability detection framework for smart contracts. Autom. Softw. Eng. 2024, 31, 24. [Google Scholar] [CrossRef]
  15. Surucu, O.; Yeprem, U.; Wilkinson, C.; Hilal, W.; Gadsden, S.A.; Yawney, J.; Alsadi, N.; Giuliano, A. A survey on ethereum smart contract vulnerability detection using machine learning. Disruptive Technol. Inf. Sci. VI 2022, 12117, 110–121. [Google Scholar]
  16. Qian, P.; Liu, Z.; He, Q.; Huang, B.; Tian, D.; Wang, X. Smart contract vulnerability detection technique: A survey. arXiv 2022, arXiv:2209.05872. [Google Scholar]
  17. 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]
  18. Sun, T.; Yu, W. A formal verification framework for security issues of blockchain smart contracts. Electronics 2020, 9, 255. [Google Scholar] [CrossRef]
  19. Torres, C.F.; Schütte, J.; State, R. Osiris: Hunting for integer bugs in ethereum smart contracts. In Proceedings of the 34th Annual Computer Security Applications Conference, San Juan, PR, USA, 3–7 December 2018; pp. 664–676. [Google Scholar]
  20. Zheng, Z.B.; Wang, C.D.; Cai, J.H. Analysis of the current status of smart contract security research and detection methods. Inf. Secur. Commun. Priv. 2020, 7, 93–105. [Google Scholar]
  21. Hildenbrandt, E.; Saxena, M.; Rodrigues, N.; Zhu, X.; Daian, P.; Guth, D.; Moore, B.; Park, D.; Zhang, Y.; Stefanescu, A.; et al. Kevm: A complete formal semantics of the ethereum virtual machine. In Proceedings of the 2018 IEEE 31st Computer Security Foundations Symposium (CSF), Oxford, UK, 9–12 July 2018; IEEE: Piscataway, NJ, USA, 2018; pp. 204–217. [Google Scholar]
  22. Jiang, B.; Chen, Y.; Wang, D.; Ashraf, I.; Chan, W.K. WANA: Symbolic execution of wasm bytecode for extensible smart contract vulnerability detection. In Proceedings of the 2021 IEEE 21st International Conference on Software Quality, Reliability and Security (QRS), Hainan, China, 6–10 December 2021; IEEE: Piscataway, NJ, USA, 2021; pp. 926–937. [Google Scholar]
  23. Yang, H.; Gu, X.; Chen, X.; Zheng, L.; Cui, Z. CrossFuzz: Cross-contract fuzzing for smart contract vulnerability detection. Sci. Comput. Program. 2024, 234, 103076. [Google Scholar] [CrossRef]
  24. Wang, S.; Zhao, X. Contractsentry: A static analysis tool for smart contract vulnerability detection. Autom. Softw. Eng. 2025, 32, 1. [Google Scholar] [CrossRef]
  25. Qian, S.; Ning, H.; He, Y.; Chen, M. Multi-label vulnerability detection of smart contracts based on Bi-LSTM and attention mechanism. Electronics 2022, 11, 3260. [Google Scholar] [CrossRef]
  26. 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]
  27. Wen, Q.; Zhou, T.; Zhang, C.; Chen, W.; Ma, Z.; Yan, J.; Sun, L. Transformers in time series: A survey. arXiv 2022, arXiv:2202.07125. [Google Scholar]
  28. Guo, J.; Lu, L.; Li, J. Smart Contract Vulnerability Detection Based on Multi-Scale Encoders. Electronics 2024, 13, 489. [Google Scholar] [CrossRef]
  29. Tong, V.; Dao, C.; Tran, H.-A.; Tran, T.X.; Souihi, S. Enhancing BERT-Based Language Model for Multi-label Vulnerability Detection of Smart Contract in Blockchain. J. Netw. Syst. Manag. 2024, 32, 63. [Google Scholar] [CrossRef]
  30. Wu, H.; Peng, Y.; He, Y.; Lu, S. EDSCVD: Enhanced Dual-Channel Smart Contract Vulnerability Detection Method. Symmetry 2024, 16, 1381. [Google Scholar] [CrossRef]
  31. Wood, G. Ethereum: A secure decentralised generalised transaction ledger. Ethereum Proj. Yellow Pap. 2014, 151, 1–32. [Google Scholar]
  32. Mujahid, M.; Kına, E.; Rustam, F.; Villar, M.G.; Alvarado, E.S.; Diez, I.D.L.T.; Ashraf, I. Data oversampling and imbalanced datasets: An investigation of performance for machine learning and feature engineering. J. Big Data 2024, 11, 87. [Google Scholar] [CrossRef]
  33. Yuan, D.; Wang, X.; Li, Y.; Zhang, T. Optimizing smart contract vulnerability detection via multi-modality code and entropy embedding. J. Syst. Softw. 2023, 202, 111699. [Google Scholar] [CrossRef]
  34. Liu, Y. RoBERTa: A robustly optimized BERT pretraining approach. arXiv 2019, arXiv:1907.11692. [Google Scholar]
  35. Feng, Z.; Guo, D.; Tang, D.; Duan, N.; Feng, X.; Gong, M.; Shou, L.; Qin, B.; Liu, T.; Jiang, D.; et al. Codebert: A pre-trained model for programming and natural languages. arXiv 2020, arXiv:2002.08155. [Google Scholar]
  36. Rossini, M. Slither Audited Smart Contracts Dataset. 2022. Available online: https://huggingface.co/datasets/mwritescode/slither-audited-smart-contracts/ (accessed on 6 February 2025).
  37. 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), Montréal, QC, Canada, 27 May 2019; IEEE: Piscataway, NJ, USA, 2019; pp. 8–15. [Google Scholar]
  38. Bogatinovski, J.; Todorovski, L.; Džeroski, S.; Kocev, D. Comprehensive comparative study of multi-label classification methods. Expert Syst. Appl. 2022, 203, 117215. [Google Scholar] [CrossRef]
Figure 1. RTMS structural diagram. Created by the authors.
Figure 1. RTMS structural diagram. Created by the authors.
Electronics 14 00768 g001
Figure 2. Opcode simplification effect diagram. Created by the authors.
Figure 2. Opcode simplification effect diagram. Created by the authors.
Electronics 14 00768 g002
Figure 3. Internal Structure of the CodeBERT model. Created by the authors.
Figure 3. Internal Structure of the CodeBERT model. Created by the authors.
Electronics 14 00768 g003
Figure 4. DFE structure diagram. Created by the authors.
Figure 4. DFE structure diagram. Created by the authors.
Electronics 14 00768 g004
Figure 5. AGM unit structure diagram. Created by the authors.
Figure 5. AGM unit structure diagram. Created by the authors.
Electronics 14 00768 g005
Figure 6. RTBlock structure diagram. Created by the authors.
Figure 6. RTBlock structure diagram. Created by the authors.
Electronics 14 00768 g006
Figure 7. The proportion of each type of vulnerability in the dataset. Created by the authors.
Figure 7. The proportion of each type of vulnerability in the dataset. Created by the authors.
Electronics 14 00768 g007
Figure 8. The ability of different neural network structures to learn vulnerability correlations. Created by the authors.
Figure 8. The ability of different neural network structures to learn vulnerability correlations. Created by the authors.
Electronics 14 00768 g008
Table 2. Parameters of the MEVD model. Created by the authors.
Table 2. Parameters of the MEVD model. Created by the authors.
ParameterValue
OptimizerAdam
Learning rate2 × 10−5
Dropout rate0.3
Batch size16
Epochs30
Table 3. Detection performance of five methods for four types of vulnerabilities. Created by the authors based on experimental results.
Table 3. Detection performance of five methods for four types of vulnerabilities. Created by the authors based on experimental results.
VulnerabilityMetricsRTMSBi-LSTM-ATTBi-GRU-ATTMEVDEDSCVD
Re-entrancypre0.96620.78570.81590.89180.8778
rec0.95190.81280.83720.92660.8706
F10.95890.79910.82640.90890.8742
Permission Controlpre0.93290.71090.75270.85930.8342
rec0.89820.74610.74510.87440.8032
F10.91530.72810.74890.86680.8184
Integer Overflowpre0.95380.76110.78190.89720.8664
rec0.93810.79160.82810.90700.8342
F10.94590.77610.80430.90210.8501
Insecure
Calling
pre0.94680.71860.76590.81860.8090
rec0.92160.75950.79510.82420.7789
F10.92890.73850.78020.82130.7937
Table 4. The performance of RTMS using different data slicing techniques. Created by the authors based on experimental results.
Table 4. The performance of RTMS using different data slicing techniques. Created by the authors based on experimental results.
MethodPrecisionRecallF1 ScoreJaccardHamming
RTMS-GSS0.94980.93410.94190.93120.0211
RTMS-GASS0.93370.92850.93110.91040.0285
RTMS-OT0.86360.72040.78550.75410.1027
Table 5. Comparison of the ability to learn vulnerability correlations using different neural network structures. Created by the authors based on experimental results.
Table 5. Comparison of the ability to learn vulnerability correlations using different neural network structures. Created by the authors based on experimental results.
MethodPrecisionRecallF1 ScoreJaccardHamming
Dense0.90260.88730.89490.87620.0687
1DCNN0.92820.90520.91660.90690.0373
Bi-LSTM0.93310.91760.92530.91040.0285
Self-Attention0.93070.91540.92300.90780.0314
Channel-Sequence-Attention0.94980.93410.94190.93120.0211
Table 6. Ablation study. Created by the authors based on experimental results.
Table 6. Ablation study. Created by the authors based on experimental results.
MethodPrecisionRecallF1 ScoreJaccardHamming
DL-Encoder-RTNet0.94980.93410.94190.93120.0211
DL-Encoder-TNet0.75240.62630.68360.64860.2784
DL-Encoder0.91620.90170.90890.88120.0724
DL-Encoder-BiLSTM0.93860.92310.93070.91720.0261
CodeBERT0.87520.73140.78950.72670.1054
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

Gao, G.; Li, Z.; Jin, L.; Liu, C.; Li, J.; Meng, X. RTMS: A Smart Contract Vulnerability Detection Method Based on Feature Fusion and Vulnerability Correlations. Electronics 2025, 14, 768. https://doi.org/10.3390/electronics14040768

AMA Style

Gao G, Li Z, Jin L, Liu C, Li J, Meng X. RTMS: A Smart Contract Vulnerability Detection Method Based on Feature Fusion and Vulnerability Correlations. Electronics. 2025; 14(4):768. https://doi.org/10.3390/electronics14040768

Chicago/Turabian Style

Gao, Gaimei, Zilu Li, Lizhong Jin, Chunxia Liu, Junji Li, and Xiangqi Meng. 2025. "RTMS: A Smart Contract Vulnerability Detection Method Based on Feature Fusion and Vulnerability Correlations" Electronics 14, no. 4: 768. https://doi.org/10.3390/electronics14040768

APA Style

Gao, G., Li, Z., Jin, L., Liu, C., Li, J., & Meng, X. (2025). RTMS: A Smart Contract Vulnerability Detection Method Based on Feature Fusion and Vulnerability Correlations. Electronics, 14(4), 768. https://doi.org/10.3390/electronics14040768

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