Block chain execution time sequence vulnerability-oriented analysis and identification method and system

By building a control flow diagram of the blockchain source code and performing symbolic inference, the execution timing vulnerability in the blockchain is solved, and the problem of difficulty in identifying twin tree vulnerabilities in the existing technology is solved, and effective protection of blockchain security is achieved .

CN119397540AActive Publication Date: 2025-02-07INSTITUTE OF INFORMATION ENGINEERING CHINESE ACADEMY OF SCIENCES
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411333823.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-02-07
Estimated Expiration
2044-09-24

AI Technical Summary

Technical Problem

It is difficult for the existing technology to effectively identify and analyze execution timing vulnerabilities in blockchains, especially twin tree vulnerabilities, which leads to the threat of the security of blockchain.

Method used

By constructing a control flow diagram of blockchain source code, symbolic reasoning is performed to generate execution states and execution trajectories, and time-series-related operations within and between execution blocks are analyzed to identify execution sequences with execution sequence vulnerabilities.

Benefits of technology

Effectively identify and analyze execution timing vulnerabilities in blockchain, protect the property security of blockchain users, and enhance the security of blockchain systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119397540A_ABST
    Figure CN119397540A_ABST
Patent Text Reader

Abstract

The invention discloses a block chain execution time sequence vulnerability-oriented analysis and identification method and system, and belongs to the technical field of block chains. The method comprises the following steps: constructing a control flow diagram of a block chain source code, and optimizing and simplifying the control flow diagram to obtain a trunk control flow diagram; executing symbolic reasoning on the trunk control flow chart based on virtual input and output, and generating an execution state and an execution track; based on the execution state and the execution trajectory, time sequence related operations within and between the execution blocks are analyzed to identify an execution sequence having an execution sequence vulnerability. And injecting abnormal time series data, analyzing simulation execution output, and eliminating false alarms. According to the method, the potential endogenous security risk of the block chain can be analyzed, and the property security of users on the block chain is effectively protected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of blockchain, and proposes an analysis and identification method and system for blockchain execution timing vulnerabilities. Background Art

[0002] Due to its excellent decentralized characteristics and trust-building mechanism, blockchain has been widely used in finance, Internet of Things, energy, healthcare, supply chain and other fields. The immutable nature of the chain builds the cornerstone of blockchain credit, which makes double-spending attacks, 51% attacks and other attacks that affect the security of chain data have a huge impact on the blockchain system, not only causing huge losses to users, but also seriously impacting the credit of the blockchain system. In order to ensure the security of chain data, existing blockchain systems are generally equipped with a series of verification mechanisms, such as Merkle Tree, which protects transaction information through binary hash trees and provides low-cost verification capabilities.

[0003] Although blockchain is designed with security in mind, it does not mean that it is completely invulnerable. The MTCopy vulnerability reveals the fact that by exploiting the Merkle Tree verification vulnerability, attackers can achieve a 51% attack at a very low cost, which directly threatens the security of the blockchain. In order to eliminate such endogenous risks, researchers and developers use existing static and dynamic analysis techniques to discover possible chain code security issues. However, when faced with the new twin tree vulnerability, the limitations of these methods are particularly obvious. The twin tree vulnerability uses specially designed blocks to modify the transaction execution order in the blockchain, thereby tampering with the chain. Since this attack does not affect consensus and does not produce any execution anomalies, it is difficult to detect using dynamic analysis methods, and static analysis methods are difficult to effectively define security modes, and are prone to a large number of false positives and false negatives. Summary of the invention

[0004] In order to overcome the above problems, the present invention provides a method and system for analyzing and identifying blockchain execution timing vulnerabilities, analyzing the potential intrinsic security risks of blockchain, and effectively protecting the property security of users on the blockchain.

[0005] To achieve the above object, the technical solution of the present invention includes the following contents.

[0006] A method for analyzing and identifying blockchain execution timing vulnerabilities, the method comprising:

[0007] Constructing a control flow graph of the blockchain source code, and optimizing and simplifying the control flow graph to obtain a main control flow graph;

[0008] Performing symbolic reasoning based on virtual input and output on the main control flow graph to generate execution status and execution trajectory;

[0009] Based on the execution state and the execution trace, time sequence related operations within and between execution blocks are analyzed to identify execution sequences with execution sequence vulnerabilities.

