Intelligent contract auditing method and system based on model detection technology

By constructing formal models of smart contracts through model checking technology and detecting contract execution paths, the time-consuming and false positive/false negative issues of traditional auditing methods are resolved, enabling efficient and accurate security vulnerability detection and remediation.

CN122020668APending Publication Date: 2026-05-12XIAMEN SLOWMIST TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XIAMEN SLOWMIST TECHNOLOGY CO LTD
Filing Date
2026-02-09
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Traditional smart contract auditing methods are time-consuming and error-prone, manual review has limited accuracy, static analysis is prone to false positives and false negatives, and cannot fully cover security vulnerabilities in the contract execution path.

Method used

By employing model checking technology, a formal model of the contract is constructed, security attributes are defined, and a model checking algorithm is used to traverse the contract execution path to generate an audit report and provide remediation suggestions.

Benefits of technology

It enables comprehensive and accurate security vulnerability detection of smart contracts, improves the security and reliability of contracts, reduces the risk of false positives and false negatives, and provides a rapid remediation solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
Patent Text Reader

Abstract

The invention discloses an intelligent contract auditing method and system based on a model detection technology, and belongs to the technical field of block chains, and the system comprises a contract model construction module, a security attribute definition module, a model detection module, a result analysis module, and a repair suggestion module. Potential security vulnerabilities and risks in the smart contract are found and repaired comprehensively, accurately and intelligently, and the security and reliability of the contract are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and more specifically to a smart contract auditing method and system based on model detection technology. Background Technology

[0002] A smart contract is a computer protocol designed to transmit, verify, or execute contracts in an informational manner.

[0003] Traditional smart contract auditing methods primarily rely on manual code review and testing, which has several drawbacks. First, manual review and testing are time-consuming and prone to overlooking potential problems, especially for complex smart contracts, where the auditing process can be tedious and error-prone. Second, the accuracy of manual auditing is limited by the experience and expertise of the auditors; different auditors may have different understandings and judgments, affecting the consistency and reliability of the audit results.

[0004] On the other hand, static analysis-based smart contract auditing methods detect potential security vulnerabilities and risks by statically analyzing contract code. However, static analysis methods are prone to false positives and false negatives. False positives occur when code that is actually safe in the contract is marked as unsafe, while false negatives occur when potential problems in the contract are not detected. These problems mainly stem from the limited ability of static analysis methods to understand complex contract logic and dynamic behavior. Furthermore, static analysis methods typically only analyze the static properties of the contract and cannot cover all execution paths, thus failing to uncover some hidden security vulnerabilities and risks. Summary of the Invention

[0005] To address the shortcomings of existing technologies, the present invention aims to provide a smart contract auditing method and system based on model detection technology. Its advantage lies in its ability to comprehensively, accurately, and intelligently discover and repair potential security vulnerabilities and risks in smart contracts through model detection technology, thereby improving the security and reliability of contracts.

[0006] To achieve the above objectives, the present invention provides the following technical solution: a smart contract auditing system based on model detection technology, comprising:

[0007] The contract model building module is used to receive smart contract code, parse the code to extract the contract's state variables, functions and event information, and build a formal model of the contract based on the extracted information. The formal model is represented by a finite state machine or a transition system, and the execution path of the contract is abstracted into the state transition path in the model.

[0008] The security attribute definition module is used to define security attributes and execution specifications according to the security requirements of smart contracts, and to formally describe the security attributes and execution specifications using temporal logic or modal logic.

[0009] The model detection module has a built-in model detector and model detection algorithm. The model detection module uses the model detection algorithm to check whether there are states or paths in the formal model that violate the security attributes or execution specifications output by the security attribute definition module.

[0010] The results analysis module receives the detection results from the model detection module, identifies the specific paths, states, and corresponding security vulnerability types that violate security attributes or execution specifications, counts the number and impact of vulnerabilities, and generates an audit report that includes vulnerability descriptions and the scope of impact.

[0011] The remediation suggestion module generates targeted remediation suggestions based on the vulnerability types identified by the result analysis module and the audit report.

[0012] A further preferred embodiment of the present invention: the contract model construction module includes a code parsing unit and a model generation unit;

[0013] The code parsing unit uses a syntax analyzer to perform lexical and syntactic analysis on the smart contract code, generates an abstract syntax tree, and extracts the type and initial value of state variables, the input parameters and execution logic of functions, and the triggering conditions of events from the abstract syntax tree.

