Vulnerability detection method for blockchain smart contract and computer equipment
By using multimodal feature fusion and generative adversarial networks for data augmentation, the problem of insufficient accuracy in smart contract vulnerability detection is solved, and higher accuracy vulnerability detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI DEV CENT OF COMP SOFTWARE TECH
- Filing Date
- 2026-02-11
- Publication Date
- 2026-05-15
AI Technical Summary
In existing technologies, smart contract vulnerability detection methods rely on single feature representations, which makes it difficult to comprehensively and accurately capture complex behavioral patterns and ever-changing vulnerability forms, resulting in high false negative and false positive rates and affecting detection accuracy.
By employing multimodal feature fusion technology, image features, syntactic features, and structural features of smart contracts are extracted. Then, a synthetic feature vector is generated through generative adversarial networks, and an enhanced training set with balanced category distribution is constructed to improve the accuracy of vulnerability detection.
By combining multimodal feature fusion and generative adversarial networks, the essence of smart contracts can be comprehensively characterized, the accuracy of vulnerability detection can be improved, the false negative and false positive rates can be reduced, and the detection capability for rare and novel vulnerabilities can be enhanced.
Smart Images

Figure CN122046375A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of intelligent vulnerability detection, and in particular to a vulnerability detection method and computer device for blockchain smart contracts. Background Technology
[0002] With the popularization of blockchain technology, smart contracts have been widely applied in key areas such as finance, supply chain, and digital identity. However, the difficulty in altering smart contracts once deployed makes their security issues particularly prominent. Vulnerabilities such as reentrancy attacks, integer overflows, and improper access control can lead to huge asset losses. Therefore, smart contract vulnerability detection technology has become a core component in ensuring the security of the blockchain ecosystem. Blockchain smart contract vulnerability detection involves a systematic review of the smart contract code deployed on the blockchain platform through various technical means, including static smart contract sample analysis and formal risk verification, to ensure the security and stability of the blockchain system.
[0003] In related technologies, smart contract vulnerability detection methods mainly rely on static analysis, dynamic analysis, or a combination of both. They typically extract feature data from smart contract samples, characterize this sample data, and then perform vulnerability detection. This primarily involves using predefined patterns or code standards to analyze the smart contract code. However, this single feature representation is insufficient to comprehensively and accurately capture the complex behavioral patterns and varied vulnerability forms of smart contracts. It lacks sensitivity to potential vulnerabilities, resulting in high false negative and false positive rates, thus affecting the accuracy of the vulnerability detection process.
[0004] Therefore, there is an urgent need in this field for a high-precision vulnerability detection solution that can integrate multi-dimensional features and effectively solve the problem of data imbalance. Summary of the Invention
[0005] The purpose of this application is to provide a vulnerability detection method and computer device for blockchain smart contracts, so as to improve the accuracy of the vulnerability detection process.
[0006] To achieve the above objectives, this application provides the following solution: In a first aspect, this application provides a vulnerability detection method for blockchain smart contracts, comprising: acquiring a smart contract sample; extracting image feature vectors based on code visualization, syntax feature vectors based on abstract syntax trees, and structural feature vectors based on control flow graphs from the smart contract sample; concatenating the image feature vectors, syntax feature vectors, and structural feature vectors of the smart contract sample to generate a multimodal fusion feature vector; generating a synthetic feature vector for a specified vulnerability category based on a generative adversarial network, using vulnerability category labels as conditions, and forming an enhanced training set with a balanced category distribution based on the synthetic feature vectors and the multimodal fusion feature vectors; constructing a classification model, and training the classification model based on the enhanced training set for vulnerability detection of the smart contract.
[0007] For example, extracting image feature vectors based on code visualization specifically includes: converting the source code or bytecode of the smart contract sample into an image; performing standardized preprocessing on the image and inputting it into a pre-trained ResNet18 residual neural network model; removing the original classification layer of the ResNet18 residual neural network model and retaining the global average pooling layer as a feature extractor to output a fixed-dimensional image feature vector.
[0008] For example, extracting grammatical feature vectors based on abstract syntax trees specifically includes: compiling the smart contract source code using the solc compiler to generate an abstract syntax tree; traversing the abstract syntax tree using a structure-based traversal method to generate a sequence structure that preserves the hierarchical relationship between nodes; performing embedding learning on the SBT sequence and Token sequence in the sequence structure using a Word2Vec model to obtain the corresponding word embedding matrices; performing a pooling operation on the word embedding matrices, and concatenating the pooled vectors to obtain grammatical feature vectors based on the abstract syntax tree.
[0009] For example, extracting structural feature vectors based on the control flow graph specifically includes: converting the source code of the smart contract sample into bytecode using the solc compiler, and then converting the bytecode into opcodes; constructing a control flow graph based on the sequence of opcodes; learning node features of the control flow graph using a graph convolutional network model with a node feature extractor, and generating feature vectors for each node through message passing and reading; and weighting and aggregating the feature vectors of all nodes according to the node feature extractor to obtain a structural feature vector representing the entire control flow graph.
[0010] For example, the generative adversarial network includes a generator and a discriminator. Training the classification model based on the augmented training set includes: inputting random noise and specified vulnerability category labels into the generator to output the synthetic feature vector; inputting the multimodal fusion feature vector as real feature data, along with the synthetic feature vector and its corresponding vulnerability category labels, into the discriminator to output the probability that the synthetic feature vector is true; and performing adversarial training on the generator and the discriminator based on a preset optimization objective so that the synthetic feature vector can pass the discrimination of the discriminator.
[0011] For example, the preset optimization objective is as follows: Where G represents the generator, D represents the discriminator, V(D, G) is the value function, x is the true feature data, y is the corresponding vulnerability category label, and P... data(x) This represents the data distribution of the true feature data, where z is random noise and P z(z) Let G(z|y) represent the prior distribution of random noise, and let G(z|y) represent the synthesized feature vector generated by the generator with z and y as inputs. When the result of the optimization objective is within a preset range, the synthesized feature vector can be discriminated by the discriminator.
[0012] For example, training the classification model based on the augmented training set further includes: training the classification model based on the augmented training set and a loss function to minimize the loss value of the loss function, wherein the loss function is as follows: In the formula, Loss represents the loss value, x represents the total number of training samples in the augmented dataset, and y i This represents the vulnerability category label of the i-th sample. The vector representation predicted for the target node.
[0013] Secondly, this application provides a computer device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the vulnerability detection method for blockchain smart contracts described above.
[0014] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-mentioned vulnerability detection methods for blockchain smart contracts.
[0015] Fourthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the vulnerability detection method for blockchain smart contracts described above. According to the specific embodiments provided in this application, the following technical effects are disclosed: This application provides a vulnerability detection method for blockchain smart contracts. It employs multimodal feature fusion technology to extract and fuse image features, syntactic features, and structural features, enabling a comprehensive characterization of the smart contract's essence from multiple complementary dimensions. Simultaneously, it introduces a conditional generative adversarial network (GAN) data augmentation process to generate high-quality synthetic feature vectors for specific vulnerability categories. By merging these synthetic data with real data, an augmented training set with a balanced category distribution is constructed. This ensures that the model can learn vulnerability features across all categories equally during training, improving vulnerability detection capabilities and achieving higher accuracy. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of the vulnerability detection method in the embodiments of this application.
[0018] Figure 2 This is a flowchart of the vulnerability detection method in the embodiments of this application.
[0019] Figure 3 This is a structural block diagram of the computer device in the embodiments of this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0021] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0022] like Figure 1As shown in the figure, this application provides a vulnerability detection method for blockchain smart contracts. The method includes: S110. Obtain smart contract samples and extract image feature vectors based on code visualization, syntax feature vectors based on abstract syntax trees, and structural feature vectors based on control flow graphs from the smart contract samples.
[0023] S120. The image feature vector, syntax feature vector and structural feature vector of the smart contract sample are concatenated to generate a multimodal fusion feature vector.
[0024] S130. Based on generative adversarial networks, using vulnerability category labels as conditions, generate synthetic feature vectors for specified vulnerability categories, and form an enhanced training set with balanced category distribution based on the synthetic feature vectors and multimodal fusion feature vectors.
[0025] S140. Construct a classification model and train it using an enhanced training set for smart contract vulnerability detection.
[0026] The method provided in this application employs multimodal feature fusion technology, extracting and fusing image features, syntactic features, and structural features to comprehensively characterize the essence of smart contracts from multiple complementary dimensions. Simultaneously, it introduces a conditional generative adversarial network (GAN) data augmentation process, which generates high-quality synthetic feature vectors for specific vulnerability categories. By merging these synthetic data with real data, an augmented training set with a balanced category distribution is constructed. This ensures that the model can learn vulnerability features of all categories equally during training, improving vulnerability detection capabilities and achieving higher accuracy in vulnerability detection.
[0027] like Figure 2 As shown, the simplified process of this application includes: acquiring source data (mainly including smart contract samples), performing feature preprocessing on the data to obtain various features, then processing it based on a generative adversarial network (i.e., generative adversarial network) to obtain a new dataset (i.e., an enhanced dataset), and then detecting the smart contracts of the blockchain through a classification model as a detection module.
[0028] For example, in step S110 above, extracting the image feature vector based on code visualization from the smart contract sample specifically includes the following steps: S111: Convert the source code or bytecode of the smart contract sample into an image.
[0029] To construct a realistic, comprehensive, and usable smart contract vulnerability dataset, vulnerability data was first extracted from open-source software platforms, and vulnerability data from some literature was aggregated and used as a training dataset for artificial intelligence models to assist in supervised training of the detection models. These aggregated training datasets were then used as the aforementioned smart contract samples.
[0030] S112. After standardizing the image, input it into the pre-trained ResNet18 residual neural network model.
[0031] S113. Remove the original classification layer of the ResNet18 residual neural network model and retain the global average pooling layer as a feature extractor to output a fixed-dimensional image feature vector.
[0032] ResNet18 specifically refers to a residual neural network architecture with 18 layers. After an image is input into the ResNet18 residual neural network model, the original classification layer is removed, leaving a global average pooling layer as a feature extractor. During forward propagation, the model captures hierarchical features of the image step by step through residual block stacking. Shallow convolutions extract low-level features such as edges / textures, while deep convolutions model high-level semantic features. Finally, the global average pooling layer compresses the 7×7×512 feature map into a 512-dimensional vector to complete the output of a fixed-dimensional image feature vector. Each convolutional operation can be represented as follows: (1) Where x is the input feature map. This represents the convolution operation. These are the weight parameters of the convolutional layer. is the output feature map, and r is the residual connection, which means that the input is added to the convolution output to alleviate the gradient vanishing problem.
[0033] For example, the extraction of syntax feature vectors based on abstract syntax trees in step S110 above specifically includes: S114, compiling the smart contract source code according to the solc compiler to generate an abstract syntax tree.
[0034] S115. Traverse the abstract syntax tree using a structure-based traversal method to generate a sequence structure that preserves the hierarchical relationships between nodes.
[0035] S116. Using the Word2Vec model, embedding learning is performed on the SBT sequence and Token sequence in the sequence structure to obtain the corresponding word embedding matrix.
[0036] S117. Perform pooling operation on the word embedding matrix, and concatenate the pooled vectors to obtain the grammatical feature vector based on the abstract syntax tree.
[0037] Specifically, for smart contract samples, the solc compiler is used to compile the smart contract source code to generate an Abstract Syntax Tree (AST). However, the AST contains highly redundant content, including a large amount of irrelevant feature information. To better present the hierarchical structure of the AST and maintain its clarity, this application uses a novel Structure-Based Traversal (SBT) method to traverse the AST, transforming it into a sequence structure that fully preserves the hierarchical relationships between nodes. For example, the sequence structure includes an SBT sequence reflecting the syntactic structure obtained through SBT traversal, and a Token sequence reflecting lexical information extracted from the source code. Starting from the root node, all subtrees of the root node are traversed, and each subtree is labeled. This process is repeated recursively. Combining the following formula, the embedding vectors of the SBT and Token sequences can be represented as: (2) in, This is the final syntactic feature vector, representing the vector representation of the SBT sequence after pooling. It is the vector representation of the pooled sequence of lexical terms. and These are the SBT sequence and the token word embedding matrix learned through the Word2Vec model, respectively. This means concatenating two vectors along their dimensions. Ultimately, all the syntactic features in the smart contracts are transformed into vectors of uniform dimensions.
[0038] For example, the extraction of structural feature vectors based on the control flow graph in step S110 above specifically includes: S118. The source code of the smart contract sample is converted into bytecode using the solc compiler, and the bytecode is then converted into opcode.
[0039] S119. Construct a control flow graph based on the sequence of opcodes.
[0040] S1110. The control flow graph is subjected to node feature learning through a graph convolutional network model with a node feature extractor, and the feature vector of each node is generated through message passing and reading.
[0041] S1111. The feature vectors of all nodes are weighted and aggregated according to the node feature extractor to obtain the structural feature vector representing the entire control flow graph.
[0042] For the sample features of the control flow graph (CFG), the smart contract source code is first converted into bytecode using Solc, then the bytecode is converted into opcodes, and the control flow graph CFG, G=(V,E), is generated based on the sequence of opcodes. It consists of two parts: nodes V and control flow edges E. After constructing the graph G, a GCN model with a node feature extractor is used to extract local node features. The GCN model mainly consists of message passing and reading phases, and transforms each node into a k-dimensional feature vector. In the message passing phase, the GCN model uses... Convolutional layers update all using the following methods Feature vectors of graph nodes The specific formula is as follows: (3) in, Combined with adjacency matrix and self-circulating matrix , It is the sigma activation function. and Representing all nodes and the first node respectively The trainable weight matrix in the layer. This represents a diagonal matrix, which is used to normalize a matrix. For each graph node It updates its vectors using the same convolutional layer by aggregating the vectors of all neighboring nodes. The updated node vectors were obtained using the above method.
[0043] During the reading phase, the feature vectors of all nodes are read and node features are generated. Among them, the node feature extractor This method processes all node vectors, highlighting key elements in each node vector and avoiding overfitting, and updates all node vectors. Then, based on the following, the node characteristics generated by CFG are... : (4) in, This represents the updated node vector mentioned above, combined with the node feature extractor. The summation calculation is performed to obtain the node features representing the entire control flow graph, which serve as the structural feature vectors mentioned earlier.
[0044] After obtaining the aforementioned image feature vector, syntactic feature vector, and structural feature vector, step S120 described above is executed to concatenate the three features, thereby generating a multimodal fusion feature vector. Specifically, the feature concatenation process is as follows: Let the image feature vector extracted in step S110 be V. img The grammatical feature vector is V ast The graph structure feature vector is V cfg Where d1, d2, and d3 represent the dimensions of each feature vector.
[0045] The feature concatenation described above refers to concatenating these three feature vectors end-to-end along the vector dimension to create a new, higher-dimensional feature vector. This multimodal fusion feature vector V fusion The generation method is as follows: V fusion =Concat(V img V ast V cfg ) Where Concat(⋅) represents the vector concatenation function, and the resulting multimodal fusion feature vector V is obtained after concatenation. fusion ∈R d Its total dimension d = d1 + d2 + d3. The concatenation operation is a deterministic, parameter-free process; its output depends only on the content and order of the input vectors. The concatenation operation completely preserves all the information of each original feature vector, avoiding dilution or interference between different modal features in the early stages of fusion, thus providing a reliable data foundation for subsequent models.
[0046] For step S130 above, based on generative adversarial networks, using vulnerability category labels as conditions, a synthetic feature vector for a specified vulnerability category is generated, and an enhanced training set with balanced category distribution is formed based on the synthetic feature vector and the multimodal fusion feature vector.
[0047] For example, the Generative Adversarial Network (GAN) includes a generator and a discriminator. The generator in the GAN generates new smart contract vulnerability data samples, and the discriminator analyzes and identifies the generated samples. Specifically, a Generative Adversarial Network is an unsupervised neural network learning model composed of two parts: a generator network (G) and a discriminator network (D). The generator G inputs random noise information into the model, continuously learns the feature distribution of real data, and generates new deception samples. The discriminator D analyzes the new intrusion samples to determine whether these samples are genuine intrusion data.
[0048] In step S140 above, training the classification model based on the augmented training set includes the following steps: S141. Input random noise and specified vulnerability category labels into the generator to output a synthetic feature vector.
[0049] S142. The multimodal fusion feature vector is used as the real feature data, and the synthesized feature vector and its corresponding vulnerability category label are input into the discriminator to output the probability that the synthesized feature vector is true.
[0050] S143. Based on the preset optimization objective, the generator and discriminator are subjected to adversarial training so that the synthesized feature vector can be discriminated by the discriminator.
[0051] In the method of this application embodiment, the generator G simulates the feature distribution of real smart contract data through a prior distribution and gradually transforms random noise data input into deceptive feature sample data. The input of the discriminator includes real feature data and data generated by the generator. The output of the discriminator is the probability of whether the input data is real feature data. During the training process, G and D engage in a dynamic game until the discriminator D can no longer determine that the sample data is fake data generated by the generator G, which means that the two networks reach Nash equilibrium. The optimization objective function F of GAN is as follows: (5) in, The value function is calculated as follows: (6) in, D( represents the true data distribution of the feature samples) () is the discriminator that judges samples The probability of being a real sample. To be from a specific distribution The sampling data obtained in the process. This represents the probability that the discriminator will classify the sample generated by the generator as fake data, and log represents the natural logarithm.
[0052] When training the discriminator D, the goal is to train a detection model with the greatest possible discriminative power. In each iteration, the model randomly selects... A real feature sample and The deceptive feature samples generated by the generator are used to train the discriminator D. When training the generator G, the goal is to train samples that can deceive the discriminator while consuming as little generator as possible. The training calculation formulas for the discriminator and the generator are shown in equations (7) and (8) below, respectively: (7) (8) in, For real samples, For the generator's generated samples, These are the training parameters for the discriminator. These are the training parameters for the generator. When both are optimal, the feature sample data generated by the adversarial generative network can be identified by the discriminator.
[0053] In this embodiment of the application, to address the problem that traditional generative adversarial networks (GANs) do not consider other features of the sample itself, resulting in poor detection accuracy, sample information can be included as input to generate the desired sample more accurately. For example, the included sample information is the vulnerability category label mentioned above; by introducing the vulnerability category label as input, the obtained sample is more accurate. The above equation (6) is optimized and updated, and the final calculation method for the optimization objective is as follows: (9) In the formula, G represents the generator, D represents the discriminator, V(D, G) is the value function, x is the true feature data, y is the corresponding vulnerability category label, and P... data(x) This represents the data distribution of the true feature data, where z is random noise and P z(z) Let G(z|y) represent the prior distribution of random noise, and let G(z|y) represent the synthesized feature vector generated by the generator with z and y as inputs. When the result of the optimization objective is optimal, the synthesized feature vector can be discriminated by the discriminator. The optimal optimization objective can be that the obtained result is within a preset range.
[0054] After completing the optimized training of the generative adversarial network, the generated feature data is merged with the real data (that is, the synthetic feature data and the multimodal fusion feature vector are merged as mentioned above), and the same number of samples are extracted from each malicious sample category in proportion to construct the training dataset of the final detection model, which is used for the training of the vulnerability detection model in the next step.
[0055] For example, the vulnerability detection model employs a classification model, primarily comprising a classifier. In a preferred embodiment, the classification model is a multilayer perceptron (MLP), a type of feedforward artificial neural network whose structure is particularly well-suited for processing the multimodal fusion feature vectors generated by this invention. This MLP includes at least one input layer, one hidden layer, and one output layer.
[0056] Input Layer: The number of neurons in this layer matches the dimension of the multimodal fusion feature vector, and it receives this vector as input. Hidden Layers: These can be one or more layers, each containing several neurons, and use non-linear activation functions to learn complex non-linear relationships between features. Output Layer: Its configuration depends on the specific requirements of the vulnerability detection task. For binary classification tasks, the output layer may contain only one neuron and use the sigmoid activation function, whose output value is a scalar between 0 and 1, representing the predicted probability that the smart contract sample contains a vulnerability. For multi-class classification tasks, the output layer should contain the same number of neurons as the number of vulnerability categories and use the softmax activation function to normalize the output to the predicted probability distribution for each category.
[0057] Based on the augmented training set mentioned above, the training process of the classification model is as follows: The multimodal fusion feature vector from the augmented training set is input into the MLP, and the predicted output is obtained through forward propagation. Subsequently, the error between the predicted value and the true label is calculated using the binary cross-entropy loss function. Finally, all weights and bias parameters in the MLP are updated using the backpropagation algorithm and gradient descent optimizer until the model converges. The loss function is shown in the following equation: (10) In the formula, Loss represents the loss value, x represents the total number of training samples in the augmented dataset, and y i This represents the vulnerability category label of the i-th sample. The vector representation predicted for the target node.
[0058] In the preceding sections, we have already optimized the generative adversarial network, enhanced the acquisition of the training set, and trained the classification model, resulting in a more accurate model. Subsequently, after obtaining the blockchain smart contract, we can use the classification model described earlier to perform vulnerability detection on the smart contract.
[0059] The method in this application employs multimodal feature fusion technology, which simultaneously extracts and fuses image features (capturing visual texture and global patterns), AST syntactic features (capturing code syntactic structure information), and CFG graph structure features (capturing program execution logic and control flow relationships). This allows the model to comprehensively characterize the essence of smart contracts from multiple complementary dimensions. Compared to single features, this fused feature contains richer information and is more discriminative, thus enabling more accurate identification of potential and hidden vulnerabilities and fundamentally reducing false positive and false negative rates.
[0060] This application also incorporates a data augmentation step using Generative Adversarial Networks (CGANs). This step generates realistic, high-quality synthetic feature vectors for specific vulnerability categories with limited sample sizes. By merging these synthetic data with real data, an augmented training set with a balanced category distribution is constructed. This ensures that the model learns vulnerability features across all categories equally during training, significantly improving the detection capabilities for rare and novel vulnerabilities, and enhancing the overall robustness and generalization of the model. Furthermore, this application integrates feature extraction, data augmentation, and model detection into a complete automated process. Users or inspectors do not need extensive professional backgrounds or to manually write detection scripts; they only need to input the smart contract to be detected to automatically output the detection results. This greatly improves the efficiency and ease of use of vulnerability detection, making large-scale, rapid smart contract security screening possible.
[0061] like Figure 3 As shown in the figure, this application embodiment also provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the above-described vulnerability detection method for blockchain smart contracts.
[0062] This computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and databases. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media to run. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection.
[0063] This application also provides a computer-readable storage medium and a computer program product, wherein the computer-readable storage medium stores the computer program product, and the computer program, when executed by a processor, implements the above-described vulnerability detection method for blockchain smart contracts.
[0064] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).
[0065] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0066] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0067] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A vulnerability detection method for blockchain smart contracts, characterized in that, The vulnerability detection method for blockchain smart contracts includes: Obtain smart contract samples and extract image feature vectors based on code visualization, syntax feature vectors based on abstract syntax trees, and structural feature vectors based on control flow graphs from the smart contract samples. The image feature vector, syntax feature vector, and structural feature vector of the smart contract sample are concatenated to generate a multimodal fusion feature vector; Based on generative adversarial networks, a synthetic feature vector for a specified vulnerability category is generated using vulnerability category labels as conditions, and an enhanced training set with balanced category distribution is formed based on the synthetic feature vector and the multimodal fusion feature vector. A classification model is constructed and trained based on the enhanced training set for use in detecting vulnerabilities in the smart contract.
2. The vulnerability detection method for blockchain smart contracts according to claim 1, characterized in that, Extracting image feature vectors based on code visualization, specifically including: Convert the source code or bytecode of the smart contract sample into an image; After the image is standardized and preprocessed, it is input into a pre-trained ResNet18 residual neural network model. The original classification layer of the ResNet18 residual neural network model is removed, and the global average pooling layer is retained as a feature extractor to output a fixed-dimensional image feature vector.
3. The vulnerability detection method for blockchain smart contracts according to claim 1, characterized in that, Extracting syntactic feature vectors based on abstract syntax trees, specifically including: The smart contract source code is compiled using the solc compiler to generate an abstract syntax tree; The abstract syntax tree is traversed using a structure-based traversal method to generate a sequence structure that preserves the hierarchical relationships between nodes; The Word2Vec model is used to learn the embeddings of the SBT sequence and the Token sequence in the sequence structure, respectively, to obtain the corresponding word embedding matrix. The word embedding matrix is pooled, and the pooled vectors are concatenated to obtain a grammatical feature vector based on an abstract syntax tree.
4. The vulnerability detection method for blockchain smart contracts according to claim 1, characterized in that, Extracting structural feature vectors based on the control flow graph, specifically including: The source code of the smart contract sample is converted into bytecode using the solc compiler, and then the bytecode is converted into opcode. A control flow graph is constructed based on the sequence of opcodes; The control flow graph is subjected to node feature learning through a graph convolutional network model with a node feature extractor, and the feature vector of each node is generated by message passing and reading. The feature vectors of all nodes are weighted and aggregated by the node feature extractor to obtain a structural feature vector representing the entire control flow graph.
5. The vulnerability detection method for blockchain smart contracts according to claim 1, characterized in that, The generative adversarial network includes a generator and a discriminator, and training the classification model based on the augmented training set includes: The generator is fed random noise and a specified vulnerability category label to output the synthesized feature vector. The multimodal fusion feature vector is used as the real feature data, and the synthesized feature vector and its corresponding vulnerability category label are input into the discriminator to output the probability that the synthesized feature vector is true; The generator and the discriminator are subjected to adversarial training based on a preset optimization objective, so that the synthesized feature vector can pass the discrimination of the discriminator.
6. The vulnerability detection method for blockchain smart contracts according to claim 5, characterized in that, The preset optimization objectives are as follows: ; Where G represents the generator, D represents the discriminator, V(D, G) is the value function, x is the true feature data, y is the corresponding vulnerability category label, and P... data(x) This represents the data distribution of the true feature data, where z is random noise and P z(z) Let G(z|y) represent the prior distribution of random noise, and let G(z|y) represent the synthetic feature vector generated by the generator with z and y as inputs. When the result of the optimization objective is within a preset range, the synthesized feature vector can be discriminated by the discriminator.
7. The vulnerability detection method for blockchain smart contracts according to claim 1, characterized in that, The step of training the classification model based on the enhanced training set further includes: The classification model is trained based on the enhanced training set and the loss function to minimize the loss value of the loss function, wherein the loss function is as follows: ; In the formula, Loss represents the loss value, x represents the total number of training samples in the augmented dataset, and y i This represents the vulnerability category label of the i-th sample. The vector representation predicted for the target node.
8. A computer device, comprising: A memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that the processor executes the computer program to implement the vulnerability detection method for blockchain smart contracts according to any one of claims 1-7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the vulnerability detection method for blockchain smart contracts as described in any one of claims 1-7.
10. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the vulnerability detection method for blockchain smart contracts as described in any one of claims 1-7.