Application program fault positioning method and device, electronic equipment and storage medium
By modeling fault transactions on the blockchain as dynamic control flow graphs and using graph attention mechanisms, the problem of low fault location efficiency of decentralized applications is solved, and efficient and accurate fault detection and suspicion are achieved. ranks, reducing troubleshooting costs.
Patent Information
- Application Number
- CN202411486018.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-10-23
AI Technical Summary
Existing fault location technologies are difficult to efficiently and accurately locate faults in decentralized applications, especially when transactions trigger on-chain application failures, resulting in too long troubleshooting and ineffective results.
Model the transactions that cause failures on the blockchain as dynamic control flow diagrams, and use the graph neural network that introduces the graph attention mechanism to extract the dynamic control flow diagrams to generate the fault node representation, and determine the potential fault elements through suspicion ranking. .
It realizes efficient detection and suspicion ranking of smart contract fault elements, improves the accuracy of fault location, reduces the cost of troubleshooting, and provides a new idea to deal with complex interactive relationships of blockchain systems in decentralized application scenarios.
Smart Images

Figure CN119226024A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application fault analysis, and in particular to an application fault locating method, device, electronic device and storage medium. Background Art
[0002] Decentralized Applications (DApps) are applications built on blockchain technology. They have the characteristics of decentralized networks, smart contracts, user-controlled data, and high security. Because DApps can provide advantages such as anti-censorship, transparency, and data privacy protection, they are widely used in many fields such as finance, social networks, and games. Taking the financial field as an example, DApps are closely linked to cryptocurrency transactions. Due to the large amount of funds involved, DApps are often the target of hacker attacks.
[0003] However, locating faults for decentralized applications is a challenging task. The reason is that a single transaction may trigger a chain reaction in multiple decentralized applications. This makes it time-consuming and complicated to manually investigate the semantic reasons behind the transaction. In particular, when a transaction causes a failure in an on-chain application, developers are faced with the challenge of quickly locating the problematic code segment. Improving the efficiency of fault location for decentralized applications is crucial to ensuring the security of funds and safeguarding the interests of relevant personnel.
[0004] Most of the existing fault localization technologies focus on the research of traditional software fields. They 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).
[0005] However, in practical applications, spectrum-based fault localization methods rely too much on coverage information, thus ignoring the semantic information of the code, which makes them not widely used. Mutation-based fault localization methods rely too much on semantic information, and although they are effective, they are too time-consuming. For decentralized applications, the rescue time for fault localization is urgent, so they cannot be used for application fault localization. Although 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 results. Summary of the invention
[0006] The present invention provides an application fault location method, device, electronic device and storage medium, which are used to solve or partially solve the technical problems that the existing fault location methods cannot be widely used in decentralized application fault location and the fault location effect is poor.
[0007] The present invention provides an application fault location method, which is applied to decentralized applications. The method comprises:
[0008] Modeling the fault-causing transactions on the blockchain as a dynamic control flow graph;
[0009] A graph neural network with a graph attention mechanism is used to extract features of the dynamic control flow graph to obtain multiple fault node representations;
[0010] The multiple fault node representations are ranked according to suspicion, and the potential fault element causing the faulty transaction is determined according to the suspicion ranking result.
[0011] Optionally, modeling the fault-causing transaction on the blockchain as a dynamic control flow graph includes:
[0012] Collecting the transactions causing the fault on the blockchain, wherein the transactions causing the fault correspond to the bytecode of the function when the fault is triggered;
[0013] The fault-causing transaction is modeled as a dynamic control flow graph based on the bytecode.
[0014] Optionally, the node types in the dynamic control flow graph include external account nodes, smart contract nodes, bytecode block nodes and log nodes; the edge representation types in the dynamic control flow graph include control flow jumps, contract calls, function calls, token transfers, token authorizations and output logs.
[0015] Optionally, the adopting of a graph neural network that introduces a graph attention mechanism to perform feature extraction on the dynamic control flow graph to obtain multiple fault node representations includes:
[0016] Combined with the edge representation of the dynamic control flow graph, by introducing a graph neural network with a graph attention mechanism, each node of the dynamic control flow graph is embedded and learned, and different attention weights are assigned to each node to generate an initial node representation corresponding to the node, wherein the initial node representation includes the type and attributes of the node and the position and connection relationship of the node in the dynamic control flow graph;
[0017] The loss function value of each of the initial node representations is calculated, and multiple fault node representations are obtained by minimizing the loss function.
[0018] Optionally, calculating the loss function value represented by each of the initial nodes includes:
[0019] Calculating a fault prediction value represented by each of the initial nodes;
[0020] For each node, based on the binary cross entropy loss function, a binary cross entropy loss value between the fault prediction value and the actual fault value is calculated as the loss function value represented by the initial node;
[0021] The actual fault value is determined based on prior knowledge or historical data and is used to indicate whether the node is a fault element.
[0022] Optionally, obtaining multiple fault node representations by minimizing the loss function includes:
[0023] Adjust node representations through the back-propagation algorithm to minimize the loss function;
[0024] During the adjustment process, based on the introduced graph attention mechanism, the model gradually focuses on the node representations that contribute the most to the fault, and after the adjustment is completed, multiple fault node representations are obtained.
[0025] Optionally, the step of ranking the multiple fault node representations by suspicion, and determining the potential fault element causing the faulty transaction according to the suspicion ranking result, includes:
[0026] Generate a suspicion score for the fault node representation according to the minimized loss function value, wherein the suspicion score is used to reflect the possibility that the node where the fault node representation is located is a fault point;
[0027] Ranking the suspicion scores of all the faulty node representations in descending order to obtain a suspicion ranking list;
[0028] Filtering target fault nodes with suspicion scores greater than or equal to a preset score threshold from the suspicion ranking list as potential fault elements causing the faulty transaction;
[0029] Among all the target fault node representations, the target fault node representation with the largest suspicion score is the greatest potential fault element causing the faulty transaction.
[0030] The present invention also provides an application fault location device, which is applied to decentralized applications, and the device includes:
[0031] A dynamic control flow graph modeling unit, used to model the fault-causing transactions on the blockchain as a dynamic control flow graph;
[0032] A feature extraction unit, configured to extract features from the dynamic control flow graph using a graph neural network that introduces a graph attention mechanism, and obtain multiple fault node representations;
[0033] The suspicion ranking unit is used to rank the suspicions of the multiple faulty node representations and determine the potential faulty elements causing the faulty transaction according to the suspicion ranking results.
[0034] The present invention also provides an electronic device, the device comprising a processor and a memory:
[0035] The memory is used to store program code and transmit the program code to the processor;
[0036] The processor is used to execute the application fault locating method as described in any one of the above items according to the instructions in the program code.
[0037] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the application fault locating method as described in any one of the above items.
[0038] It can be seen from the above technical solutions that the present invention has the following advantages:
[0039] A fault location method for decentralized applications is provided. First, the transaction that causes the fault on the blockchain is modeled as a dynamic control flow graph; then, a graph neural network with a graph attention mechanism is used to extract features from the dynamic control flow graph to obtain multiple fault node representations; finally, multiple fault node representations are ranked for suspicion, and based on the suspicion ranking results, the potential fault elements that cause the faulty transaction are determined. Therefore, the combination of dynamic control flow graph and graph neural network with a graph attention mechanism for fault location can not only achieve efficient detection and suspicion ranking of smart contract fault elements, improve location accuracy, and reduce troubleshooting costs, but also provide a new idea to deal with complex interactive relationships in blockchain systems in decentralized application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 A flowchart of the steps of an application fault location method;
[0042] Figure 2 A schematic diagram for modeling a dynamic control flow graph that causes a faulty transaction;
[0043] Figure 3The figure is a schematic diagram of the overall process of an application fault location method;
[0044] Figure 4 The present invention is a structural block diagram of an application fault location device. DETAILED DESCRIPTION
[0045] The embodiments of the present invention provide an application fault location method, device, electronic device and storage medium, which are used to solve or partially solve the technical problems that the existing fault location methods cannot be widely used in decentralized application fault location and the fault location effect is poor.
[0046] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] In order to enable those skilled in the art to better understand the technical solution provided by the embodiment of the present invention, some technical features and related technical contents involved in the solution are briefly described first:
[0048] Fault Localization: The process of identifying the specific part or cause of an error or failure in software or a system.
[0049] Smart Contracts: Self-executing codes deployed on the blockchain. They define the business logic and rules of decentralized applications. Smart contracts mainly involve source code, bytecode, and opcode.
[0050] Source code: The initial form of a smart contract. Usually written in a high-level programming language, such as Solidity (used for Ethereum smart contracts) or Rust. The source code needs to be converted by a compiler into a format that can be executed by the blockchain. The compilation process includes multiple stages. First, the high-level language is converted into a low-level intermediate representation (IR), which is 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 the smart contract, but bytecode is platform-independent and can be executed by different blockchain platforms.
[0052] Opcode: A 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. The opcode is the most basic unit of smart contract execution and is directly executed by the virtual machine.
[0053] As an example, most of the existing fault location technologies focus on the research of traditional software fields, and can be roughly divided into three categories: spectrum-based fault location technology SBFL, variation-based fault location technology MBFL, and machine learning-based fault location technology MLFL.
[0054] However, in practical applications, spectrum-based fault localization methods rely too much on coverage information, thus ignoring the semantic information of the code, which makes them not widely used. Mutation-based fault localization methods rely too much on semantic information, and although they are effective, they are too time-consuming. For decentralized applications, the rescue time for fault localization is urgent, so they cannot be used for application fault localization. Although 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 results.
[0055] Through further analysis, the present invention finds that most existing methods rely on source code for fault location. However, most current smart contracts are closed-source contracts, and source code cannot be obtained. Therefore, it can be seen that existing fault location methods cannot be widely used for smart contract fault location.
[0056] Therefore, one of the core invention points of the embodiment of the present invention is to propose a general fault location method suitable for blockchain smart contracts in decentralized applications. Specifically, by first introducing a dynamic control flow graph (DCFG) to model the bytecode, the execution process of the transaction is modeled as a dynamic control flow graph, which can not only locate the faults of all smart contracts on the blockchain in a bytecode manner, but also capture rich control flow information. On this basis, the suspicion of graph nodes is sorted by introducing a graph neural network with a graph attention mechanism (such as a graph attention neural network (GAT)) to quickly determine potential fault elements. Therefore, combining the dynamic control flow graph with the graph neural network with the graph attention mechanism for fault location can not only achieve efficient detection and suspicion ranking of smart contract fault elements, improve positioning accuracy, and reduce troubleshooting costs, but also provide a new idea to deal with complex interactive relationships in blockchain systems in decentralized application scenarios.
[0057] Reference Figure 1, shows a flowchart of a method for locating an application fault provided by an embodiment of the present invention, the method is applied to a decentralized application, and specifically may include the following steps:
[0058] Step 101, modeling the transaction causing the fault on the blockchain as a dynamic control flow graph;
[0059] Combined with the previous discussion, it can be seen that most existing technologies rely on source code for fault location. However, most current smart contracts are closed-source contracts, and source code cannot be obtained. Based on this, we can only consider starting from bytecode for fault location. However, since bytecode lacks sufficient semantic information, it is difficult to directly obtain sufficient control flow information from it.
[0060] Therefore, the embodiment of the present invention uses a dynamic control flow graph to model the bytecode, models the transaction that causes the failure on the blockchain as a dynamic control flow graph, models the transaction execution process as a dynamic control flow, and establishes a connection between the transaction execution result and the dynamic control flow to capture rich control flow information. Among them, the transaction that causes the failure specifically refers to the transaction that causes the property loss of the application.
[0061] In a specific implementation, modeling the fault-causing transactions on the blockchain as a dynamic control flow graph can be as follows: first, collect the fault-causing transactions on the blockchain, and the bytecode of the function corresponding to the fault triggering of the fault-causing transactions; based on the bytecode, model the fault-causing transactions as a dynamic control flow graph.
[0062] In order to enable those skilled in the art to better understand the technical solution of the present invention, Figure 2 A schematic diagram of dynamic control flow graph modeling that causes a faulty transaction provided by an embodiment of the present invention is shown.
[0063] In the modeling phase of the dynamic control flow graph, the main goal is to model the bytecode of the function triggered by the faulty transaction into a dynamic control flow graph. In this process, the following four node types are defined:
[0064] (1) External account nodes: These nodes represent accounts controlled by users.
[0065] (2) Smart contract nodes: These nodes represent smart contracts running on the blockchain and carry specific business logic and rules.
[0066] (3) Bytecode block nodes: These nodes represent the bytecode blocks of the program and are the basic execution units of smart contracts.
[0067] (4) Log nodes: These nodes are used to store events and state change information during the execution of smart contracts, providing detailed records of the execution trajectory.
[0068] Furthermore, the dynamic control flow graph also 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 the execution process.
[0069] For example, a control flow jump edge represents a program control flow jump between bytecode blocks. A contract call edge represents the calling relationship between smart contracts. A function call edge represents the call between functions within a contract. A token transfer edge represents the operation of transferring tokens from one account to another. A token authorization edge represents the operation of one account authorizing another account to use its tokens. An output log edge represents the record of log information generated during the execution of a contract.
[0070] Therefore, by introducing a dynamic control flow graph to model the bytecode, the transaction execution process is modeled as a dynamic control flow graph, which can not only locate the faults of all smart contracts on the blockchain in a bytecode manner, but also capture rich control flow information.
[0071] Step 102, using a graph neural network that introduces a graph attention mechanism to extract features from the dynamic control flow graph to obtain multiple 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) and graph transformer (GT)) to process the dynamic control flow graph to achieve code element suspicion ranking in the subsequent process. The code element suspicion refers to the probability that the code element contains a fault after being processed by the graph neural network.
[0073] Graph neural networks can efficiently capture the complex relationships between nodes and edges in graph structures. In order to further improve the accuracy of fault detection, the embodiment of the present invention also introduces a graph attention mechanism into the graph neural network. This enables the model to dynamically adjust the degree of attention to different nodes according to the context by assigning different attention weights to each node when processing graph data, based on the graph attention mechanism, so as to flexibly focus on the key parts of the graph, thereby more accurately identifying faulty elements.
[0074] In the specific implementation, a graph neural network with a graph attention mechanism is used to extract features of the dynamic control flow graph to obtain multiple fault node representations. This can be done as follows: first, combined with the edge representation of the dynamic control flow graph, each node of the dynamic control flow graph is embedded and learned by introducing a graph neural network with a graph attention mechanism. At the same time, different attention weights are assigned to each node to generate the initial node representation corresponding to the node (that is, the initial node vector representation, which contains the node type, attributes, position and connection relationship in the graph); then, the loss function value of each initial node representation is calculated, and multiple fault node representations are obtained by minimizing the loss function.
[0075] When calculating the loss function value, the present invention mainly adopts the Binary Cross Entropy (BCE) loss function. Specifically, for each node, a probability value (fault prediction value) is output through model prediction to indicate the possibility that the node is a faulty node. The difference between the probability value and the actual label (0 or 1, where 1 represents a faulty node) is quantified by the binary cross entropy loss function and fed back to the model to optimize its parameters. In an embodiment of the present invention, the loss function is used to compare the node suspicion predicted by the graph neural network with the bytecode representation of the known actual faulty node.
[0076] Based on the foregoing introduction, in a specific implementation, the loss function value represented by each initial node is calculated as follows: the fault prediction value represented by each initial node is calculated; for each node, based on the binary cross entropy loss function, the binary cross entropy loss value between the fault prediction value and the actual fault value is calculated as the loss function value represented by the initial node; wherein the actual fault value is usually determined based on prior knowledge or historical data, and is used to indicate whether the node is a fault element.
[0077] Furthermore, by minimizing the loss function, multiple fault node representations are obtained, which can be specifically: adjusting the node representation through the back propagation algorithm to minimize the loss function; during the adjustment process, based on the introduced graph attention mechanism, the model gradually focuses on the node representation with the largest fault contribution, thereby improving the accuracy of fault detection, and after the adjustment is completed, multiple fault node representations are obtained.
[0078] Step 103: rank the suspicions of the multiple faulty node representations, and determine the potential faulty elements causing the faulty transaction based on the suspicion ranking results.
[0079] After the previous model-related training, the trained model generates a suspicion score for each node. The score reflects the likelihood of the node being a failure point. Based on these scores, a list of code elements ranked from high to low suspicion can be formed, helping developers quickly locate and fix potential security vulnerabilities in contracts.
[0080] Suspicion ranking is actually ranking all nodes according to the minimized loss function value. Nodes with higher loss values are considered potential fault elements and thus occupy the top position in the suspicion ranking.
[0081] In a specific implementation, the process of ranking the suspicions of multiple faulty node representations and determining the potential faulty elements causing the faulty transaction according to the suspicion ranking results may be:
[0082] First, according to the minimized loss function value, the suspicion score of the fault node representation is generated, where the suspicion score is used to reflect the possibility that the node where the fault node representation is located is the fault point;
[0083] Secondly, the suspicion scores are ranked from large to small to obtain a suspicion ranking list.
[0084] Finally, target fault nodes with suspicion scores greater than or equal to a preset score threshold (the score threshold can be set in advance based on actual conditions or operating experience) are selected from the suspicion ranking list as potential fault elements that cause faulty transactions;
[0085] Among all the target fault node representations, the target fault node representation with the largest suspicion score (corresponding to the largest loss function value) is the most potential fault element that causes the faulty transaction.
[0086] In an embodiment of the present invention, a general fault location method suitable for blockchain smart contracts in decentralized applications is proposed. First, by introducing a dynamic control flow graph to model the bytecode, the execution process of the transaction is modeled as a dynamic control flow graph, which can not only locate the faults of all smart contracts on the blockchain in a bytecode manner, but also capture rich control flow information. On this basis, the suspicion of the graph nodes is sorted by introducing a graph neural network with a graph attention mechanism to quickly determine the potential fault elements. Therefore, by combining the dynamic control flow graph with the graph neural network with a graph attention mechanism for fault location, it is possible to achieve efficient detection and suspicion ranking of smart contract fault elements, improve positioning accuracy, and reduce troubleshooting costs, and also provide a new idea to deal with complex interactive relationships in blockchain systems in decentralized application scenarios.
[0087] For better explanation, refer to Figure 3 , showing an overall flow diagram of an application fault location method provided by an embodiment of the present invention. It should be pointed out that this embodiment only briefly describes the general process of application fault location, and the specific implementation process of each step can be understood by referring to the relevant content in the aforementioned embodiment, which will not be described here. It can be understood that the present invention does not limit this.
[0088] 1. Model the transaction hashes that cause failures in the blockchain into a dynamic control flow graph;
[0089] 2. By introducing the graph neural network with graph attention mechanism, the dynamic control flow graph is extracted to obtain multiple fault node representations;
[0090] 3. According to the minimized binary cross entropy loss function value, multiple fault node representations are ranked by the suspicion of fault elements to obtain a suspicion ranking list;
[0091] 4. Based on the loss function value (or suspicion score value), the potential fault elements in the bytecode code that cause the faulty transaction and meet the score threshold conditions are screened from the suspicion ranking list;
[0092] 5. Based on the screened potential fault elements, reverse fault location is performed on the fault function that causes the faulty transaction, and the bytecode representation of the fault function is obtained, thereby realizing the rapid location of the transaction that causes the fault in the blockchain.
[0093] Reference Figure 4 , shows a structural block diagram of an application fault location device provided by an embodiment of the present invention, which is applied to decentralized applications. The device may specifically include:
[0094] A dynamic control flow graph modeling unit 401, used to model the fault-causing transaction on the blockchain as a dynamic control flow graph;
[0095] A feature extraction unit 402 is used to extract features from the dynamic control flow graph using a graph neural network that introduces a graph attention mechanism to obtain multiple fault node representations;
[0096] The suspicion ranking unit 403 is used to rank the suspicions of the multiple faulty node representations, and determine the potential fault element causing the faulty transaction according to the suspicion ranking result.
[0097] In an optional embodiment, the dynamic control flow graph modeling unit 401 includes:
[0098] A fault-causing transaction collection module is used to collect fault-causing transactions on the blockchain, where the fault-causing transactions correspond to the bytecode of the function when the fault is triggered;
[0099] A dynamic control flow graph modeling module is used to model the fault-causing transaction into a dynamic control flow graph based on the bytecode.
[0100] In an optional embodiment, the node types in the dynamic control flow graph include external account nodes, smart contract nodes, bytecode block nodes and log nodes; the edge representation types in the dynamic control flow graph include control flow jumps, contract calls, function calls, token transfers, token authorizations and output logs.
[0101] In an optional embodiment, the feature extraction unit 402 includes:
[0102] An initial node representation generation module is used to combine the edge representation of the dynamic control flow graph, and by introducing a graph neural network with a graph attention mechanism, embed each node of the dynamic control flow graph and assign different attention weights to each node to generate an initial node representation corresponding to the node, wherein the initial node representation includes the type and attributes of the node and the position and connection relationship of the node in the dynamic control flow graph;
[0103] The loss function value calculation module is used to calculate the loss function value of each of the initial node representations, and obtain multiple 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, used to calculate the fault prediction value represented by each of the initial nodes;
[0106] A binary cross entropy loss value calculation module, used for calculating, for each node, a binary cross entropy loss value between the fault prediction value and the fault actual value based on a binary cross entropy loss function as a loss function value represented by the initial node;
[0107] The actual fault value is determined based on prior knowledge or historical data and is used to indicate 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 used to adjust the node representation through the back-propagation algorithm to minimize the loss function;
[0110] The fault node representation acquisition module is used to gradually focus the model on the node representation with the largest fault contribution based on the introduced graph attention mechanism during the adjustment process, and obtain multiple fault node representations after the adjustment is completed.
[0111] In an optional embodiment, the suspicion ranking unit 403 includes:
[0112] A suspicion score generating module, used to 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 possibility that the node where the fault node representation is located is a fault point;
[0113] A suspicion ranking module is used to rank the suspicions of all the fault node representations in descending order of suspicion scores to obtain a suspicion ranking list;
[0114] A potential fault element screening module, used to screen target fault node representations having a suspicion score greater than or equal to a preset score threshold from the suspicion ranking list as the potential fault element causing the faulty transaction;
[0115] Among all the target fault node representations, the target fault node representation with the largest suspicion score is the greatest potential fault element causing the faulty transaction.
[0116] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the aforementioned method embodiment.
[0117] An embodiment of the present invention further provides an electronic device, the device comprising a processor and a memory:
[0118] The memory is used to store the program code and transmit the program code to the processor;
[0119] The processor is used to execute the application fault locating method of any embodiment of the present invention according to the instructions in the program code.
[0120] An embodiment of the present invention further provides a computer-readable storage medium, which is used to store program codes, and the program codes are used to execute the application fault locating method of any embodiment of the present invention.
[0121] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0122] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0123] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0124] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0125] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0126] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for locating an application fault, characterized in that: Applied to decentralized applications, the method includes: Modeling the fault-causing transactions on the blockchain as a dynamic control flow graph; A graph neural network with a graph attention mechanism is used to extract features of the dynamic control flow graph to obtain multiple fault node representations; The multiple fault node representations are ranked according to suspicion, and the potential fault element causing the faulty transaction is determined according to the suspicion ranking result.
2. The method for locating an application fault according to claim 1, characterized in that: The method of modeling the fault-causing transaction on the blockchain as a dynamic control flow graph includes: Collecting the transactions causing the fault on the blockchain, wherein the transactions causing the fault correspond to the bytecode of the function when the fault is triggered; The fault-causing transaction is modeled as a dynamic control flow graph based on the bytecode.
3. The method for locating an application fault according to claim 2, characterized in that: The node types in the dynamic control flow graph include external account nodes, smart contract nodes, bytecode block nodes and log nodes; the edge representation types in the dynamic control flow graph include control flow jumps, contract calls, function calls, token transfers, token authorizations and output logs.
4. The method for locating application faults according to claim 3, characterized in that: The graph neural network with graph attention mechanism is used to extract features from the dynamic control flow graph to obtain multiple fault node representations, including: Combined with the edge representation of the dynamic control flow graph, by introducing a graph neural network with a graph attention mechanism, each node of the dynamic control flow graph is embedded and learned, and different attention weights are assigned to each node to generate an initial node representation corresponding to the node, wherein the initial node representation includes the type and attributes of the node and the position and connection relationship of the node in the dynamic control flow graph; The loss function value of each of the initial node representations is calculated, and multiple fault node representations are obtained by minimizing the loss function.
5. The method for locating application faults according to claim 4, characterized in that: The calculating the loss function value represented by each of the initial nodes comprises: Calculating a fault prediction value represented by each of the initial nodes; For each node, based on the binary cross entropy loss function, a binary cross entropy loss value between the fault prediction value and the actual fault value is calculated as the loss function value represented by the initial node; The actual fault value is determined based on prior knowledge or historical data and is used to indicate whether the node is a fault element.
6. The method for locating application faults according to claim 4, characterized in that: By minimizing the loss function, multiple fault node representations are obtained, including: Adjust node representations through the back-propagation algorithm to minimize the loss function; During the adjustment process, based on the introduced graph attention mechanism, the model gradually focuses on the node representations that contribute the most to the fault, and after the adjustment is completed, multiple fault node representations are obtained.
7. The application fault location method according to any one of claims 4 to 6, characterized in that: The step of ranking the suspicions of the multiple faulty node representations and determining the potential faulty elements causing the faulty transaction according to the suspicion ranking results includes: Generate a suspicion score for the fault node representation according to the minimized loss function value, wherein the suspicion score is used to reflect the possibility that the node where the fault node representation is located is a fault point; Ranking the suspicion scores of all the faulty node representations in descending order to obtain a suspicion ranking list; Filtering target fault nodes with suspicion scores greater than or equal to a preset score threshold from the suspicion ranking list as potential fault elements causing the faulty transaction; Among all the target fault node representations, the target fault node representation with the largest suspicion score is the greatest potential fault element causing the faulty transaction.
8. An application fault location device, characterized in that: Applied to decentralized applications, the device comprises: A dynamic control flow graph modeling unit, used to model the fault-causing transactions on the blockchain as a dynamic control flow graph; A feature extraction unit, configured to extract features from the dynamic control flow graph using a graph neural network that introduces a graph attention mechanism, and obtain multiple fault node representations; The suspicion ranking unit is used to rank the suspicions of the multiple faulty node representations and determine the potential faulty elements causing the faulty transaction according to the suspicion ranking results.
9. An electronic device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the application fault locating method according to any one of claims 1 to 7 according to the instructions in the program code.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program codes, and the program codes are used to execute the application fault locating method according to any one of claims 1 to 7.
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
