Methods, apparatus, equipment, media, and program products for constructing vulnerability sample data

By constructing a method for multidimensional feature alignment and multimodal fusion, high-quality smart contract vulnerability sample data is generated, which solves the problems of single feature dimension and lack of contextual information in existing datasets and improves the training effect of smart contract vulnerability detection models.

CN123069372APending Publication Date: 2026-11-10CHINA UNITED NETWORK COMM GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610984920.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-02
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection datasets have limited feature dimensions, coarse annotation granularity, and ignore runtime context information, resulting in poor model training performance, especially in terms of fine-grained vulnerability localization and dynamic behavior recognition capabilities.

Method used

By extracting multidimensional feature data from smart contract vulnerability samples, including source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features, and performing feature alignment and multimodal fusion, high-quality vulnerability sample data is generated for training smart contract vulnerability detection models.

Benefits of technology

It improves the training effect of the smart contract vulnerability detection model, provides high-quality training and evaluation data support, and enhances the model's ability to identify smart contract vulnerabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123069372A_ABST
    Figure CN123069372A_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, device, medium, and program product for constructing vulnerability sample data, relating to the field of artificial intelligence technology, and is used to improve the training effect of smart contract vulnerability detection models. The specific technical solution is as follows: after obtaining a smart contract vulnerability sample, extract the multi-dimensional feature data corresponding to the vulnerability sample. This multi-dimensional feature data includes: source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features; perform feature alignment on the multi-dimensional feature data, and input the aligned multi-dimensional feature data into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample; based on the fused feature data corresponding to the smart contract vulnerability sample and the vulnerability label corresponding to the smart contract vulnerability sample, generate vulnerability sample data, which is used to train the smart contract vulnerability detection model. This application is applied to smart contract vulnerability detection scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to methods, apparatus, devices, media and program products for constructing vulnerability sample data. Background Technology

[0002] With the widespread application of blockchain technology, smart contracts on blockchain platforms such as Ethereum, with their characteristics of automatic execution and immutability, have been widely used in many fields such as decentralized finance (DeFi), NFTs, and supply chain management. However, the fact that smart contracts cannot be modified after deployment makes their code vulnerabilities extremely easy to exploit maliciously, leading to security incidents such as the theft of huge amounts of assets. Therefore, conducting smart contract vulnerability detection can mitigate various potential risks before smart contracts go live, ensuring the secure and stable operation of the blockchain. Currently, conventional smart contract vulnerability detection solutions mainly rely on smart contract vulnerability detection models, and high-quality dataset construction technology is crucial as the foundation of these models.

[0003] In related technologies, dataset construction is primarily based on source code and bytecode. Specifically, the smart contract source code and bytecode are cleaned, and then abstract syntax tree features are extracted from the cleaned source code, while a basic control flow graph is extracted from the cleaned bytecode. Based on this basic control flow graph, a cross-chain control flow graph feature is constructed. Finally, based on the abstract syntax tree features and the cross-chain control flow graph feature, a final fused feature vector is obtained, thus completing the feature construction of the dataset for the smart contract vulnerability detection model.

[0004] However, in the process of constructing the above dataset, although the source code and bytecode were combined in multiple dimensions, it still remained at the level of physical splicing of features, which resulted in insufficient reliability of the final constructed dataset. Summary of the Invention

[0005] This application provides a method, apparatus, device, medium, and program product for constructing vulnerability sample data, which can be used to improve the training effect of smart contract vulnerability detection models.

[0006] In a first aspect, embodiments of this application provide a method for constructing vulnerability sample data. The method includes: acquiring a smart contract vulnerability sample; acquiring multi-dimensional feature data corresponding to the smart contract vulnerability sample, the multi-dimensional feature data including: source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features; wherein the aforementioned historical interaction features are determined based on the logs of multiple contract calls and interaction relationships of the smart contract vulnerability sample on the blockchain network; aligning the aforementioned multi-dimensional feature data, and inputting the aligned multi-dimensional feature data into a multimodal fusion model for feature fusion to obtain fused feature data corresponding to the smart contract vulnerability sample; generating vulnerability sample data based on the fused feature data corresponding to the smart contract vulnerability sample and the vulnerability tag corresponding to the smart contract vulnerability sample, the vulnerability sample data being used to train a smart contract vulnerability detection model.

[0007] The technical solution provided in this application brings at least the following beneficial effects: This application extracts multi-dimensional features from the obtained smart contract vulnerability samples to obtain multi-dimensional feature data including source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. The multi-dimensional feature data is then aligned to obtain structurally unified multi-dimensional feature data. This unified multi-dimensional feature data is then fused using a multi-modal fusion model to obtain fused feature data. After standardizing the fused feature data, high-quality vulnerability sample data for training the smart contract vulnerability detection model can be obtained. This provides high-quality training and evaluation data support for the smart contract vulnerability detection model, effectively improving the training effect of the smart contract vulnerability detection model.

[0008] One possible implementation is that the aforementioned source code features include the embedding vector; the acquisition of multi-dimensional feature data corresponding to the aforementioned smart contract vulnerability sample includes: extracting an abstract semantic analysis tree and a control flow graph of the aforementioned smart contract vulnerability sample, wherein the abstract semantic analysis tree is used to describe the code syntax structure and the control flow graph is used to describe the code execution logic; extracting structured features from the abstract semantic analysis tree and the control flow graph, wherein the structured features include security features, structural features, variable features, and constant features; and generating the aforementioned embedding vector based on the aforementioned structured features.

[0009] Another possible implementation involves obtaining the multi-dimensional feature data corresponding to the aforementioned smart contract vulnerability sample, including: obtaining the bytecode of the smart contract vulnerability sample based on its source code, and converting the bytecode into an opcode sequence; extracting basic statistical features and opcode semantic features from the opcode sequence; analyzing the jump relationships between bytecode instructions based on the basic statistical features to construct a control flow profile; extracting bytecode structural features from the basic statistical features, including the number of basic blocks, loop depth, and control complexity of the bytecode; obtaining bytecode features based on the control flow profile and the bytecode structural features; and obtaining opcode features based on the opcode semantic features and the basic statistical features.

[0010] Another possible implementation involves obtaining the multi-dimensional feature data corresponding to the aforementioned smart contract vulnerability sample, including: obtaining multiple contract call and interaction relationship logs of the aforementioned smart contract vulnerability sample on the blockchain network, with each of the multiple contract call and interaction relationship logs corresponding to a timestamp; constructing a time-series dependency graph based on the log features extracted from the multiple contract call and interaction relationship logs, wherein the log features include call frequency, call time, caller address, and interaction relationship with other contracts; each node in the time-series dependency graph corresponds to a caller address or contract address, and each edge in the time-series dependency graph corresponds to an interaction relationship and is accompanied by a timestamp attribute; and obtaining the aforementioned historical interaction features based on the time-series dependency graph.

[0011] Another possible implementation involves obtaining the multi-dimensional feature data corresponding to the aforementioned smart contract vulnerability sample, including: generating control flow edges based on the abstract semantic analysis tree and control flow graph of the aforementioned smart contract vulnerability sample; the control flow edges are used to characterize the program execution sequence; and based on the aforementioned smart contract vulnerability sample... Variable data Data flow edges are constructed to represent the data transfer relationship of variables from their definition location to their usage location. Based on the logs of multiple contract calls and interactions on the blockchain network of the smart contract vulnerability samples mentioned above, cross-contract call edges are constructed to represent the call relationship between different smart contracts. Multi-dimensional edge fusion is performed based on the control flow edges, data flow edges, and cross-contract call edges to obtain multi-dimensional graph structure features.

[0012] Another possible implementation involves aligning the aforementioned multidimensional feature data and inputting the aligned multidimensional feature data into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the aforementioned smart contract vulnerability sample. This includes: performing feature mapping between the aforementioned temporal dependency graph and control flow graph, using the nodes representing external calls in the control flow graph as key anchor points, mapping the corresponding interaction relationships in the temporal dependency graph to the aforementioned key anchor points, and adding the aforementioned historical interaction features to the aforementioned key anchor points; aligning the aforementioned source code features, the aforementioned bytecode features, the aforementioned opcode features, the aforementioned historical interaction features, and the multidimensional graph structure features to obtain the aligned multidimensional feature data.

[0013] Another possible implementation is that the aforementioned multimodal fusion model is a neural network fusion model based on an attention mechanism, in which each layer of the decoder is configured with multiple independent attention heads. The process of inputting the aligned multidimensional feature data into the multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample includes: inputting the aligned multidimensional feature data into the multimodal fusion model, performing weighted processing on the aligned multidimensional feature data to obtain processed multidimensional feature data; and using different attention heads in the encoder to perform deep processing on the feature data of different dimensions in different representation subspaces of the processed multidimensional feature data, and fusing them to obtain the fused feature data.

[0014] Another possible implementation method for constructing vulnerability sample data includes: inputting the vulnerability sample data into a neural network fusion model based on an attention mechanism, wherein each layer of the decoder in the neural network fusion model is configured with multiple independent attention heads; using the multiple attention heads in the decoder, processing feature data of different dimensions in the fusion feature data of the vulnerability sample data in different representation subspaces in parallel, learning the importance weights of feature data of different dimensions to the vulnerability sample data, so as to train the neural network model.