[0010] Furthermore, the control flow graph of constructing the blockchain source code includes:

[0011] After extracting the statements in the blockchain source code, use the compiler to generate the AST syntax tree of the blockchain source code;

[0012] Divide the blockchain source code into basic blocks according to the AST syntax tree;

[0013] Determine the control flow relationship between basic blocks based on the transfer statements in the blockchain source code;

[0014] A control flow graph is generated based on the control flow relationship between basic blocks.

[0015] Furthermore, the control flow graph is simplified, including: merging basic blocks, deleting redundant control flow paths, and retaining control functions related to blockchain transaction submission and timing.

[0016] Furthermore, symbolic reasoning is performed on the main control flow chart based on virtual input and output to generate execution status and execution trajectory, including:

[0017] Along the main control flow graph, an execution block obtains the state output by the previous execution block;

[0018] Based on the acquired state, a virtual interpreter loop is executed in the execution block to output a corresponding state; wherein the virtual interpreter loop is to execute symbolic reasoning along the control flow to acquire a state before there is no remaining state in the execution block or a manually defined timeout is reached, and to simulate the execution of a single instruction using a symbolic execution method in the context of the state to obtain a next state;

[0019] Based on the status of the output of this execution block, jump to the next execution block;

[0020] After the last execution block is executed, a set of symbolic trace paths is generated;

[0021] The constraint solver is used to eliminate the symbolic tracking paths that are proven to be infeasible, and the execution status and execution trajectory are obtained.

[0022] Further, based on the state of the output of the execution block, jumping to the next execution block includes:

[0023] Whether the branch condition can be proved on the current path through the state query, and whether the current path is true or false; wherein the current path is the path from the execution block to the next execution block;

[0024] In the case where this current path is true, the program counter is updated to the corresponding target address;

[0025] In the case that the current path is false, the two paths are explored in a depth-first search manner, and after updating the program counter and path conditions one by one, the corresponding edges are added to the main control flow graph.

[0026] Furthermore, based on the execution state and the execution trajectory, time sequence related operations within and between execution blocks are analyzed to identify blockchain execution timing vulnerabilities, including:

[0027] A symbol variable is used to represent block time information, wherein the block time information includes: a timestamp, a random number, and a hash value;

[0028] The symbolic variable is used to execute the characteristics of each function of the simulation function, so as to symbolize the parameters of the function and then explore all possible execution paths based on the execution state and the execution trajectory;

[0029] Collect all chain operation execution statements that depend on the symbolic variable during the exploration process to build an execution access graph, and generate a time variable sequence t based on the symbolic variable;

[0030] Model the execution of transaction operations to obtain a transaction execution model<s,σ,π> ; where s = s 1 ,s 2 ,…,s n To execute the access graph, s n To execute the nth chain operation execution statement in the access graph, σ is the state environment of the chain, which includes the variables, variable relations and time variable sequence t involved in the transaction, and π is the restriction condition of the chain operation execution statement;

[0031] Deform the time variable sequence t, and determine whether there is an execution sequence that is executed normally under the deformed time variable sequence;

[0032] When an execution sequence is executed normally, the execution sequence is determined to be an execution sequence with an execution sequence vulnerability.

[0033] Furthermore, the deforming the time variable sequence t includes:

[0034] Swap the last adjacent elements in the time variable sequence t to obtain the variable sequence t 1 ;

[0035] and,

[0036] Copy the last element in the time variable sequence t and extend the last element to the end of the time variable sequence t to obtain the variable sequence t 2 ;

[0037] and,

[0038] Exchange the end and any position element in the time variable sequence t to obtain the variable sequence t 3 .

[0039] Furthermore, after analyzing the time sequence related operations within and between execution blocks based on the execution state and the execution trace to identify the execution sequence with the execution sequence vulnerability, the method further includes:

[0040] Whether the execution sequence with the execution sequence vulnerability has an impact on the operation of the blockchain is verified to verify whether the execution sequence with the execution sequence vulnerability is a real execution sequence with the execution sequence vulnerability.

[0041] Furthermore, whether the execution sequence with the execution sequence vulnerability has an impact on the operation of the blockchain is verified to determine whether the execution sequence with the execution sequence vulnerability is a real execution sequence with the execution sequence vulnerability, including:

[0042] Based on the execution sequence with the execution sequence vulnerability, a virtual environment is constructed;

