A method and system for automatically formalizing verification of business properties of smart contracts

By constructing a control flow graph at the intermediate language layer of smart contracts and utilizing data flow analysis and abstract predicate techniques, the problems of high coverage and high accuracy in the formal verification of smart contracts in existing technologies are solved. This enables effective verification of high-level business attributes of contracts, reduces false positives, and improves the accuracy of verification.

CN116432245BActive Publication Date: 2026-07-21成都链安科技有限公司
View PDF 6 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
成都链安科技有限公司
Filing Date
2023-02-20
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing formal verification technologies for smart contracts cannot achieve high-coverage program path detection, nor can they obtain high-precision code defect detection results within a reasonable time. They also cannot effectively describe and verify the high-level business logic attributes of contracts, leading to an increased possibility of false positives.

Method used

A program control flow graph is constructed in an intermediate language layer close to the source code. Data flow analysis techniques are used to extract function constraints related to business attributes. Logical verification is performed through abstract predicates and fixed-point iterative algorithms, and a finite state machine is generated to check contract attributes.

Benefits of technology

It improves the verification capabilities of the symbolic constraint verification engine, reduces false alarms, supports efficient and accurate contract logic verification, and can describe complex business attribute specifications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116432245B_ABST
    Figure CN116432245B_ABST
Patent Text Reader

Abstract

The application discloses a method and system for automatically formalizing verification of business attributes of smart contracts, and relates to the technical field of blockchains.The technical scheme is as follows:an abstract syntax tree of a smart contract source code is generated;the abstract syntax tree of the smart contract source code is converted into intermediate language code;an appropriate control flow graph is constructed according to the intermediate language code, and a dependency relationship table is generated;time sequence logic attributes of target attributes are converted into semantically equivalent state reachable logic attributes;the state reachable logic attributes are used as pre-assumption conditions and post-verification conditions of each function constraint;the satisfiability of the state reachable logic attributes is solved for function constraints in a logic formula;and public functions that do not satisfy the state reachable logic attributes are subjected to abstract behavior verification.The application solves the problem of the limitation of the solving capacity of a symbolic solver by function constraints constructed by a symbolic execution virtual machine based on a bytecode or other underlying language, and improves the verification capacity of a symbolic constraint verification engine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain technology, and more specifically, to a method and system for automatically and formally verifying the business attributes of smart contracts. Background Technology

[0002] Due to the immutable nature of blockchain, any design flaws leading to attacks on smart contracts could result in irreversible and significant losses. Considering that smart contracts typically have relatively small codebases and fewer computationally intensive operations, such as nonlinear formula calculations, existing technologies often leverage the advantage of formal verification methods, which can fully cover the program path. These methods are used to verify the logical functionality and security attributes of smart contracts, identifying and promptly fixing flawed code to prevent future problems. As blockchain technology is increasingly industrialized in fields such as finance and government, the business logic of blockchain smart contracts is becoming more diversified and complex. To meet business demands, smart contracts need to implement more complex logic and perform a large number of computationally intensive operations.

[0003] Existing formal verification technologies for smart contracts are typically based on simple incremental exploration strategies, such as the breadth-and-depth search algorithms used in Chinese patents (CN108985073B, CN109063477B, CN108536445B, CN112286828B). These technologies utilize symbolic execution virtual machines (VMs) to extract and solve constraint expressions for program paths. However, the variable types of constraint expressions extracted from these VMs are usually consistent with the specific smart contract execution VM, typically the underlying bytecode VM. For example, bit vectors may be used to represent different machine integer types, or more complex bytecode expressions may be used to represent an equivalent source code logic. These characteristics from the underlying symbolic VM greatly limit the solving capabilities of symbolic solvers, preventing formal verification engines from achieving high program path coverage. Ultimately, this makes it difficult or impossible to obtain high-precision code defect detection results within a reasonable timeframe. Furthermore, existing formal verification systems for smart contracts lack sufficient support for describing and verifying high-level business logic. Specifically, in terms of formal description, they cannot use highly expressive logic languages ​​such as sequential logic to concisely and clearly describe business attribute specifications. In terms of formal verification, they are limited to the logical details of a single function and cannot automatically model and verify the high-level business attribute specifications of the entire contract logic at a reasonable and effective level of abstraction. The excessive approximation of single functions may lead to false alarms, increasing the burden on smart contract security analysis and auditing personnel.

