A method and system for analyzing and identifying blockchain execution timing vulnerabilities
By constructing the control flow graph and symbolic reasoning of the blockchain source code, timing vulnerabilities in the execution sequence are identified and analyzed, solving the problem of difficulty in detecting twin tree vulnerabilities in existing technologies and achieving security assurance for the blockchain system.
Patent Information
- Application Number
- CN202411333823.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-09-24
AI Technical Summary
Existing blockchain systems struggle to effectively detect and identify twin tree vulnerabilities, which threaten the security of the blockchain by modifying the order of transaction execution and are difficult to detect using dynamic analysis methods.
The control flow graph of the blockchain source code is constructed, optimized and simplified, and a main control flow graph is generated. Then, execution states and trajectories are generated through symbolic reasoning, time-series related operations are analyzed, and vulnerabilities in the execution sequence are identified.
By deeply analyzing the source code and simulating the execution environment, the system can identify potential timing vulnerabilities, generate detailed vulnerability reports, help developers respond quickly and fix problems, and ensure the security of the blockchain system.
Smart Images

Figure CN119397540B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of blockchain technology and proposes a method and system for analyzing and identifying blockchain execution timing vulnerabilities. Background Technology
[0002] Due to its excellent decentralized characteristics and trust-building mechanisms, blockchain has been widely applied in finance, the Internet of Things, energy, healthcare, and supply chain fields. The immutability of the blockchain forms the cornerstone of its trust, making it highly vulnerable to attacks such as double-spending and 51% attacks that compromise data security. These attacks can cause significant losses to users and severely damage the credibility of the blockchain system. To ensure data security, existing blockchain systems generally employ a series of verification mechanisms, such as Merkle Trees, which use binary hash trees to protect transaction information and provide low-cost verification capabilities.
[0003] While blockchains are designed with security in mind, they are not entirely invincible. The MTCopy vulnerability reveals that by exploiting a Merkle Tree validation flaw, attackers can achieve a 51% attack at extremely low cost, directly threatening blockchain security. To eliminate such inherent risks, researchers and developers rely on existing static and dynamic analysis techniques to discover potential chaincode security issues. However, the limitations of these methods become particularly apparent when faced with novel twin-tree vulnerabilities. Twin-tree vulnerabilities exploit specially designed blocks to modify the transaction execution order in the blockchain, thereby tampering with the chain. Because this attack does not affect consensus or produce any execution anomalies, it is difficult to detect using dynamic analysis methods, while static analysis methods struggle to effectively define security patterns, leading to numerous false positives and false negatives. Summary of the Invention
[0004] To overcome the problems mentioned above, this invention provides a method and system for analyzing and identifying blockchain execution timing vulnerabilities, analyzing potential inherent security risks in blockchain, and effectively protecting the property security of users on the blockchain.
[0005] To achieve the above objectives, the technical solution of the present invention includes the following contents.
[0006] A method for analyzing and identifying execution timing vulnerabilities in blockchain, the method comprising:
[0007] Construct the control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain the main control flow graph;
[0008] Symbolic reasoning is performed on the main control flowchart based on virtual inputs and outputs to generate execution states and execution trajectories;
[0009] Based on the execution state and the execution trajectory, analyze the time-series related operations within and between execution blocks to identify execution sequences with execution sequence vulnerabilities.
[0010] Furthermore, the control flow graph for constructing the blockchain source code includes:
[0011] After extracting statements from the blockchain source code, a compiler is used to generate the AST syntax tree of the blockchain source code.
[0012] The blockchain source code is divided into basic blocks according to the AST syntax tree;
[0013] Based on the transfer statements in the blockchain source code, determine the control flow relationship between basic blocks;
[0014] A control flow graph is generated based on the control flow relationships between basic blocks.
[0015] Furthermore, the control flow graph is simplified by merging basic blocks, removing 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 inputs and outputs to generate execution states and execution trajectories, 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 within the execution block to output the corresponding state; wherein, the virtual interpreter loop is performed by performing symbolic reasoning along the control flow to acquire a state before the execution block has no remaining state or reaches a manually defined timeout, and then using symbolic execution methods to simulate the execution of a single instruction in the context of that state to obtain the next state;
[0019] Based on the state output by this execution block, jump to the next execution block;
[0020] After the last execution block has finished executing, a set of symbolic trace paths is generated;
[0021] The constraint solver is used to exclude symbolic tracing paths that have been proven infeasible, thus obtaining the execution state and execution trajectory.
[0022] Furthermore, based on the state output by this execution block, the program jumps to the next execution block, including:
[0023] The status query branch condition is used to determine whether the current path is true or false by checking whether it can be proven on the current path; where the current path is the path from the current execution block to the next execution block.
[0024] If the current path is true, the program counter will be updated to the corresponding target address;
[0025] If the current path is false, explore the two paths using a depth-first search, update the program counter and path conditions one by one, and then add the corresponding edges to the main control flow graph.
[0026] Furthermore, based on the execution state and the execution trajectory, time-series related operations within and between execution blocks are analyzed to identify blockchain execution timing vulnerabilities, including:
[0027] A symbolic variable is used to represent the block time information, which includes: timestamp, random number, and hash value;
[0028] By utilizing the characteristics of each function in the simulation function to symbolize the function parameters, all possible execution paths are explored based on the execution state and the execution trajectory.
[0029] Collect all chain operation execution statements that depend on this symbolic variable during the exploration process to construct an execution access graph, and generate a time variable sequence t based on this symbolic variable;
[0030] The execution of trading operations is modeled to obtain a trading execution model.<s,σ,π> Where s = s1, s2, ..., s n To perform the access graph, s n To execute the operation statement for the nth chain in the access graph, σ is the state environment of the chain, which includes the variables involved in the transaction, the relationships between variables, and the time variable sequence t, and π is the constraint condition for the chain operation execution statement;
[0031] The time variable sequence t is transformed, and it is determined whether there is an execution sequence that executes normally under the transformed time variable sequence;
[0032] If an execution sequence executes normally, it is determined that the execution sequence contains an execution sequence vulnerability.
[0033] Furthermore, the transformation of the time variable sequence t includes:
[0034] Swap the last adjacent elements in the time variable sequence t to obtain the variable sequence t1;
[0035] and,
[0036] Copy the last element of the time variable sequence t and extend that last element to the end of the time variable sequence t to obtain the variable sequence t2;
[0037] and,
[0038] Swapping the last element of the time variable sequence t with any element at any position yields the variable sequence t3.
[0039] Furthermore, based on the execution state and the execution trajectory, after analyzing the time-series related operations within and between execution blocks to identify execution sequences with execution sequence vulnerabilities, the process further includes:
[0040] The determination of whether the execution sequence with the execution order vulnerability affects the operation of the blockchain is verified to determine whether the execution sequence with the execution order vulnerability is a genuine execution sequence with an execution order vulnerability.
[0041] Furthermore, to verify whether the execution sequence with the execution order vulnerability truly has an execution order vulnerability, we will examine whether it affects the operation of the blockchain. This includes:
[0042] A virtual environment is constructed based on an execution sequence containing an execution order vulnerability;
[0043] In the virtual environment, sequence data with specific forward sorting characteristics and sequence data with specific reverse sorting characteristics are injected into the blockchain execution sequence correlation function, and the time correlation sequence after the function execution is recorded.
[0044] If there are differences in the time-related sequences after function execution, then the execution sequence with the execution order vulnerability is determined to be the execution sequence with the actual execution order vulnerability.
[0045] A system for analyzing and identifying execution timing vulnerabilities in blockchain, the system comprising:
[0046] The control flow graph construction module is used to construct the control flow graph of the blockchain source code, and to optimize and simplify the control flow graph to obtain the main control flow graph;
[0047] The execution symbolic reasoning module is used to perform symbolic reasoning based on virtual inputs and outputs on the main control flow diagram, and generate execution states and execution trajectories;
[0048] The execution sequence vulnerability identification module is used to analyze the time-series related operations within and between execution blocks based on the execution state and the execution trajectory, so as to identify execution sequences with execution sequence vulnerabilities.
[0049] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0050] This invention focuses on the underlying implementation and operational characteristics of blockchain systems. Through in-depth analysis of source code and simulated execution environments, it reveals and identifies potential timing vulnerabilities. This invention demonstrates its unique value through several core aspects: the in-depth source code analysis process ensures a deep understanding of the blockchain's internal workings, laying a solid foundation for subsequent timing analysis; based on the source code analysis results, the system constructs a control flow diagram (CFG) for the blockchain program, and further builds a timing model on this basis. This model details the execution order and dependencies between different parts of the program, especially time-sensitive operations and conditional judgments; to verify the accuracy of the timing model and identify potential vulnerabilities, the system employs an efficient simulated execution mechanism. In the simulation environment, the system can simulate the actual operation of the blockchain, recording and analyzing the state changes and execution trajectories of each execution unit. By comparing the expected state with the actual state, the system can quickly locate timing anomalies or potential vulnerabilities, 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 a vulnerability description, scope of impact, potential risks, and suggested remediation measures, helping developers respond quickly and fix problems. Attached Figure Description
[0051] Figure 1 A flowchart illustrating the analysis and identification methods for timing vulnerabilities in blockchain execution.
[0052] Figure 2 This is a sequence code pattern diagram for execution.
[0053] Figure 3 This is a schematic diagram of a twin tree vulnerability.
[0054] Figure 4 The flowchart for normal execution sequence detection.
[0055] Figure 5 This is a flowchart for detecting abnormal execution sequences. Detailed Implementation
[0056] The present invention will be further described in detail below with reference to specific embodiments. The embodiments given are only for illustrating the present invention and are not intended to limit the scope of the present invention.
[0057] This invention analyzes twin tree vulnerabilities to discover their key characteristic: time consistency, a feature often overlooked during verification. By leveraging the time dependencies in the code, numerous redundant paths can be eliminated. The state of a transaction profoundly impacts the execution condition statements; different chain states will direct execution along different paths, meaning different execution orders result in different transaction chain states, affecting the fulfillment of transaction execution conditions. Starting from the function's execution conditions, the detection scope of execution order vulnerabilities is further narrowed. Through dynamic injection and execution order comparison, the existence of blockchain execution order vulnerabilities, exemplified by twin tree vulnerabilities, can be confirmed.
[0058] Specifically, such as Figure 1 As shown, the present invention provides the following technical solution:
[0059] Step 1: Construct 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] This invention first constructs an AST syntax tree of the blockchain source code, then automatically analyzes the execution sequence of the code through a syntax analyzer, uses formal methods to perform automated static analysis of the blockchain source code, automatically separates the blockchain execution code blocks, then collects the program structure, statements and control flow relationships to generate a control flow graph, and finally optimizes and simplifies the control flow graph to obtain the main control flow graph.
[0061] In a preferred embodiment, the process of generating the backbone control flow graph includes:
[0062] Step 1.1: After extracting the statements from the blockchain source code, use a compiler to generate the AST syntax tree of the blockchain source code.
[0063] Users input the source code of the blockchain system. Based on the syntax rules of the source code, a syntax analyzer is used to extract information such as statements from the blockchain source code. A compiler is then used to generate an abstract syntax tree (AST) of the code, from which expressions are obtained. The state of variables contained in these expressions is tracked through variable relationships.
[0064] When multiple related code files are 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 fundamental unit of the blockchain control flow graph, representing an entire blockchain function required for execution within the control flow. A basic block typically consists of one entry point and multiple exit points, where the entry point is the first instruction or jump entry point of the block, and the exit points are the last instruction or transfer instruction of the block. Therefore, this embodiment can divide the blockchain source code into basic blocks based on 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 based on 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 relationships between basic blocks.
[0070] Draw a control flow graph based on the control flow relationships between basic blocks. Control flow graphs typically use 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 the main control flow graph.
[0072] The generated control flow graph may be large and complex. By merging basic blocks, removing redundant control flow paths, and retaining control functions related to blockchain transaction submission and timing, a main control flow graph is constructed.
[0073] Step 2: Perform symbolic reasoning based on virtual inputs and outputs on the main control flow diagram to generate execution states and execution trajectories.
[0074] In a preferred embodiment, the process of generating the execution state and 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 relationships between basic blocks, the state output by the previous execution block can be carried into the next execution block along the main control flow graph.
[0077] Step 2.2: Based on the acquired state, execute a virtual interpreter loop within the execution block to output the corresponding state.
[0078] The virtual interpreter loop described in this invention involves performing symbolic reasoning along the control flow to obtain a state before the execution block has no remaining state or before a manually defined timeout is reached. Within the context of that state, a single instruction is simulated using symbolic execution methods to obtain the next state. This loop continues to execute during monitoring until the execution block has no remaining state or the manually defined timeout is reached.
[0079] Step 2.3: Based on the status output of this execution block, jump to the next execution block.
[0080] The program counter changes the state based on whether a condition is true or false. The state queries whether the branch condition can be proven true or false on the current path. If it can, the program counter is updated to the corresponding target address. Otherwise, both branches are possible, and both paths are explored using a depth-first search, updating the program counter and path conditions one by one. More edges are added to the main control flow graph.
[0081] Step 2.4: After the last execution block has finished executing, generate a set of symbolic trace paths.
[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. This auxiliary data includes variable data involved in the execution state.
[0083] Step 2.5: Use the constraint solver to exclude symbolic tracing paths that have been proven 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 execution sequences with execution sequence vulnerabilities.
[0085] In the preferred embodiment of the present invention, step 3 includes the following steps:
[0086] Step 3.1: Research on public blockchain twin tree vulnerabilities revealed that code leading to abnormal blockchain transaction order generally shares a common characteristic: the neglect of time consistency during verification. A special symbolic variable is used to represent block time information, including timestamps, random numbers, and hash values. For a traced path, we check whether the entire path involves this symbolic variable. If any operation in an execution sequence depends on this symbolic variable, it is marked as a time-dependent execution. Furthermore, if the execution path involves chain update operations, the entire execution sequence and its dependent functions are also marked as time-dependent. Using this definition, we transform the question of whether a blockchain execution order vulnerability exists into a question of whether a time dependency exists. Next, symbolic execution can be used to simulate the characteristics of each function, symbolizing the function parameters and exploring all possible execution paths. Time-related judgment operations are collected, and an execution access graph is constructed for use in Step 3.2.
[0087] Step 3.2: By defining time-related factors, this invention eliminates the influence of execution sequences unrelated to time order. However, this does not mean that execution sequence vulnerabilities necessarily exist in time-dependent execution sequences. This invention needs to further analyze the conditions under which blockchain execution time order vulnerabilities occur. Functions, as the main carriers of chain code execution, are composed of execution statements, which are categorized into assignment, operation, condition, and loop types. Conditional statements, using the if...else... form, specify the execution of functions in the blockchain when the condition is true or false. Loop statements, using forms like while, restrict the loop execution of function statements, exiting the loop when the condition is met. These statements that affect function execution are referred to as execution condition statements, and the constraints they specify are referred to as execution constraints. Utilizing execution constraints, upon encountering each jump instruction, this invention obtains the path conditions before the jump. Then, this invention checks whether the condition still holds after the sequence (e.g., storage sequence, time sequence) has been updated (i.e., whether the call can be executed again). If so, it is considered that an execution order vulnerability may exist because there is an incorrect blockchain time order state. To characterize the impact of the chain operation execution order on execution conditions, this invention first needs to model the execution of transaction operations.<s,σ,π> s = s1, s2, ..., s nThe access graph is composed of the execution information contained in the function, including assignment, operation, judgment, loop, etc. σ represents the state environment of the chain, including the variables involved in the transaction and the time variable sequence t (keeping an odd number of elements). π represents the constraints on the execution of the chain's operations, indicating the constraints on the execution of the operations. Next, the last adjacent elements in the time variable sequence t are swapped to obtain the variable sequence t1. The last element in the time variable sequence t is copied and extended to the end of the time variable sequence t to obtain the variable sequence t2. The last element in the time variable sequence t is swapped with any element at any position to obtain the variable sequence t3. During code execution, each statement is executed...<s,σ,π> Accordingly, update σ, π, t1, t2, and t3, and input the updated variable sequences t1, t2, and t3 into the code block operation to obtain the executed state. Determine whether the execution condition of the next statement is met under this executed state, i.e., whether the process can be re-executed normally under an incorrect timing. If any execution sequence under conditions t1, t2, and t3 can be executed normally during the entire simulation, then this execution sequence can be identified as a code block execution sequence that may have an execution order vulnerability.
[0088] Step 4: Inject abnormal timing data, analyze the simulated execution output, and eliminate false alarms.
[0089] To further eliminate false positives, the validator constructs a virtual environment based on the execution sequence of code blocks that may have execution order vulnerabilities, and uses simulated calls to verify whether disordered chain timing affects the operation of the blockchain.
[0090] In the preferred embodiment of the present invention, step 4 includes the following steps:
[0091] Step 4.1: Inject designed labeled data with specific positive sorting characteristics into the blockchain execution order correlation function, and record the time correlation sequence after the function execution.
[0092] Step 4.2: Inject the sequence data with reverse sorting features and record the time-related sequence after the function execution.
[0093] Step 4.3: Compare whether there are timing anomalies before and after the execution of the two injection scenarios. If there are timing differences before and after execution, it indicates that there are execution order anomaly vulnerabilities such as twin trees.
[0094] The following is based on Figure 2 The invention will be explained using the twin tree vulnerability code as an example.
[0095] While the MT algorithm can prevent transaction data tampering, the sorting operation in its construction weakens the protection of transaction order information, thus creating the possibility of tampering with the transaction order. The specific construction method of the attack is as follows: Figure 3 Because of the lack of time-order protection for blockchain nodes, attackers can design the hash of the last block D, ensuring it is ordered before its predecessor C during the MT verification process. This allows them to construct the hash of higher-level nodes, resulting in tree collisions. In this scenario, attackers can swap the transaction order of the last two nodes in the blockchain, creating an execution order vulnerability and continuing to broadcast malicious blocks to the network. Even worse, by constructing a new set of blocks, attackers can swap the positions of the two subtrees under any non-leaf node of the MT, effectively swapping the overall order of the two sets of blocks. This still passes the MT verification, theoretically allowing each block to generate many O(2n-1) collisions, thus silently creating more blockchain forks.
[0096] Using the twin tree vulnerability as an example again, this invention, through code analysis and control flow generation, located a basic block containing the following code:
[0097]
[0098] As you can see, the code includes comparison, judgment, and writing of hash values. Based on the detection method described earlier, we mark it as a potentially time-related operation. We simplify the hashList to a symbol group t = <t1,t2,……,t m , t n > where n is the length of the symbolic array, and the control flow of the entire function is traced to input the reentrancy detection sequence. Next, the reentrancy detection is read in for further processing. To simplify the analysis process, we assume that executing s1 corresponds to executing the first operation of the sequence entry, s i The first branch assignment operation corresponds to sj, the second branch assignment operation corresponds to sj, and the final boundary check operation corresponds to sk. Thus, we obtain a simplified execution model: s = s1, ..., sj. i ,…,s j ,…,s k ..., thus further obtaining a<s,σ,π> σ contains a group of symbols for t, and the entire sequence is executed sequentially. The specific construction and execution are as follows: Figure 4 As shown.
[0099] Next, construct t1 = <t1,t2,……,t n ,t m >,t2= <t1,t2,……t m ,t n ,t n >,t3= <t1,t n ,……,t m ,t2>, checks whether the code block can continue execution; its specific construction and execution are as follows: Figure 5 As shown.
[0100] Symbolic execution analysis reveals that abnormal sequences t1 and t2 can successfully navigate the symbolic execution path in some cases, indicating an execution order vulnerability in this function block. After marking and entering simulated call detection, the execution order vulnerability detection result can be output. This demonstrates that this method can effectively detect twin tree vulnerabilities.
[0101] Based on the same concept, this invention also discloses an analysis and identification system for blockchain execution timing vulnerabilities, comprising:
[0102] The control flow graph construction module is used to construct the control flow graph of the blockchain source code, and to optimize and simplify the control flow graph to obtain the main control flow graph;
[0103] The execution symbolic reasoning module is used to perform symbolic reasoning based on virtual inputs and outputs on the main control flow diagram, and generate execution states and execution trajectories;
[0104] The execution sequence vulnerability identification module is used to analyze the time-series related operations within and between execution blocks based on the execution state and the execution trajectory, so as to identify execution sequences with execution sequence vulnerabilities.
[0105] The above embodiments are only for illustrating the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand and implement the present invention. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for analyzing and identifying execution timing vulnerabilities in blockchain, characterized in that, The method includes: Construct the control flow graph of the blockchain source code, and optimize and simplify the control flow graph to obtain the main control flow graph; Symbolic reasoning is performed on the main control flowchart based on virtual inputs and outputs to generate execution states and execution trajectories; Based on the execution state and the execution trajectory, analyze the time-series related operations within and between execution blocks to identify execution sequences with execution sequence vulnerabilities.
2. The method according to claim 1, characterized in that, The control flow graph for constructing the blockchain source code includes: After extracting statements from the blockchain source code, a compiler is used to generate the AST syntax tree of the blockchain source code. The blockchain source code is divided into basic blocks according to the AST syntax tree; Based on the transfer statements in the blockchain source code, determine the control flow relationship between basic blocks; A control flow graph is generated based on the control flow relationships between basic blocks.
3. The method according to claim 1, characterized in that, The control flow graph is simplified by merging basic blocks, removing 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, Symbolic reasoning is performed on the main control flowchart based on virtual inputs and outputs to generate execution states and execution trajectories, 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 within the execution block to output the corresponding state; wherein, the virtual interpreter loop is performed by performing symbolic reasoning along the control flow to acquire a state before the execution block has no remaining state or reaches a manually defined timeout, and then using symbolic execution methods to simulate the execution of a single instruction in the context of that state to obtain the next state; Based on the state output by this execution block, jump to the next execution block; After the last execution block has finished executing, a set of symbolic trace paths is generated; The constraint solver is used to exclude symbolic tracing paths that have been proven infeasible, thus obtaining the execution state and execution trajectory.
5. The method according to claim 4, characterized in that, Based on the state output by this execution block, jump to the next execution block, including: The status query branch condition is used to determine whether the current path is true or false by checking whether it can be proven on the current path; where the current path is the path from the current execution block to the next execution block. If the current path is true, the program counter will be updated to the corresponding target address; If the current path is false, explore the two paths using a depth-first search, update the program counter and path conditions one by one, and then add the corresponding edges 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, analyze the time-series related operations within and between execution blocks to identify blockchain execution timing vulnerabilities, including: A symbolic variable is used to represent the block time information, which includes: timestamp, random number, and hash value; By utilizing the characteristics of each function in the simulation function to symbolize the function parameters, all possible execution paths are explored based on the execution state and the execution trajectory. Collect all chain operation execution statements that depend on this symbolic variable during the exploration process to construct an execution access graph, and generate a time variable sequence t based on this symbolic variable; The execution of trading operations is modeled to obtain a trading execution model.<s,σ,π> Where s = s1, s2, ..., s n To perform the access graph, s n To execute the operation statement for the nth chain in the access graph, σ is the state environment of the chain, which includes the variables involved in the transaction, the relationships between variables, and the time variable sequence t, and π is the constraint condition for the chain operation execution statement; The time variable sequence t is transformed, and it is determined whether there is an execution sequence that executes normally under the transformed time variable sequence; If an execution sequence executes normally, it is determined that the execution sequence contains an execution sequence vulnerability.
7. The method according to claim 6, characterized in that, The transformation of the time variable sequence t includes: Swap the last adjacent elements in the time variable sequence t to obtain the variable sequence t1; and, Copy the last element of the time variable sequence t and extend that last element to the end of the time variable sequence t to obtain the variable sequence t2; and, Swapping the last element of the time variable sequence t with any element at any position yields the variable sequence t3.
8. The method according to any one of claims 1 to 7, characterized in that, Based on the execution state and the execution trajectory, after analyzing the time-series related operations within and between execution blocks to identify execution sequences with execution sequence vulnerabilities, the process further includes: The determination of whether the execution sequence with the execution order vulnerability affects the operation of the blockchain is verified to determine whether the execution sequence with the execution order vulnerability is a genuine execution sequence with an execution order vulnerability.
9. The method according to claim 8, characterized in that, To verify whether the execution sequence with the execution order vulnerability truly has an execution order vulnerability, we need to determine whether it affects the operation of the blockchain. This includes: A virtual environment is constructed based on an execution sequence containing an execution order vulnerability; In the virtual environment, sequence data with specific forward sorting characteristics and sequence data with specific reverse sorting characteristics are injected into the blockchain execution sequence correlation function, and the time correlation sequence after the function execution is recorded. If there are differences in the time-related sequences after function execution, then the execution sequence with the execution order vulnerability is determined to be the execution sequence with the actual execution order vulnerability.
10. A system for analyzing and identifying execution timing vulnerabilities in blockchain, characterized in that, The system includes: The control flow graph construction module is used to construct the control flow graph of the blockchain source code, and to optimize and simplify the control flow graph to obtain the main control flow graph; The execution symbolic reasoning module is used to perform symbolic reasoning based on virtual inputs and outputs on the main control flow diagram, and generate execution states and execution trajectories; The execution sequence vulnerability identification module is used to analyze the time-series related operations within and between execution blocks based on the execution state and the execution trajectory, so as to identify execution sequences with execution sequence vulnerabilities.
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