[0015] Secondly, embodiments of this application provide a vulnerability sample data construction apparatus, comprising: an acquisition module for acquiring smart contract vulnerability samples; the acquisition module is further configured to acquire multi-dimensional feature data corresponding to the smart contract vulnerability samples, the multi-dimensional feature data including: source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features; wherein the historical interaction features are determined based on the logs of multiple contract calls and interaction relationships of the smart contract vulnerability samples on the blockchain network; a processing module for feature alignment of the multi-dimensional feature data, and inputting the aligned multi-dimensional feature data into a multimodal fusion model for feature fusion to obtain fused feature data corresponding to the smart contract vulnerability samples; and a generation module for generating vulnerability sample data based on the fused feature data corresponding to the smart contract vulnerability samples obtained by the processing module and the vulnerability tags corresponding to the smart contract vulnerability samples, the vulnerability sample data being used to train a smart contract vulnerability detection model.

[0016] One possible implementation is that the acquisition module described above is specifically used to: extract the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample, wherein the abstract semantic analysis tree is used to describe the code syntax structure and the control flow graph is used to describe the code execution logic; extract structured features from the abstract semantic analysis tree and the control flow graph, wherein the structured features include security features, structural features, variable features and constant features; and generate the embedding vector based on the structured features.

[0017] In another possible implementation, the aforementioned acquisition module is further configured to: acquire the bytecode of the aforementioned smart contract vulnerability sample based on the source code of the aforementioned smart contract vulnerability sample, and convert the aforementioned bytecode into an opcode sequence; extract basic statistical features and opcode semantic features from the aforementioned opcode sequence; analyze the jump relationships between bytecode instructions based on the aforementioned basic statistical features to construct a control flow profile; extract bytecode structural features from the aforementioned basic statistical features, the aforementioned bytecode structural features including the number of basic blocks, loop depth, and control complexity of the aforementioned bytecode; obtain bytecode features based on the aforementioned control flow profile and the aforementioned bytecode structural features; and obtain opcode features based on the aforementioned opcode semantic features and the aforementioned basic statistical features.

[0018] In another possible implementation, the aforementioned acquisition module is further configured to: acquire multiple contract call and interaction relationship logs of the aforementioned smart contract vulnerability sample on the blockchain network, each of the aforementioned multiple contract call and interaction relationship logs corresponding to a timestamp; construct a time-series dependency graph based on the log features extracted from the aforementioned multiple contract call and interaction relationship logs, the aforementioned log features including call frequency, call time, caller address, and interaction relationship with other contracts; each node in the aforementioned time-series dependency graph corresponds to a caller address or contract address, each edge in the aforementioned time-series dependency graph corresponds to an interaction relationship and is accompanied by a timestamp attribute; and obtain the aforementioned historical interaction features based on the aforementioned time-series dependency graph.

[0019] Another possible implementation is that the aforementioned acquisition module is further used to: generate control flow edges based on the abstract semantic analysis tree and control flow graph of the aforementioned smart contract vulnerability sample; the aforementioned control flow edges are used to characterize the program execution sequence; based on the aforementioned smart contract vulnerability sample... Variable data Data flow edges are constructed to represent the data transfer relationship of variables from their definition location to their usage location. Based on the logs of multiple contract calls and interactions on the blockchain network of the smart contract vulnerability samples mentioned above, cross-contract call edges are constructed to represent the call relationship between different smart contracts. Multi-dimensional edge fusion is performed based on the control flow edges, data flow edges, and cross-contract call edges to obtain multi-dimensional graph structure features.

[0020] Another possible implementation is that the above processing module is specifically used to: perform feature mapping between the above-mentioned time-series dependency graph and the control flow graph, take the node representing the external call in the control flow graph as the key anchor point, map the corresponding interaction relationship in the time-series dependency graph to the above-mentioned key anchor point, and add the above-mentioned historical interaction features to the above-mentioned key anchor point; align the above-mentioned source code features, the above-mentioned bytecode features, the above-mentioned opcode features, the above-mentioned historical interaction features and the multidimensional graph structure features to obtain aligned multidimensional feature data.

[0021] In another possible implementation, the above processing module is further used to: input the aligned multidimensional feature data into the multimodal fusion model, perform weighted processing on the aligned multidimensional feature data to obtain the processed multidimensional feature data; and perform deep processing on the feature data of different dimensions in the processed multidimensional feature data in different representation subspaces through different attention heads in the encoder, and fuse them to obtain the fused feature data.

[0022] In another possible implementation, the aforementioned processing module is further configured to: input vulnerability sample data into a neural network fusion model based on an attention mechanism, wherein each layer of the neural network fusion model is configured with multiple independent attention heads; through the multiple attention heads in the aforementioned decoder, process the feature data of different dimensions in the aforementioned fused feature data of the aforementioned vulnerability sample data in parallel in different representation subspaces, and learn the importance weights of the feature data of different dimensions to the aforementioned vulnerability sample data, so as to train the aforementioned neural network model.

[0023] Thirdly, this application provides an electronic device comprising: a processor and a memory; the memory stores a program or instructions executable on the processor, wherein the program or instructions, when executed by the processor, implement the method of the first aspect described above.

[0024] Fourthly, this application provides a readable storage medium on which a program or instructions are stored, which, when executed by a computer, implement the method of the first aspect described above.

[0025] Fifthly, this application provides a computer program product stored in a storage medium, which, when executed by a computer, implements the method described in the first aspect.

[0026] In a sixth aspect, embodiments of this application provide a chip including a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the method as described in the first aspect above.

[0027] The beneficial effects of the second to sixth aspects mentioned above are described in the corresponding description of the first aspect and will not be repeated here. Attached Figure Description

[0028] Figure 1 A schematic diagram of the network architecture for an application of a vulnerability sample data construction method provided in this application embodiment;

[0029] Figure 2 A flowchart illustrating a vulnerability sample data construction method provided in an embodiment of this application;

[0030] Figure 3 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0031] Figure 4 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0032] Figure 5 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0033] Figure 6 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0034] Figure 7 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0035] Figure 8 A flowchart illustrating another vulnerability sample data construction method provided in this application embodiment;

[0036] Figure 9 A flowchart illustrating a method for constructing a model training method using vulnerability sample data, provided in an embodiment of this application;

[0037] Figure 10 A flowchart illustrating the implementation process of another vulnerability sample data construction method provided in this application embodiment;

[0038] Figure 11 A flowchart illustrating a method for obtaining smart contract vulnerability samples provided in an embodiment of this application;

[0039] Figure 12 A flowchart illustrating a method for obtaining source code features provided in an embodiment of this application;

[0040] Figure 13 A flowchart illustrating a method for obtaining bytecode features and opcode features provided in an embodiment of this application;

[0041] Figure 14 A flowchart illustrating a method for obtaining historical interaction relationship features provided in an embodiment of this application;

[0042] Figure 15 A flowchart illustrating a method for obtaining multidimensional graph features provided in an embodiment of this application;

[0043] Figure 16 A flowchart illustrating a multidimensional data feature alignment and fusion method provided in an embodiment of this application;

[0044] Figure 17 A schematic diagram of a vulnerability sample data construction device provided in this application embodiment;

[0045] Figure 18 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0046] The following section will describe in detail, with reference to the accompanying drawings, the method, apparatus, equipment, media, and program products for constructing vulnerability sample data provided in this application.

[0047] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0048] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0049] The terms "at least one," "at least one of," etc., used in the specification and claims of this application refer to any one, any two, or a combination of two or more of the included items. For example, at least one of a, b, and c can mean: "a," "b," "c," "a and b," "a and c," "b and c," and "a, b, and c," where a, b, and c can be single or multiple. Similarly, "at least two" refers to two or more items, and its meaning is similar to that of "at least one."

[0050] In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0051] The embodiments of this application provide a method, apparatus, device, medium, and program product for constructing vulnerability sample data, which can be applied to smart contract vulnerability detection scenarios.

[0052] With the widespread application of blockchain technology, smart contracts on blockchain platforms such as Ethereum, with their characteristics of automatic execution and immutability, have been widely used in many fields such as decentralized finance (DeFi), NFTs, and supply chain management. However, the fact that smart contracts cannot be modified after deployment makes their code vulnerabilities extremely easy to exploit maliciously, leading to security incidents such as the theft of huge amounts of assets. Therefore, conducting smart contract vulnerability detection can mitigate various potential risks before smart contracts go live, ensuring the secure and stable operation of the blockchain. Currently, conventional smart contract vulnerability detection solutions mainly rely on smart contract vulnerability detection models, and high-quality dataset construction technology is crucial as the foundation of these models.

[0053] In existing technologies, the methods for constructing vulnerability sample datasets mainly fall into the following three categories.