[0004] Therefore, how to research and design a method and system for automatically formally verifying the business attributes of smart contracts that can overcome the above-mentioned defects is a problem that we urgently need to solve. Summary of the Invention

[0005] To address the shortcomings of existing technologies, the present invention aims to provide a method and system for automatically formally verifying the business attributes of smart contracts. This method constructs a program control flow graph at an intermediate language layer close to the source code and effectively extracts function constraints related to business attributes using data flow analysis techniques. This effectively solves the problem of function constraints built by existing symbolic execution virtual machines based on low-level languages ​​such as bytecode limiting the solution capabilities of symbolic solvers, thereby improving the verification capabilities of symbolic constraint verification engines.

[0006] The above-mentioned technical objective of the present invention is achieved through the following technical solution:

[0007] Firstly, a method for automatically and formally verifying the business attributes of smart contracts is provided, including the following steps:

[0008] Parse each attribute in the business attribute specification document corresponding to the smart contract, and embed the attributes into the smart contract source code in the form of smart contract language comments to generate a smart contract source code abstract syntax tree containing attribute specifications;

[0009] Transform the abstract syntax tree of smart contract source code into intermediate language code that can be analyzed.

[0010] Based on the intermediate language code, construct the corresponding control flow graph, generate a dependency table between contract state variables and public functions other than constructors, and filter out public functions that are irrelevant to the state variables of the selected target attribute to obtain a set of public functions;

[0011] Transform the temporal logical attributes of the selected target attributes into semantically equivalent state-reachable logical attributes;

[0012] Find functions without generated constraints based on the public function set, generate function constraints for the corresponding functions based on the control flow graph of the intermediate language code, and after all public functions that need to be modeled have generated function constraints, use the state reachability logical attributes as the pre-assumptions and post-verification conditions for each function constraint to form a logical formula.

[0013] Solve the satisfiability constraints of the state reachability logical attributes for the function constraints in the logical formula, and output the first result of the smart contract satisfying the target attribute when the state reachability logical attributes are satisfied in any path of all public functions in the public function set.

[0014] Perform abstract behavior verification on public functions that do not satisfy the state reachability logical property, and generate counterexamples that violate the property when the abstract behavior verification fails to satisfy the state reachability logical property.

[0015] The first result, the second result verified through abstract behavior, and the counterexamples are organized into a verification result and then output.

[0016] Furthermore, the business attribute specification document corresponding to the smart contract is written in a temporal logic language and is used to describe the high-level business logic related to the smart contract state variables.

[0017] Furthermore, the process of performing abstract behavior verification on public functions that do not satisfy the state reachability logical property is specifically as follows:

[0018] Abstract predicates are generated by extraction to form an abstract predicate domain;

[0019] A finite state machine for the abstract predicate domain is generated using a fixed-point iterative algorithm.

[0020] On the fixed-point abstract state machine, check whether the target business attribute is satisfied. If it is satisfied, output the target business attribute to the verification result document generator through a verification message, and then return to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified. If it is not satisfied, generate a counterexample of the violated attribute. The counterexample includes the function call sequence and the specific parameter values.

[0021] Furthermore, the process of extracting and generating abstract predicates specifically involves:

[0022] A. Receive the reachable logical attributes of the business attribute classifier and extract logical predicates from the reachable logical attributes;

[0023] B. Receive the function constraints generated by the function constraint generator, and extract logical predicates containing only contract state variables and constants from the function constraints;

[0024] C. When the predicate domain formed by A and B cannot infer the target business attributes, the predicate information that cannot be inferred will be fed back to the user, and the user can add logical predicates according to the verification requirements.

[0025] Furthermore, the process of generating a finite state machine about the abstract predicate domain using the fixed-point iterative algorithm is specifically as follows:

