Smart contract vulnerability detection method, system and device based on multimodal fusion
Through multimodal fusion technology, the structural, semantic and spatial characteristics of smart contracts are extracted, combined with attention and cross-attention processing, and multimodal fusion characteristics are generated, solving the problems of low efficiency and limited coverage of existing smart contract vulnerability detection methods, and achieving efficient and stable vulnerability detection effects.
Patent Information
- Application Number
- CN202411596069.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-11
AI Technical Summary
The existing smart contract vulnerability detection methods are inefficient and have limited coverage, difficult to deal with complex contracts, and rely on the quality and quantity of test cases, and have weak stability.
The smart contract vulnerability detection method based on multimodal fusion is adopted. By converting the source code of the smart contract to be detected into a contract graph, the contract structure features are extracted; the running bytecode in the bytecode is obtained, decompiled and bidirectional semantic feature extraction are performed, and the contract semantic features are extracted; the source code is converted into a contract syntax highlighting graph, and the convolutional neural network processing is performed to extract contract space features. The three modal features are treated with attention and cross-attention processing to generate multimodal fusion features, and finally the vulnerability detection results are obtained through full connection layer and probability mapping.
It improves the efficiency and stability of smart contract vulnerability detection, has high accuracy, recall, accuracy and F1 score, and can capture the complex relationships of contract code more comprehensively and deeply.
Smart Images