[0043] In the virtual environment, sequence data with specific forward sorting characteristics and sequence data with specific reverse sorting characteristics are respectively injected into the blockchain execution sequence-related functions, and the time-related sequence after the function is executed is recorded;

[0044] If there is a difference in the time-related sequence after the function is executed, it is determined that the execution sequence with the execution sequence vulnerability is the execution sequence that actually has the execution sequence vulnerability.

[0045] A system for analyzing and identifying blockchain execution timing vulnerabilities, the system comprising:

[0046] A control flow graph construction module is used to construct a control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain a main control flow graph;

[0047] An execution symbolic reasoning module is used to perform symbolic reasoning based on virtual input and output on the main control flow chart to generate an execution state and an execution trajectory;

[0048] The execution sequence vulnerability identification module is used to analyze the time sequence related operations within and between execution blocks based on the execution state and the execution trajectory to identify the execution sequence with the execution sequence vulnerability.

[0049] Compared with the prior art, the present invention has the following beneficial effects:

[0050] The present invention focuses on the underlying implementation and operation characteristics of the blockchain system, and reveals and identifies potential timing vulnerabilities by deeply analyzing the source code and simulating the execution environment. The present invention demonstrates its unique value through the following core aspects: the deep analysis process of the source code ensures that the system can deeply understand the internal working mechanism of the blockchain, laying a solid foundation for subsequent timing analysis; based on the results of the source code analysis, the system constructs a control flow graph (CFG) of the blockchain program, and further constructs a timing model on this basis. The model describes in detail the execution order and dependencies between the various parts of the program, especially those time-sensitive operations and conditional judgments; in order to verify the accuracy of the timing model and identify potential vulnerabilities, the system adopts an efficient simulation execution mechanism. In the simulation environment, the system can simulate the actual operation of the blockchain, record and analyze the state changes and execution trajectories of each execution unit. By comparing the expected state with the actual state, the system can quickly locate the anomalies or potential vulnerabilities in the timing, which may include logical errors, data inconsistencies or security issues caused by improper execution order. The system will also generate a detailed vulnerability report, including vulnerability description, impact range, potential risks and recommended repair measures, to help developers respond and fix problems quickly. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 Flowchart of the method for analyzing and identifying blockchain execution timing vulnerabilities.

[0052] Figure 2 This is a diagram of the execution timing code mode.

[0053] Figure 3 This is the schematic diagram of the twin tree vulnerability.

[0054] Figure 4 This is a normal execution sequence detection flow chart.

[0055] Figure 5 This is a flowchart for detecting abnormal execution sequence. DETAILED DESCRIPTION

[0056] The present invention is further described in detail below in conjunction with specific embodiments. The given examples are only for illustrating the present invention, but not for limiting the scope of the present invention.

[0057] The present invention discovers vulnerability characteristics by analyzing the twin tree vulnerability, that is, the time consistency that is generally ignored in the verification process. The time correlation of the code can exclude a large number of redundant paths. The state of the transaction has a profound impact on the execution conditional statement. The execution conditional statement will direct the execution to different execution paths when the chain state is different, that is, different execution orders lead to different states of the transaction chain, which affects the satisfaction of the transaction execution conditions. Starting from the execution conditions of the function, the detection scope of the execution sequence vulnerability is further narrowed. By dynamically injecting and comparing the execution sequence, it can be confirmed whether there is a blockchain execution sequence vulnerability represented by the twin tree vulnerability.

[0058] Specifically, if Figure 1 As shown, the present invention provides the following technical solutions:

[0059] Step 1: Build the control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain the main control flow graph.

[0060] The present invention first constructs the AST syntax tree of the blockchain source code, then automatically analyzes the execution sequence of the code through a syntax analyzer, uses a formal method to perform automatic static analysis on the blockchain source code, automatically separates the blockchain execution code blocks, and then collects the structure, statements and control flow relationships of the program to generate a control flow graph. Finally, the control flow graph is optimized and simplified to obtain a trunk control flow graph.

[0061] In a preferred embodiment, the process of generating the main control flow graph includes:

[0062] Step 1.1: After extracting the statements in the blockchain source code, use the compiler to generate the AST syntax tree of the blockchain source code.