[0026] Based on the initial values ​​of the smart contract state variables, select all satisfiable states from the abstract predicate domain as initial abstract reachable states and add them to the initially defined set of abstract reachable states;

[0027] Entering the outer loop, the outer loop terminates when no new elements are added to the abstract reachable state set;

[0028] Within the outer loop: First, select a new reachable state, then enter the inner loop. The inner loop terminates when all paths of all functions have been traversed.

[0029] Within the inner loop: the satisfiability of the preconditions for the function path obtained by the current traversal is solved. If there is no solution, the next inner loop is entered; if there is a solution, the state logic relationship before and after the execution of the function path is extracted, and then the specific symbolic relationship is mapped to the abstract domain and abstract predicate domain through the satisfiability constraint solution to obtain a reachable abstract state of the path function path, which is added to the abstract reachable state set and the next inner loop iteration is entered.

[0030] Furthermore, the counterexamples include function call sequences and parameter values.

[0031] Secondly, a system for automatically and formally verifying the business attributes of smart contracts is provided, including:

[0032] The source code modeler is used to parse each attribute in the business attribute specification document corresponding to the smart contract, and embed the attributes into the smart contract source code in the form of smart contract language comments, generating a smart contract source code abstract syntax tree containing attribute specifications.

[0033] Intermediate language generator is used to transform the abstract syntax tree of smart contract source code into intermediate language code that can be analyzed.

[0034] The data flow analyzer is used to construct the corresponding control flow graph based on the intermediate language code, generate a dependency table between contract state variables and public functions other than constructors, and filter out public functions that are irrelevant to the state variables of the selected target attribute to obtain a set of public functions.

[0035] The business attribute classifier is used to convert the temporal logical attributes of the selected target attributes into semantically equivalent state-reachable logical attributes.

[0036] The function constraint generator is used to find functions without constraints generated based on the set of public functions, generate function constraints for the corresponding functions based on the control flow graph of the intermediate language code, and, after all the public functions that need to be modeled have generated function constraints, use the state reachability logical properties as the pre-assumptions and post-verification conditions for each function constraint to form a logical formula.

[0037] The symbolic constraint solver is used to solve the satisfiability constraints of the state reachability logical attributes of the function constraints in the logical formula. When the state reachability logical attributes are satisfied by the successful execution of any path of all public functions in the public function set, the first result of the smart contract satisfying the target attribute is output.

[0038] The abstract behavior analysis module is used to perform abstract behavior verification on public functions that do not satisfy the state reachability logic property, and generate counterexamples that violate the property when the abstract behavior verification fails to satisfy the state reachability logic property.

[0039] The validation result document generator is used to compile the first result, the second result validated through abstract behavior, and the counterexamples into a validation result and output it.

[0040] Furthermore, the abstract behavior analysis module includes:

[0041] An abstract predicate generator is used to generate abstract predicates by extraction to form an abstract predicate domain;

[0042] A reachable state fixed-point generator is used to generate a finite state machine about an abstract predicate domain through a fixed-point iterative algorithm.

[0043] The abstract behavior analyzer checks whether the target business attributes are satisfied on the fixed-point abstract state machine. If satisfied, the target business attributes are output to the verification result document generator through verification messages. Then, it returns to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes are verified. If not satisfied, it generates counterexamples of the violated attributes. Counterexamples include function call sequences and specific parameter values.

[0044] In a second aspect, a computer terminal is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement a method for automatically formally verifying the business attributes of a smart contract as described in any one of the first aspects.

[0045] Thirdly, a computer-readable medium is provided having a computer program stored thereon, the computer program being executed by a processor to implement a method for automatically formally verifying the business attributes of a smart contract as described in any one of the first aspects.

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

[0047] 1. The present invention provides a method for automatically formally verifying the business attributes of smart contracts. It constructs a program control flow graph in an intermediate language layer close to the source code and effectively extracts function constraints related to business attributes using data flow analysis technology. This effectively solves the problem that the function constraints constructed by existing symbolic execution virtual machines based on low-level languages ​​such as bytecode limit the solution capability of symbolic solvers, thereby improving the verification capability of symbolic constraint verification engines.