Figure QLYQS_1
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, and specifically to a smart contract vulnerability detection method, system and device based on multimodal fusion. Background Art
[0002] The widespread use of smart contracts has brought many conveniences, but it also faces severe security challenges. To ensure the security of smart contracts, researchers and developers are constantly improving the security audit and vulnerability detection methods of contract codes to ensure the safe and reliable operation of smart contracts.
[0003] Traditional smart contract vulnerability detection methods mainly rely on expert knowledge and manual analysis. According to their technical routes, they can be divided into three categories: rule / pattern matching-based methods, symbolic execution-based methods, and fuzz testing-based methods. Rule / pattern matching-based methods rely on rules or patterns pre-defined by experts to identify vulnerabilities in the code. Representative tools include Slither, SmartCheck, and Securify, etc. However, the detection coverage of these methods is limited. Symbolic execution-based methods convert smart contract code into symbolic expressions, and use symbolic execution engines to simulate the execution process of the code to explore all possible execution paths to detect whether there are vulnerabilities; representative tools include Oyente, Mythril, and Manticore, etc. However, these methods are inefficient and difficult to handle complex contracts, and are prone to path explosion problems. Fuzz testing-based methods test the behavior of smart contracts by generating a large number of random inputs to observe whether there are abnormal situations, thereby discovering potential vulnerabilities; representative tools include ContractFuzzer, ConFuzzius, and sFuzz, etc. However, these methods rely on the quality and quantity of test cases, and their efficiency and coverage are difficult to guarantee, and their stability is weak. Summary of the invention
[0004] The purpose of the present invention is to provide a smart contract vulnerability detection method, system and device based on multimodal fusion.
[0005] The technical solution of the present invention is as follows:
[0006] A smart contract vulnerability detection method based on multimodal fusion includes the following operations:
[0007] S1. Convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features;
[0008] S2. Obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain an operation code sequence through decompilation; normalize different operation codes belonging to the same control instruction in the operation code sequence to obtain a normalized operation code sequence; extract the normalized operation code sequence through bidirectional semantic features to obtain the contract semantic features;
[0009] S3. Different characters in the source code of the smart contract to be inspected are converted into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features;
[0010] S4. Contract structure features, contract semantic features, and contract space features are processed by attention respectively and then concatenated to obtain initial fusion features. The initial fusion features are pooled with contract structure features, contract semantic features, and contract space features after cross-attention processing to obtain multimodal fusion features. The multimodal fusion features are processed by the fully connected layer and probability mapping to obtain vulnerability detection results.
[0011] The graph convolution operation based on node connection relationship in S1 is implemented by the following formula:
[0012] ,
[0013] H (l+1) For the l+1 The graph convolution features of the layer, σ is the sigmoid function, A r For the r The adjacency matrix corresponding to the connection relationship is: R is the total number of connection relationships, which are edge connection relationships between nodes in the contract graph, including control flow edge connections, data flow edge connections, forward edge connections, and back-off edge connections; W r For the r The corresponding weights of the connection relationships are H (l) For the l The graph convolutional features of the layer, W (l) No. l The graph convolution weights of the layer.
[0014] After obtaining the contract graph in S1, it also includes: adding the feature information and edges of the amount node and / or the fallback node to the nodes connected to the amount node and / or the fallback node, deleting the amount node and / or the fallback node in the contract graph, and obtaining an optimized contract graph for performing graph convolution processing operations based on node connection relationships.
[0015] The normalization operation in S2 is achieved by replacing different operation codes belonging to the same control instruction with the same control operation code.
[0016] The specific operations of bidirectional semantic feature extraction and processing in S2 are as follows: cutting the normalized operation code sequence into a number of subsequences, and processing the subsequences by a number of long short-term memory units in the order of their forward positions in the normalized operation code sequence to obtain positive semantic features; processing the subsequences by a number of long short-term memory units in the order of their reverse positions in the normalized operation code sequence to obtain reverse semantic features; and weighted fusion processing of the reverse semantic features and the forward semantic features to obtain the contract semantic features.
[0017] The specific operations of the convolutional neural network processing in S3 are as follows: the contract syntax highlighting graph is processed by convolution, RELU activation function and maximum pooling to obtain a pooled feature map; the pooled feature map is flattened, and then fully connected layer processing and nonlinear processing are performed to obtain the contract space features.
[0018] The specific operation of cross-attention processing in S4 is: the query vector of the contract structure feature, or the contract semantic feature, or the contract space feature is subjected to feature fusion with the key vector of the initial fusion feature and then subjected to nonlinear processing, and then subjected to feature fusion with the value vector of the initial fusion feature to obtain the structural semantic initial fusion feature, or the structural space initial fusion feature, or the semantic space initial fusion feature; the structural semantic initial fusion feature, or the structural space initial fusion feature, or the semantic space initial fusion feature, is respectively subjected to layer normalization processing, feedforward neural network processing and layer normalization processing in turn to obtain the structural semantic fusion feature, or the structural space fusion feature, or the semantic space fusion feature, which is used to perform the pooling processing operation.
[0019] A smart contract vulnerability detection system based on multimodal fusion, used to implement the above-mentioned smart contract vulnerability detection method based on multimodal fusion, comprising:
[0020] The contract structure feature generation module is used to convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features;
[0021] The contract semantic feature generation module is used to obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain the operation code sequence through decompilation; the different operation codes belonging to the same control instruction in the operation code sequence are normalized to obtain the normalized operation code sequence; the normalized operation code sequence is processed through bidirectional semantic feature extraction to obtain the contract semantic feature;
[0022] The contract space feature generation module is used to convert different characters in the source code of the smart contract to be inspected into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features;
[0023] The vulnerability detection result generation module is used for contract structure features, contract semantic features and contract space features, which are respectively processed by attention and then spliced to obtain initial fusion features; the initial fusion features are respectively pooled with contract structure features, contract semantic features and contract space features after cross attention processing to obtain multimodal fusion features; the multimodal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results.
[0024] A smart contract vulnerability detection device based on multimodal fusion includes a processor and a memory, wherein the processor implements the above-mentioned smart contract vulnerability detection method based on multimodal fusion when executing a computer program stored in the memory.
[0025] The beneficial effects of the present invention are:
[0026] The present invention provides a smart contract vulnerability detection method based on multimodal fusion. First, a contract graph of the smart contract to be tested is obtained, which is convenient for capturing the complex relationship between functions and variables. After graph convolution processing and global maximum pooling processing based on node connection relationships, the structural information and node features of the contract graph are extracted, the control flow and data flow relationship of the code are captured, and the contract structural features are obtained; at the same time, the running bytecode in the bytecode of the smart contract to be tested is obtained, and after decompilation and normalization processing, a bidirectional semantic feature extraction processing is performed to extract the semantic features of the bytecode sequence, capture the context dependency between operation codes, and obtain the contract semantic features; in addition, the source code of the smart contract to be tested is converted into a contract syntax highlighting graph that is convenient for analyzing the code space layout, and then a convolutional neural network processing is performed to extract the visual features of the contract syntax highlighting graph to capture the contract to be tested. The spatial information of the smart contract code is obtained to obtain the contract space features; finally, the three modal features (contract structure features, contract semantic features and contract space features) are processed with attention respectively and then spliced to achieve the initial fusion of multi-modality and obtain the initial fusion features with strong comprehensive characteristics; then the different modal features (contract structure features, contract semantic features and contract space features) are further cross-attention processed with the initial fusion features and then pooled to fully capture the complex relationships between different modalities, obtain a more comprehensive and deeper representation of the contract code, and obtain multi-modal fusion features; finally, the multi-modal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results; when this method is used for smart contract vulnerability detection, it has high efficiency and good stability, and has high accuracy, recall rate, precision and F1 score. DETAILED DESCRIPTION
[0027] This embodiment provides a smart contract vulnerability detection method based on multimodal fusion, including the following operations:
[0028] S1. Convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features;
[0029] S2. Obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain an operation code sequence through decompilation; normalize different operation codes belonging to the same control instruction in the operation code sequence to obtain a normalized operation code sequence; extract the normalized operation code sequence through bidirectional semantic features to obtain the contract semantic features;
[0030] S3. Different characters in the source code of the smart contract to be inspected are converted into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features;
[0031] S4. Contract structure features, contract semantic features, and contract space features are processed by attention respectively and then concatenated to obtain initial fusion features. The initial fusion features are pooled with contract structure features, contract semantic features, and contract space features after cross-attention processing to obtain multimodal fusion features. The multimodal fusion features are processed by the fully connected layer and probability mapping to obtain vulnerability detection results.
[0032] S1. Convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure characteristics.
[0033] The source code of the smart contract to be inspected is converted into a contract graph that is easy to capture the complex relationships between functions and variables. Then, graph convolution processing and global maximum pooling processing based on the node connection relationship are performed to extract the structural information and node features of the contract graph, capture the control flow and data flow relationship of the code, and effectively identify complex calling logic and dependency relationships to obtain the contract structure characteristics.
[0034] The source code of the smart contract to be inspected is converted into a contract graph; the nodes in the contract graph are call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph are control flow edges (edges corresponding to call and jump operations), data flow edges (edges corresponding to assignment and access operations), forward edges (edges of natural order relations) and fallback edges (edges corresponding to the interaction relationship with the Fallback function).
[0035] Among them, the call function node symbolizes the call to the custom function or built-in function in the source code, and is the node corresponding to the call function in the source code; the amount node symbolizes the user balance and bonus sign, and is the node corresponding to the amount in the source code; the fallback node is the node corresponding to the Fallback function in the source code, which is used to simulate the Fallback function of the attack contract.
[0036] The contract graph is processed by graph convolution and global maximum pooling based on the node connection relationship to extract the structural information and node features of the contract graph, capture the control flow and data flow relationship of the code, so as to effectively identify complex calling logic and dependency relationships and obtain the contract structure characteristics.
[0037] In order to highlight the key nodes and better obtain semantic information such as key control flow and data flow during the graph convolution processing, after obtaining the contract graph, it also includes: adding the feature information and edges of the amount node and / or the fallback node to the nodes (calling function nodes) connected to the amount node and / or the fallback node, deleting the amount node and / or the fallback node in the contract graph, and obtaining an optimized contract graph for performing graph convolution processing operations based on node connection relationships.
[0038] The above-mentioned graph convolution operation based on node connection relationship is implemented by the following formula:
[0039] ,
[0040] H (l+1) For the l+1 The graph convolutional features of the layer, σ is the sigmoid function, A r For the r The adjacency matrix corresponding to the connection relationship is: R is the total number of connection relationships, where the connection relationship is the edge connection relationship between nodes in the contract graph or optimized contract graph, including control flow edge connection, data flow edge connection, forward edge connection and fallback edge connection; W r For the r The corresponding weights of the connection relationships are H (l) For the l The graph convolutional features of the layer,H (0) Initial node features for the contract graph or optimized contract graph, W (l) No. l The graph convolution weights of the layer.
[0041] S2. Obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain an operation code sequence through decompilation. Normalize different operation codes belonging to the same control instruction in the operation code sequence to obtain a normalized operation code sequence. The normalized operation code sequence is processed through bidirectional semantic feature extraction to obtain contract semantic features.
[0042] The running bytecode in the smart contract bytecode to be inspected is obtained, and after decompilation and normalization, bidirectional semantic feature extraction is performed to extract the semantic features of the bytecode sequence, capture the contextual dependencies between the opcodes, and obtain the contract semantic features, so as to better understand the execution logic of the code.
[0043] First, obtain the running bytecode (runtime bytecode) in the bytecode of the smart contract to be tested, so as to analyze the content of the running process of the smart contract to be tested. Specifically, use the Solidity compiler to compile the source code of the smart contract to be tested into bytecode, and in the compilation options, specify to compile only the bytecode of the runtime part, read the compiled bytecode into the memory, and parse out the runtime part.
[0044] Then, the running bytecode is decompiled to obtain the opcode sequence. Specifically, the EVMdisassemblers tool is used to translate the running bytecode into an opcode list to obtain the opcode sequence, which is convenient for understanding the running logic of the smart contract to be inspected.
[0045] Next, the different opcodes belonging to the same control instruction in the opcode sequence are normalized to reduce data noise and obtain a normalized opcode sequence. The normalization operation is achieved by replacing different opcodes belonging to the same control instruction with the same control opcode. For example, the "JUMP" instruction may have variants such as "JUMP", "JUMPI", and "JUMPDEST". These variant instructions can be unified into a standard format, such as all converted to "JUMP". Sometimes, the functions of some instructions are very similar, such as "PUSH1", "PUSH2", and "PUSH32" all push data into the stack, but the size of the operands is different. These instructions can be merged into one instruction, such as "PUSH", and the size of the operand is used as an attribute of the instruction. In this way, the normalized opcodes are easier to analyze and process later.
[0046] Finally, the normalized opcode sequence is processed by bidirectional semantic feature extraction to capture the contextual dependencies between opcodes, thereby better understanding the execution logic of the code and obtaining the contract semantic features.
[0047] Among them, the operation of bidirectional semantic feature extraction and processing is specifically as follows: cutting the normalized operation code sequence into a number of subsequences, and processing the subsequences by a number of long short-term memory units in the order of their forward positions in the normalized operation code sequence to obtain positive semantic features; processing the subsequences by a number of long short-term memory units in the order of their reverse positions in the normalized operation code sequence to obtain reverse semantic features; and obtaining contract semantic features by weighted fusion of the reverse semantic features and the forward semantic features.
[0048] The operation of bidirectional semantic feature extraction processing can also be: cutting the normalized operation code sequence into several sub-sequences, and processing the several sub-sequences through several long short-term memory units in the forward position order and the reverse position order in the normalized operation code sequence to obtain contract semantic features; during the processing of several long short-term memory units, the forward semantic features output by the previous position in the forward position sequence and the average of the reverse semantic features output by the previous position in the reverse position sequence are used as the input of the next long short-term memory unit in the forward position sequence and the input of the next long short-term memory unit in the reverse position sequence.
[0049] The operations currently processed by the long short-term memory unit can be implemented by the following formula:
[0050] i t =σ(W i e t +U i h t-1 +bi),
[0051] f t =σ(W f e t +U f h t-1 +b f ),
[0052] o t =σ(W o e t+U o h t-1 +b o ),
[0053] g t =tanh(W g e t +U g h t-1 +b g ),
[0054] Ct =f t ⊙c t-1 +i t ⊙g t ,
[0055] h t =o t ⊙tanh(c t ),
[0056] e t for t The initial input vector at time t, h t for t The final output vector at time , h t-1 for t-1 The final output vector at time , i t for t The forget gate output vector at time , σ is the sigmoid function, W i is the forget gate weight matrix, U i is the forget gate bias vector, b i is the forget gate compensation parameter, f t for t The input gate output vector at time , W f is the input gate weight matrix,U f is the input gate bias vector, b f is the input gate compensation parameter, o t is the reset gate output vector, W o To reset the gate weight matrix, U o To reset the gate bias vector, b o To reset the gate compensation parameters, g t is the update gate output vector, tanh( ) is the hyperbolic tangent function, W g To update the gate weight matrix, U g To update the gate bias vector, b g To update the gate compensation parameters, c t for t The output gate output vector at time , c t-1 for t-1 The output gate outputs the vector at time .
[0057] S3. Different characters in the source code of the smart contract to be inspected are converted into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features.
[0058] After converting the source code of the smart contract to be tested into a contract syntax highlighting graph that is convenient for analyzing the code space layout, convolutional neural network processing is performed to extract the visual features of the contract syntax highlighting graph, capture the spatial information of the smart contract code to be tested, and obtain the contract space features, which is conducive to improving the vulnerability identification ability.
[0059] First, the different characters in the source code of the smart contract to be inspected are converted into an RGB matrix after RGB color marking to obtain a contract syntax highlighting diagram. Specifically, the character codes such as brackets, keywords, calculation operators, identifiers, currency units, comments, etc. in the source code are marked with RGB colors according to the corresponding element pixel values, converted into an RGB matrix of corresponding size according to the image size, and then the RGB matrix is mapped into a code color image to obtain a contract syntax highlighting diagram that is convenient for intuitive analysis of the spatial layout of the contract code.
[0060] Then, the contract syntax highlighting graph is processed by a convolutional neural network to obtain the contract space features.
[0061] The specific operations of convolutional neural network processing are as follows: the contract syntax highlighting graph is processed by convolution, RELU activation function and maximum pooling to obtain a pooled feature map; the pooled feature map is flattened, and then fully connected layer and nonlinear processing are performed to obtain the contract space features.
[0062] The operation of convolutional neural network processing is achieved through the following formula:
[0063] S=MaxPool(RELU(Conv(X))) ,
[0064] Z=RELU(W q ·fla(S)+b q ) ,
[0065] S is the pooling feature map, MaxPool( ) For the maximum pooling process, RELU( ) It is processed by RELU activation function. Conv ( ) For convolution processing, X This is the contract syntax highlighting diagram. W q is the weight of the fully connected layer, fla() For flattening, b q is the bias of the fully connected layer, Z It is the contract space feature.
[0066] S4. Contract structure features, contract semantic features, and contract space features are processed by attention respectively and then concatenated to obtain initial fusion features. The initial fusion features are pooled with contract structure features, contract semantic features, and contract space features after cross-attention processing to obtain multimodal fusion features. The multimodal fusion features are processed by the fully connected layer and probability mapping to obtain vulnerability detection results.
[0067] The three modal features (contract structure features, contract semantic features and contract space features) are processed with attention respectively and then spliced to achieve preliminary multi-modal fusion and obtain initial fusion features with strong comprehensive characteristics; then the different modal features (contract structure features, contract semantic features and contract space features) are further cross-attention processed with the initial fusion features and then pooled to fully capture the complex relationships between different modalities, obtain a more comprehensive and deeper contract code representation, and obtain multi-modal fusion features; finally, the multi-modal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results.
[0068] First, the contract structure features, contract semantic features, and contract space features are processed by attention respectively, and the features from different modalities are mapped to a unified feature space, and then spliced (which can be achieved through weighted summation) to obtain the initial fusion features.
[0069] Then, in order to further capture the complex relationships between different modal features, the initial fusion features are respectively combined with the contract structure features, contract semantic features and contract space features, and pooled after cross-attention processing to achieve multi-scale fusion and obtain multi-modal fusion features.
[0070] The specific operation of cross-attention processing is: the query vector of the contract structure feature, or the contract semantic feature, or the contract space feature is subjected to feature fusion with the key vector of the initial fusion feature (which can be achieved by vector multiplication), and then subjected to nonlinear processing, and then subjected to feature fusion with the value vector of the initial fusion feature to obtain the structural semantic initial fusion feature, or the structural space initial fusion feature, or the semantic space initial fusion feature; the structural semantic initial fusion feature, or the structural space initial fusion feature, or the semantic space initial fusion feature, is subjected to layer normalization processing, feedforward neural network processing and layer normalization processing respectively, to obtain the structural semantic fusion feature, or the structural space fusion feature, or the semantic space fusion feature, which is used to perform pooling processing (which can be achieved by average pooling or maximum pooling).
[0071] Finally, the multimodal fusion features are processed by the fully connected layer and probability mapping (can be passed) to obtain the vulnerability detection results including the vulnerability type and the corresponding vulnerability probability.
[0072] The vulnerability probability in the vulnerability detection result can be obtained by the following formula: P=σ(W p H f +b p ) , is the vulnerability probability, σ is the sigmoid function, W p is the fully connected weight matrix, b p is the fully connected bias vector, W p It is a multi-modal fusion feature.
[0073] To verify the effect of the detection method of this embodiment, the following experiment was conducted.
[0074] Dataset. In order to comprehensively evaluate the performance of the method in this embodiment, the experiment used the smart contract vulnerability detection benchmark dataset constructed and publicly released by Peng Qian and Zhenguang Liu et al., see Towards automated reentrancy detection for smart contracts based on sequential models ". This dataset covers a wide range of smart contract samples and multiple vulnerability types, involving multiple types of vulnerabilities, including reentrancy, timestamp dependency, integer overflow, and delegate call. The dataset was created by collecting smart contracts from three different sources, namely the Ethereum platform, GitHub repository, and blog posts analyzing contracts. It collected a total of 42,910 smart contract samples, which have both source code and bytecode. Among them, 680 contracts have reentrancy vulnerabilities, 2,242 contracts have timestamp dependency vulnerabilities, 1,368 contracts have integer overflow vulnerabilities, and 136 contracts have delegate call vulnerabilities. In the experiment, the dataset was stratified and randomly sampled in a ratio of 3:1:1 to obtain training, validation, and test sets. Each experiment was repeated 5 times, and the average result was taken as the final experimental result.
[0075] Evaluation indicators. In the experiment, four evaluation indicators were used to evaluate the performance of the detection method, namely, accuracy (ACC), recall (RE), precision (PRE) and F1-score (F1).
[0076] The above evaluation indicators are obtained through the following formula:
[0077] ,
[0078] ,
[0079] ,
[0080] ,
[0081] TP is a true positive, TN is a true negative, FP is a false positive, and FN is a false negative. The above evaluation indicators comprehensively measure the performance of the tool in the vulnerability detection task, ensuring that we can deeply understand the advantages and disadvantages of different detection methods in different aspects.
[0082] Parameter setting. All experiments were conducted on a computer equipped with a 3.3GHz Intel Core i9 CPU, a 2080Ti GPU, and 64GB of memory. The learning rate was adjusted in {0.0001, 0.0005, 0.001, 0.002}, the hidden layer size was searched in {64, 128, 256, 512}, and the batch size was searched in {16, 32, 64, 128}. In the experiment, a set of hyperparameters that achieved the best performance on the training set was selected, namely, the learning rate was 0.0001, the hidden layer size was 128, and the batch size was 64.
[0083] Performance comparison. In the experiment, the method of this embodiment is compared with 12 advanced existing methods, including rule / pattern matching-based methods (Oyente, SmartCheck, Slither), symbolic execution-based methods (Osiris, Mythril), fuzz testing-based methods (ConFuzzius, sFuzz) and deep learning methods (Vanilla-RNN, Rechecker, DR-GCN, TMP, AME). The experimental comparison results are shown in Table 1. As can be seen from Table 1, in the detection results of reentrant vulnerabilities by traditional methods, the accuracy of SmartCheck and Slither is only 44.32% and 69.38%, the accuracy of Oyente and Osiris is 65.56% and 52.86%, and sFuzz and ConFuzzius only achieve 60.42% and 78.02% accuracy. However, the method of this embodiment performs best in all four indicators of four types of vulnerabilities (reentrancy vulnerability, timestamp dependency vulnerability, integer overflow vulnerability, and delegate call vulnerability), and the accuracy gains on the four types of vulnerabilities are 12.73%, 24.53%, 13.41%, and 8.51%, respectively. In the process of comparing with deep learning methods, Vanilla-RNN and Rechecker use bytecode sequences, while DR-GCN, TMP, and AME use the contract graph of the source code. From the experimental results in Table 1, it can be seen that the performance of Vanilla-RNN and Rechecker is relatively poor, and DR-GCN, TMP, and AME perform slightly better, but they are not as good as the method of this embodiment.
[0084] Table 1 Performance comparison of different vulnerability detection methods
[0085] .
[0086] Comparison of multimodal learning effects. In the experiment, single modalities (text modality, visual modality, and graph modality (contract graph modality)) were used for vulnerability detection. The experimental results are shown in Table 2. The experimental results show that the three modalities have achieved certain results when performing vulnerability detection alone, but the multimodal fusion performance of the method in this embodiment significantly exceeds all single-modal methods, which can prove that the combination of multimodal information in the method in this embodiment can capture more contextual information and details, thereby having better generalization ability and prediction accuracy in vulnerability detection.
[0087] Table 2 Summary of the effects of different modalities for vulnerability detection
[0088] .
[0089] This embodiment also provides a smart contract vulnerability detection system based on multimodal fusion, which is used to implement the above-mentioned smart contract vulnerability detection method based on multimodal fusion, including:
[0090] The contract structure feature generation module is used to convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features;
[0091] The contract semantic feature generation module is used to obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain the operation code sequence through decompilation; the different operation codes belonging to the same control instruction in the operation code sequence are normalized to obtain the normalized operation code sequence; the normalized operation code sequence is processed through bidirectional semantic feature extraction to obtain the contract semantic feature;
[0092] The contract space feature generation module is used to convert different characters in the source code of the smart contract to be inspected into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features;
[0093] The vulnerability detection result generation module is used for contract structure features, contract semantic features and contract space features, which are respectively processed by attention and then spliced to obtain initial fusion features; the initial fusion features are respectively pooled with contract structure features, contract semantic features and contract space features after cross attention processing to obtain multimodal fusion features; the multimodal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results.
[0094] This embodiment also provides a smart contract vulnerability detection device based on multimodal fusion, including a processor and a memory, wherein the processor implements the above-mentioned smart contract vulnerability detection method based on multimodal fusion when executing a computer program stored in the memory.
[0095] This embodiment also provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the above-mentioned smart contract vulnerability detection method based on multimodal fusion.
[0096] The present embodiment provides a smart contract vulnerability detection method based on multimodal fusion. First, a contract graph of the smart contract to be tested is obtained, which is convenient for capturing the complex relationship between functions and variables. After graph convolution processing and global maximum pooling processing based on node connection relationships, the structural information and node features of the contract graph are extracted, the control flow and data flow relationship of the code are captured, and the contract structure features are obtained; at the same time, the running bytecode in the bytecode of the smart contract to be tested is obtained, and after decompilation and normalization processing, a bidirectional semantic feature extraction processing is performed to extract the semantic features of the bytecode sequence, capture the context dependency between the operation codes, and obtain the contract semantic features; in addition, the source code of the smart contract to be tested is converted into a contract syntax highlighting graph that is convenient for analyzing the code space layout, and then a convolutional neural network processing is performed to extract the visual features of the contract syntax highlighting graph to capture the contract. The spatial information of the smart contract code is obtained to obtain the contract space features; finally, the three modal features (contract structure features, contract semantic features and contract space features) are processed with attention respectively and then spliced to achieve the initial fusion of multi-modality and obtain the initial fusion features with strong comprehensive characteristics; then the different modal features (contract structure features, contract semantic features and contract space features) are further cross-attention processed with the initial fusion features and then pooled to fully capture the complex relationships between different modalities, obtain a more comprehensive and deeper representation of the contract code, and obtain multi-modal fusion features; finally, the multi-modal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results; when this method is used for smart contract vulnerability detection, it has high efficiency and good stability, and has high accuracy, recall rate, precision and F1 score.
Claims
1. A smart contract vulnerability detection method based on multimodal fusion, characterized in that: The following operations are included: S1. Convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features; S2. Obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain the operation code sequence through decompilation; Normalizing different operation codes belonging to the same control instruction in the operation code sequence to obtain a normalized operation code sequence; The normalized opcode sequence is processed by bidirectional semantic feature extraction to obtain the contract semantic features; S3. Different characters in the source code of the smart contract to be inspected are converted into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features; S4, contract structure features, contract semantic features and contract space features are processed by attention respectively and then concatenated to obtain the initial fusion features; The initial fusion features are pooled with the contract structure features, contract semantic features, and contract space features respectively after cross-attention processing to obtain multimodal fusion features; The multimodal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results.
2. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1 is characterized in that: In S1, the operation of graph convolution processing based on node connection relationship is implemented by the following formula: , H (l+1) For the l+1 The graph convolution features of the layer, σ is the sigmoid function, A r For the r The adjacency matrix corresponding to the connection relationship is: R is the total number of connection relationships, which are edge connection relationships between nodes in the contract graph, including control flow edge connections, data flow edge connections, forward edge connections, and back-off edge connections; W r For the r The corresponding weights of the connection relationships are H (l) For the l The graph convolution features of the layer, W (l) No. l The graph convolution weights of the layer.
3. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1 is characterized in that: In the S1, after obtaining the contract graph, it also includes: adding the feature information and edges of the amount node and / or the fallback node to the nodes connected to the amount node and / or the fallback node, deleting the amount node and / or the fallback node in the contract graph, and obtaining an optimized contract graph for performing graph convolution processing operations based on node connection relationships.
4. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1, characterized in that: The normalization operation in S2 is achieved by replacing different operation codes belonging to the same control instruction with the same control operation code.
5. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1 is characterized in that: The specific operation of the bidirectional semantic feature extraction process in S2 is: The normalized operation code sequence is cut into a number of subsequences, and the subsequences are processed by a number of long short-term memory units respectively according to the positive position order in the normalized operation code sequence to obtain positive semantic features; Several subsequences are processed by several long short-term memory units in the reverse position order of the normalized operation code sequence to obtain reverse semantic features; the reverse semantic features and the forward semantic features are weighted fused to obtain the contract semantic features.
6. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1, characterized in that: The operations of the convolutional neural network processing in S3 are specifically as follows: The contract syntax highlighting graph is processed by convolution, RELU activation function and maximum pooling to obtain a pooled feature map; after the pooled feature map is flattened, it is processed by a fully connected layer and nonlinearly to obtain the contract space features.
7. The method for detecting smart contract vulnerabilities based on multimodal fusion according to claim 1 is characterized in that: The operation of the cross attention processing in S4 is specifically as follows: The query vector of the contract structure feature, or the contract semantic feature, or the contract space feature is subjected to feature fusion with the key vector of the initial fusion feature, and then subjected to nonlinear processing, and then subjected to feature fusion with the value vector of the initial fusion feature to obtain the structural semantic initial fusion feature, or the structural space initial fusion feature, or the semantic space initial fusion feature; The structural semantic initial fusion features, or the structural space initial fusion features, or the semantic space initial fusion features, are respectively processed by layer normalization, feedforward neural network processing and layer normalization processing to obtain structural semantic fusion features, or structural space fusion features, or semantic space fusion features, which are used to perform pooling operations.
8. A smart contract vulnerability detection system based on multimodal fusion, used to implement the smart contract vulnerability detection method based on multimodal fusion according to claim 1, characterized in that: include: The contract structure feature generation module is used to convert the source code of the smart contract to be inspected into a contract graph; the nodes in the contract graph include call function nodes, amount nodes and fallback nodes; the edges between nodes in the contract graph include control flow edges, data flow edges, forward edges and fallback edges; the contract graph is processed by graph convolution based on the node connection relationship and global maximum pooling to obtain the contract structure features; The contract semantic feature generation module is used to obtain the running bytecode in the bytecode of the smart contract to be inspected, and obtain the operation code sequence after decompiling; Normalizing different operation codes belonging to the same control instruction in the operation code sequence to obtain a normalized operation code sequence; The normalized opcode sequence is processed by bidirectional semantic feature extraction to obtain the contract semantic features; The contract space feature generation module is used to convert different characters in the source code of the smart contract to be inspected into an RGB matrix after RGB color marking to obtain a contract syntax highlighting image; the contract syntax highlighting image is processed by a convolutional neural network to obtain the contract space features; The vulnerability detection result generation module is used for contract structure features, contract semantic features, and contract space features. After attention processing, they are spliced to obtain the initial fusion features; The initial fusion features are pooled with the contract structure features, contract semantic features, and contract space features respectively after cross-attention processing to obtain multimodal fusion features; The multimodal fusion features are processed by the fully connected layer and probability mapping to obtain the vulnerability detection results.
9. A smart contract vulnerability detection device based on multimodal fusion, characterized in that: It includes a processor and a memory, wherein when the processor executes the computer program stored in the memory, it implements the smart contract vulnerability detection method based on multimodal fusion as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Intelligent contract vulnerability detection method and device based on syntax and semantic feature fusion
CN116089957A
Multi-modal feature-based vulnerability detection method for generative smart contract
CN116595537A