[0054] Dataset construction based on source code, such as a smart contract vulnerability detection method based on heterogeneous graph attention networks, involves several approaches. First, the smart contract source code is preprocessed to construct a Smart Contract Code Intermediate Representation (SCIR), reducing code complexity and enriching vulnerability features. Next, a Smart Contract Code Property Graph (SCPG) is built based on the SCIR, integrating various code graph structures such as Abstract Syntax Trees (ASTs) and Control Flow Graphs (CFBGs) to comprehensively characterize the contract's syntactic and semantic features. Finally, a Heterogeneous Smart Contract Code Graph (SCHG) is constructed on top of the SCPG to optimize the code graph structure representation and achieve high-quality modeling of node features.

[0055] Dataset construction based on bytecode, such as a smart contract vulnerability detection method based on a multi-level data dependency heterogeneous graph, is proposed. This method takes smart contract bytecode as input, converts the contract bytecode into opcode, and constructs a control-data heterogeneous graph with basic blocks as nodes. It designs intra-block data dependency subgraphs to form multi-level data dependencies with inter-block data flows. Based on the generated control-data heterogeneous graph, a feature-weighted relational graph convolutional network is proposed. By utilizing static node attributes such as the depth of the dominator tree, the feature weights of the control flow and data flow are dynamically optimized to achieve efficient aggregation of multimodal semantics.

[0056] Dataset construction is based on source code and bytecode. For example, a cross-chain smart contract vulnerability detection method and system based on multi-feature fusion learning extracts features from source code and bytecode. An Abstract Syntax Tree (AST) is extracted from the cleaned source code, and a Basic Control Flow Graph (CFG) is extracted from the bytecode to construct a cross-chain control flow graph (xCFG). The AST and xCFG are used for feature representation, and graph vectors are generated using a Graph Neural Network (GNN) and semantic vectors are generated using CodeBert. These are then fused into a feature fusion vector, thus completing the feature construction of the dataset for the smart contract vulnerability detection model.

[0057] However, among the aforementioned methods for constructing datasets, some methods result in datasets with limited feature dimensions and insufficient information. While some methods combine source code and bytecode in multiple dimensions, they still remain at the level of physical feature splicing, leading to insufficient reliability of the final datasets and consequently poor training performance of smart contract vulnerability detection models.

[0058] In other words, this application aims to address the technical problems of existing smart contract vulnerability detection datasets, such as limited feature dimensions, coarse annotation granularity, lack of contextual information, and insufficient vulnerability samples. Specifically, to address the shortcomings of current datasets built based on source code, bytecode, or a simple combination of both, which struggle to support fine-grained vulnerability localization and high-generalization model training, this application provides a method for constructing a Solidity multidimensional dataset for smart contract vulnerability detection, solving the following problems:

[0059] (1) To solve the problem that existing datasets only contain source code, bytecode or a simple combination of the two, and lack systematic integration of multi-dimensional feature representations such as syntax structure, control flow, data flow, temporal dependencies and semantic features;

[0060] (2) To address the problem that vulnerability annotation is usually performed on a per-file basis, which cannot be accurate to the contract function level, making it difficult for the model to learn the local features of the vulnerability;

[0061] (3) To address the problem that existing datasets ignore runtime context information such as contract call history and interaction relationships, thus limiting the model's ability to identify vulnerabilities related to dynamic behavior;

[0062] (4) To solve the problem that some vulnerability types have insufficient training data due to the scarcity of real samples, which leads to weak generalization ability and low recognition accuracy of vulnerability detection models.

[0063] To address the aforementioned issues, this application constructs a smart contract Solidity dataset with a unified structure, multidimensional features, fine annotation, and integrated runtime context information. This invention provides high-quality training and evaluation data support for smart contract vulnerability detection models.

[0064] In other words, this application provides a method, apparatus, device, medium, and program product for constructing vulnerability sample data. This application extracts multi-dimensional features from the obtained smart contract vulnerability samples to obtain multi-dimensional feature data including source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. The multi-dimensional feature data is then aligned to obtain structurally unified multi-dimensional feature data. This structurally unified multi-dimensional feature data is then fused using a multi-modal fusion model to obtain fused feature data. After standardizing the fused feature data, high-quality vulnerability sample data for training smart contract vulnerability detection models can be obtained. This provides high-quality training and evaluation data support for smart contract vulnerability detection models, effectively improving the training effect of smart contract vulnerability detection models.

[0065] The following description, in conjunction with the accompanying drawings, details the vulnerability sample data construction method, apparatus, device, medium, and program product provided in the embodiments of this application.

[0066] Figure 1 The network architecture of a vulnerability sample data construction method provided in an embodiment of this application is illustrated. For example... Figure 1 As shown, the network architecture includes a vulnerability sample data construction device 101 and a terminal device 102. The vulnerability sample data construction device 101 and the terminal device 102 are interconnected.

[0067] In some embodiments, the vulnerability sample data construction apparatus 101 may be a server, a computer, or a processor or processing unit within a server or computer. The server may be a single server or a server cluster consisting of multiple servers. It should be noted that the embodiments of this application do not limit the specific device form of the vulnerability sample data construction apparatus 101. Figure 1 The Sino-Israeli vulnerability sample data construction device 101 is shown as an example of a single server.

[0068] In some embodiments, the terminal device may be a mobile phone, tablet computer, laptop computer, handheld computer, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, personal computer (PC), ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., and the embodiments of this application do not specifically limit it. Figure 1 The terminal device 102 between China and Israel is shown as an example of a laptop computer.

[0069] In some embodiments, the vulnerability sample data construction device 101 acquires smart contract vulnerability samples; the vulnerability sample data construction device 101 extracts multi-dimensional feature data corresponding to the smart contract vulnerability samples; the vulnerability sample data construction device 101 performs feature alignment on the multi-dimensional feature data, and inputs the aligned multi-dimensional feature data into a multi-modal fusion model for feature fusion to obtain fused feature data corresponding to the smart contract vulnerability sample; the vulnerability sample data construction device 101 generates vulnerability sample data based on the fused feature data corresponding to the smart contract vulnerability sample and the vulnerability tag corresponding to the smart contract vulnerability sample, trains a smart contract vulnerability detection model based on the vulnerability sample data, and deploys the trained smart contract vulnerability detection model in the terminal device 102 for vulnerability detection.

[0070] It should be noted that the network architecture described in the embodiments of this application is for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and does not constitute a limitation on the technical solutions provided in the embodiments of this application. As network architectures evolve, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.

[0071] See Figure 2 This is a flowchart illustrating a vulnerability sample data construction method provided in an embodiment of this application. Figure 2 As shown, the vulnerability sample data construction method provided in this application embodiment can be implemented by the above-described vulnerability sample data construction device, specifically including the following steps 201 to 204.

[0072] Step 201: The vulnerability sample data construction device obtains smart contract vulnerability samples.

[0073] In some embodiments, the smart contract vulnerability sample described above includes a vulnerability type label, which is used to indicate the vulnerability type of the smart contract vulnerability sample.

[0074] In some embodiments, the above-mentioned smart contract vulnerability samples may be one or more smart contract vulnerability samples.

[0075] In some embodiments, data augmentation can be performed on smart contract data samples to obtain high-quality smart contract data samples. After the high-quality smart contract data samples are labeled with vulnerability types, smart contract vulnerability samples can be obtained.

[0076] In some embodiments, the smart contract data sample collection platform can be the GitHub open-source platform.

[0077] In some embodiments, the data augmentation technique described above refers to: writing a variant template with semantic equivalence based on existing vulnerability data characteristics in smart contract data samples; inserting controllable noise into the code structure of the variant template to simulate real development scenarios; and then using the Slither static analysis framework to compile and verify the generated code of the variant template with inserted controllable noise, thereby obtaining high-quality smart contract data samples. This is used to increase the number of samples of specific vulnerability types, improve the authenticity, coverage, and generalization ability of the data training.

[0078] In some embodiments, the aforementioned controllable noise refers to artificially added smart contract vulnerabilities with freely adjustable parameters, used to expand the sample and improve the model's generalization ability.

[0079] In some embodiments, the vulnerability sample data construction device uses a vulnerability annotation tool to annotate the vulnerability types in high-quality smart contract data samples according to the Smart Contract Weakness Classification (SWC) standard.

[0080] In some embodiments, the aforementioned vulnerability labeling tools include, but are not limited to, static execution tools such as Slither, Mythril, Oyente, and Securify, or semi-automatic vulnerability labeling combined with large models.

[0081] In some embodiments, the aforementioned SWC standard refers to the Smart Contract Vulnerability Classification Standard, used to label vulnerability categories in security training samples.

[0082] In some embodiments, the above-mentioned smart contract vulnerability annotation uses smart contract functions as the smallest annotation unit, and the annotation content includes: vulnerability type, specific location (i.e., file name, line number, function name), and vulnerability severity level.

[0083] In some embodiments, the vulnerability types include, but are not limited to: integer overflow vulnerability SWC-101, reentrancy vulnerability SWC-107, and timestamp dependency vulnerability SWC-112.

[0084] Step 202: The vulnerability sample data construction device obtains the multi-dimensional feature data corresponding to the smart contract vulnerability samples mentioned above.

[0085] In some embodiments, the multidimensional feature data described above includes feature data of at least one dimension.

[0086] In some embodiments, the multidimensional feature data mentioned above includes: source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features.