[0048] 2. This invention addresses the false alarm problem caused by the over-approximation of symbolic constraints in existing solutions. It improves the accuracy of verification by automatically modeling and further verifying the entire contract logic through predicate abstraction technology.

[0049] 3. By effectively combining efficient symbolic constraint generation and verification technology with predicate abstraction technology, this invention can support the concise and clear description of business attribute specifications using logical languages ​​with strong expressive capabilities such as sequential logic, and perform efficient and accurate formal verification. Attached Figure Description

[0050] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings:

[0051] Figure 1 This is a flowchart from an embodiment of the present invention;

[0052] Figure 2 This is a system block diagram in an embodiment of the present invention;

[0053] Figure 3 This is a flowchart of the generation of a finite abstract state machine for the abstract predicate domain in an embodiment of the present invention. Detailed Implementation

[0054] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.

[0055] Example 1: A method for automatically formally verifying the business attributes of smart contracts, such as... Figure 1 As shown, this is achieved through the following steps.

[0056] Step 1: Obtain the business attribute specification document and smart contract source code corresponding to the smart contract, parse out each attribute in the business attribute specification document, and embed the attribute into the smart contract source code in the form of smart contract language comments to generate a smart contract source code abstract syntax tree containing attribute specifications.

[0057] The business attribute specification document for smart contracts is written in a temporal logic language, such as Linear Temporal Logic (LTL) or Computational Tree Logic (CTL), to describe the high-level business logic related to smart contract state variables (global storage variables). The intermediate language generator receives the abstract syntax tree of the smart contract source code containing the attribute specifications and converts it into intermediate language code that facilitates program analysis (e.g., data flow analysis).

[0058] Step 2: Transform the abstract syntax tree of the smart contract source code into intermediate language code that can be analyzed.

[0059] Step 3: Construct the corresponding control flow graph based on the intermediate language code, and generate a dependency table between contract state variables and public functions other than the constructor. Then, select a target attribute and mark it as the target attribute iteration point. Filter out public functions that are unrelated to the state variables of the selected target attribute. The remaining public functions constitute the public function set F. Among them, public functions are functions that can be called arbitrarily from the outside.

[0060] Step 4: Receive the target attribute, and then convert the temporal logical attribute of the target attribute into a semantically equivalent state-reachable logical attribute.

[0061] Assuming the target attribute logic is Past LTL (Past Linear Time Logic), for example, the target attribute is... The semantics are: if b < c is true, then a cannot be true (once b < c occurs, a cannot occur again), which translates to the semantically equivalent state reachable logical property: ψ represents determining the truth value of b < c by symbolically tracking the state of the smart contract. Specifically, it involves the predicate... State tracking verification is performed as a precondition and postcondition for each f. Here, the predicate is determined by symbolic tracking of any possible state of any function. The truth value of the statement ensures semantic consistency with the temporal predicate.

[0062] in, This indicates that all states from the past to this moment make If true, This indicates that, starting from this moment, there was a state that made... If true, → indicates implication. < indicates logical NOT, and < indicates less than.

[0063] Step 5: First, check if all functions in the public function set F have generated function constraints. If any functions lack constraints, generate constraints for those functions based on the control flow graph of the intermediate language code. Once all public functions requiring modeling have generated function constraints, then assign state reachability logic attributes. As a constraint ρ for each function f The pre-assumptions and post-verification conditions of (f∈F) form a logical formula. The public function constraint ρ here f The constraint ρ is formed by all paths that can be successfully executed (e.g., non-revert paths) of the function. p And the logical relationship between the new contract state s′ after the path is successfully executed, the initial state s, and the function input parameter a. The set of path summaries