[0014] The model generation unit defines each execution state of the contract as a set of state variable values ​​plus a tuple of function execution phases based on the extracted information. It defines operations such as function calls and variable modifications as state transition conditions, constructs a formal model of a finite state machine, or describes the nondeterministic transition relationships between states through a transition system.

[0015] A further preferred embodiment of the present invention: the security attribute definition module includes an attribute classification unit and a formal description unit;

[0016] The attribute classification unit divides security attributes into basic security attributes and business security attributes;

[0017] The formal description unit adopts CTL logic description or LTL logic description to ensure that the security attributes can be parsed by the model detection algorithm.

[0018] In a further preferred embodiment of the present invention, the model detection module further includes a state space optimization unit; the state space optimization unit uses symbolic execution technology or abstract interpretation technology to compress the state space of the formal model, remove redundant states and unreachable states, and reduce the time and space complexity of model detection.

[0019] A further preferred embodiment of the present invention is that the result analysis module includes a vulnerability location unit and a risk rating unit;

[0020] The vulnerability location unit traces the path that violates security attributes in reverse to locate the corresponding key statements in the contract code and associates the line numbers of the statements in the code.

[0021] The risk rating unit classifies vulnerabilities into three levels: high risk, medium risk, and low risk, based on the scope of their impact and the difficulty of exploitation.

[0022] A smart contract auditing method based on model detection technology includes the following steps:

[0023] S1: Contract model construction, parsing smart contract code, extracting state variables, functions and event information, and constructing a formal model represented by a finite state machine or transition system;

[0024] S2: Security attribute definition. Based on the security requirements of smart contracts, security attributes and execution specifications are defined by category, and formal description is performed using temporal logic or modal logic.

[0025] S3: Model detection. The model detector traverses the state space of the formal model and checks for states or paths that violate security attributes or execution specifications using CTL or LTL model detection algorithms.

[0026] S4: Results analysis, identifying vulnerability types, locating vulnerability locations, calculating vulnerability risk levels, and generating audit reports;

[0027] S5: Remediation suggestion generation. Based on the vulnerability type and risk level, output targeted code modification and logic optimization suggestions.

[0028] A further preferred embodiment of the present invention includes: the formal model construction process in step S1 comprising:

[0029] S11: Code parsing. The ANTLR tool is used to generate a syntax parser for the smart contract language. Lexical analysis is performed on the contract code, which is broken down into lexical units such as keywords, identifiers, and operators. Then, an abstract syntax tree is generated through syntax analysis.

[0030] S12: Information extraction, traversing the abstract syntax tree, extracting the type, initial value and modification function of the state variable, the parameter list, return value and execution branch logic of the function, and the triggering condition of the event;

[0031] S13: Model generation, defining the combination of values ​​of each state variable and the current function stage as a state, defining variable modification and branch jump caused by function calls as state transitions, and constructing a finite state machine.

[0032] A further preferred embodiment of the present invention includes: the specific implementation process of model detection in step S3 includes:

[0033] S31: Model import, converting the formal model built in step S1 into a format recognizable by the model detector;

[0034] S32: Attribute Import, import the formal security attributes defined in step S2 into the model detector;

[0035] S33: State traversal. The model detector uses a depth-first search or breadth-first search strategy to traverse the model's state space and record whether each state satisfies the safety attributes.

[0036] S34: Counterexample generation. If a path that violates security attributes is detected, the model detector automatically generates a counterexample.

[0037] A further preferred embodiment of the present invention: the process of generating the repair suggestion in step S5 includes:

[0038] S51: Vulnerability matching, matching the preset remediation solution library according to the vulnerability type identified in step S4;

[0039] S52: Verification Supplement: Add verification steps to the remediation recommendations to ensure that the remediation solution can completely eliminate the vulnerability.

[0040] In summary, the present invention has the following advantages:

[0041] By employing model detection technology, this invention can comprehensively, accurately, and intelligently identify security vulnerabilities and risks in smart contracts. Compared to traditional manual auditing methods, this invention provides more accurate and consistent audit results, avoiding false positives and false negatives. Furthermore, this invention can generate remediation suggestions based on the model detection results, helping developers quickly fix security vulnerabilities in contracts and improving contract security and reliability.

[0042] Through experimental data and comparative analysis, this invention achieves significant advantages in terms of accuracy, efficiency, and cost in smart contract auditing. This will promote the secure development of smart contracts and provide assurance for the security and trustworthiness of blockchain technology. The application value and practical significance of this invention lies in improving the security and reliability of smart contracts and promoting the further development and application of blockchain technology. Attached Figure Description

