An intelligent contract vulnerability detection method combining adversarial transfer learning and multi-task learning

By combining adversarial transfer learning and multi-task learning into a hybrid parameter-sharing framework, the problems of low detection accuracy and poor applicability in smart contract vulnerability detection are solved, achieving efficient and accurate contract vulnerability detection that is suitable for large-scale contract detection.

CN116595530BActive Publication Date: 2026-06-02BEIJING UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING UNIV OF TECH
Filing Date
2022-12-08
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection methods suffer from low detection accuracy, poor applicability, high false positive rate, and are not friendly to the detection of contracts with small or scarce data, especially machine learning methods which require a large amount of labeled data.

Method used

By combining adversarial transfer learning and multi-task learning, a smart contract vulnerability detection model is constructed through a hybrid parameter-sharing multi-task learning framework to extract general features and task-specific features. Adversarial transfer learning is also introduced to reduce the impact of noise. The model includes data preprocessing, model building, and detection stages.

Benefits of technology

It achieves accurate and efficient automatic detection of smart contract vulnerabilities, is suitable for large-scale contract vulnerability detection, improves detection accuracy and applicability, and reduces dependence on data volume.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116595530B_ABST
    Figure CN116595530B_ABST
Patent Text Reader

Abstract

The application discloses an intelligent contract vulnerability detection method combining adversarial transfer learning and multi-task learning. First, in the data preprocessing stage, the operation code sequence formed by the decompilation of the intelligent contract sample source code is processed by using an N-Gram language model to construct a 2-gram operation code syntax sequence, and the input of the model is formed. Secondly, in the model construction stage, a bottom shared layer based on a mixed parameter sharing architecture design is constructed to extract general features and private features; a top task layer of a multi-task classification network based on a neural network is constructed to realize the detection and identification tasks of the intelligent contract vulnerability; and finally, the intelligent contract vulnerability detection model is constructed by combining adversarial transfer learning and multi-task learning. In the training stage, the 2-gram operation code syntax sequence obtained in the data preprocessing stage is input into the model for training, and the application has good generalization performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of blockchain smart contract security technology, specifically involving a vulnerability detection method for smart contracts that combines adversarial transfer learning and multi-task learning. Background Technology

[0002] Blockchain technology is a novel distributed infrastructure and computing method that utilizes a block-chain data structure to verify and store data, distributed node consensus algorithms to generate and update data, cryptography to ensure the security of data transmission and access, and smart contracts to program and manipulate data. Smart contracts, as a key technology and computer transaction protocol for executing contract terms, have always attracted considerable attention from researchers. Their security is of paramount concern because smart contracts store and manage large amounts of financial assets and operate in an open and transparent network, increasing the risk of attacks and potentially leading to significant economic losses. The increasingly serious security problems of blockchain and the resulting economic losses are becoming increasingly substantial, prompting widespread attention to the security of smart contracts.

[0003] However, security checks on smart contracts are still in their early stages and require improvement through practice. Although many security tools are available, they are immature and have various problems. Security tools based on symbolic analysis can achieve accurate and comprehensive degree analysis, but are susceptible to program branches and loops, facing the problem of path explosion. Security tools based on formal verification strictly use mathematical logic reasoning and proof to determine whether the contract logic meets security attributes, with high detection accuracy, but low automation and difficulty in detecting a large number of contracts. Security tools based on fuzzing mainly use randomly generated test samples to trigger vulnerabilities and monitor abnormal behavior during program execution. Although they achieve dynamic detection, their detection accuracy is low and their applicability is poor. Static analysis tools based on program analysis are also widely used in contract vulnerability detection, but have a high false positive rate. Machine learning-based vulnerability detection methods have become the most popular in recent years. This method extracts features from massive amounts of data for subsequent detection and identification. It has a high degree of automation and good scalability, but requires a large amount of labeled data for learning, making it unfriendly to small data or vulnerability types that are difficult to collect.

[0004] To address the aforementioned issues, this invention provides a smart contract vulnerability detection method that combines adversarial transfer learning and multi-task learning. This method is based on a hybrid parameter-sharing multi-task learning framework, focusing on shared layer learning to extract general features and task-specific features. Simultaneously, the model optimizes existing multi-task model frameworks and uses adversarial transfer learning to mitigate the noise impact of task-specific differences during model training, thereby improving detection accuracy. Summary of the Invention