[0064] Step Six: For the input ρf Perform attributes Solving the satisfiability constraints, if the successful execution of any path of all functions f (f∈F) satisfies the property. If the smart contract satisfies the target business attribute, it outputs the target business attribute to the verification result document generator via a verification message, and then returns to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified; due to the logical formula Preconditions were performed for each function. The assumptions can be satisfied and ρ f All state variables involved are symbolic values ​​(a complete but imprecise detection scheme that may produce false positives but will not miss any). Therefore, if a path in a function violates an attribute... There is a possibility of false alarms, and further testing and verification are needed in the abstract behavior analysis module.

[0065] Step 7: Perform abstract behavior verification on public functions that do not satisfy the state reachability logical property, and generate a counterexample that violates the property when the abstract behavior verification fails to satisfy the state reachability logical property.

[0066] The process of performing abstract behavior verification on public functions that do not satisfy the state reachability logical property is as follows: Abstract predicates are extracted to form an abstract predicate domain; a finite state machine about the abstract predicate domain is generated using a fixed-point iterative algorithm; the target business property is checked on the fixed-point abstract state machine to see if it is satisfied. If satisfied, the target business property is output to the verification result document generator via a verification message, and then the process returns to the target property iteration point to select the next target business property for iterative verification until all target properties are verified; if not satisfied, a counterexample of the violation is generated, including the function call sequence and specific parameter values.

[0067] Abstract predicate domains are formed by extracting abstract predicates through three methods. Method 1: Receive the reachable logical attributes of the service attribute classifier status. from Extracting logical predicates: Method 2: Receive function constraints generated by the function constraint generator and extract logical predicates containing only contract state variables and constants. Method 3: When the predicate domain formed by methods 1 and 2 cannot infer the target business attributes, the abstract behavior analyzer will feed back the predicate information that cannot be inferred to the user, and the user can add logical predicates according to the verification requirements.

[0068] Generate the abstract predicate domain using a fixed-point iterative algorithm. The algorithm steps for a finite state machine are as follows: First, define an abstract set of reachable states. Based on the initial values ​​of the smart contract state variables, from (1) Select all satisfyable states as initial abstract reachable states and add them to set R. (2) Enter the outer loop. The outer loop terminates when no new elements are added to set R. (3) In the outer loop: First, select a new reachable state r∈R, and then enter the inner loop. The inner loop terminates when all paths of all functions have been traversed. (4) In the inner loop: For the function path ρ obtained by the current traversal, p The satisfiability of the precondition r is evaluated. If no solution is found, the inner loop continues. If a solution is found, the state logic relationship between p before and after execution is further extracted. Then, the specific symbolic relations are solved through satisfiability constraints. Mapping to abstract domain This yields a reachable abstract state for path p, which is added to set R, and the process proceeds to the next inner loop iteration. This is due to the abstract predicate domain. Since it is finite, the above algorithm can guarantee termination on a domain of abstract predicates. The reachable state of the fixed point.

[0069] On the fixed-point abstract state machine, check whether the target business attribute is satisfied. If it is satisfied, output the target business attribute to the verification result document generator through a verification message, and then return to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified. If it is not satisfied, generate a counterexample of the violated attribute. The counterexample includes the function call sequence and the specific parameter values.

[0070] Step 8: After organizing the first result, the second result verified through abstract behavior, and the counterexamples into a verification result, output it.

[0071] Taking the Solidity smart contract Foo.sol as an example, the process of automatically formally verifying the business attributes of a smart contract using the method described in this invention will be explained in detail below. The main steps are as follows:

[0072] (1) Write a business attribute specification document based on linear time sequence logic, Spec≡■(s≠State.SUCCESS→x==r), the meaning of the business attribute is: the contract state variable x must be equal to the state variable r, unless the contract state variable s becomes SUCCESS.

[0073] (2) Parse the attribute Spec from the business attribute specification document and embed it into the smart contract source code Foo in the form of smart contract language comments. Finally, generate an abstract syntax tree of the smart contract source code containing the attribute specification Spec.

[0074] (3) The intermediate language generator is based on Generate intermediate language code for Foo Then, the intermediate language code control flow graph is constructed. And a dependency table T between state variables {x, y, r, s} and public functions {Increase, End, Suc}.

