Application program fault positioning method and device, electronic equipment and storage medium
By modeling blockchain transactions as a dynamic control flow graph and using graph neural networks for feature extraction and suspicion ranking, the efficiency and accuracy issues of fault location in decentralized applications are solved, enabling rapid fault location and cost reduction in smart contracts.
Patent Information
- Application Number
- CN202411486018.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2044-10-23
AI Technical Summary
Existing fault location methods are difficult to apply effectively to decentralized applications, especially smart contracts, and are inefficient, inaccurate, and unable to respond quickly to security incidents such as hacker attacks.
The transaction that causes failure on the blockchain is modeled as a dynamic control flow graph. A graph neural network with graph attention mechanism is used for feature extraction and suspicion ranking to identify potential failure elements.
It enables efficient detection and suspicion ranking of faulty elements in smart contracts, improves the accuracy of fault location, reduces the cost of troubleshooting, and is suitable for complex interaction relationships in decentralized application scenarios.
Smart Images

Figure CN119226024B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of application program fault analysis, and in particular to an application program fault positioning method and device, an electronic device and a storage medium. BACKGROUND
[0002] Decentralized applications (DApps) are applications built based on blockchain technology. They have characteristics such as decentralized network, smart contract, user control data, security, etc. Due to the advantages of anti-censorship, transparency and data privacy protection, decentralized applications are widely used in finance, social networks, games and other fields. For example, in the financial field, decentralized applications are closely related to cryptocurrency transactions. Because a large amount of money is involved, decentralized applications often become the target of hacker attacks.
[0003] However, locating faults in decentralized applications is a highly challenging task. The reason is that a single transaction can trigger a chain reaction of multiple decentralized applications, making it both time-consuming and complex to manually investigate the semantic reasons behind the transaction. Especially when the transaction causes the on-chain application to malfunction, developers face the difficult problem of quickly locating the problematic code segment. Improving the fault localization efficiency of decentralized applications is crucial to protect the safety of funds and the interests of relevant personnel.
[0004] Existing fault localization techniques mostly focus on traditional software fields. They can be roughly divided into three categories: spectrum-based fault localization (SBFL), mutation-based fault localization (MBFL), and machine learning-based fault localization (MLFL).
[0005] However, in practical applications, spectrum-based fault localization methods rely too much on coverage information, ignoring the semantic information of the code, which makes them not widely applicable. Mutation-based fault localization methods rely too much on semantic information, which is effective but time-consuming. For decentralized applications, fault localization rescue time is of the essence, so it cannot be used for application fault localization. Machine learning-based fault localization techniques can improve the accuracy and efficiency of fault localization to some extent, but the model generalization ability is poor, ultimately leading to poor fault prediction results. SUMMARY
[0006] The application provides an application program fault positioning method and device, electronic equipment and storage medium, which are used for solving or partially solving the technical problems that the existing fault positioning method cannot be widely applied to decentralized application program fault positioning and the fault positioning effect is poor.
[0007] The application provides an application program fault positioning method, which is applied to a decentralized application program, and the method comprises the following steps:
[0008] Modeling a fault-causing transaction on a blockchain as a dynamic control flow graph;
[0009] Performing feature extraction on the dynamic control flow graph by using a graph neural network with an introduced graph attention mechanism to obtain a plurality of fault node representations;
[0010] Ranking the plurality of fault node representations according to suspicion degrees, and determining potential fault elements of the fault-causing transaction according to a ranking result of the suspicion degrees.
[0011] Optionally, the step of modeling the fault-causing transaction on the blockchain as the dynamic control flow graph comprises the following steps:
[0012] Collecting a fault-causing transaction on a blockchain, wherein the fault-causing transaction corresponds to bytecode of a fault-triggering function;
[0013] Modeling the fault-causing transaction as a dynamic control flow graph based on the bytecode.
[0014] Optionally, the node types in the dynamic control flow graph comprise an external account node, a smart contract node, a bytecode block node and a log node; and the edge representation types in the dynamic control flow graph comprise a control flow jump, a contract call, a function call, a token transfer, a token authorization and an output log.
[0015] Optionally, the step of performing feature extraction on the dynamic control flow graph by using the graph neural network with the introduced graph attention mechanism to obtain the plurality of fault node representations comprises the following steps:
[0016] In combination with edge representations of the dynamic control flow graph, each node of the dynamic control flow graph is subjected to embedding learning by using the graph neural network with the introduced graph attention mechanism, different attention weights are allocated to each node, an initial node representation corresponding to the node is generated, and the initial node representation comprises a type, an attribute, a position in the dynamic control flow graph and a connection relationship of the node.
[0017] A loss function value of each initial node representation is calculated, and a plurality of fault node representations are obtained by minimizing the loss function.
[0018] Optionally, the step of calculating the loss function value of each initial node representation comprises the following steps:
[0019] calculating a failure prediction value of each of the initial node representations;
[0020] For each node, calculating a binary cross-entropy loss value between the failure prediction value and a failure actual value based on a binary cross-entropy loss function as a loss function value of the initial node representation;
[0021] The failure actual value is determined based on prior knowledge or historical data and is used to represent whether the node is a failure element.
[0022] Optionally, the obtaining a plurality of failure node representations by minimizing the loss function comprises:
[0023] adjusting the node representations by a back propagation algorithm to minimize the loss function;
[0024] During the adjustment process, based on the introduced graph attention mechanism, the model gradually focuses attention on the node representation with the largest failure contribution, and after the adjustment is completed, a plurality of failure node representations are obtained.
[0025] Optionally, the ranking the plurality of failure node representations according to suspicion degrees and determining the potential failure element causing the failure transaction according to a result of the ranking according to suspicion degrees comprises:
[0026] generating a suspicion degree score of the failure node representation according to the minimized loss function value, the suspicion degree score being used to reflect a possibility of the node where the failure node representation is located as a failure point;
[0027] ranking all the failure node representations according to suspicion degrees in a descending order of suspicion degree scores to obtain a suspicion degree ranking list;
[0028] screening a target failure node representation with a suspicion degree score greater than or equal to a preset score threshold from the suspicion degree ranking list as the potential failure element causing the failure transaction;
[0029] Among all the target failure node representations, the target failure node representation with the largest suspicion degree score is the largest potential failure element causing the failure transaction.
[0030] The application further provides an application program failure positioning device applied to a decentralized application program, the device comprising:
[0031] a dynamic control flow graph modeling unit configured to model a failure transaction on a block chain as a dynamic control flow graph;
[0032] a feature extraction unit configured to extract features of the dynamic control flow graph by a graph neural network with an introduced graph attention mechanism to obtain a plurality of failure node representations;
[0033] The suspicion degree ranking unit is configured to rank the plurality of fault node representations according to suspicion degrees, and determine the potential fault element causing the fault transaction according to the ranking result.
[0034] The present application also provides an electronic device, which comprises a processor and a memory:
[0035] The memory is configured to store program codes and transmit the program codes to the processor.
[0036] The processor is configured to execute the application program fault locating method according to the instructions in the program codes.
[0037] The present application also provides a computer readable storage medium, which is configured to store program codes for executing the application program fault locating method.
[0038] From the above technical solutions, the present application has the following advantages:
[0039] A fault locating method applied to a decentralized application is provided. Firstly, a fault transaction on a block chain is modeled as a dynamic control flow graph; then a graph neural network with a graph attention mechanism is used to extract features of the dynamic control flow graph, and a plurality of fault node representations are obtained; finally, the plurality of fault node representations are ranked according to suspicion degrees, and a potential fault element causing the fault transaction is determined according to the ranking result. Thus, the dynamic control flow graph and the graph neural network with the graph attention mechanism are combined for fault locating, which not only can realize efficient detection and suspicion degree ranking of smart contract fault elements, improve locating accuracy, and reduce fault elimination cost, but also can provide a new idea for processing complex interaction relationships in a block chain system in a decentralized application scenario. BRIEF DESCRIPTION OF DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without creative labor.
[0041] Figure 1 A step flow chart of an application program fault locating method;
[0042] Figure 2 A modeling schematic diagram of a fault transaction dynamic control flow graph;
[0043] Figure 3A schematic diagram of the overall flow of an application fault localization method is shown in FIG. 1.
[0044] Figure 4 A structural block diagram of an application fault localization device is shown in FIG. 2. DETAILED DESCRIPTION
[0045] Embodiments of the present application provide an application fault localization method, device, electronic equipment and storage medium, which are used to solve or partially solve the technical problems that existing fault localization methods cannot be widely applied to decentralized application fault localization and the fault localization effect is poor.
[0046] In order to make the application purpose, features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the embodiments described below are only some of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of the present application.
[0047] In order to make those skilled in the art better understand the technical solutions provided by the embodiments of the present application, first, some technical features and related technical contents involved in the solutions will be briefly described:
[0048] Fault localization: a process of identifying specific parts or causes of errors or faults in software or systems.
[0049] Smart contract: an automatically executed code deployed on a blockchain. It defines the business logic and rules of a decentralized application. Smart contracts mainly involve source code, bytecode and operation code.
[0050] Source code: the initial form of a smart contract. It is usually written in a high-level programming language such as Solidity (for Ethereum smart contracts) or Rust. The source code needs to be converted into a format executable by the blockchain through a compiler. The compilation process includes multiple stages. First, the high-level language is converted into a low-level intermediate representation (IR), and then further optimized and converted.
[0051] Bytecode: a low-level representation of source code. It is an intermediate form that can be executed by a specific virtual machine (such as Ethereum Virtual Machine, EVM). Bytecode contains the logic of a smart contract, but bytecode is platform-independent and can be executed by different blockchain platforms.
[0052] Opcode: further abstraction of bytecode. It is a binary instruction used to control the operation of the virtual machine. Each opcode represents a specific low-level operation. Such as arithmetic operations, logical operations, data storage, calling other contracts, etc. Opcode is the most basic unit of smart contract execution, which is directly executed by the virtual machine.
[0053] As an example, existing fault localization techniques mostly focus on the research of traditional software field. It can be roughly divided into three categories: spectrum-based fault localization technology SBFL, mutation-based fault localization technology MBFL and machine learning-based fault localization technology MLFL.
[0054] However, in practical application, the spectrum-based fault localization method relies too much on coverage information, thereby ignoring the semantic information of the code, so that it cannot be widely used. The mutation-based fault localization method relies too much on semantic information, which is good but time-consuming. For decentralized applications, the rescue time of fault localization is urgent, so it cannot be used for application fault localization. Although the machine learning-based fault localization technology can improve the accuracy and efficiency of fault localization to a certain extent, the model generalization ability is poor, which ultimately leads to poor fault prediction effect.
[0055] The present application further analyzes that the existing method mostly relies on source code for fault localization. And most of the current smart contracts are closed source contracts, and the source code cannot be obtained. Therefore, the existing fault localization method cannot be widely used for smart contract fault localization.
[0056] Therefore, one of the core invention points of the embodiment of the present application is to propose a general fault localization method suitable for blockchain smart contracts in decentralized applications. Specifically, first, the bytecode is modeled by introducing a dynamic control flow graph (DCFG), and the execution process of the transaction is modeled as a dynamic control flow graph, which not only can localize faults in bytecode for all smart contracts on the blockchain, but also can capture rich control flow information. On this basis, the graph neural network (such as graph attention neural network (GAT)) with graph attention mechanism is introduced to sort the suspicion degree of the graph node, so as to quickly determine the potential fault element. Thus, combining the dynamic control flow graph and the graph neural network with graph attention mechanism for fault localization, not only can realize efficient detection and suspicion degree ranking of smart contract fault elements, improve the positioning accuracy, reduce the fault elimination cost, but also can provide a new way to deal with the complex interaction relationship in the blockchain system in the decentralized application scenario.
[0057] Reference Figure 1, a step flowchart of an application fault positioning method provided by an embodiment of the application is shown, the method is applied to a decentralized application, and specifically can include the following steps:
[0058] In step 101, a transaction causing a fault on a block chain is modeled as a dynamic control flow graph.
[0059] As can be known from the foregoing, most of the prior art depends on source code for fault positioning. However, most of the smart contracts at present are closed-source contracts, and the source code cannot be obtained. Based on this, only the fault positioning can be started from the bytecode. However, since the bytecode lacks sufficient semantic information, it is difficult to directly obtain sufficient control flow information from the bytecode.
[0060] Therefore, in the embodiment of the application, the transaction causing a fault on a block chain is modeled as a dynamic control flow graph by modeling the bytecode by using the dynamic control flow graph, so as to model the transaction execution process as a dynamic control flow, and to establish a connection between the transaction execution result and the dynamic control flow, so as to capture rich control flow information. The transaction causing a fault specifically refers to a transaction causing a property loss of an application.
[0061] In a specific implementation, modeling the transaction causing a fault on a block chain as a dynamic control flow graph can be: first, collecting the transaction causing a fault on a block chain, and the bytecode of the function triggered by the transaction causing a fault; and modeling the transaction causing a fault as a dynamic control flow graph based on the bytecode.
[0062] To enable those skilled in the art to better understand the technical solutions of the present application, Figure 2 A dynamic control flow graph modeling schematic diagram of the transaction causing a fault is shown.
[0063] In the modeling phase of the dynamic control flow graph, the bytecode of the function triggered by the transaction causing a fault is mainly modeled as a dynamic control flow graph. In this process, the following four types of nodes are defined:
[0064] (1) External account node: These nodes represent accounts controlled by users.
[0065] (2) Smart contract node: These nodes represent smart contracts running on a block chain, carrying specific business logic and rules.
[0066] (3) Bytecode block node: These nodes represent the bytecode blocks of a program, which are the basic execution units of a smart contract.
[0067] (4) Log node: These nodes are used to store event and state change information in the execution process of a smart contract, and provide detailed records of the execution track.
[0068] Further, the dynamic control flow graph further includes the following edge representation types: control flow jump, contract call, function call, token transfer, token authorization and output log. These edges represent different types of interactions and dependencies during execution.
[0069] For example, the control flow jump edge represents the program control flow jump between bytecode blocks. The contract call edge represents the calling relationship between smart contracts. The function call edge represents the call between functions within a contract. The token transfer edge represents the operation of transferring tokens from one account to another account. The token authorization edge represents the operation of one account authorizing another account to use its tokens. The output log edge represents the record of log information generated during contract execution.
[0070] Therefore, by introducing the dynamic control flow graph to model the bytecode, the execution process of the transaction is modeled as a dynamic control flow graph, which not only enables fault localization of all smart contracts on the blockchain in bytecode, but also captures rich control flow information.
[0071] At step 102, a graph neural network with a graph attention mechanism is used to extract features from the dynamic control flow graph to obtain a plurality of fault node representations.
[0072] After constructing the above dynamic control flow graph, the next step is to extract features from the dynamic control flow graph. The main principle is to use graph neural network technology (such as graph convolutional network (GCN), graph transformer (GT)) to process the dynamic control flow graph, so as to realize the code element suspicion degree ranking in the subsequent process. Among them, the code element suspicion degree refers to the probability that the code element contains a fault after being processed by the graph neural network.
[0073] The graph neural network can efficiently capture the complex relationships between nodes and edges in the graph structure. In order to further improve the accuracy of fault detection, the graph attention mechanism is introduced into the graph neural network in the embodiment of the present application. Therefore, the model can assign different attention weights to each node based on the graph attention mechanism when processing graph data, so that the model can dynamically adjust the attention degree of different nodes according to the context, so as to flexibly focus on the key part of the graph, thereby more accurately identifying the fault element.
[0074] In a specific implementation, a graph neural network with a graph attention mechanism is used to extract features from the dynamic control flow graph to obtain a plurality of fault node representations. Specifically, first, the edges of the dynamic control flow graph are represented, and a graph neural network with a graph attention mechanism is introduced to learn the embedding of each node in the dynamic control flow graph. At the same time, different attention weights are assigned to each node to generate the initial node representation (i.e., the initial node vector representation, which includes the type, attributes, and position and connection relationship of the node in the graph) corresponding to the node. Then, the loss function value of each initial node representation is calculated, and a plurality of fault node representations are obtained by minimizing the loss function.
[0075] When calculating the loss function value, the present application mainly uses the binary cross entropy (BCE) loss function. Specifically, for each node, a probability value (fault prediction value) is output by the model prediction, which represents the possibility of the node being a fault node. The difference between this probability value and the actual label (0 or 1, where 1 represents a fault node) is quantified by the binary cross entropy loss function and fed back to the model to optimize its parameters. In the embodiment of the present application, the loss function is used to compare the node suspicion degree predicted by the graph neural network with the bytecode representation of the known actual fault node.
[0076] Based on the foregoing, in a specific implementation, the loss function value of each initial node representation can be calculated as follows: the fault prediction value of each initial node representation is calculated; for each node, the binary cross entropy loss value between the fault prediction value and the fault actual value is calculated based on the binary cross entropy loss function, which is used as the loss function value of the initial node representation; wherein the fault actual value is usually determined based on prior knowledge or historical data, and is used to represent whether the node is a fault element.
[0077] Further, by minimizing the loss function, a plurality of fault node representations are obtained, which can be specifically as follows: the node representation is adjusted by the backpropagation algorithm to minimize the loss function; during the adjustment process, based on the introduced graph attention mechanism, the model gradually focuses attention on the node representation with the largest fault contribution, thereby improving the accuracy of fault detection, and after the adjustment is completed, a plurality of fault node representations are obtained.
[0078] Step 103: ranking the plurality of fault node representations according to the suspicion degree, and determining the potential fault element causing the fault transaction according to the suspicion degree ranking result.
[0079] After the foregoing model-related training, the trained model generates a suspicion score for each node. The score reflects the likelihood of the node as a fault point. According to the scores, a list of code elements ranked from high to low suspicion can be formed, thereby helping developers quickly locate and repair potential security vulnerabilities in the contract.
[0080] The suspicion ranking is actually a ranking of all nodes according to the minimized loss function value. Nodes with higher loss values are considered potential fault elements and thus occupy the top positions in the suspicion ranking.
[0081] In a specific implementation, the process of ranking the fault node representations according to suspicion and determining the potential fault elements causing the fault transaction according to the suspicion ranking result can be as follows:
[0082] First, generate a suspicion score of the fault node representation according to the minimized loss function value, wherein the suspicion score is used to reflect the likelihood of the node where the fault node representation is located as a fault point.
[0083] Second, rank all fault node representations according to suspicion in descending order of suspicion score to obtain a suspicion ranking list.
[0084] Finally, filter target fault node representations with suspicion scores greater than or equal to a preset score threshold (which can be set in advance based on actual conditions or running experience) from the suspicion ranking list as potential fault elements causing the fault transaction.
[0085] Among all target fault node representations, the target fault node representation with the maximum suspicion score (corresponding to the maximum loss function value) is the maximum potential fault element causing the fault transaction.
[0086] In an embodiment of the present application, a general fault locating method for blockchain smart contracts in a decentralized application is proposed. First, a dynamic control flow graph is introduced to model the bytecode, and the execution process of the transaction is modeled as a dynamic control flow graph. Not only can the fault be located in all smart contracts on the blockchain in bytecode form, but also rich control flow information can be captured. On this basis, a graph neural network with a graph attention mechanism is introduced to sort the suspicion of the graph nodes to quickly determine the potential fault elements. Thus, combining the dynamic control flow graph with the graph neural network with the graph attention mechanism for fault locating can not only achieve efficient detection and suspicion ranking of smart contract fault elements, improve positioning accuracy, and reduce fault elimination cost, but also provide a new way to handle complex interaction relationships in blockchain systems in decentralized application scenarios.
[0087] For better illustration, reference will be made toFigure 3 Fig. 1 shows a schematic diagram of the overall flow of a method for application fault localization according to an embodiment of the present application. It should be noted that the embodiment only briefly describes the general flow of the application fault localization, and the specific implementation process of each step can be understood with reference to the related content in the foregoing embodiments, which will not be described here again. It can be understood that the present application does not limit this.
[0088] 1. Model the transaction causing the fault in the blockchain into a dynamic control flow graph;
[0089] 2. Extract features of the dynamic control flow graph by introducing a graph attention mechanism of a graph neural network to obtain a plurality of fault node representations;
[0090] 3. Rank the plurality of fault node representations according to the minimized binary cross-entropy loss function value to obtain a suspicion degree ranking list;
[0091] 4. Based on the loss function value (or suspicion degree score value), filter the potential fault elements causing the fault transaction in the bytecode code from the suspicion degree ranking list that meet the score threshold condition;
[0092] 5. Based on the filtered potential fault elements, perform reverse fault localization on the fault function causing the fault transaction to obtain the bytecode representation of the fault function, thereby realizing the rapid localization of the transaction causing the fault in the blockchain.
[0093] Reference Figure 4 Fig. 1 shows a structural block diagram of an application fault localization device according to an embodiment of the present application, which is applied to a decentralized application. The device can specifically include:
[0094] A dynamic control flow graph modeling unit 401 is configured to model the fault transaction on the blockchain into a dynamic control flow graph;
[0095] A feature extraction unit 402 is configured to extract features of the dynamic control flow graph by introducing a graph attention mechanism of a graph neural network to obtain a plurality of fault node representations;
[0096] A suspicion degree ranking unit 403 is configured to rank the plurality of fault node representations according to the suspicion degree, and determine the potential fault elements causing the fault transaction according to the suspicion degree ranking result.
[0097] In an optional embodiment, the dynamic control flow graph modeling unit 401 includes:
[0098] A fault transaction collection module is configured to collect the fault transaction on the blockchain, and the fault transaction corresponds to the bytecode of the function triggered by the fault;
[0099] A dynamic control flow graph modeling module is configured to model the faulty transaction as a dynamic control flow graph based on the bytecode.
[0100] In an optional embodiment, the node types in the dynamic control flow graph include an external account node, a smart contract node, a bytecode block node, and a log node; and the edge representation types in the dynamic control flow graph include a control flow jump, a contract call, a function call, a token transfer, a token authorization, and an output log.
[0101] In an optional embodiment, the feature extraction unit 402 includes:
[0102] An initial node representation generation module is configured to, in combination with the edge representation of the dynamic control flow graph, perform embedding learning on each node of the dynamic control flow graph by introducing a graph neural network with a graph attention mechanism, assign different attention weights to each node, and generate an initial node representation corresponding to the node, where the initial node representation includes the type, attributes, position, and connection relationship of the node in the dynamic control flow graph.
[0103] A loss function value calculation module is configured to calculate a loss function value of each initial node representation, and obtain a plurality of fault node representations by minimizing the loss function.
[0104] In an optional embodiment, the loss function value calculation module includes:
[0105] A fault prediction value calculation module is configured to calculate a fault prediction value of each initial node representation.
[0106] A binary cross-entropy loss value calculation module is configured to, for each node, calculate a binary cross-entropy loss value between the fault prediction value and a fault actual value based on a binary cross-entropy loss function, as the loss function value of the initial node representation.
[0107] The fault actual value is determined based on prior knowledge or historical data, and is used to represent whether the node is a fault element.
[0108] In an optional embodiment, the loss function value calculation module includes:
[0109] A node representation adjustment module is configured to adjust the node representation by a back propagation algorithm to minimize the loss function.
[0110] A fault node representation obtaining module is configured to, during the adjustment process, cause the model to gradually focus attention on the node representation with the largest fault contribution based on the introduced graph attention mechanism, and obtain a plurality of fault node representations after the adjustment is completed.
[0111] In an optional embodiment, the suspicion degree ranking unit 403 comprises:
[0112] a suspicion degree score generation module, configured to generate a suspicion degree score of the fault node representation according to the minimized loss function value, the suspicion degree score being used to reflect a possibility of the node where the fault node representation is located as a fault point;
[0113] a suspicion degree ranking module, configured to rank all the fault node representations according to the suspicion degree scores from large to small, and obtain a suspicion degree ranking list;
[0114] a potential fault element screening module, configured to screen, from the suspicion degree ranking list, target fault node representations with suspicion degree scores greater than or equal to a preset score threshold, as the potential fault elements of the fault-causing transaction;
[0115] Among all the target fault node representations, a target fault node representation with the largest suspicion degree score is the largest potential fault element of the fault-causing transaction.
[0116] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts can be referred to the foregoing description of the method embodiment.
[0117] The embodiment of the application further provides an electronic device, which comprises a processor and a memory:
[0118] The memory is used to store program code and transmit the program code to the processor;
[0119] The processor is used to execute the application program fault locating method according to the instructions in the program code.
[0120] The embodiment of the application further provides a computer readable storage medium, which is used to store program code, and the program code is used to execute the application program fault locating method.
[0121] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiment, and will not be described here.
[0122] In several embodiments provided by the present application, it should be understood that the disclosed system, device and method can be implemented in other manners. For example, the described device embodiments are merely schematic. For example, the division of the units is only a logical function division. There can be another division manner for the actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between different units, can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0123] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0124] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can be physically present separately, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0125] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part of the prior art that contributes to the technical solutions or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program code storage media.
[0126] The above embodiments are merely used to illustrate the technical solutions of the present application, rather than limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent replacements to some technical features. Such modifications or replacements do not cause the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An application fault localization method, characterized by, The method applied to a decentralized application, comprising: Modeling a fault-causing transaction on a blockchain as a dynamic control flow graph; Extracting features of the dynamic control flow graph by using a graph neural network with an introduced graph attention mechanism to obtain a plurality of fault node representations; Ranking suspicion degrees of the plurality of fault node representations, and determining potential fault elements of the fault-causing transaction according to a ranking result of the suspicion degrees; The modeling of the fault-causing transaction on the blockchain as the dynamic control flow graph comprises: Collecting a fault-causing transaction on a blockchain, the fault-causing transaction corresponding to bytecode of a fault-triggering-time function; Modeling the fault-causing transaction as a dynamic control flow graph based on the bytecode; a node type in the dynamic control flow graph comprises an external account node, a smart contract node, a bytecode block node, and a log node; an edge representation type in the dynamic control flow graph comprises a control flow jump, a contract call, a function call, a token transfer, a token authorization, and an output log; The feature extraction of the dynamic control flow graph by using the graph neural network with the introduced graph attention mechanism to obtain the plurality of fault node representations comprises: In combination with an edge representation of the dynamic control flow graph, embedding learning is performed on each node of the dynamic control flow graph by using the graph neural network with the introduced graph attention mechanism, different attention weights are assigned to each node, and an initial node representation corresponding to the node is generated, the initial node representation comprising a type, an attribute, a position, and a connection relationship of the node in the dynamic control flow graph; A loss function value of each initial node representation is calculated, and a plurality of fault node representations are obtained by minimizing the loss function.
2. The application fault localization method of claim 1, wherein, The calculation of the loss function value of each initial node representation comprises: A fault prediction value of each initial node representation is calculated; For each node, a binary cross-entropy loss value between the fault prediction value and a fault actual value is calculated as the loss function value of the initial node representation based on a binary cross-entropy loss function; The fault actual value is determined based on prior knowledge or historical data, and is used to represent whether the node is a fault element.
3. The application fault localization method of claim 1, wherein, The obtaining of the plurality of fault node representations by minimizing the loss function comprises: The node representation is adjusted by a back propagation algorithm to minimize the loss function; During the adjustment, the model gradually focuses on the node representation with the largest fault contribution based on the introduced graph attention mechanism, and the plurality of fault node representations are obtained after the adjustment is completed.
4. The application fault localization method of any one of claims 1 to 3, wherein, The ranking of the suspicion degrees of the plurality of fault node representations, and the determination of the potential fault elements of the fault-causing transaction according to the ranking result of the suspicion degrees comprise: A suspicion degree score of the fault node representation is generated according to the minimized loss function value, the suspicion degree score being used to reflect a possibility of the node as a fault point; Suspicion degrees of all the fault node representations are ranked in an order from large to small according to the suspicion degree scores to obtain a suspicion degree ranking list; and The potential fault elements of the fault-causing transaction are determined according to the suspicion degree ranking list. screening, from the suspicious degree ranking list, a target fault node representation with a suspicious degree score greater than or equal to a preset score threshold, as a potential fault element causing the fault transaction; wherein, among all the target fault node representations, a target fault node representation with the largest suspicious degree score is the largest potential fault element causing the fault transaction.
5. An application fault localization apparatus characterized by comprising: The apparatus is applied to a decentralized application, and the apparatus comprises: a dynamic control flow graph modeling unit configured to model the fault transaction on the blockchain as a dynamic control flow graph; a feature extraction unit configured to perform feature extraction on the dynamic control flow graph by using a graph neural network with a graph attention mechanism, to obtain a plurality of fault node representations; a suspicious degree ranking unit configured to rank the plurality of fault node representations according to suspicious degrees, and determine a potential fault element causing the fault transaction according to a result of the ranking; the dynamic control flow graph modeling unit comprises: a fault transaction collection module configured to collect the fault transaction on the blockchain, the fault transaction corresponding to bytecode of a fault trigger time function; a dynamic control flow graph modeling module configured to model the fault transaction as a dynamic control flow graph based on the bytecode; a node type in the dynamic control flow graph comprises an external account node, a smart contract node, a bytecode block node, and a log node; and an edge representation type in the dynamic control flow graph comprises a control flow jump, a contract call, a function call, a token transfer, a token authorization, and an output log. the feature extraction unit comprises: an initial node representation generation module configured to combine edge representations of the dynamic control flow graph, perform embedding learning on each node of the dynamic control flow graph by using a graph neural network with a graph attention mechanism, assign different attention weights to each node, and generate an initial node representation corresponding to the node, the initial node representation comprising a type, an attribute, a position, and a connection relationship of the node in the dynamic control flow graph; a loss function value calculation module configured to calculate a loss function value of each initial node representation, and obtain a plurality of fault node representations by minimizing the loss function.
6. An electronic device, comprising: The device comprises a processor and a memory: the memory is configured to store program code and transmit the program code to the processor; the processor is configured to execute the application fault locating method according to instructions in the program code.
7. A computer-readable storage medium, characterized in that, The computer readable storage medium is configured to store program code, and the program code is configured to execute the application fault locating method. The computer readable storage medium is configured to store program code, and the program code is configured to execute the application fault locating method.
Citation Information
Patent Citations
Method for detecting abnormal behavior of block chain based on graph embedding
CN114612235A
Intelligent contract vulnerability detection method based on graph neural network
CN116383832A