[0087] The aforementioned historical interaction characteristics were determined based on the logs of multiple contract calls and interactions on the blockchain network of the aforementioned smart contract vulnerability sample.

[0088] Step 203: The vulnerability sample data construction device performs feature alignment on the above-mentioned multi-dimensional feature data, and inputs the aligned multi-dimensional feature data into the multi-modal fusion model for feature fusion to obtain the fused feature data corresponding to the above-mentioned smart contract vulnerability sample.

[0089] It should be noted that, in addition to using a multimodal fusion model, other multimodal fusion methods include: feature concatenation followed by a fully connected network, multi-relation aggregation in graph neural networks (such as R-GCN) to process CFG, DFG, call edges, and multi-task learning frameworks respectively, assigning an independent encoder to each type of feature and sharing high-level representations.

[0090] Step 204: The vulnerability sample data construction device generates vulnerability sample data based on the fusion feature data and vulnerability tags corresponding to the smart contract vulnerability samples.

[0091] The aforementioned vulnerability sample data was used to train a smart contract vulnerability detection model.

[0092] In some embodiments, the vulnerability sample data construction apparatus can generate one or more vulnerability sample data based on the fusion feature data corresponding to the smart contract vulnerability sample and the vulnerability tag corresponding to the smart contract vulnerability sample. For example, a smart contract vulnerability sample can be used to generate one vulnerability sample data or multiple vulnerability sample data; this application does not limit this.

[0093] In the vulnerability sample data construction method provided in this application, multi-dimensional data features corresponding to smart contract vulnerability samples are extracted, and after aligning the multi-dimensional data features, they are input into a multimodal fusion model for feature fusion to obtain fused feature data corresponding to the smart contract vulnerability sample. Based on the fused feature data, vulnerability sample data for training the smart contract vulnerability detection model is obtained. The vulnerability sample data contains multi-dimensional data features and has a unified structure, providing high-quality training and evaluation data support for the smart contract vulnerability detection model and effectively improving the training effect of the smart contract vulnerability detection model.

[0094] It should be noted that existing technologies for smart contract vulnerability detection often rely solely on static source code analysis or bytecode pattern matching. Even when attempting to combine multi-dimensional features, they mostly remain at the level of physical feature assembly, ignoring the inherent contradictions and complementary relationships between different modal features. The core essence of this application lies in constructing a feature alignment and dynamic fusion mechanism at the function level, enabling cross-dimensional cross-verification of the high-dimensional semantics of the source code, the underlying execution logic of the bytecode, and the dynamic temporal characteristics of on-chain interactions, thereby identifying hidden vulnerabilities that cannot be detected by a single dimension.

[0095] In some embodiments, such as Figure 3 As shown, the process of "obtaining the source code features corresponding to the smart contract vulnerability sample" in step 202 can be implemented through the following steps 301 and 303.

[0096] Step 301: The vulnerability sample data construction device extracts the abstract semantic analysis tree and control flow graph of the above-mentioned smart contract vulnerability sample.

[0097] The abstract semantic analysis tree described above is used to describe the code syntax structure, and the control flow graph described above is used to describe the code execution logic.

[0098] In some embodiments, the abstract semantic analysis tree described above is used to express the program's syntactic structure, reflecting the logical hierarchy and operational relationships of the code. Generally, an abstract semantic analysis tree is a structured tree data structure that retains only the core semantic logic nodes of the program or text after stripping away syntax-independent symbols.

[0099] In some embodiments, the control flow graph mentioned above refers to a graphical model that uses nodes to represent code statements and edges to represent execution jump relationships, intuitively presenting all branches and loop execution paths of the program.

[0100] In some embodiments, the abstract semantic analysis tree and control flow graph are generated by a custom static analyzer, including but not limited to analysis frameworks based on LLVM IR or EVM opcodes or the Slither static analysis framework.

[0101] Step 302: The vulnerability sample data construction device extracts structured features from the above-mentioned abstract semantic analysis tree and the above-mentioned control flow graph.

[0102] The aforementioned structured features include security features, structural features, variable features, and constant features.

[0103] In some embodiments, the aforementioned security features refer to attribute identifiers in the code related to vulnerabilities, permissions, and data protection, used to identify program security risk points.

[0104] In some embodiments, the above-mentioned structural features refer to code organization information such as program statements, branches, and loops.

[0105] In some embodiments, the above-mentioned variable characteristics refer to attribute information such as the type, value range, read / write operations, and transitive dependencies of various variables in the program.

[0106] In some embodiments, the aforementioned constant characteristics refer to inherent attributes such as fixed and unchanging numerical values, string constant values, uses, and occurrence positions in the code.

[0107] Step 303: The vulnerability sample data construction device generates an embedding vector based on the above-mentioned structured features.

[0108] Among these, the aforementioned source code features include embedding vectors.

[0109] In some embodiments, the above-mentioned embedding vectors can be generated by GraphCodeBERT, CodeBERT, UniXcoder, or a self-developed pre-trained model.

[0110] Thus, by extracting source code features from smart contract vulnerability samples and using these features as input for training a smart contract vulnerability detection model, the model can learn about the code structure, semantics, and security risks of smart contract vulnerabilities. This provides the underlying code logic for the model and serves as the original basis for it to learn the inherent rules of the code.

[0111] In some embodiments, such as Figure 4 As shown, the process of "obtaining the bytecode features and opcode features corresponding to the smart contract vulnerability sample" in step 202 above can be implemented through the following steps 401 to 406.

[0112] Step 401: The vulnerability sample data construction device obtains the bytecode of the smart contract vulnerability sample based on the source code of the smart contract vulnerability sample, and converts the bytecode into an opcode sequence.

[0113] In some embodiments, the bytecode of the smart contract vulnerability sample is obtained by compiling the source code of the smart contract vulnerability sample using py-solc-x.

[0114] In some embodiments, the opcode sequence of a smart contract vulnerability sample is obtained by disassembling the bytecode of the smart contract vulnerability sample using the disassemble_hex disassembler.

[0115] Step 402: The vulnerability sample data construction device extracts basic statistical features and opcode semantic features from the above opcode sequence.

[0116] In some embodiments, the aforementioned basic statistical characteristics include: total number of bytes of smart contracts, number of contracts, total number of opcodes, frequency of critical opcodes, proportion of ordinary call calls, proportion of static call calls, proportion of delegated call calls, and proportion of self-destruction operations.

[0117] In some embodiments, opcode semantic features refer to the semantic information composed of the instruction function, data read / write logic, and operation behavior corresponding to each opcode, which is used to characterize the actual execution meaning of the underlying instruction.

[0118] Step 403: The vulnerability sample data construction device analyzes the jump relationships between bytecode instructions based on the above basic statistical characteristics to construct a control flow profile.

[0119] In some embodiments, the aforementioned control flow profile refers to a simplified feature set obtained by statistically compressing the program control flow graph, which is used to comprehensively characterize the distribution pattern of execution paths of program branches, loops, and jumps.

[0120] Step 404: The vulnerability sample data construction device extracts bytecode structure features from the above basic statistical features.

[0121] The aforementioned bytecode structural features include the number of basic blocks, loop depth, and control complexity of the bytecode.

[0122] Step 405: The vulnerability sample data construction device obtains bytecode features based on the above control flow profile and the above bytecode structure features.

[0123] Step 406: The vulnerability sample data construction device obtains the opcode features based on the above opcode semantic features and the above basic statistical features.

[0124] Thus, since the bytecode features extracted from smart contract vulnerability samples can eliminate various high-level source code syntax differences and provide a unified and standardized intermediate program execution logic, and the opcode features extracted from smart contract vulnerability samples can disassemble low-level execution instructions and reconstruct basic behaviors such as data reading and writing, and jump operations, inputting bytecode features and opcode features as two data branches into the smart contract vulnerability detection model can completely cover all execution information of smart contract vulnerability samples from high-level structure to low-level instructions.

[0125] In some embodiments, such as Figure 5 As shown, the step 202 above, "obtaining the historical interaction features corresponding to the smart contract vulnerability sample", can be achieved through the following steps 501 to 503.

[0126] Step 501: Obtain the logs of multiple contract calls and interactions of the above-mentioned smart contract vulnerability sample on the blockchain network.

[0127] It should be noted that each of the above multiple contract call and interaction relationship logs corresponds to a timestamp.

[0128] In some embodiments, the current smart contract vulnerability sample may have call and interaction relationships with multiple smart contracts on the blockchain network. The call and interaction relationships between the current smart contract vulnerability sample and other smart contracts have a time attribute.

[0129] Step 502: Based on the log features extracted from the logs of the above-mentioned multiple contract call and interaction relationships, construct a time-series dependency graph.

[0130] The log characteristics mentioned above include call frequency, call time, caller address, and interaction with other contracts.

[0131] In this context, each node in the aforementioned time-series dependency graph corresponds to a caller address or contract address, and each edge in the aforementioned time-series dependency graph corresponds to an interaction relationship and is accompanied by a timestamp attribute.

[0132] Step 503: Based on the above temporal dependency graph, obtain the above historical interaction features.