[0075] (4) Select a target attribute Spec. Since all public functions here are related to the Spec state variables {x, r, s}, the set of public functions to be modeled is F≡{Increase, End, Suc}, which is output to the function constraint generator.

[0076] (5) Use the business attribute classifier to classify the target attribute Spec into

[0077] (6) Use the function constraint generator to generate function constraints.

[0078] (7) Symbolic constraint solver for ρ f All symbolic paths are attributed. Solve for the satisfiability constraints, where x≥0, y==100, r≥0, v≥0;

[0079] Obviously, the above It will not always be true; there is a violation. The solution is found, while the other formulas do not violate any rules. The solution. Next, the abstract behavior analysis module will be used to analyze the program's violation of attributes. Further precision analysis should be conducted.

[0080] (8) Obtain the abstract predicate domain using an abstract predicate generator from From the function constraint ρ, we can extract {s≠State.SUCCESS, x==r}. f The following can be extracted: {flag==1, flag≠1, s==State.OPEN, x≥y}, which can be merged to form

[0081] (9) such as Figure 3 As shown, a reachable state fixed-point generator is used to generate a domain of abstract predicates. A finite abstract state machine.

[0082] The initial precise contract state after contract deployment is as follows:

[0083] {x==0, y==100, flag==0, r==0, r==x, s==State.OPEN}

[0084] Mapping to abstract domain The initial abstract state after that is:

[0085] {x<y, flag≠1, x==r, s==State.OPEN}.

[0086] (10) Use the abstract behavior analyzer to examine the target business attributes on the fixed-point abstract state machine. Whether it satisfies the condition, it is found through reasoning that any reachable state of the contract satisfies the condition. Therefore, step 7) is a false alarm. At this point, the target business attribute of this example has been verified and the conclusion that the verification is successful has been reached.

[0087] (11) Use the business attribute verification result document generator to generate a message that the contract meets the target business attribute Spec.

[0088] Example 2: A system for automatically formally verifying the business attributes of smart contracts. This system is used to implement the method for automatically formally verifying the business attributes of smart contracts described in Example 1, such as... Figure 2 As shown, it includes a source code modeler, an intermediate language generator, a data flow analyzer, a business attribute classifier, a function constraint generator, a symbolic constraint solver, an abstract behavior analysis module, and a verification result document generator.

[0089] The system comprises the following components: a source code modeler, which parses each attribute from the business attribute specification document corresponding to the smart contract and embeds the attributes into the smart contract source code in the form of smart contract language comments, generating an abstract syntax tree (AST) containing the attribute specifications; an intermediate language generator, which converts the AST into intermediate language code suitable for program analysis; a data flow analyzer, which constructs the corresponding control flow graph based on the intermediate language code, generates a dependency table between contract state variables and public functions (excluding constructors), and filters out public functions irrelevant to the state variables of the selected target attribute, resulting in a set of public functions; a business attribute classifier, which converts the temporal logical attributes of the selected target attribute into semantically equivalent state-reachable logical attributes; and a function constraint generator, which finds functions without generated constraints based on the set of public functions and, based on the intermediate language code... The system generates function constraints for corresponding functions from the control flow graph of the inter-language code. After generating function constraints for all public functions that need to be modeled, it uses the state reachability logical attribute as the pre-assumption and post-verification condition for each function constraint to form a logical formula. The symbolic constraint solver solves the satisfiability constraints of the state reachability logical attribute for the function constraints in the logical formula. When all public functions in the set of public functions successfully execute on any path and satisfy the state reachability logical attribute, it outputs the first result that the smart contract satisfies the target attribute. The abstract behavior analysis module verifies the abstract behavior of public functions that do not satisfy the state reachability logical attribute and generates counterexamples that violate the attribute when the abstract behavior verification fails to satisfy the state reachability logical attribute. The verification result document generator organizes the first result, the second result that passes the abstract behavior verification, and the counterexamples into a verification result and outputs it.