[0063] The user inputs the source code of the blockchain system, and uses the syntax analyzer to extract the statements and other information in the blockchain source code according to the syntax rules of the source code. The compiler is used to generate the code AST syntax tree, from which the expression is obtained. The variable status contained in the expression is tracked through the variable relationship.

[0064] Among them, when multiple related code files are used as input, the compiler can uniformly parse their jump relationships; when multiple independent code modules are input, they can be parsed by multiple threads to improve parsing efficiency.

[0065] Step 1.2: Divide the blockchain source code into basic blocks according to the AST syntax tree.

[0066] A basic block is the basic unit of a blockchain control flow graph, representing an entire blockchain function required for execution in the control flow. A basic block usually consists of an entry point and multiple exit points, where the entry point is the first instruction or jump entry of the block, and the exit point is the last instruction or transfer instruction of the block. Therefore, this embodiment can divide the blockchain source code into basic blocks according to the AST syntax tree.

[0067] Step 1.3: Determine the control flow relationship between basic blocks based on the transfer statements in the blockchain source code.

[0068] This embodiment determines the control flow relationship between basic blocks according to the transfer statements (such as conditional statements, loop statements, jump statements, etc.) in the program.

[0069] Step 1.4: Generate a control flow graph based on the control flow relationship between basic blocks.

[0070] Draw a control flow graph based on the control flow relationship between basic blocks. A control flow graph usually uses nodes (representing basic blocks) and edges (representing control flow relationships) to represent the control flow of a program.

[0071] Step 1.5: Optimize and simplify the control flow graph to obtain a main control flow graph.

[0072] The generated control flow graph may be large and complex. By merging basic blocks, deleting redundant control flow paths, retaining control functions related to blockchain transaction submission and timing, and constructing the backbone control flow graph.

[0073] Step 2: Perform symbolic reasoning based on virtual input and output on the main control flow graph to generate execution status and execution trajectory.

[0074] In a preferred embodiment, the process of generating the execution status and the execution trajectory includes:

[0075] Step 2.1: Along the main control flow graph, an execution block obtains the state output by the previous execution block.

[0076] Since the edges of the control flow graph represent the control flow relationship between basic blocks, the state output by the previous execution block can enter the next execution block along the main control flow graph.

[0077] Step 2.2: Based on the obtained state, a virtual interpreter loop is executed within the execution block to output the corresponding state.

[0078] The virtual interpreter loop described in the present invention is to perform symbolic reasoning along the control flow to obtain a state before the execution block has no remaining state or reaches the manually defined timeout period, and simulate the execution of a single instruction using the symbolic execution method in the context of the state to obtain the next state. During the monitoring period, the loop will be executed until the execution block has no remaining state or reaches the manually defined timeout period.

[0079] Step 2.3: Based on the status of the output of this execution block, jump to the next execution block.

[0080] The program counter changes state depending on whether the condition is true or false. The state is checked to see if the branch condition can be proven to be true or false on the current path. If it can be determined, the program counter is updated with the corresponding target address. Otherwise, both branches are possible, and both paths are explored in a depth-first search manner, updating the program counter and path conditions one by one. More edges are added to the trunk control flow graph.

[0081] Step 2.4: After the last execution block is executed, a set of symbolic trace paths is generated.

[0082] At the end of the exploration phase, a set of symbolic traces is generated. Each trace is associated with path constraints and auxiliary data required for subsequent phase analysis. The auxiliary data includes variable data involved in the execution state.

[0083] Step 2.5: Use the constraint solver to eliminate the symbolic tracking paths that are proven to be infeasible and obtain the execution status and execution trajectory.

[0084] Step 3: Based on the execution status and execution trajectory, analyze the time-series related operations within and between execution blocks to identify the execution sequences with execution sequence vulnerabilities.

[0085] In the preferred technical solution provided by the present invention, step 3 comprises the following steps:

[0086] Step 3.1: Through the study of the public chain twin tree vulnerability, it is found that the code that causes the abnormal order of blockchain transactions generally has a feature, that is, the consistency of time is generally ignored during the verification process. Use a special symbolic variable to represent the block time information, including timestamps, random numbers, and hash values. For a traced path, we will check whether the entire path involves this symbolic variable. If any operation of an execution sequence depends on this symbolic variable, it will be marked as a time-related dependent execution. In addition, if the execution path involves the update operation of the chain, the entire execution sequence and the dependent function are also marked as time-related. Using this definition, we transform the question of whether there is a blockchain execution sequence vulnerability into a judgment question of whether there is a time dependency. Next, symbolic execution can be used to simulate the characteristics of each function, symbolize the parameters of the function, and explore all possible execution paths. Collect the judgment operations related to time information and construct an execution access graph for detection in step 3.2.