[0005] This invention proposes a smart contract vulnerability detection method by combining adversarial transfer learning and multi-task learning. In this invention, multi-task learning is mainly used to jointly learn multiple tasks, enabling knowledge sharing among them and thus improving the performance of each task. Multi-task learning should not only learn common knowledge among tasks but also the unique knowledge of each task. To this end, this invention implements a hybrid sharing framework, dividing and differentiating sharing layers, and giving each task a unique sharing layer fusion method, so that each task has its own model and parameters, and achieves inter-level sharing of parameters. Simultaneously, this invention introduces adversarial transfer learning knowledge to reduce the mutual interference between general features and private features, providing as many general features as possible. In summary, this invention proposes a smart contract vulnerability detection method by combining adversarial transfer learning and multi-task learning.

[0006] Specifically, including:

[0007] In the data preprocessing stage, the smart contract source code is compiled and cleaned into valid bytecode of the contract. Then, the valid bytecode is decompiled into an opcode sequence. Then, the N-Gram language model is used to process and construct a 2-gram opcode syntax sequence, which forms the input sequence of the model as the input of the model.

[0008] In the model building phase, firstly, a multi-task learning framework based on hybrid parameter sharing is constructed to extract general and private features. This addresses the limitation of hard parameter sharing frameworks in constraining the shared layer, preventing it from being affected by additional noise while providing information gain. Then, adversarial transfer learning is introduced, utilizing game theory principles to reduce noise contamination of general features by task features and mitigate mutual interference between general and private features. Secondly, a neural network-based multi-task classification network is constructed as the top task layer of the multi-task learning framework to implement the detection and identification of smart contract vulnerabilities. Finally, the bottom shared layer and the top task layer are combined to construct the overall model, forming a smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning.

[0009] In the smart contract vulnerability detection phase, the source code of the smart contract to be detected is processed into a 2-gram syntax opcode sequence according to the processing method in the data preprocessing phase. Then, it is input into the constructed multi-task smart contract vulnerability detection model based on adversarial transfer learning to realize multiple task functions, including identifying vulnerable contracts (binary classification task) and recognizing multiple vulnerability types (multi-label classification task), etc.

[0010] In summary Figure 1 As shown, the present invention mainly includes three stages: data preprocessing stage, model building stage, and contract vulnerability detection stage.

[0011] (1) The data preprocessing stage includes:

[0012] 1.1) Collect and organize the vulnerability types to be detected, including: classifying and labeling the vulnerability types to be detected. The labels are X = [x1, x2, ..., x...]. n ], where n represents the various vulnerability types that need to be detected, x i =0 indicates that the smart contract sample does not belong to the i-th type of vulnerability, x i =1 indicates that the contract sample belongs to the i-th type of vulnerability.

[0013] 1.2) Compile and clean the smart contract source code into valid bytecode, and then decompile the valid bytecode into an opcode sequence;

[0014] Smart contract source code is difficult to obtain and contains too many human variables, making source code analysis unsuitable. However, smart contracts run on the blockchain in bytecode form, which is readily available; therefore, contract bytecode is used as input for model analysis. On the other hand, bytecode represents specific operation sequences and parameters, and due to its long length, it is difficult to analyze and model. Therefore, using bytecode as direct input is impractical and requires further processing. In this invention, the bytecode will be further decompiled to generate opcode sequences, simplifying and constructing the model input.

[0015] 1.3) Use the N-Gram language model to process and construct the 2-gram opcode syntax sequence, forming the input sequence of the model as the input of the model.

[0016] The opcode sequence also represents the order of operations in the contract to some extent. The N-Gram language model is used to process the opcode sequence and a 2-gram opcode syntax sequence is constructed to obtain better opcode context information and improve the robustness of the model.

[0017] (2) The model construction stage includes:

[0018] 2.1) Construct a multi-task learning framework based on hybrid parameter sharing. In the bottom shared layer of the framework, a task-shared feature extraction layer and a task-specific feature extraction layer are constructed to extract 2-gram opcode features, i.e., general features and private features;

[0019] Specifically, this invention divides the shared layer, giving each task a unique shared layer fusion method, so that each task has its own obtained model and parameters, and achieves inter-level sharing of parameters, constructing a hybrid parameter sharing framework, the framework structure of which is as follows: Figure 2 As shown, the overall structure of the model is as follows: Figure 3 As shown.

[0020] 2.2) Task Sharing and Private Feature Extractor Design

[0021] This invention uses BiLSTM to construct a task-sharing layer and a private layer, i.e., a feature extractor, as shown in the following structure. Figure 4 As shown.