[0090] The abstract behavior analysis module includes an abstract predicate generator, a reachable state fixed-point generator, and an abstract behavior analyzer. The abstract predicate generator is used to extract and generate abstract predicates to form an abstract predicate domain. The reachable state fixed-point generator is used to generate a finite state machine about the abstract predicate domain using a fixed-point iterative algorithm. The abstract behavior analyzer checks whether the target business attributes are satisfied on the fixed-point abstract state machine. If satisfied, it outputs the target business attributes to the verification result document generator via verification messages, then returns to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified. If not satisfied, it generates counterexamples of the violated attributes, including function call sequences and specific parameter values.

[0091] Working Principle: This invention constructs a program control flow graph at an intermediate language layer close to the source code and effectively extracts function constraints related to business attributes using data flow analysis technology. This effectively solves the problem of function constraints built by existing symbolic execution virtual machines based on low-level languages ​​such as bytecode limiting the solution capability of symbolic solvers, thus improving the verification capability of the symbolic constraint verification engine. In addition, addressing the false alarm problem caused by over-approximation of symbolic constraints in existing solutions, this invention automatically models and further verifies the entire contract logic through predicate abstraction technology, improving verification accuracy. Furthermore, by effectively combining efficient symbolic constraint generation and verification technology with predicate abstraction technology, this invention can support the concise and clear description of business attribute specifications using logic languages ​​with strong expressive capabilities such as sequential logic, and perform efficient and accurate formal verification.

[0092] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0093] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0094] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0095] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0096] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for automatically formally verifying the business attributes of smart contracts, characterized in that, Includes the following steps: Parse each attribute in the business attribute specification document corresponding to the smart contract, and embed the attributes into the smart contract source code in the form of smart contract language comments to generate a smart contract source code abstract syntax tree containing attribute specifications; Transform the abstract syntax tree of smart contract source code into intermediate language code that can be analyzed. Based on the intermediate language code, construct the corresponding control flow graph, generate a dependency table between contract state variables and public functions other than constructors, and filter out public functions that are irrelevant to the state variables of the selected target attribute to obtain a set of public functions; Transform the temporal logical attributes of the selected target attributes into semantically equivalent state-reachable logical attributes; Find functions without generated constraints based on the public function set, generate function constraints for the corresponding functions based on the control flow graph of the intermediate language code, and after all public functions that need to be modeled have generated function constraints, use the state reachability logical attributes as the pre-assumptions and post-verification conditions for each function constraint to form a logical formula. Solve the satisfiability constraints of the state reachability logical attributes for the function constraints in the logical formula, and output the first result of the smart contract satisfying the target attribute when the state reachability logical attributes are satisfied in any path of all public functions in the public function set. Perform abstract behavior verification on public functions that do not satisfy the state reachability logical property, and generate counterexamples that violate the property when the abstract behavior verification fails to satisfy the state reachability logical property. The first result, the second result verified through abstract behavior, and the counterexamples are organized into a verification result and then output.

2. The method for automatically formally verifying the business attributes of smart contracts according to claim 1, characterized in that, The business attribute specification document corresponding to the smart contract is written in a time-series logic language and is used to describe the high-level business logic related to the smart contract's state variables.

3. The method for automatically formally verifying the business attributes of smart contracts according to claim 1, characterized in that, The process of performing abstract behavior verification on public functions that do not satisfy the state reachability logical attribute is as follows: Abstract predicates are generated by extraction to form an abstract predicate domain; A finite state machine for the abstract predicate domain is generated using a fixed-point iterative algorithm. On the fixed-point abstract state machine, check whether the target business attribute is satisfied. If it is satisfied, output the target business attribute to the verification result document generator through a verification message, and then return to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified. If it is not satisfied, generate a counterexample of the violated attribute. The counterexample includes the function call sequence and the specific parameter values.

4. The method for automatically formally verifying the business attributes of smart contracts according to claim 3, characterized in that, The process of extracting and generating abstract predicates is specifically as follows: A. Receive the reachable logical attributes of the business attribute classifier and extract logical predicates from the reachable logical attributes; B. Receive the function constraints generated by the function constraint generator, and extract logical predicates containing only contract state variables and constants from the function constraints; C. When the predicate domain formed by A and B cannot infer the target business attributes, the predicate information that cannot be inferred will be fed back to the user, and the user can add logical predicates according to the verification requirements.