[0043] Figure 1 This is a system framework diagram of this embodiment;

[0044] Figure 2 This is the main flowchart of this embodiment. Detailed Implementation

[0045] The present invention will be further described in detail below with reference to the accompanying drawings.

[0046] As shown in the figure, a smart contract auditing system based on model detection technology includes:

[0047] The contract model building module receives smart contract code, parses the code to extract the contract's state variables, functions, and event information, and builds a formal model of the contract based on the extracted information. The formal model is represented by a finite state machine or a transition system, and the execution path of the contract is abstracted into the state transition path in the model.

[0048] The security attribute definition module is used to define security attributes and execution specifications according to the security requirements of smart contracts. Security attributes include constraints related to fund security and access control, and execution specifications include constraints related to preventing reentrancy attacks and preventing integer overflow. The security attributes and execution specifications are formally described using temporal logic or modal logic.

[0049] The model detection module has a built-in model detector and model detection algorithm. The model detector is used to automatically traverse the state space of the formal model output by the contract model construction module. The model detection algorithm includes CTL modal logic model detection algorithm or LTL linear temporal logic model detection algorithm. The model detection module checks whether there are states or paths in the formal model that violate the security attributes or execution specifications output by the security attribute definition module.

[0050] The results analysis module receives the detection results from the model detection module, identifies the specific paths, states, and corresponding security vulnerability types that violate security attributes or execution specifications, counts the number and impact of vulnerabilities, and generates an audit report that includes vulnerability descriptions and the scope of impact.

[0051] The remediation suggestion module generates targeted remediation suggestions based on the vulnerability types identified by the results analysis module and the audit report. The remediation suggestions include contract code modification schemes, security check logic addition schemes, and contract execution process optimization schemes.

[0052] Preferably, the contract model building module includes a code parsing unit and a model generation unit;

[0053] The code parsing unit uses a syntax analyzer to perform lexical and syntactic analysis on the smart contract code, which includes Solidity and Vyper language code, generating an abstract syntax tree. From the abstract syntax tree, it extracts the types and initial values ​​of state variables, the input parameters and execution logic of functions, and the triggering conditions of events. Based on the extracted information, the model generation unit defines each execution state of the contract as a tuple of the set of state variable values ​​plus the function execution phase. It defines operations such as function calls and variable modifications as state transition conditions, constructs a formal finite state machine model, or describes the nondeterministic transition relationships between states through a transition system.

[0054] Preferably, the security attribute definition module includes an attribute classification unit and a formal description unit;

[0055] The attribute classification unit divides security attributes into basic security attributes and business security attributes. Basic security attributes include the inability to transfer funds at will and the inability to obtain permissions beyond one's authority. Business security attributes include the compliance of the liquidation logic of DeFi contracts and the limitation on the number of NFT contracts that can be minted.

[0056] Formal description units can be described using CTL logic (e.g., authorization verification is required before fund transfer in all execution paths) or LTL logic (e.g., there is no function re-entry in the execution path that would cause repeated modification of state variables) to ensure that security attributes can be parsed by the model detection algorithm.

[0057] Preferably, the model detection module also includes a state space optimization unit. The state space optimization unit uses symbolic execution technology or abstract interpretation technology to compress the state space of the formal model, remove redundant and unreachable states, and reduce the time and space complexity of model detection. When the number of original states of the contract model exceeds 10^5, the state space optimization unit can compress the number of states to less than 30% of the original size.

[0058] Preferably, the results analysis module includes a vulnerability location unit and a risk rating unit;

[0059] The vulnerability localization unit traces the path that violates security attributes to locate the corresponding key statements in the contract code, including unlocked reentrant function call statements and unverified permission judgment statements, and associates the line numbers of the statements in the code.

[0060] The risk rating unit classifies vulnerabilities into three levels—high-risk (P0), medium-risk (P1), and low-risk (P2)—based on their impact scope and exploitation difficulty. The impact scope includes affecting only a single user or all users of the contract, and the exploitation difficulty includes requiring specific input or requiring no special conditions.

[0061] As shown in the figure, a smart contract auditing method based on model detection technology includes the following steps:

[0062] S1: Contract model construction, parsing smart contract code, extracting state variables, functions and event information, and constructing a formal model represented by a finite state machine or transition system;