[0022] Recurrent Neural Networks (RNNs) are neural networks suitable for learning features from sequential data and have achieved excellent performance in sequential learning problems such as speech recognition and natural language processing. However, RNNs suffer from the vanishing and exploding gradient problems, which make them difficult to train correctly. To address the vanishing, exploding, and long-term dependency issues in RNNs, this invention uses a Long Short-Term Memory (LSTM) neural network as the shared layer network.

[0023] Long Short-Term Memory (LSTM) neural networks, a variant of Recurrent Neural Networks (RNNs), address the vanishing and exploding gradient problems in RNNs by introducing gating networks and storage units to control the flow of information in any given repeating unit (input gate, forget gate, and output gate). The LSTM architecture is as follows: Figure 5 As shown, where c t It is a storage unit, h t It is a hidden state, where t is time. A storage unit c is introduced. t For internal long-term storage, c t and h t All will pass through three gates (input gate i) t Forgotten Gate t and output gate o t The function is used to calculate, in order to ensure the long-term and short-term storage of information, as shown in formulas (1) and (2):

[0024] c t =f t ⊙c t-1 +i t ⊙g t #(1)

[0025] ht =o t ⊙tanh(c t )#(2)

[0026] In the above formula, tanh(·) is the hyperbolic tangent function, while ⊙ represents element-wise multiplication in the opcode matrix.

[0027] Forgotten Gate f t By multiplying c t Storage unit c directly connected to the previous neural unit t-1 Input gate i t and output gate o t Controls the information flow within a neural unit. Each gate function has its own weight matrix w. x In this invention, the forgetting gate function is represented by the subscript f, the input gate function by i, and the output gate function by o. The input gate i in LSTM... t Forgotten Gate t Output gate o t The calculation is as shown in formulas (3)(4)(5):

[0028] i t =sigmoid(w xi x t +w hi h t-1 +b i )#(3)

[0029] f t =sigmoid(w xf x t +w hf h t-1 +b f )#(4)

[0030] o t =sigmoid(w xo x o +w ho h t-1 +bo ) #(5) The gating function is calculated as shown in formula (6):

[0031] g t =tanh(w xg x t +w hg h t-1 +bg ) #(6)

[0032] However, unidirectional LSTM can only use past information and ignores future information. To integrate information from both sides of the sequence, this invention employs a bidirectional long short-term memory neural network (BiLSTM) to extract contract features, such as... Figure 4 As shown. Specifically, the forward hidden state representation of BiLSTM is calculated as shown in Equation (7):

[0033]

[0034] The backward hidden state representation is calculated as shown in formula (8):

[0035]

[0036] The overall hidden state representation is calculated as shown in formula (9):

[0037]

[0038] In the formula, This represents matrix addition between two hidden states.

[0039] A shared BiLSTM feature extractor is used to learn features common to the task. The calculation of the hidden state in the task is shown in Equation (10):

[0040] s t =BiLSTM(x t ,s t-1 ;θ s )#(10)

[0041] In the formula, θ s This indicates that the parameters in the shared BiLSTM feature extractor are used.

[0042] The dedicated BiLSTM feature extractor is used to extract specific features in the task, and the calculation of the hidden state of the task is shown in formula (11):

[0043] p t =BiLSTM(x t ,p t-1 ;θ p )#(11)

[0044] In the formula, θ p This represents the parameters in the BiLSTM feature extractor.

[0045] 2.3) Attention Network Design

[0046] After the contract 2-gram opcode sequence is described by BiLSTM, it will be input into the attention network for feature learning and extraction. When the model processes each word of the input sequence, the attention network will pay attention to all words in the entire input sequence, which can help the model to see other positions in the input sequence and find relevant clues to achieve better encoding effect. The calculation formula is shown in (12):

[0047]

[0048] Simultaneously, multi-head attention is superimposed to improve the attention network, enhance its performance, and expand the model's ability to focus on different positions. The multi-head self-attention network maintains an independent vector weight matrix for each head, thus generating different vector matrices. The matrices generated by each head are then concatenated and multiplied by an additional weight matrix, resulting in a matrix that fuses information from all attention heads. This matrix is ​​then fed into a feed-forward network to output the results of the feature network layer. Specific calculations are shown in formulas (13), (14), and (15).

[0049]