5. The method for automatically formally verifying the business attributes of smart contracts according to claim 3, characterized in that, The process of generating a finite state machine about the abstract predicate domain using the fixed-point iterative algorithm is as follows: Based on the initial values ​​of the smart contract state variables, select all satisfiable states from the abstract predicate domain as initial abstract reachable states and add them to the initially defined set of abstract reachable states; Entering the outer loop, the outer loop terminates when no new elements are added to the abstract reachable state set; Within the outer loop: First, select a new reachable state, then enter the inner loop. The inner loop terminates when all paths of all functions have been traversed. Within the inner loop: For the function path obtained by the current traversal, the satisfiability of the preconditions is solved. If there is no solution, the next inner loop is entered. If a solution exists, continue to extract the state logic relationship before and after the execution of the function path, and then map the specific symbolic relationship to the abstract predicate domain by solving the satisfiability constraint to obtain a reachable abstract state of the path function path, add it to the abstract reachable state set, and enter the next inner loop iteration.

6. The method for automatically formally verifying the business attributes of smart contracts according to claim 1, characterized in that, The counterexamples include function call sequences and parameter values.

7. A system for automatically formally verifying the business attributes of smart contracts, characterized in that, include: The source code modeler is used to parse each attribute in the business attribute specification document corresponding to the smart contract, and embed the attributes into the smart contract source code in the form of smart contract language comments, generating a smart contract source code abstract syntax tree containing attribute specifications. Intermediate language generator is used to transform the abstract syntax tree of smart contract source code into intermediate language code that can be analyzed. The data flow analyzer is used to construct the corresponding control flow graph based on the intermediate language code, generate a dependency table between contract state variables and public functions other than constructors, and filter out public functions that are irrelevant to the state variables of the selected target attribute to obtain a set of public functions. The business attribute classifier is used to convert the temporal logical attributes of the selected target attributes into semantically equivalent state-reachable logical attributes. The function constraint generator is used to find functions without constraints generated based on the set of public functions, generate function constraints for the corresponding functions based on the control flow graph of the intermediate language code, and, after all the public functions that need to be modeled have generated function constraints, use the state reachability logical properties as the pre-assumptions and post-verification conditions for each function constraint to form a logical formula. The symbolic constraint solver is used to solve the satisfiability constraints of the state reachability logical attributes of the function constraints in the logical formula. When the state reachability logical attributes are satisfied by the successful execution of any path of all public functions in the public function set, the first result of the smart contract satisfying the target attribute is output. The abstract behavior analysis module is used to perform abstract behavior verification on public functions that do not satisfy the state reachability logic property, and generate counterexamples that violate the property when the abstract behavior verification fails to satisfy the state reachability logic property. The validation result document generator is used to compile the first result, the second result validated through abstract behavior, and the counterexamples into a validation result and output it.

8. The system for automatically formally verifying the business attributes of smart contracts according to claim 7, characterized in that, The abstract behavior analysis module includes: An abstract predicate generator is used to generate abstract predicates by extraction to form an abstract predicate domain; A reachable state fixed-point generator is used to generate a finite state machine about an abstract predicate domain through a fixed-point iterative algorithm. The abstract behavior analyzer checks whether the target business attributes are satisfied on the fixed-point abstract state machine. If satisfied, the target business attributes are output to the verification result document generator through verification messages. Then, it returns to the target attribute iteration point to select the next target business attribute for iterative verification until all target attributes have been verified. If not satisfied, it generates counterexamples of the violated attributes. Counterexamples include function call sequences and specific parameter values.

9. A computer terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements a method for automatically formally verifying the business attributes of a smart contract as described in any one of claims 1-6.

10. A computer-readable medium having a computer program stored thereon, characterized in that, The computer program, when executed by a processor, can implement a method for automatically formally verifying the business attributes of a smart contract as described in any one of claims 1-6.