[0087] Step 3.2: Through the definition of time-related, the present invention excludes the influence of execution sequences that are not related to timing, but it does not mean that there must be execution sequence vulnerabilities in execution sequences that are time-dependent. The present invention needs to further analyze the conditions for the occurrence of blockchain execution timing vulnerabilities. Functions, which are the main carriers of chain code execution, are composed of execution statements, which are divided into types such as assignment, operation, condition, and loop. Among them, the conditional statement specifies the execution of the function by the blockchain in the form of if...else... when the judgment condition of the conditional statement is true or false. The loop statement limits the loop execution of the function statement in the form of while, etc., and the execution jumps out of the loop when the condition is met. For these statements that affect the execution of the function, the present invention refers to them as execution conditional statements, and the constraints specified by these statements are referred to as execution constraints in the present invention. Utilize execution constraints. When encountering each jump instruction, the present invention obtains the path condition before the jump is executed. Then, the present invention checks whether the condition is still established (i.e., whether the call can be executed again) when the sequence (such as storage sequence, time sequence) is updated. If so, it is believed that there may be an execution sequence vulnerability because there is an incorrect blockchain timing state. In order to characterize the impact of chain operation execution order on execution conditions, the present invention needs to first model the execution of transaction operations.<s,σ,π> , s=s 1 ,s 2 ,…,s nThe access graph is composed of the execution information contained in the function, including assignment, operation, judgment, loop and other information. σ is the state environment of the chain, including the variables involved in the transaction and the time variable sequence t (keep an odd number of elements) and other information. π is the restriction condition of the chain operation execution statement, indicating the constraints on the execution of the operation. Next, the last adjacent elements in the time variable sequence t are exchanged to obtain the variable sequence t 1 , copy the last element in the time variable sequence t and extend it to the end of the time variable sequence t to obtain the variable sequence t 2 , swap the end and any position element in the time variable sequence t to obtain the variable sequence t 3 During code execution, each time a statement is executed,<s,σ,π> Update σ, π, t accordingly 1 ,t 2 ,t 3 , and obtain the updated variable sequence t 1 ,t 2 ,t 3 All are input into the code block operation to obtain the state after execution. Determine whether the execution condition of the next statement is met in the state after execution, that is, whether the process can be re-executed normally under the error timing. If in the entire simulation process, t 1 ,t 2 ,t 3 If any execution sequence can be executed normally under the given conditions, then the execution sequence can be judged as a code block execution sequence that may have an execution sequence vulnerability.

[0088] Step 4: Inject abnormal timing data, analyze the simulation execution output, and eliminate false positives.

[0089] To further remove false positives, the validator builds a virtual environment based on the execution sequence of code blocks that may have execution sequence vulnerabilities, and uses simulated calls to verify whether the chaotic chain timing has an impact on the operation of the blockchain.

[0090] In the preferred technical solution provided by the present invention, the step 4 comprises the following steps:

[0091] Step 4.1: Inject the designed tag data with specific positive sorting characteristics into the blockchain execution sequence related functions to record the time-related sequence after the function is executed.

[0092] Step 4.2: Inject sequence data with reverse sorting features and record the time-related sequence after the function is executed.

[0093] Step 4.3: Compare the two injection situations before and after execution to see if there are any timing anomalies. If there are timing differences before and after execution, it means that there is an execution order anomaly vulnerability such as a twin tree.

[0094] Below Figure 2 The present invention is described by taking the twin tree vulnerability code in as an example.

[0095] Although the MT algorithm can prevent the tampering of transaction data, the existence of the sorting operation in the construction algorithm makes the protection of transaction order information ineffective, thus creating the possibility of tampering with the transaction order. The specific construction method of the attack is as follows: Figure 3 Due to the lack of timing protection for blockchain nodes, attackers can design the HASH of the last block D so that it is sorted before its previous node C during the MT verification process, thereby constructing the upper node HASH and achieving tree collision. In this case, attackers can swap the transaction order of the last two nodes of the blockchain, resulting in an execution order vulnerability, and continue to broadcast malicious blocks to the network. What's more, by constructing a whole group of new blocks, the positions of the two subtrees under any non-leaf node of MT can be swapped, that is, the overall order of the two groups of blocks can be directly swapped, and it can still pass the MT verification. Therefore, in theory, each block can construct many O(2n-1) collisions, and thus silently construct more blockchain forks.