[0050] MultiHead(Q,K,V)=Concat(head1,…,head h W O #(14)

[0051] Output=LayerNorm(x+FFN(x)#(15)

[0052] 2.4) Design of a multi-task classification network based on neural networks

[0053] A neural network-based multi-task classification network is constructed as the top task layer of the multi-task learning framework. Specific task layers are constructed by building different branch network layers based on different tasks to achieve two tasks. In the contract vulnerability detection task branch, a binary classification neural network is constructed. This classification consists of a fully connected layer (FC), an activation layer (Sigmoid), and a dropout layer, as shown below. Figure 6 As shown, the classification network uses focal loss, and the calculation formula is shown in (16):

[0054]

[0055] In the multi-vulnerability type identification task branch, a multi-classification convolutional neural network is constructed. This classification network includes pooling layers, dropout layers, and fully connected (FC / Dense) layers, such as... Figure 7As shown, this classification network uses cross-entropy loss, and the calculation formula is shown in (17):

[0056]

[0057] To accomplish their respective specific tasks, the vulnerability assessment task branch will be connected to a classification layer, which will perform classification operations using the sigmoid function and directly output the results; while the multi-vulnerability type identification task branch will be connected to an FC layer to further reduce dimensionality, and then connected to a classification layer, which will perform classification operations using the softmax function and output the results.

[0058] 2.5) Gradient Inversion Layer Design

[0059] To distinguish between task-general and task-specific features, adversarial transfer learning (GRL) is introduced. This leverages game theory principles to reduce noise contamination of general features caused by task-specific features and mitigate mutual interference between general and private features. A gradient reversal layer is designed. Specifically, features extracted from the shared layer undergo dimensionality reduction in a fully connected layer (FC), and then the gradient is inverted by the GRL, multiplying the gradient input to the GRL by a negative number. This reverses the training objectives of the networks before and after the GRL. The gradient reversal layer network structure is designed as follows: Figure 8 As shown.

[0060] Inspired by adversarial networks, adversarial transfer learning is introduced to ensure that task-specific and task-specific features are distinguished as much as possible. To this end, a gradient inversion layer is used, which automatically inverts the gradient direction during backpropagation and achieves an identity transformation during forward propagation. Simultaneously, a discriminator is used to determine which task a feature belongs to, calculated as shown in formula (18):

[0061]

[0062] In the formula, θ D These are discriminator parameters, W D b D These are the weight parameters of the discriminator. An adversarial loss function is also introduced to prevent task-specific features from mixing with shared features; the calculation formula is shown in (19).

[0063]

[0064] In the formula, E s Represents a shared feature extractor, θ s These are the parameters of the shared feature extractor.

[0065] Although adversarial learning can largely separate general and private features, feature redundancy is inevitable. To address this issue, based on the paper, orthogonality constraints are used to improve the model's ability to extract domain-invariant features. The calculation formula is shown in (20).

[0066]

[0067] In the formula, S k and P k There are two matrices, each row of which represents the output of the general feature extractor and the private feature extractor in the shared layer of the input text features, that is, the general features and the private features.

[0068] Therefore, the overall loss of the multi-task learning model is calculated as shown in formula (21).

[0069] Loss MTL =∑w i ·L i +γL Adv +λL Diff #(twenty one)

[0070] Where w i It is the weight of each task, L i It is the loss function for different tasks, i.e., L Tower A and L Tower B . Attached Figure Description

[0071] Figure 1 This is a flowchart illustrating the steps of the smart contract detection method of the present invention.

[0072] Figure 2 This is the hybrid parameter sharing framework described in this invention.

[0073] Figure 3 This is the overall architecture of the smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning as described in this invention.

[0074] Figure 4 This refers to the BiLSTM structure in the model.

[0075] Figure 5 This refers to the LSTM structure.

[0076] Figure 6 Neural network structure for contract vulnerability assessment task.

[0077] Figure 7 Neural network structure for identifying multiple vulnerability types.

[0078] Figure 8 Design a gradient inversion layer for the model. Detailed Implementation

[0079] The present invention will be described in detail with reference to the accompanying drawings and examples.

[0080] To extract general and private features for each task, this invention employs a multi-task learning framework based on hybrid parameter sharing. To address the shortcomings of hard parameter sharing frameworks in constraining the shared layer and to prevent the shared layer from being affected by additional noise while bringing information gain, this invention introduces adversarial transfer learning and designs a gradient inversion layer. To achieve specific tasks, this invention constructs a neural network-based multi-task classification network as the top task layer of the multi-task learning framework, used to implement smart contract vulnerability judgment tasks and multi-vulnerability type identification tasks.

[0081] like Figure 1 The flowchart of the vulnerability detection method of the present invention shown is divided into several stages, namely the data preprocessing stage, the model construction stage, and the model training stage.

[0082] (1) Data preprocessing stage