[0063] S2: Security attribute definition. Based on the security requirements of smart contracts, security attributes and execution specifications are defined by category, and formal description is performed using temporal logic or modal logic.

[0064] S3: Model detection. The model detector traverses the state space of the formal model and checks for states or paths that violate security attributes or execution specifications using CTL or LTL model detection algorithms.

[0065] S4: Results analysis, identifying vulnerability types, locating vulnerability locations, calculating vulnerability risk levels, and generating audit reports;

[0066] S5: Remediation suggestion generation. Based on the vulnerability type and risk level, output targeted code modification and logic optimization suggestions.

[0067] Preferably, the formal model construction process in step S1 includes:

[0068] S11: Code parsing. The ANTLR tool is used to generate a syntax parser for the smart contract language. Lexical analysis is performed on the contract code, which is broken down into lexical units such as keywords, identifiers, and operators. Then, an abstract syntax tree is generated through syntax analysis.

[0069] S12: Information extraction, traversing the abstract syntax tree, extracting the state variable type, initial value and modification function, function parameter list, return value and execution branch logic, and event triggering conditions;

[0070] S13: Model generation. Define the combination of values ​​of each state variable and the current function stage as a state. Define the variable modification and branch jump caused by function call as state transition. Construct a finite state machine. For example, state S0 (balanceOf[userA]=100, before executing the transfer function) is transformed into state S1 (balanceOf[userA]=50, balanceOf[userB]=50, after executing the transfer function) after "calling transfer(userB,50) and passing the verification".

[0071] 8. A smart contract auditing method based on model detection technology according to claim 6, characterized in that the specific implementation process of model detection in step S3 includes:

[0072] S31: Model import, converting the formal model constructed in step S1 into a format recognizable by the model detector, including SMV format and Promela format;

[0073] S32: Attribute Import, import the formal security attributes defined in step S2 into the model detector;

[0074] S33: State traversal. The model detector uses a depth-first search or breadth-first search strategy to traverse the model's state space and record whether each state satisfies the safety attributes.

[0075] S34: Counterexample generation. If a path that violates security attributes is detected, the model detector automatically generates a counterexample. The counterexample contains the complete execution sequence of "initial state → trigger operation → intermediate state → vulnerability state", such as initial state S0 → call the unlocked withdraw function → re-entrancy call to the withdraw function → state Sx (user balance is negative, violating fund security attributes).

[0076] Preferably, the process of generating repair suggestions in step S5 includes:

[0077] S51: Vulnerability matching. Based on the vulnerability types identified in step S4, including reentrancy vulnerabilities and integer overflow vulnerabilities, a preset remediation solution library is matched. The remediation solution library stores the mapping relationship of "vulnerability type - remediation logic - code example".

[0078] S51: Vulnerability matching. Based on the vulnerability type identified in step S4 (such as reentrancy vulnerability, integer overflow vulnerability), match the preset remediation solution library. The remediation solution library stores the mapping relationship of "vulnerability type - remediation logic - code example".

[0079] S53: Verification Supplement: Add a verification step to the remediation suggestion that "model detection must be re-executed after remediation" to ensure that the remediation solution can completely eliminate the vulnerability.

[0080] The working process and beneficial effects of this invention are as follows:

[0081] By constructing contract models, defining security attributes and specifications, and performing model testing, this invention can comprehensively discover security vulnerabilities and risks in contracts. Furthermore, it provides remediation suggestions to help improve the security and reliability of contracts. By introducing an intelligent auditing process, this invention can improve the accuracy and efficiency of auditing, providing strong support for the secure use of smart contracts.

[0082] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the design concept of the present invention should be included within the protection scope of the present invention.

Claims

1. A smart contract auditing system based on model checking technology, characterized in that, include: The contract model building module is used to receive smart contract code, parse the code to extract the contract's state variables, functions and event information, and build a formal model of the contract based on the extracted information. The formal model is represented by a finite state machine or a transition system, and the execution path of the contract is abstracted into the state transition path in the model. The security attribute definition module is used to define security attributes and execution specifications according to the security requirements of smart contracts, and to formally describe the security attributes and execution specifications using temporal logic or modal logic. The model detection module has a built-in model detector and model detection algorithm. The model detection module uses the model detection algorithm to check whether there are states or paths in the formal model that violate the security attributes or execution specifications output by the security attribute definition module. The results analysis module receives the detection results from the model detection module, identifies the specific paths, states, and corresponding security vulnerability types that violate security attributes or execution specifications, counts the number and impact of vulnerabilities, and generates an audit report that includes vulnerability descriptions and the scope of impact. The remediation suggestion module generates targeted remediation suggestions based on the vulnerability types identified by the result analysis module and the audit report.