[0096] Here, we still take the twin tree vulnerability as an example. Through code analysis and control flow generation, the present invention locates the basic block containing the following code:

[0097]

[0098] As you can see, the code contains the comparison, judgment and writing of hash values. According to the detection method described above, it is marked as a possible time-related operation. We simplify hashList into the symbol group t= <t 1 ,t 2 ,……,t m , t n >, where n is the length of the symbolic array, and tracks the control flow of the entire function to enter the reentrancy detection sequence. Next, read the reentrancy detection for further processing. To simplify the analysis process, we assume that execution s 1 For the first operation of the execution sequence entry, s i Corresponding to the first branch assignment operation, sj corresponds to the second branch assignment operation, and sk corresponds to the final boundary judgment operation. In this way, we get a simplified execution model s=s 1 ,…,s i ,…,s j ,…,s k ,…, and thus further obtain a<s,σ,π> , where σ contains a symbol group of t, and the entire sequence is executed in sequence. The specific construction and execution are as follows Figure 4 shown.

[0099] Next, construct t 1 = <t 1 ,t 2 ,……,t n ,t m >, t 2 = <t 1 ,t 2 ,……t m ,t n ,t n >, t 3 = <t 1 ,t n ,……,t m ,t 2 >, detect whether the code block can continue to execute, the specific construction and execution are as follows Figure 5 shown.

[0100] After symbolic execution analysis, it can be seen that the abnormal sequence t 1 , and t 2 In some cases, the symbolic execution path can be successfully passed, and it can be concluded that this function code block has an execution sequence vulnerability. After marking and entering the simulated call detection, the execution sequence vulnerability detection result can be output. It can be seen that this method can effectively detect the twin tree vulnerability.

[0101] Based on the same concept, the present invention also discloses a system for analyzing and identifying blockchain execution timing vulnerabilities, including:

[0102] A control flow graph construction module is used to construct a control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain a main control flow graph;

[0103] An execution symbolic reasoning module is used to perform symbolic reasoning based on virtual input and output on the main control flow chart to generate an execution state and an execution trajectory;

[0104] The execution sequence vulnerability identification module is used to analyze the time sequence related operations within and between execution blocks based on the execution state and the execution trajectory to identify the execution sequence with the execution sequence vulnerability.

[0105] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology in this field to understand the content of the present invention and implement it, and they cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made according to the spirit of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for analyzing and identifying blockchain execution timing vulnerabilities, characterized in that: The method comprises: Constructing a control flow graph of the blockchain source code, and optimizing and simplifying the control flow graph to obtain a main control flow graph; Performing symbolic reasoning based on virtual input and output on the main control flow graph to generate execution status and execution trajectory; Based on the execution state and the execution trace, time sequence related operations within and between execution blocks are analyzed to identify execution sequences with execution sequence vulnerabilities.

2. The method according to claim 1, characterized in that The control flow graph of constructing the blockchain source code includes: After extracting the statements in the blockchain source code, use the compiler to generate the AST syntax tree of the blockchain source code; Divide the blockchain source code into basic blocks according to the AST syntax tree; Determine the control flow relationship between basic blocks based on the transfer statements in the blockchain source code; A control flow graph is generated based on the control flow relationship between basic blocks.

3. The method according to claim 1, characterized in that The control flow graph is simplified, including: merging basic blocks, deleting redundant control flow paths, and retaining control functions related to blockchain transaction submission and timing.

4. The method according to claim 1, characterized in that: Performing symbolic reasoning based on virtual input and output on the main control flow chart to generate execution status and execution trajectory, including: Along the main control flow graph, an execution block obtains the state output by the previous execution block; Based on the acquired state, a virtual interpreter loop is executed in the execution block to output a corresponding state; wherein the virtual interpreter loop is to execute symbolic reasoning along the control flow to acquire a state before there is no remaining state in the execution block or a manually defined timeout is reached, and to simulate the execution of a single instruction using a symbolic execution method in the context of the state to obtain a next state; Based on the status of the output of this execution block, jump to the next execution block; After the last execution block is executed, a set of symbolic trace paths is generated; The constraint solver is used to eliminate the symbolic tracking paths that are proven to be infeasible, and the execution status and execution trajectory are obtained.