[0083] 1.1) Select multiple vulnerability types to be detected, and use existing vulnerability detection tools or manual analysis to label the smart contract dataset, including vulnerability classification and tagging, to obtain a labeled smart contract dataset. The tags include whether it is a vulnerability (Flag) and the specific type of vulnerability (Label).

[0084] This invention cleans 149,369 collected contract data entries, yielding 148,384 valid contract data entries, of which 27 vulnerability types are available for detection. Within each vulnerability type, the tags are independent. This invention sets the number of vulnerability types to be classified to three categories, constructing one tag for each smart contract sample. This tag consists of a four-dimensional column [x1, x2, x3, x4], where each element x... i The value of x is either 0 or 1. i =1 indicates that the smart contract has the i-th type of vulnerability, x i =0 indicates that the smart contract does not have the i-th vulnerability. Specifically, x1 represents the tag indicating whether the smart contract has a vulnerability. The vulnerability types detected by this invention are shown in Table 1.

[0085] Table 1 Smart Contract Dataset

[0086]

[0087] After the above operations, the smart contract dataset is finally transformed into a labeled sample set, with each sample corresponding to a label.

[0088] 1.2) For the smart contract datasets labeled in the above stages, the smart contract source code is obtained from the dataset and compiled to obtain contract bytecode. A bytecode cleaning script is written to delete invalid bytecode, clear operands, and obtain the valid opcode sequence of the contract. Then, the N-gram language model is used to process the contract opcode sequence to obtain the 2-gram feature sequence. The processed dataset is shown in Table 2.

[0089] Table 2 Smart Contract Dataset

[0090]

[0091]

[0092] 1.3) As a typical anomaly detection problem, the number of vulnerable smart contracts is far less than the number of normal contracts, and the number of contracts with specified vulnerabilities is even rarer. To ensure the model can be trained effectively and learn to collect sufficient feature information, an oversampling method (SMOTE) is used on the smart contract dataset to increase the number of vulnerable contracts and the number of vulnerabilities of specified categories, thus achieving data balance. Simultaneously, the dataset is divided into three sets according to a certain ratio (7:1:2): training set, validation set, and test set.

[0093] Based on the above operations, write a dataset sampling and partitioning program script to process the smart contract data sample set as the input of the model. The training set is used to train the model's hyperparameters; the validation set is used to validate the model's hyperparameters and provide feedback to the model so that it can make further adjustments; and the test set is used to test the model's performance.

[0094] (2) Model construction stage

[0095] As described above, a smart contract vulnerability detection model based on multi-task learning is constructed, and model parameters are set for the next stage of training.

[0096] √Batch size: The number of samples selected in one training session

[0097] This invention sets the initial batch size to 16 and gradually increases the batch size from [16, 32, 64, 128, 256] to select the most suitable batch size.

[0098] √Learn rate: Learning rate

[0099] Regarding the configuration of the learning rate, this invention sets the initial value of the learning rate to 0.0001, and then increases the learning rate with each training session until a better training effect is achieved.

[0100] √Dropout: Random dropout rate

[0101] Dropout refers to the process of temporarily removing neural network units from the network with a certain probability during the training of deep learning networks. Its main function is to prevent overfitting and improve model performance. This invention sets the dropout value starting from 0.05 and increases this value with each training iteration until a better training effect is achieved.

[0102] √Optimizer: Optimizer

[0103] The essence of model training is minimizing the loss. After defining the loss function, an optimizer is used to optimize the gradient. The optimizer used in this invention is Adam, which can converge quickly.

[0104] √Epoch: Number of iterations

[0105] This invention sets the initial epoch value to 50 and gradually increases the epoch from [50, 60, 80, 90, 100, 120] until a better training effect is achieved.

[0106] Based on the above, set the important hyperparameters of the model, conduct the model training phase, and continuously adjust the model hyperparameters according to the training results until the model achieves good results.

[0107] (3) Model training phase

[0108] Based on the above operations, the training set is fed into the smart contract detection model to train hyperparameters, the model hyperparameters are validated using the validation set, and the model is optimized through backpropagation algorithm until the hyperparameters with optimal performance are obtained.

[0109] Experiments have shown that the smart contract vulnerability detection model achieves better performance when configured as shown in Table 3.

[0110] Table 3 Hyperparameter Settings

[0111]

[0112]

[0113] The detection results for the three types of contract vulnerabilities are shown in Table 4.

[0114] Table 4 Experimental Results

[0115]