[0133] Thus, since historical interaction relationships are dynamic behavioral characteristics, this application incorporates historical interaction characteristics as a component of vulnerability sample data. By parsing real blockchain transaction logs to extract call frequency, caller distribution, and inter-contract call paths, it constructs contextual features that reflect runtime behavior and precisely aligns historical interaction characteristics with static code features. This significantly enhances the vulnerability detection model's ability to identify dynamic vulnerabilities (such as reentrancy vulnerabilities) that rely on external calls or state interactions.

[0134] In some embodiments, such as Figure 6 As shown, the step 202 above, "obtaining the multidimensional graph structure features corresponding to the smart contract vulnerability sample", can be achieved through the following steps 601 to 604.

[0135] Step 601: The vulnerability sample data construction device generates control flow edges based on the abstract semantic analysis tree and control flow graph of the above-mentioned smart contract vulnerability samples.

[0136] The aforementioned control flow edges are used to characterize the program execution sequence.

[0137] Step 602: The vulnerability sample data construction device constructs a data flow edge based on the variable data in the smart contract vulnerability sample mentioned above.

[0138] The aforementioned data flow edges are used to characterize the data transfer relationship of variables from their definition location to their usage location.

[0139] Step 603: The vulnerability sample data construction device constructs a cross-contract call edge based on the logs of multiple contract calls and interactions of the aforementioned smart contract vulnerability samples on the blockchain network.

[0140] Among them, the aforementioned cross-contract call edge is used to represent the call relationship between different smart contracts;

[0141] In some embodiments, the current smart contract vulnerability sample may have call or interaction relationships with multiple smart contracts in the blockchain network. Based on the call and interaction relationships between the current smart contract vulnerability sample and other smart contracts, a cross-contract call edge is constructed.

[0142] Step 604: The vulnerability sample data construction device performs multi-dimensional edge fusion based on the above control flow edge, data flow edge, and cross-contract call edge to obtain multi-dimensional graph structure features.

[0143] Thus, since the control flow edge records the program execution direction, the data flow edge records the data interaction information in the smart contract vulnerability sample, and the cross-contract call edge records the dynamic call characteristics with time attributes, the constructed multidimensional graph structure features build a multidimensional set of relationships that comprehensively describe the contract syntax, semantics, and runtime context, providing a complete set of program logic relationships for the smart contract vulnerability detection model.

[0144] In some embodiments, combined with Figure 2 ,like Figure 7 As shown, the "feature alignment of multidimensional feature data" in step 203 above can be achieved through the following steps 701 to 702.

[0145] Step 701: The vulnerability sample data construction device performs feature mapping between the aforementioned temporal dependency graph and the control flow graph. Taking the node representing the external call in the control flow graph as the key anchor point, the corresponding interaction relationship in the temporal dependency graph is mapped to the aforementioned key anchor point, and the aforementioned historical interaction features are added to the aforementioned key anchor point.

[0146] In some embodiments, this application constructs a unique identifier with "contract name + function name" as the composite key, then performs feature mapping between the temporal dependency graph and the control flow graph, takes the node representing the external call in the control flow graph as the key anchor point, uses the "contract name + function name" composite key to map the corresponding interaction relationship in the temporal dependency graph to the above key anchor point, and adds the above historical interaction features to the above key anchor point.

[0147] In some embodiments, the function name refers to the smallest unit of labeling the aforementioned smart contract vulnerability.

[0148] In some embodiments, the unique identifier may also be the hash value of the function body content, wherein the hash value of the function body content refers to the fixed digest value obtained by hashing all the code text within a function of a smart contract vulnerability sample.

[0149] Step 702: The vulnerability sample data construction device aligns the above-mentioned source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features to obtain aligned multidimensional feature data.

[0150] In this way, by aligning the multi-dimensional feature data in the smart contract vulnerability sample, the external call nodes of the originally independent control flow graph are endowed with dynamic attributes, forming a heterogeneous attribute graph with dynamic and static multi-dimensional feature alignment, realizing an analysis method that combines dynamic and static analysis.

[0151] In some embodiments, the multimodal fusion model described above is a neural network fusion model based on an attention mechanism. The neural network fusion model includes multiple layers of decoders, and each layer of decoder in the neural network fusion model is configured with multiple independent attention heads.

[0152] In some embodiments, the multimodal fusion model described above includes a 6-layer encoder, each of which is configured with 8 independent attention heads.

[0153] In some embodiments, each attention head can form a subspace. Parallel processing of the aforementioned source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features can be implemented in different subspaces.

[0154] In some embodiments, combined with Figure 2 ,like Figure 8 As shown, the step 203 above, "inputting the aligned multidimensional feature data into the multimodal fusion model for feature fusion", can be achieved through the following steps 801 to 802.

[0155] Step 801: The vulnerability sample data construction device inputs the aligned multidimensional feature data into the multimodal fusion model, performs weighted processing on the aligned multidimensional feature data, and obtains the processed multidimensional feature data.

[0156] In some embodiments, after inputting the aligned multidimensional feature data into the multimodal fusion model, the vulnerability sample data construction device can perform weighted processing on the aligned multidimensional feature data based on the weights of the multidimensional feature data to obtain the processed multidimensional feature data.

[0157] In some embodiments, the aforementioned multidimensional feature data weights are used to characterize the importance of different dimensional features to the current vulnerability sample.

[0158] In some embodiments, the multidimensional feature data weights mentioned above include the importance weights corresponding to each dimension feature.

[0159] Step 802: The vulnerability sample data construction device uses different attention heads in the encoder of the multimodal fusion model to perform deep processing on the feature data of different dimensions in the above-processed multidimensional feature data in different representation subspaces, and then fuses them to obtain the above-mentioned fused feature data. In some embodiments, if there is a case where the feature dimension is too high, PCA principal component analysis technology can be used to reduce the dimension of the high-dimensional features to a specified dimension.

[0160] Thus, multi-head attention mechanisms are used to force the model to learn cross-dimensional features. This fusion process, which integrates weighted features across code semantics, underlying bytecode, and on-chain behavior, enables the multimodal fusion model to identify the true vulnerability triggering situation, significantly reducing the false positive rate and improving vulnerability identification accuracy during the vector generation stage.

[0161] In some embodiments, such as Figure 9 As shown, the vulnerability sample data construction method provided in this application embodiment may further include the following steps 901 and 902:

[0162] Step 901: Input the vulnerability sample data into the attention-based neural network fusion model.

[0163] In the aforementioned neural network fusion model, each layer of the decoder is configured with multiple independent attention heads.

[0164] Step 902: Using multiple attention heads in the decoder, the feature data of different dimensions in the fused feature data of the vulnerability sample data are processed in parallel in different representation subspaces to learn the importance weights of the feature data of different dimensions to the vulnerability sample data, so as to train the neural network model.

[0165] In this way, by training the above neural network model, the importance weights of different dimensional feature data to the vulnerability sample data are learned, which makes it easier for the model to output more accurate fused feature data and provide high-quality training data for the smart contract vulnerability detection model.

[0166] like Figure 10 As shown, Figure 10 The complete flow of the vulnerability sample data construction method provided in this application is illustrated. This complete flow includes the following five steps, executed sequentially and with strict upstream and downstream dependencies:

[0167] Step 1: Collection of raw smart contract data samples.

[0168] For example, the vulnerability sample data construction device collects public datasets from platforms such as GitHub to obtain raw smart contract data samples, and uses data augmentation techniques to generate high-quality smart contract data samples for vulnerability types with insufficient samples.

[0169] Step 2: Vulnerability type labeling and classification.

[0170] For example, the vulnerability sample data construction device uses the slither static analysis tool to perform function-level vulnerability annotation on the above-mentioned high-quality smart contract data sample to obtain smart contract vulnerability samples.

[0171] For example, the vulnerability sample data construction device saves the vulnerabilities that have been annotated in the smart contract vulnerability samples in a directory of specified vulnerability types.

[0172] Step 3: Multi-dimensional feature extraction.

[0173] For example, the vulnerability sample data construction device synchronously extracts source code, bytecode and historical interaction relationships between other smart contract vulnerability samples from the above-mentioned smart contract vulnerability samples, and constructs control flow, data flow and cross-contract call edges, transforming heterogeneous data into an intermediate representation with a graph topology structure, forming a multi-dimensional graph structure feature covering syntax, semantics and runtime context.

[0174] Step 4: Multidimensional feature alignment and fusion.

[0175] For example, the vulnerability sample data construction device injects dynamic temporal features into a static graph structure through anchor point mapping, and uses a neural network fusion model with attention mechanism to realize dynamic weighted resonance of multi-dimensional features, mapping features of different dimensions into fused feature data.

[0176] Step 5: Dataset standardization and storage.

[0177] For example, the vulnerability sample data construction device processes the above-mentioned fused feature data and corresponding labels according to a unified data structure (Data format) to obtain standardized vulnerability sample data, and then stores it in a serialized format (.pt file), so that the downstream neural network can directly read the fused features generated in step 4, which facilitates the training and evaluation of smart contract vulnerability detection models by the machine learning framework.

[0178] The following describes the vulnerability sample data construction method of this application through specific embodiments.