5. The method according to claim 4, characterized in that Based on the status of the output of this execution block, jump to the next execution block, including: Whether the branch condition can be proved on the current path through the state query, and whether the current path is true or false; wherein the current path is the path from the execution block to the next execution block; In the case where this current path is true, the program counter is updated to the corresponding target address; In the case that the current path is false, the two paths are explored in a depth-first search manner, and after updating the program counter and path conditions one by one, the corresponding edges are added to the main control flow graph.

6. The method according to claim 1, characterized in that Based on the execution state and the execution trajectory, time sequence related operations within and between execution blocks are analyzed to identify blockchain execution timing vulnerabilities, including: A symbol variable is used to represent block time information, wherein the block time information includes: a timestamp, a random number, and a hash value; The symbolic variable is used to execute the characteristics of each function of the simulation function, so as to symbolize the parameters of the function and then explore all possible execution paths based on the execution state and the execution trajectory; Collect all chain operation execution statements that depend on the symbolic variable during the exploration process to build an execution access graph, and generate a time variable sequence t based on the symbolic variable; Model the execution of transaction operations to obtain a transaction execution model<s,σ,π> ; where s=s1,s2,…,s n To execute the access graph, s n To execute the nth chain operation execution statement in the access graph, σ is the state environment of the chain, which includes the variables, variable relations and time variable sequence t involved in the transaction, and π is the restriction condition of the chain operation execution statement; Deform the time variable sequence t, and determine whether there is an execution sequence that is executed normally under the deformed time variable sequence; When an execution sequence is executed normally, the execution sequence is determined to be an execution sequence with an execution sequence vulnerability.

7. The method according to claim 6, characterized in that The deforming the time variable sequence t comprises: Exchange the last adjacent elements in the time variable sequence t to obtain the variable sequence t1; and, Copy the last element in the time variable sequence t and extend the last element to the end of the time variable sequence t to obtain the variable sequence t2; and, Exchange the last element and any position element in the time variable sequence t to obtain the variable sequence t3.

8. The method according to any one of claims 1 to 7, characterized in that: After analyzing the time sequence related operations within and between execution blocks based on the execution state and the execution trace to identify the execution sequence with the execution sequence vulnerability, the method further includes: Whether the execution sequence with the execution sequence vulnerability has an impact on the operation of the blockchain is verified to verify whether the execution sequence with the execution sequence vulnerability is a real execution sequence with the execution sequence vulnerability.

9. The method according to claim 8, characterized in that Whether the execution sequence with the execution sequence vulnerability has an impact on the operation of the blockchain, verify whether the execution sequence with the execution sequence vulnerability is a real execution sequence with the execution sequence vulnerability, including: Based on the execution sequence with the execution sequence vulnerability, a virtual environment is constructed; In the virtual environment, sequence data with specific forward sorting characteristics and sequence data with specific reverse sorting characteristics are respectively injected into the blockchain execution sequence-related functions, and the time-related sequence after the function is executed is recorded; If there is a difference in the time-related sequence after the function is executed, it is determined that the execution sequence with the execution sequence vulnerability is the execution sequence that actually has the execution sequence vulnerability.

10. A system for analyzing and identifying blockchain execution timing vulnerabilities, characterized in that: The system comprises: A control flow graph construction module is used to construct a control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain a main control flow graph; An execution symbolic reasoning module is used to perform symbolic reasoning based on virtual input and output on the main control flow chart to generate an execution state and an execution trajectory; The execution sequence vulnerability identification module is used to analyze the time sequence related operations within and between execution blocks based on the execution state and the execution trajectory to identify the execution sequence with the execution sequence vulnerability.

Citation Information

Patent Citations

  • Method and interpretation device for analyzing and executing program language

    CN103077064A

  • Method and system for detecting SQL injection vulnerabilities of power information system

    CN111064735A

  • Block chain intelligent contract threat detection device and method

    CN115022026A

  • Intelligent contract Pincer cheating detection method and system based on control flow graph reduction

    CN116452222A

  • Smart terminal device for obtaining medical infomration including hearing

    KR102782322B1