[0116] In summary, the vulnerability detection method proposed in this embodiment of the invention achieves accurate and efficient automatic detection of three types of contract vulnerabilities through multi-task learning and adversarial transfer learning, utilizing deep learning algorithms. This method is suitable for application scenarios involving large-scale contract vulnerability detection.

[0117] The above description is merely an embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A smart contract vulnerability detection method combining adversarial transfer learning and multi-task learning, characterized in that, Includes the following steps: (1) In the data preprocessing stage, the opcode sequence formed by compiling and decompiling the smart contract source code is processed, and the N-Gram language model is used to process and construct the 2-gram opcode syntax sequence to form the input sequence of the smart contract vulnerability detection model. (2) In the model building stage, firstly, a multi-task learning framework based on hybrid parameter sharing is constructed to extract general features and private features. Then, adversarial transfer learning is introduced to use game theory to alleviate the noise pollution caused by task private features on general features and to alleviate the mutual interference between general features and task private features. A multi-task classification network based on neural network is constructed as the top task layer of the multi-task learning framework to realize the detection and identification of smart contract vulnerabilities. Finally, the bottom sharing layer and the top task layer are combined to construct the overall model, forming a smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning. (3) In the smart contract vulnerability detection stage, the source code of the smart contract to be detected is processed into a 2-gram opcode syntax sequence according to the processing method of the data preprocessing stage, and then input into the constructed smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning to realize multiple task functions, including judging the vulnerability contract and identifying multiple vulnerability types. In the model building phase, the model construction includes: Step 1: Construct the input sequence for the smart contract vulnerability detection model; The N-Gram language model is used to process the opcode sequence, and a 2-gram opcode syntax sequence is constructed to form the input sequence for the smart contract vulnerability detection model. Step 2: Construct a bottom sharing layer for multi-task learning based on hybrid parameter sharing; Feature extraction is performed based on the 2-gram opcode syntax sequence generated in step 1. A bottom shared layer in a multi-task learning framework is designed. Based on the hybrid parameter sharing framework, a task-general feature extraction layer and a task-private feature extraction layer are constructed to extract general features and task-private features respectively. Each task-private feature is fused with the general feature separately through attention. Step 3: Construct the top task layer for multi-task learning based on a convolutional neural network; Based on the bottom shared layer of the smart contract vulnerability detection model constructed in step 2, a top task layer in a multi-task learning framework is designed, and the bottom shared layer and the top task layer are linked together. The top task layer constructs two tasks based on convolutional neural networks: a contract vulnerability judgment task and a multi-vulnerability type identification task. In the contract vulnerability judgment task, a binary classification neural network is established to realize vulnerability judgment. In the multi-vulnerability type identification task, a multi-classification neural network is established to realize vulnerability type identification. Step 4: Construct the gradient inversion layer (GRL); Based on the smart contract vulnerability detection model constructed in step 3, a gradient inversion layer (GRL) is constructed to achieve adversarial transfer learning. The features extracted from the task-general feature extraction layer are passed through a fully connected layer (FC) for feature dimensionality reduction, and then connected to the gradient inversion layer (GRL). The gradient input to the GRL is multiplied by a negative number, so that the training objectives in the network before and after the GRL are opposite, making it as difficult as possible to determine which task domain the features extracted by the feature extractor come from. Step 5: Construct a smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning; Based on steps 2, 3, and 4, the bottom shared layer, top task layer, and gradient inversion layer of the smart contract vulnerability detection model are integrated to construct a smart contract vulnerability detection model that combines adversarial transfer learning and multi-task learning, so as to realize the contract vulnerability judgment task and the multi-vulnerability type identification task. The discriminator is used to determine which task a feature belongs to, calculated as shown in the following formula: ; In the formula, These are discriminator parameters. , These are the weight parameters of the discriminator; simultaneously, an adversarial loss function is introduced to prevent task-specific features from mixing with general features, calculated as follows: ; In the formula, Represents a general feature extraction layer. These are the parameters of a general feature extraction layer.

2. The smart contract vulnerability detection method combining adversarial transfer learning and multi-task learning according to claim 1, characterized in that, The data preprocessing stage includes: (1) Decompile the smart contract source code into an opcode sequence; Contract bytecode is used as input for model analysis; the bytecode is further decompiled to generate opcode sequences, simplifying and constructing the model's input. (2) The N-Gram language model is used to process the opcode sequence; An N-gram language model is used to process opcode sequences, and a 2-gram opcode syntax sequence is constructed to obtain opcode context information, thereby improving the robustness of the model.