[0179] The implementation process of the vulnerability sample data construction method provided in this application includes the following steps 1 to 5:

[0180] Step 1: Acquisition of raw smart contract data.

[0181] For example, the vulnerability sample data construction device collects smart contract data samples from different Solidity versions from the GitHub open source platform and performs data cleaning operations on the smart contract data samples (e.g., deduplication and removal of compilation failure samples).

[0182] For example, for specific vulnerability types where samples are insufficient, template-based data augmentation techniques can be used to obtain high-quality smart contract data samples.

[0183] For example. As Figure 11 As shown, Figure 11 The implementation process for constructing a high-quality smart contract data sample is shown, which includes the following steps 1.1 to 1.4.

[0184] Step 1.1: The vulnerability sample data construction device writes template variants with semantic equivalence based on known vulnerability characteristics.

[0185] Step 1.2: The vulnerability sample data construction device inserts controllable noise into the above template variant code structure to simulate real development scenarios.

[0186] Step 1.3: The vulnerability sample data construction device uses the Slither static analysis framework to compile and verify the generated code of the above template variants, ensuring the syntactic and logical rationality of the template variants with the insertion of controllable noise.

[0187] Step 1.4: If the syntax and logic of the template variant with inserted controllable noise pass verification, the vulnerability sample data construction device generates high-quality smart contract data samples in batches based on the template variants of each vulnerability type, using random parameters and structural variations. If the syntax and logic of the template variant with inserted controllable noise fail verification, controllable noise is re-inserted into the generated code of the template variant.

[0188] It should be noted that in step 1, in response to the scarcity of real vulnerability samples for some vulnerability types, a data augmentation method based on control flow perturbation, logical equivalence transformation and context adaptation is designed to generate diverse vulnerability variants while ensuring that the program's functional behavior remains unchanged. This effectively alleviates class imbalance and training distribution shift, and improves the model's generalization performance.

[0189] For example, the high-quality smart contract data samples generated in step 1 can significantly improve the authenticity, coverage, and generalization ability of smart contract vulnerability samples and model training. The high-quality smart contract data samples generated by this enhancement strategy can play a "regularization" role in the multi-dimensional feature fusion in the subsequent step 4. That is, only when the generated template samples show vulnerability consistency in both the source code semantics and bytecode opcode dimensions can they obtain high weight in the fusion stage, thereby effectively filtering out "pseudo-vulnerability" samples that only remain on the surface of the syntax but cannot be triggered in the actual bytecode.

[0190] Step 2: Vulnerability type labeling and classification.

[0191] For example, the vulnerability sample data construction device writes an automated script for reading the high-quality smart contract data samples mentioned above. The automated script calls the Slither static analysis tool to scan the high-quality smart contract data samples according to the SWC standard, accurately extracting vulnerability tags, including vulnerability type (SWC-ID), specific location (such as file name, line number, function name) and severity level. Finally, the data is saved to a preset directory according to the SWC category, thereby providing structured supervision signals for model training.

[0192] For example, step 2 above abandons the traditional "contract-level" coarse-grained labeling and forces the output of "function-level" labels. This fine-grained labeling directly determines the accuracy of feature alignment during the feature alignment and fusion process, and is a prerequisite for subsequently discovering cross-contract call vulnerabilities (such as reentrancy attacks that often occur in specific external call functions).

[0193] Step 3: Multi-dimensional feature extraction.

[0194] Step 3.1: Extraction of syntactic and semantic features.

[0195] For example, such as Figure 12 As shown, Figure 12 The implementation process of source code feature extraction is shown, which includes the following:

[0196] First, the vulnerability sample data construction device uses the Slither tool to perform static analysis on smart contract vulnerability samples, generating high-level intermediate representations, including an Abstract Syntax Tree (AST) and a Control Flow Graph (CFG). The AST describes the code syntax structure, and the CFG describes the code execution logic. Then, four types of structured features—security features, structural features, variable features, and constant features—are extracted from the AST and CFG. Finally, code snippets with the above four types of structured features are input into a fine-tuned GraphCodeBERT model to generate embedding vectors.

[0197] It should be noted that source code features can only capture logical flaws in the literal sense of the code and cannot detect deviations caused by compiler optimizations or underlying EVM stack operations.

[0198] Step 3.2: Bytecode and opcode feature extraction.

[0199] For example, such as Figure 13 As shown, Figure 13 The implementation process for extracting bytecode features and opcode features is shown, and the implementation process includes the following:

[0200] First, the vulnerability sample data construction device uses py-solc-x to compile the contract source code of the aforementioned smart contract vulnerability sample to obtain the bytecode of the smart contract vulnerability sample, and then uses the disassembler disassemble_hex to convert the bytecode of the smart contract vulnerability sample into an opcode sequence. Next, basic statistical features are extracted from this opcode sequence, including the total number of bytes in the contract, the number of contracts, the total number of opcodes, the frequency of critical opcodes, the proportion of ordinary call calls, the proportion of static call calls, the proportion of delegate calls, and the proportion of self-destruct operations. Finally, the jump relationships between bytecode instructions are analyzed to construct its control flow profile, and bytecode structural features are extracted from the basic statistical features. These bytecode structural features include structural features such as the number of basic blocks, loop depth, and control complexity. Semantic features are also extracted from the opcode sequence, including function interaction patterns, exception handling logic, and state recovery mechanisms.

[0201] It should be noted that bytecode and opcode features are highly fragmented, lack high-dimensional semantics, and are difficult to directly correspond to specific business logic.

[0202] Step 3.3: Extraction of historical interaction relationship features.

[0203] For example, such as Figure 14 As shown, Figure 14 The implementation process for extracting historical interaction relationship features is shown, which includes the following:

[0204] First, the vulnerability sample data construction device acquires multiple contract call and interaction relationship logs of smart contract vulnerability samples on the blockchain network. Then, it extracts log features from the contract call and interaction relationship logs, including call frequency, call time distribution, distribution of the top-n caller addresses, and interaction relationships with other contracts. Finally, based on the features extracted from multiple contract call and interaction relationship logs, it constructs a time-series dependency graph, where nodes represent the smart contract vulnerability sample address and the caller smart contract address, and edges represent the interaction behavior between the smart contract vulnerability sample and the caller smart contract with timestamp attributes.

[0205] It should be noted that historical interaction relationships are dynamic behavioral characteristics. If removed from the context of static code, frequent calls alone cannot prove the existence of a vulnerability.

[0206] Step 3.4 Construct control flow edges, data flow edges, and cross-contract call edges.

[0207] For example, such as Figure 15 As shown, Figure 15 The implementation process of multidimensional graph structure feature extraction is shown, which includes the following:

[0208] First, the vulnerability sample data construction device uses Slither to statically analyze the source code of the aforementioned smart contract vulnerability samples, constructing an Abstract Syntax Tree (AST) and a Control Flow Graph (CFG) to generate control flow edges, which are used to represent the program execution sequence. Then, data flow edges are constructed by tracing the dependencies between variables, constants, and their usage through static analysis techniques. Finally, the calling relationship between the smart contract vulnerability samples and the calling smart contracts is analyzed to construct calling edges that represent cross-contract interactions. These three types of edges together constitute a multi-dimensional set of relationships that comprehensively describes the contract syntax, semantics, and runtime context.

[0209] Step 4: Multidimensional feature alignment and fusion.

[0210] For example, directly concatenating source code features, bytecode features, opcode features, and historical interaction features can lead to dimensionality explosion due to the heterogeneity between features of different dimensions (different vector dimensions, different physical meanings), and can also result in the loss of causal logic between features. This step addresses this issue through two core stages: feature alignment and adaptive fusion.

[0211] For example, the vulnerability sample data construction device maps heterogeneous features into highly expressive fusion vectors, achieving unified representation learning of multi-dimensional features of smart contracts. Figure 16 As shown, Figure 16 The implementation process of aligning and fusing multidimensional data features of smart contract vulnerability samples is shown.

[0212] Step 4.1 Multidimensional feature alignment.

[0213] For example, the implementation process of the above-mentioned multidimensional feature alignment includes the following:

[0214] First, the vulnerability sample data construction device constructs a unique identifier using a composite key of "contract name + function name". Then, it maps the temporal dependency graph features to the control flow graph features, using nodes representing external calls (such as CALL, DELEGATECALL) in the control flow graph as key anchors. Using the composite key of "contract name + function name", the corresponding interaction relationships in the temporal dependency graph are precisely mapped to these static nodes. Each mapped control flow graph anchor node is added from the temporal dependency graph to the aforementioned historical interaction features. Finally, all heterogeneous features of the smart contract vulnerability sample—source code features, bytecode features, interaction relationship features, control flow edges, data flow edges, and cross-contract call edges—are precisely aligned to form a unified feature view.

[0215] It should be noted that aligning multidimensional features allows the previously isolated code control flow graph to now possess dynamic attributes such as "who calls it on the real chain and at what frequency." This forms a heterogeneous attribute graph with aligned static and dynamic features, breaking down the barriers between static and dynamic analysis.

[0216] Step 4.2 Adaptive feature fusion.