2. The smart contract auditing system based on model checking technology according to claim 1, characterized in that: The contract model construction module includes a code parsing unit and a model generation unit; The code parsing unit uses a syntax analyzer to perform lexical and syntactic analysis on the smart contract code, generates an abstract syntax tree, and extracts the type and initial value of state variables, the input parameters and execution logic of functions, and the triggering conditions of events from the abstract syntax tree. The model generation unit defines each execution state of the contract as a set of state variable values ​​plus a tuple of function execution phases based on the extracted information. It defines operations such as function calls and variable modifications as state transition conditions, constructs a formal model of a finite state machine, or describes the nondeterministic transition relationships between states through a transition system.

3. The smart contract auditing system based on model checking technology according to claim 1, characterized in that: The security attribute definition module includes an attribute classification unit and a formal description unit; The attribute classification unit divides security attributes into basic security attributes and business security attributes; The formal description unit adopts CTL logic description or LTL logic description to ensure that the security attributes can be parsed by the model detection algorithm.

4. The smart contract auditing system based on model checking technology according to claim 1, characterized in that: The model detection module also includes a state space optimization unit; the state space optimization unit uses symbolic execution technology or abstract interpretation technology to compress the state space of the formal model, remove redundant and unreachable states, and reduce the time and space complexity of model detection.

5. The smart contract auditing system based on model checking technology according to claim 1, characterized in that: The results analysis module includes a vulnerability location unit and a risk rating unit; The vulnerability location unit traces the path that violates security attributes in reverse to locate the corresponding key statements in the contract code and associates the line numbers of the statements in the code. The risk rating unit classifies vulnerabilities into three levels: high risk, medium risk, and low risk, based on the scope of their impact and the difficulty of exploitation.

6. A smart contract auditing method based on model checking technology, characterized in that, Includes the following steps: S1: Contract model construction, parsing smart contract code, extracting state variables, functions and event information, and constructing a formal model represented by a finite state machine or transition system; S2: Security attribute definition. Based on the security requirements of smart contracts, security attributes and execution specifications are defined by category, and formal description is performed using temporal logic or modal logic. S3: Model detection. The model detector traverses the state space of the formal model and checks for states or paths that violate security attributes or execution specifications using CTL or LTL model detection algorithms. S4: Results analysis, identifying vulnerability types, locating vulnerability locations, calculating vulnerability risk levels, and generating audit reports; S5: Remediation suggestion generation. Based on the vulnerability type and risk level, output targeted code modification and logic optimization suggestions.

7. The smart contract auditing method based on model detection technology according to claim 6, characterized in that, The formal model construction process described in step S1 includes: S11: Code parsing. The ANTLR tool is used to generate a syntax parser for the smart contract language. Lexical analysis is performed on the contract code, which is broken down into lexical units such as keywords, identifiers, and operators. Then, an abstract syntax tree is generated through syntax analysis. S12: Information extraction, traversing the abstract syntax tree, extracting the type, initial value and modification function of the state variable, the parameter list, return value and execution branch logic of the function, and the triggering condition of the event; S13: Model generation, defining the combination of values ​​of each state variable and the current function stage as a state, defining variable modification and branch jump caused by function calls as state transitions, and constructing a finite state machine.

8. A smart contract auditing method based on model detection technology according to claim 6, characterized in that, The specific implementation process of model detection in step S3 includes: S31: Model import, converting the formal model built in step S1 into a format recognizable by the model detector; S32: Attribute Import, import the formal security attributes defined in step S2 into the model detector; S33: State traversal. The model detector uses a depth-first search or breadth-first search strategy to traverse the model's state space and record whether each state satisfies the safety attributes. S34: Counterexample generation. If a path that violates security attributes is detected, the model detector automatically generates a counterexample.

9. A smart contract auditing method based on model detection technology according to claim 6, characterized in that, The process of generating the repair recommendations in step S5 includes: S51: Vulnerability matching, matching the preset remediation solution library according to the vulnerability type identified in step S4; S52: Verification Supplement: Add verification steps to the remediation recommendations to ensure that the remediation solution can completely eliminate the vulnerability.