[0217] For example, the implementation process of the above adaptive feature fusion includes the following:

[0218] First, the vulnerability sample data construction device builds a neural network multimodal fusion model based on an attention mechanism. This model contains a 6-layer Transformer encoder, with each layer configured with 8 independent attention heads. Then, using the multi-head attention mechanism of this model, various heterogeneous features from source code features, bytecode features, opcode features, control flow edges, data flow edges, and cross-contract call edges are processed in parallel in different subspaces represented by each attention head. The importance weight of each feature dimension for the current smart contract vulnerability sample is dynamically learned. Finally, through nonlinear transformation and fusion of the multi-layer encoder, all weighted feature information is deeply fused. If there are heterogeneous features with excessively high dimensionality, PCA principal component analysis is used to reduce the dimensionality of the heterogeneous features to a specified dimension, ultimately mapping them into a unified fusion vector with high representational power.

[0219] For example, the adaptive feature fusion process unifies the modeling of heterogeneous features such as syntactic structure (Abstract Syntax Tree, AST), control flow (Control Flow Graph, CFG), data flow (Data Flow Graph, DFG), temporal dependencies, and semantic embeddings, and aligns the features with the source code and compiled bytecode at the contract function level. This breaks through the limitations of existing datasets that only provide raw code text or simply concatenate source code and bytecode, and constructs a multi-dimensional feature system that can comprehensively represent the static structure and dynamic semantics of a program, providing a deep, structured, and semantically consistent input foundation for vulnerability detection models.

[0220] Furthermore, the adaptive feature fusion process does not simply input features into the Transformer. Instead, it utilizes a multi-head attention mechanism to force the model to learn cross-dimensional features. For example, for a reentrant vulnerability function, the model automatically assigns high weights to "high proportion of CALL opcodes" and "high-frequency call features of external addresses" in one attention head, while simultaneously discovering "security features lacking locking mechanisms in the source code feature extraction process" and "data flow features where state variable write operations occur after the call edge during the construction of control flow edges, data flow edges, and cross-contract call edges." This joint high-weight focus across code semantics, underlying bytecode, and on-chain behavior enables the model to identify a genuine vulnerability triggering chain. Compared to using three separate unimodal models for detection and then superimposing features, this fusion process can directly eliminate "unimodal false positives" at the feature representation level (e.g., an opcode feature resembles a vulnerability, but semantic features negate it), thereby significantly reducing the false positive rate and improving representation accuracy during the vector generation stage.

[0221] Step 5: Dataset standardization and storage.

[0222] For example, the implementation process of the above dataset standardization and storage includes the following:

[0223] First, the vulnerability sample data construction device standardizes the aforementioned unified high-representation fusion vectors and corresponding vulnerability labels according to a unified data structure `Data(x=x, y=y, edge_index=edge_index)`, ensuring complete encapsulation of node features, labels, and graph edge indices to obtain a standardized dataset. Next, using the serialization mechanism supported by the PyTorch Geometric framework, the standardized dataset is efficiently and persistently stored in .pt file format, a format specifically optimized for graph neural network data processing. Finally, the constructed standardized dataset can be directly loaded and parsed by graph neural network frameworks such as PyTorchGeometric for training and evaluation of smart contract vulnerability detection models.

[0224] Thus, this application constructs a feature alignment and dynamic fusion mechanism at the function level, enabling cross-dimensional cross-verification of the high-dimensional semantics of the source code, the underlying execution logic of the bytecode, and the dynamic temporal characteristics of on-chain interactions. This allows for the identification of hidden vulnerabilities that cannot be detected by a single dimension. It provides high-quality training and evaluation data support for smart contract vulnerability detection models.

[0225] It should be noted that the descriptions of steps 1 to 5 in this embodiment can be found in the descriptions in the above embodiments, and will not be repeated here.

[0226] It should be noted that the above-described method embodiments, or the various possible implementations of the method embodiments, can be executed individually, or, provided there is no conflict, they can be combined with each other. The specific implementation can be determined according to actual usage requirements, and this application embodiment does not impose any restrictions on this.

[0227] As can be seen, the above mainly describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the above functions, the embodiments of this application provide corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, in conjunction with the modules and algorithm steps of the various examples described in the embodiments disclosed herein, the embodiments of this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0228] This application embodiment can divide the vulnerability sample data construction device into functional modules according to the above method example. For example, each function can be divided into a separate functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. Optionally, the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.

[0229] In some embodiments, this application also provides a vulnerability sample data construction apparatus. This vulnerability sample data construction apparatus may include one or more functional modules for implementing the vulnerability sample data construction method of the above method embodiments.

[0230] For example, Figure 17 This is a schematic diagram of a vulnerability sample data construction device provided in an embodiment of this application. Figure 17As shown, the vulnerability sample data construction device 1001 includes: an acquisition module 1002, a processing module 1003, and a generation module 1004.

[0231] The acquisition module 1002 is used to acquire smart contract vulnerability samples. It is also used to acquire multi-dimensional feature data corresponding to the smart contract vulnerability samples, including source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. The historical interaction features are determined based on the logs of multiple contract calls and interactions of the smart contract vulnerability samples on the blockchain network. The processing module 1003 aligns the multi-dimensional feature data and inputs the aligned multi-dimensional feature data into a multimodal fusion model for feature fusion to obtain fused feature data corresponding to the smart contract vulnerability samples. The generation module 1004 generates vulnerability sample data based on the fused feature data and vulnerability tags obtained by the processing module, and this vulnerability sample data is used to train the smart contract vulnerability detection model.

[0232] The vulnerability sample data construction device provided in this application performs multi-dimensional feature extraction on the obtained smart contract vulnerability samples to obtain multi-dimensional feature data including source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. This multi-dimensional feature data is then aligned to obtain structurally unified multi-dimensional feature data. Furthermore, this structurally unified multi-dimensional feature data is fused using a multi-modal fusion model to obtain fused feature data. After standardizing the fused feature data, high-quality vulnerability sample data for training the smart contract vulnerability detection model can be obtained. This provides high-quality training and evaluation data support for the smart contract vulnerability detection model, effectively improving the training effect of the smart contract vulnerability detection model.

[0233] In some embodiments, the acquisition module 1002 is specifically used to: extract the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample, wherein the abstract semantic analysis tree is used to describe the code syntax structure and the control flow graph is used to describe the code execution logic; extract structured features from the abstract semantic analysis tree and the control flow graph, wherein the structured features include security features, structural features, variable features and constant features; and generate an embedding vector based on the structured features.

[0234] In other embodiments, the acquisition module 1002 is further configured to: acquire the bytecode of the smart contract vulnerability sample based on the source code of the smart contract vulnerability sample, and convert the bytecode into an opcode sequence; extract basic statistical features and opcode semantic features from the opcode sequence; analyze the jump relationships between bytecode instructions based on the basic statistical features to construct a control flow profile; extract bytecode structural features from the basic statistical features, wherein the bytecode structural features include the number of basic blocks, loop depth, and control complexity of the bytecode; obtain bytecode features based on the control flow profile and the bytecode structural features; and obtain opcode features based on the opcode semantic features and the basic statistical features.

[0235] In some other embodiments, the acquisition module 1002 is further configured to: acquire multiple contract call and interaction relationship logs of the smart contract vulnerability sample on the blockchain network, each of the multiple contract call and interaction relationship logs corresponding to a timestamp; construct a time-series dependency graph based on the log features extracted from the multiple contract call and interaction relationship logs, the log features including call frequency, call time, caller address, and interaction relationship with other contracts; each node in the time-series dependency graph corresponds to a caller address or contract address, each edge in the time-series dependency graph corresponds to an interaction relationship and is accompanied by a timestamp attribute; and obtain the historical interaction features based on the time-series dependency graph.

[0236] In some other embodiments, the acquisition module 1002 is further configured to: generate control flow edges based on the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample; the control flow edges are used to characterize the program execution sequence; and based on the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample... Variable data Data flow edges are constructed to represent the data transfer relationship of variables from their definition location to their usage location. Based on the logs of multiple contract calls and interactions on the blockchain network of the smart contract vulnerability samples mentioned above, cross-contract call edges are constructed to represent the call relationship between different smart contracts. Multi-dimensional edge fusion is performed based on the control flow edges, data flow edges, and cross-contract call edges to obtain multi-dimensional graph structure features.

[0237] In some other embodiments, the processing module 1003 is specifically used to: perform feature mapping between the time-series dependency graph and the control flow graph, using the nodes representing external calls in the control flow graph as key anchor points, map the corresponding interaction relationships in the time-series dependency graph to the key anchor points, and add the historical interaction features to the key anchor points; align the source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features to obtain aligned multidimensional feature data.

[0238] In some other embodiments, the processing module 1003 is further configured to: input the aligned multidimensional feature data into a multimodal fusion model, perform weighted processing on the aligned multidimensional feature data to obtain processed multidimensional feature data; and perform deep processing on the feature data of different dimensions in the processed multidimensional feature data in different representation subspaces through different attention heads in the encoder, and fuse them to obtain the fused feature data.

[0239] In some other embodiments, the processing module 1003 is further configured to: input vulnerability sample data into a neural network fusion model based on an attention mechanism, wherein each layer of the neural network fusion model is configured with multiple independent attention heads; and process feature data of different dimensions in the fusion feature data of the vulnerability sample data in parallel in different representation subspaces through the multiple attention heads in the decoder, and learn the importance weights of feature data of different dimensions to the vulnerability sample data, so as to train the neural network model.

[0240] It should be noted that the vulnerability sample data construction device can implement all the processes implemented in the above method embodiments and achieve the same beneficial effects. To avoid repetition, it will not be described again here.

[0241] In the case where the functions of the integrated modules described above are implemented in hardware, this application provides a possible structural schematic diagram of the electronic device involved in the above embodiments. For example... Figure 18 As shown, the electronic device 90 includes: a processor 92, a communication interface 93, and a bus 94. Optionally, the electronic device 90 may also include a memory 91.

[0242] Processor 92 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 92 may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 92 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0243] Communication interface 93 is used to connect with other devices via a communication network. This communication network can be Ethernet, wireless access network, wireless local area network (WLAN), etc.

[0244] The memory 91 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto.

[0245] As one possible implementation, the memory 91 can exist independently of the processor 92. The memory 91 can be connected to the processor 92 via a bus 94 and is used to store instructions or program code. When the processor 92 calls and executes the instructions or program code stored in the memory 91, it can implement the vulnerability sample data construction method provided in the embodiments of this application.

[0246] In another possible implementation, memory 91 can also be integrated with processor 92.

[0247] Bus 94 can be an Extended Industry Standard Architecture (EISA) bus, etc. Bus 94 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 18 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0248] Through the above description of the implementation methods, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the service calling device can be divided into different functional modules to complete all or part of the functions described above.

[0249] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described vulnerability sample data construction method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0250] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0251] This application also provides a readable storage medium storing a program or instructions that, when executed by a computer, implement the vulnerability sample data construction method provided in the above embodiments. It is understood that all or part of the processes in the above method embodiments can be executed by computer instructions instructing related hardware; the readable storage medium can be any of the foregoing embodiments or memory; the readable storage medium can also be an external storage device of the service invocation device, such as a pluggable hard drive, SmartMedia Card (SMC), Secure Digital (SD) card, flash card, etc., equipped on the service invocation device. Further, the readable storage medium can include both internal storage units of the service invocation device and external storage devices. The readable storage medium is used to store the computer program and other programs and data required by the service invocation device. The readable storage medium can also be used to temporarily store data that has been output or will be output.

[0252] This application also provides a computer program product, which is stored in a storage medium and, when executed by a computer, implements the vulnerability sample data construction method provided in the above embodiments.

[0253] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0254] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the above embodiments of this application.

[0255] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A method for constructing vulnerability sample data, characterized in that, The method includes: Obtain smart contract vulnerability samples; Obtain multi-dimensional feature data corresponding to the smart contract vulnerability sample. The multi-dimensional feature data includes: source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. The historical interaction features are determined based on the logs of multiple contract calls and interaction relationships of the smart contract vulnerability sample on the blockchain network. The multidimensional feature data is aligned, and the aligned multidimensional feature data is input into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample. Based on the fusion feature data corresponding to the smart contract vulnerability sample and the vulnerability label corresponding to the smart contract vulnerability sample, vulnerability sample data is generated, and the vulnerability sample data is used to train the smart contract vulnerability detection model.

2. The vulnerability sample data construction method according to claim 1, characterized in that, The source code features include the embedding vector; obtaining the multi-dimensional feature data corresponding to the smart contract vulnerability sample includes: Extract the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample. The abstract semantic analysis tree is used to describe the code syntax structure, and the control flow graph is used to describe the code execution logic. Structured features are extracted from the abstract semantic analysis tree and the control flow graph. The structured features include security features, structural features, variable features, and constant features. The embedding vector is generated based on the structured features.

3. The method for constructing vulnerability sample data according to claim 1, characterized in that, The process of obtaining the multi-dimensional feature data corresponding to the smart contract vulnerability sample includes: Based on the source code of the smart contract vulnerability sample, obtain the bytecode of the smart contract vulnerability sample, and convert the bytecode into an opcode sequence; Extract basic statistical features and opcode semantic features from the opcode sequence; Based on the aforementioned basic statistical characteristics, the jump relationships between bytecode instructions are analyzed to construct a control flow profile; Bytecode structure features are extracted from the basic statistical features, including the number of basic blocks, loop depth, and control complexity of the bytecode. Based on the control flow profile and the bytecode structure features, the bytecode features are obtained; Based on the opcode semantic features and the basic statistical features, the opcode features are obtained.

4. The vulnerability sample data construction method according to claim 1, characterized in that, The process of obtaining the multi-dimensional feature data corresponding to the smart contract vulnerability sample includes: Obtain multiple contract call and interaction relationship logs of the smart contract vulnerability sample on the blockchain network, with each of the multiple contract call and interaction relationship logs corresponding to a timestamp; Based on the log features extracted from the multiple contract call and interaction logs, a time-series dependency graph is constructed. The log features include call frequency, call time, caller address, and interaction relationships with other contracts. Each node in the time-series dependency graph corresponds to a caller address or contract address, and each edge in the time-series dependency graph corresponds to an interaction relationship and is accompanied by a timestamp attribute. Based on the temporal dependency graph, the historical interaction features are obtained.

5. The vulnerability sample data construction method according to claim 1, characterized in that, The process of obtaining the multi-dimensional feature data corresponding to the smart contract vulnerability sample includes: Based on the abstract semantic analysis tree and control flow graph of the smart contract vulnerability sample, control flow edges are generated; the control flow edges are used to represent the program execution sequence. Based on the smart contract vulnerability sample Variable data Construct data flow edges, which are used to characterize the data transfer relationship of variables from the definition position to the usage position; Based on the smart contract vulnerability sample's logs of multiple contract calls and interactions on the blockchain network, a cross-contract call edge is constructed, which is used to represent the call relationship between different smart contracts; Multidimensional edge fusion is performed based on the control flow edge, data flow edge, and cross-contract call edge to obtain multidimensional graph structure features.

6. The vulnerability sample data construction method according to claim 1, characterized in that, The step of aligning the multidimensional feature data and inputting the aligned multidimensional feature data into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample includes: The temporal dependency graph and the control flow graph are feature-mapped. The nodes in the control flow graph that represent external calls are used as key anchors. The corresponding interaction relationships in the temporal dependency graph are mapped to the key anchors, and the historical interaction features are added to the key anchors. The source code features, bytecode features, opcode features, historical interaction features, and multidimensional graph structure features are aligned to obtain aligned multidimensional feature data.

7. The vulnerability sample data construction method according to claim 1, characterized in that, The multimodal fusion model is a neural network fusion model based on an attention mechanism, wherein each decoder layer in the neural network fusion model is configured with multiple independent attention heads; The step of inputting the aligned multidimensional feature data into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample includes: The aligned multidimensional feature data is input into the multimodal fusion model, and the aligned multidimensional feature data is weighted to obtain the processed multidimensional feature data. By using different attention heads in the encoder, the feature data of different dimensions in the processed multidimensional feature data are deeply processed in different representation subspaces and fused to obtain the fused feature data.

8. The vulnerability sample data construction method according to claim 1, characterized in that, The vulnerability sample data construction method also includes: The vulnerability sample data is input into an attention-based neural network fusion model, wherein each layer of the decoder in the neural network fusion model is configured with multiple independent attention heads; By using multiple attention heads in the decoder, the feature data of different dimensions in the fused feature data of the vulnerability sample data are processed in parallel in different representation subspaces, and the importance weights of the feature data of different dimensions to the vulnerability sample data are learned in order to train the neural network model.

9. A vulnerability sample data construction apparatus, characterized in that, The vulnerability sample data construction device includes: The acquisition module is used to acquire smart contract vulnerability samples; The acquisition module is further configured to acquire multi-dimensional feature data corresponding to the smart contract vulnerability sample. The multi-dimensional feature data includes: source code features, bytecode features, opcode features, historical interaction features, and multi-dimensional graph structure features. The historical interaction features are determined based on the logs of multiple contract calls and interaction relationships of the smart contract vulnerability sample on the blockchain network. The processing module is used to perform feature alignment on the multidimensional feature data acquired by the acquisition module, and input the aligned multidimensional feature data into a multimodal fusion model for feature fusion to obtain the fused feature data corresponding to the smart contract vulnerability sample. The generation module is used to generate vulnerability sample data based on the fusion feature data corresponding to the smart contract vulnerability sample obtained by the processing module and the vulnerability label corresponding to the smart contract vulnerability sample. The vulnerability sample data is used to train the smart contract vulnerability detection model.

10. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the method for constructing a dataset for smart contract vulnerability detection as described in any one of claims 1-8.

11. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a computer, implement the method for constructing a dataset for smart contract vulnerability detection as described in any one of claims 1-8.

12. A computer program product, characterized in that, The computer program product is stored in a storage medium, and when executed by a computer, the computer program product implements the method for constructing a dataset for smart contract vulnerability detection as described in any one of claims 1-8.