A method and system for improving the accuracy of smart contract code defect detection

By performing abstract syntax tree parsing, basic and advanced analysis of the contract code, symbol tagging, and security attribute verification on the smart contract code, the problem of low accuracy in smart contract code vulnerability detection is solved, and higher accuracy vulnerability detection is achieved.

CN115310094BActive Publication Date: 2026-04-24成都链安科技有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
成都链安科技有限公司
Filing Date
2022-08-08
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing technologies suffer from poor accuracy in detecting vulnerabilities in smart contract code, resulting in incomplete path traversal and an inability to effectively discover vulnerabilities.

Method used

By obtaining the abstract syntax tree of the smart contract source code, parsing the basic analysis information of the contract, converting it into target language code, performing advanced contract analysis and symbol marking, and combining vulnerability rules and security attribute verification, a vulnerability detection document is generated.

Benefits of technology

It improves the accuracy of vulnerability detection in smart contract code, achieving more comprehensive vulnerability detection and higher detection precision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115310094B_ABST
    Figure CN115310094B_ABST
Patent Text Reader

Abstract

The application discloses a method and system for improving the defect detection precision of smart contract code, which verifies the smart contract code from multiple aspects by means of vulnerability rules and security attributes, improves the detection precision of the smart contract code, and combines contract basic analysis information and contract advanced analysis information to comprehensively analyze the smart contract code and further improve the vulnerability detection precision of the smart contract code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain smart contract security technology, specifically to a method and system for improving the accuracy of smart contract code defect detection. Background Technology

[0002] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. It uses a decentralized consensus mechanism to maintain a complete, distributed, and immutable ledger database, enabling participants in the blockchain to achieve a unified ledger system without establishing trust relationships. A smart contract is a set of promises defined in digital form, including protocols that allow contract participants to execute these promises. In the context of blockchain technology, a smart contract refers to program code that runs on the blockchain and can perform certain functions. Writing smart contracts digitally into the blockchain ensures that the entire process of storage, retrieval, and execution is transparent, traceable, and immutable, thanks to the characteristics of blockchain technology. Simultaneously, the consensus algorithm inherent in the blockchain constructs a state machine system, enabling smart contracts to operate efficiently.

[0003] To ensure the proper functioning of smart contract code, it is often necessary to verify it to detect vulnerabilities and facilitate their repair by staff. Current technologies often involve performing a simple execution of the smart contract code to determine its vulnerability status based on the execution result. However, relying on simple execution to determine vulnerability can lead to incomplete path traversal and poor vulnerability detection accuracy. Summary of the Invention

[0004] The purpose of this application is to provide a method and system for improving the accuracy of smart contract code defect detection, thereby solving the problem of poor accuracy in detecting vulnerabilities in existing smart contract code.

[0005] This invention is achieved through the following technical solution:

[0006] In a first aspect, the present invention provides a method for improving the accuracy of smart contract code defect detection, comprising:

[0007] Obtain the source code of the smart contract and its abstract syntax tree;

[0008] The abstract syntax tree is parsed to obtain basic contract analysis information of the smart contract code;

[0009] The contract fundamental analysis information is converted into target language code to obtain the contract fundamental analysis information code;

[0010] Analyze the basic analysis information code of the contract to obtain advanced analysis information of the contract;

[0011] Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rules are matched to obtain the first vulnerability detection result;

[0012] Based on the advanced contract analysis information, the basic contract analysis information code is symbolically marked to obtain the symbolically marked basic contract analysis information code.

[0013] The security attributes of the contract basic analysis information code marked with symbols are verified to obtain the second vulnerability detection result.

[0014] Based on the first vulnerability detection result and the second vulnerability detection result, a vulnerability detection document is generated.

[0015] Furthermore, after generating the vulnerability detection document based on the first vulnerability detection result and the second vulnerability detection result, it also includes:

[0016] Based on the first vulnerability detection result and the second vulnerability detection result, mark the vulnerability location in the smart contract source code.

[0017] Furthermore, the abstract syntax tree is parsed to obtain basic contract analysis information of the smart contract code, including:

[0018] The abstract syntax tree is parsed to extract contract constants, variables, functions, inheritance relationships, and expressions, and these constants, variables, functions, inheritance relationships, and expressions are used as the basic contract analysis information for smart contract code.

[0019] Furthermore, the basic contract analysis information code is analyzed to obtain advanced contract analysis information, including:

[0020] Determine the relationships between contract constants, variables, functions, inheritance relationships, and expressions in the basic contract analysis information code, and use these relationships as the advanced contract analysis information.

[0021] Furthermore, based on the advanced contract analysis information and the basic contract analysis information, vulnerability rule matching is performed to obtain the first vulnerability detection result, including:

[0022] Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rules are matched in the vulnerability rule base. If there is a vulnerability rule that matches the advanced contract analysis information and the basic contract analysis information, the vulnerability corresponding to the vulnerability rule is taken as the first vulnerability detection result of the advanced contract analysis information and the basic contract analysis information.

[0023] The vulnerability rule base contains multiple vulnerability rules.

[0024] Furthermore, based on the advanced contract analysis information, the contract fundamental analysis information code is symbolically marked to obtain the symbolically marked contract fundamental analysis information code, including:

[0025] Based on the advanced contract analysis information, the variables in the basic contract analysis information code are marked as symbolic variables, resulting in the symbolically marked basic contract analysis information code.

[0026] Furthermore, the security attributes of the contract basic analysis information code after symbol marking are verified to obtain the second vulnerability detection result, including:

[0027] The contract basic analysis information code after execution symbol marking is used to determine in real time whether the contract basic analysis information code meets the security attribute rules in the security attribute model library. If it does, the contract basic analysis information code has no vulnerability, and the second vulnerability detection result is determined to be no vulnerability. Otherwise, the code in the contract basic analysis information code that does not meet the security attribute rules is taken as the second vulnerability detection result. The security attribute model library includes at least one security attribute rule.

[0028] During execution, the system continuously checks for the presence of symbolic markers. If a symbol is present, it interprets the marker and continues execution. Otherwise, it converts the contract's basic analysis information code into the blockchain platform's target code and executes it.

[0029] During execution, the process also includes: determining whether an execution condition is triggered; if so, executing the execution strategy corresponding to the execution condition and continuing to execute the contract basic analysis information code with the execution strategy; otherwise, continuing to execute the contract basic analysis information code. The execution conditions, execution strategies, and their relationships are all pre-stored data.

[0030] Furthermore, the symbols are interpreted, including:

[0031] Determine if a blockchain platform model library exists corresponding to the symbol. If it does, directly call the blockchain platform model library for symbol interpretation; otherwise, call the blockchain platform function interface for symbol interpretation.

[0032] Determine if a corresponding symbolic expression exists in the blockchain platform function interface. If it does, directly call the symbolic expression for symbol interpretation; otherwise, interpret the symbolic expression through the blockchain platform function interface, extract the symbolic expression corresponding to the symbol interpretation, and store it.

[0033] The blockchain platform model library is used for symbol interpretation, and the blockchain platform model library is pre-stored data. The blockchain platform function interface is used to call functions on the blockchain platform for symbol interpretation.

[0034] Secondly, the present invention provides a system for improving the accuracy of smart contract code defect detection, including a smart contract compiler, an abstract syntax tree parser, an intermediate language generator, a vulnerability detection module, a code analyzer, a hybrid execution heuristic strategy module, a hybrid execution verification module, and a smart contract vulnerability detection document generator;

[0035] The smart contract compiler is used to obtain the source code of the smart contract and to obtain the abstract syntax tree of the source code of the smart contract.

[0036] The abstract syntax tree parser is used to parse the abstract syntax tree to obtain the basic analysis information of the smart contract code.

[0037] The intermediate language generator is used to convert contract basic analysis information into target language code to obtain contract basic analysis information code.

[0038] The code analyzer is used to analyze the basic analysis information code of the contract to obtain advanced analysis information of the contract;

[0039] The vulnerability detection module is used to perform vulnerability rule matching based on the advanced contract analysis information and the basic contract analysis information to obtain the first vulnerability detection result.

[0040] The hybrid execution heuristic strategy module is used to symbolically mark the contract basic analysis information code based on the contract advanced analysis information to obtain the symbolically marked contract basic analysis information code.

[0041] The hybrid execution verification module is used to verify the security attributes of the contract basic analysis information code after symbol marking, and obtain the second vulnerability detection result;

[0042] The smart contract vulnerability detection document generator is used to generate vulnerability detection documents based on the first vulnerability detection result and the second vulnerability detection result.

[0043] Furthermore, it also includes a formal verification rule model library, which includes a security attribute model library and a blockchain platform model library;

[0044] The hybrid execution heuristic strategy module is specifically used to: execute the contract basic analysis information code after symbol marking; determine in real time whether the contract basic analysis information code satisfies the security attribute rules in the security attribute model library; if so, the contract basic analysis information code has no vulnerabilities, and the second vulnerability detection result is determined to be no vulnerability; otherwise, the code in the contract basic analysis information code that does not satisfy the security attribute rules is taken as the second vulnerability detection result; the security attribute model library includes at least one security attribute rule; during execution, it is determined in real time whether there is a symbol marking; if so, the symbol is interpreted and execution continues; otherwise, the contract basic analysis information code is converted into blockchain platform target code and executed; during execution, it is determined whether an execution condition is triggered; if so, the execution strategy corresponding to the execution condition is executed, and the contract basic analysis information code is executed with the execution strategy; otherwise, the contract basic analysis information code is executed. The execution conditions, execution strategies, and their relationships are all pre-stored data.

[0045] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0046] This invention provides a method and system for improving the accuracy of smart contract code defect detection. By verifying the vulnerability rules and security attributes of smart contract code, it performs vulnerability detection on smart contract code from multiple aspects, thereby improving the detection accuracy of smart contract code. Furthermore, by combining basic contract analysis information and advanced contract analysis information, it can perform a more comprehensive analysis of smart contract code, further enhancing the vulnerability detection accuracy of smart contract code. Attached Figure Description

[0047] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be considered as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort. In the drawings:

[0048] Figure 1 A flowchart of a method for improving the accuracy of smart contract code defect detection provided by the present invention;

[0049] Figure 2 This invention provides a schematic diagram of a system structure for improving the accuracy of smart contract code defect detection. Detailed Implementation

[0050] 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.

[0051] Example 1

[0052] like Figure 1 As shown, the present invention provides a method for improving the accuracy of smart contract code defect detection, comprising:

[0053] S11. Obtain the source code of the smart contract and the abstract syntax tree of the source code of the smart contract.

[0054] S12. Parse the abstract syntax tree to obtain the basic contract analysis information of the smart contract code.

[0055] Contract fundamental analysis information can include contract constants, variables, functions, inheritance relationships, and expressions corresponding to the smart contract code. Parsing the smart contract code into contract fundamental analysis information can better detect smart contract code vulnerabilities and achieve more comprehensive vulnerability detection.

[0056] S13. Convert the contract fundamental analysis information into target language code to obtain the contract fundamental analysis information code.

[0057] The target language code can be the machine language required for code analysis, so as to facilitate the analysis of the contract's basic analysis information code.

[0058] S14. Analyze the basic contract analysis information code to obtain advanced contract analysis information.

[0059] Advanced contract analysis information can refer to the relationships between contract constants, variables, functions, inheritance relationships, and expressions in the basic contract analysis information. For example, if there is a variable 'a', and a first function and a second function that include variable 'a', then during verification, one can verify whether there is a conflict between the first function and the second function when variable 'a' takes a fixed range of values, or verify whether the first function and the second function conform to vulnerability rules.

[0060] S15. Based on the advanced contract analysis information and the basic contract analysis information, perform vulnerability rule matching to obtain the first vulnerability detection result.

[0061] Vulnerability rules can be stored in a vulnerability rule base, which can include at least one vulnerability rule to detect vulnerabilities in smart contract code.

[0062] S16. Based on the advanced contract analysis information, the contract basic analysis information code is symbolically marked to obtain the symbolically marked contract basic analysis information code.

[0063] Marking variables in the code as symbolic variables ensures that the hybrid execution engine treats expressions associated with these symbolic variables as symbolic expressions. For example: a = 0; b = 0; c = a + b; if unmarked, the hybrid engine will actually execute c = 0. If a and b are marked as symbolic variables, the hybrid engine will execute c = a + b symbolically, where c is passively transformed into a symbolic value of a + b.

[0064] S17. Verify the security attributes of the contract basic analysis information code after the symbol is marked, and obtain the second vulnerability detection result.

[0065] Iterate through all program paths. If a program does not violate the security attribute specifications, the verification passes; otherwise, it returns the program path that violates the security attribute specifications and a counterexample.

[0066] S18. Generate a vulnerability detection document based on the results of the first vulnerability detection and the second vulnerability detection.

[0067] In this embodiment, after generating the vulnerability detection document based on the first vulnerability detection result and the second vulnerability detection result, the method further includes:

[0068] Based on the results of the first and second vulnerability detections, the vulnerability locations are marked in the smart contract source code.

[0069] In this embodiment, the abstract syntax tree is parsed to obtain the basic contract analysis information of the smart contract code, including:

[0070] The abstract syntax tree is parsed to extract contract constants, variables, functions, inheritance relationships, and expressions, and these constants, variables, functions, inheritance relationships, and expressions are used as the basic contract analysis information for smart contract code.

[0071] In this embodiment, the basic contract analysis information code is analyzed to obtain advanced contract analysis information, including:

[0072] Determine the relationships between contract constants, variables, functions, inheritance relationships, and expressions in the basic contract analysis information code, and use these relationships as the advanced contract analysis information.

[0073] For example, if we include constant c = 3, variable a > 1, function b = a + c, and function d = a + 2c, then there is a relationship between constant c = 3 and functions b = a + c and d = a + 2c, and there is a relationship between variable a > 1 and functions b = a + c and d = a + 2c.

[0074] In this embodiment, vulnerability rule matching is performed based on advanced contract analysis information and basic contract analysis information to obtain the first vulnerability detection result, including:

[0075] Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rules are matched in the vulnerability rule base. If there is a vulnerability rule that matches the advanced contract analysis information and the basic contract analysis information, the vulnerability corresponding to the vulnerability rule is taken as the first vulnerability detection result of the advanced contract analysis information and the basic contract analysis information.

[0076] Among them, there are multiple vulnerability rules in the vulnerability rule base.

[0077] In this embodiment, based on advanced contract analysis information, the contract basic analysis information code is symbolically marked to obtain the symbolically marked contract basic analysis information code, including:

[0078] Based on the advanced contract analysis information, the variables in the basic contract analysis information code are marked as symbolic variables, resulting in the symbolically marked basic contract analysis information code.

[0079] In this embodiment, the security attributes of the contract basic analysis information code after symbol marking are verified to obtain the second vulnerability detection result, including:

[0080] The contract basic analysis information code after execution symbol marking is used to determine in real time whether the contract basic analysis information code meets the security attribute rules in the security attribute model library. If it does, the contract basic analysis information code has no vulnerability, and the second vulnerability detection result is determined to be no vulnerability. Otherwise, the code in the contract basic analysis information code that does not meet the security attribute rules is used as the second vulnerability detection result. The security attribute model library includes at least one security attribute rule.

[0081] For example, if there exists a function a = b + c, and the security attribute requires a > 10, then the security attribute rule is not satisfied when b + c is less than 10. Alternatively, the security attribute rule is that the output of the first function must meet the input requirements of the second function, and if the output is not satisfied, then it can be considered that the security attribute rule is not satisfied.

[0082] During execution, the system continuously checks for the presence of symbolic markers. If a symbol is present, it interprets the marker and continues execution. Otherwise, it converts the contract's basic analysis information code into the blockchain platform's target code and executes it.

[0083] The contract's basic analysis information code is converted into the blockchain platform's target code to facilitate its actual execution. A true value refers to a variable that is always filled with a specific value during program execution. For example, an integer variable `a` can have a true value of 0, 1, or any other arbitrary integer. A symbolic value, on the other hand, represents a mathematically meaningful integer, covering all possible integer values, but does not represent a specific true value. For example: a = 0; b = 0; c = a + b; if unmarked, the hybrid engine's actual execution will result in c = 0, where c is still a specific true value of 0. If ab is marked as symbolic variables, the hybrid engine's symbolic execution will result in c = a + b, where c also passively becomes a symbolic value, with the value a + b, representing any possible integer value.

[0084] During execution, the process also includes: determining whether an execution condition is triggered; if so, executing the execution strategy corresponding to the execution condition and continuing to execute the contract basic analysis information code with the execution strategy; otherwise, continuing to execute the contract basic analysis information code. The execution conditions, execution strategies, and their relationships are all pre-stored data.

[0085] For example, by only symbolically marking and fragmenting the code related to the security attribute model library, it is still possible to ensure that the code related to security attributes can be fully traversed and formally verified even for complex smart contracts. The heuristic strategies of this strategy module can be continuously expanded or enriched to improve formal verification capabilities.

[0086] In this embodiment, symbol interpretation is performed, including:

[0087] Determine if a blockchain platform model library exists corresponding to the symbol. If it does, directly call the blockchain platform model library for symbol interpretation; otherwise, call the blockchain platform function interface for symbol interpretation.

[0088] Determine if a corresponding symbolic expression exists in the blockchain platform function interface. If it does, directly call the symbolic expression for symbol interpretation. Otherwise, interpret the symbolic expression through the blockchain platform function interface, extract the symbolic expression corresponding to the symbol interpretation, and store it.

[0089] Among them, the blockchain platform model library is used for symbol interpretation, and the blockchain platform model library is pre-stored data. The blockchain platform function interface is used to call functions on the blockchain platform for symbol interpretation.

[0090] Example 2

[0091] like Figure 2As shown, the present invention provides a system for improving the accuracy of smart contract code defect detection, including a smart contract compiler, an abstract syntax tree parser, an intermediate language generator, a vulnerability detection module, a code analyzer, a hybrid execution heuristic strategy module, a hybrid execution verification module, and a smart contract vulnerability detection document generator;

[0092] The smart contract compiler is used to obtain the source code of a smart contract and its abstract syntax tree.

[0093] In this embodiment, the Ethereum smart contract compiler Solc receives the smart contract source code, compiles it to obtain the Solidity smart contract source code abstract syntax tree, and sends it to the abstract syntax tree parser.

[0094] An abstract syntax tree parser is used to parse an abstract syntax tree to obtain basic contract analysis information of the smart contract code.

[0095] The abstract syntax tree parser receives the abstract syntax tree of the smart contract source code, parses out the basic contract analysis information such as contract constants, variables, functions, inheritance relationships, and expression lists in the smart contract code, and sends them to the vulnerability detection module and the intermediate language generator respectively.

[0096] The intermediate language generator is used to convert contract fundamental analysis information into target language code to obtain contract fundamental analysis information code.

[0097] The intermediate language generator receives basic contract information and converts it into intermediate language code that facilitates code analysis (such as taint analysis, data dependency analysis, etc.), and outputs it to the code analyzer and hybrid execution verification module.

[0098] The code analyzer is used to analyze the basic analysis information code of a contract to obtain advanced analysis information about the contract.

[0099] The code analyzer receives intermediate language code, performs pre-analysis, and obtains advanced contract analysis information such as contract code data dependency information and read / write information of different types of variables. This information is then output to the vulnerability detection module and the hybrid execution heuristic strategy module, respectively.

[0100] The vulnerability detection module is used to match vulnerability rules based on advanced contract analysis information and basic contract analysis information to obtain the first vulnerability detection result.

[0101] The vulnerability detection module receives basic contract analysis information and advanced contract analysis information. The matching engine of the vulnerability detection module performs defect code matching on the basic contract analysis information or advanced contract analysis information according to the vulnerability rules in the vulnerability rule base. Then, the matching information is sent to the smart contract vulnerability detection document generator to generate a defect code report. The source code mapping engine then locates the defect code to the specific location in the smart contract source code.

[0102] The vulnerability detection module includes a matching engine and a vulnerability rule base. The vulnerability rule base is formulated based on the characteristics of various vulnerability types in smart contracts, as well as basic and advanced contract analysis information. This rule base can be continuously expanded or refined. The matching engine performs defect code matching on the basic or advanced contract analysis information according to the vulnerability rules in the vulnerability rule base, and sends the matching information to the smart contract vulnerability detection document generator.

[0103] The hybrid execution heuristic strategy module is used to symbolically mark the contract basic analysis information code based on the contract advanced analysis information to obtain the symbolically marked contract basic analysis information code.

[0104] The intermediate language code is symbolically marked based on high-level contract analysis information, and a series of heuristic strategies are provided to improve the formal verification capability of the symbolic interpretation unit. For example, only the code parts related to the security attribute model library are symbolically marked and code fragmentation is performed. Even for complex smart contracts, it can still ensure that the code parts related to security attributes are traversed in their entirety and formally verified. The heuristic strategies of this strategy module can be continuously expanded or enriched to improve the formal verification capability.

[0105] The hybrid execution verification module is used to verify the security attributes of the contract basic analysis information code after symbol marking, and obtain the second vulnerability detection result.

[0106] The hybrid execution verification module receives intermediate language code from the intermediate language generator. First, it uses the relevant strategies of the hybrid execution heuristic module to symbolically mark the intermediate language code. Then, it performs hybrid execution on the received intermediate language code. If a symbol marker is encountered, the code is transferred to the symbol interpretation unit—the Ethereum symbolic execution virtual machine—for symbolic execution. To improve formal verification efficiency, the symbol interpretation unit prioritizes using the modeled Ethereum platform model library. For unmodeled blockchain platform parts, it can directly call Ethereum platform function interfaces and extract symbolic expressions to form a symbolic path cache. When the same blockchain platform function interface is called again under the same preconditions, the cached symbolic path can be used directly, thus saving symbolic expression extraction time. Otherwise, the code is input into the intermediate language compiler to obtain the Ethereum platform's EVM bytecode, and then input into the real execution unit—the Ethereum EVM virtual machine—for real execution. Finally, the verification result is sent to the smart contract vulnerability detection document generator to generate a defective code report. The source code mapping engine then locates the defective code to the specific location in the smart contract source code.

[0107] The hybrid execution verification module also includes an intermediate language editor, a symbol interpretation unit, a real execution unit, and a symbol path caching unit. The received intermediate language code undergoes hybrid execution. If a symbol marker is encountered, the code is transferred to the symbol interpretation unit for execution. To improve formal verification efficiency, the symbol interpretation unit prioritizes using the modeled blockchain platform model library. For unmodeled blockchain platform parts, it can directly call the blockchain platform function interface, extract symbolic expressions, and form a symbol path cache. When the same blockchain platform function interface is called again with the same preconditions, the cached symbol path can be used directly, thus saving symbolic expression extraction time. Otherwise, the code is input into the intermediate language compiler to obtain the blockchain platform target code, and then input into the real execution unit for execution. The symbol interpretation unit maintains the actual and symbolic values ​​of the smart contract state variables, and the actual values ​​of the symbol interpretation unit are kept synchronized with the contract state variable values ​​of the real execution unit to achieve reasonable switching between the two execution modes.

[0108] The smart contract vulnerability detection document generator is used to generate vulnerability detection documents based on the results of the first vulnerability detection and the results of the second vulnerability detection.

[0109] In this embodiment, a formal verification rule model library is also included, which includes a security attribute model library and a blockchain platform model library.

[0110] The hybrid execution heuristic strategy module is specifically used to execute the contract basic analysis information code after the symbol is marked, and to determine in real time whether the contract basic analysis information code meets the security attribute rules in the security attribute model library. If it does, the contract basic analysis information code has no vulnerability, and the second vulnerability detection result is determined to be no vulnerability. Otherwise, the code in the contract basic analysis information code that does not meet the security attribute rules is taken as the second vulnerability detection result.

[0111] The security attribute model library includes at least one security attribute rule. During execution, it is determined in real time whether a symbolic marker exists. If so, the symbol is interpreted and execution continues. Otherwise, the contract basic analysis information code is converted into the blockchain platform target code and executed. During execution, it is determined whether an execution condition is triggered. If so, the execution strategy corresponding to the execution condition is executed, and the contract basic analysis information code is executed using the execution strategy. Otherwise, the contract basic analysis information code is executed. The execution conditions, execution strategies, and their relationships are all pre-stored data.

[0112] This invention proposes a system to improve the accuracy of smart contract code defect detection. It effectively integrates code analysis technology, static analysis technology, and formal verification technology, thereby improving the detection accuracy and scalability of the smart contract code defect detection system.

[0113] This invention constructs an intermediate language generator and code analysis. The generated intermediate language code form is easy to integrate with more accurate program analysis techniques such as taint tracking and data dependency analysis in the code analyzer. The vulnerability detection module of this invention integrates the advanced contract analysis information output by the code analyzer and the basic contract analysis information output by the abstract syntax tree parser. Compared with the traditional method of simply searching and matching the abstract syntax tree of the code using a vulnerability rule base to find code defects, it has higher detection accuracy.

[0114] This invention constructs a code analyzer and a hybrid execution heuristic strategy module. By effectively integrating program analysis technology and hybrid formal verification technology, it realizes full path traversal and formal verification of code related to security attributes in complex smart contracts, thereby improving the accuracy of code defect detection in complex logic smart contracts.

[0115] This invention provides a method and system for improving the accuracy of smart contract code defect detection. By verifying the vulnerability rules and security attributes of smart contract code, it performs vulnerability detection on smart contract code from multiple aspects, thereby improving the detection accuracy of smart contract code. Furthermore, by combining basic contract analysis information and advanced contract analysis information, it can perform a more comprehensive analysis of smart contract code, further enhancing the vulnerability detection accuracy of smart contract code.

[0116] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is 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 improving the accuracy of smart contract code defect detection, characterized in that, include: Obtain the source code of the smart contract and its abstract syntax tree; The abstract syntax tree is parsed to obtain the basic contract analysis information of the smart contract code, including: parsing the contract constants, variables, functions, inheritance relationships and expressions of the abstract syntax tree, and using the contract constants, variables, functions, inheritance relationships and expressions as the basic contract analysis information of the smart contract code; The contract fundamental analysis information is converted into target language code to obtain the contract fundamental analysis information code; The contract basic analysis information code is analyzed to obtain the contract advanced analysis information, including: determining the relationship between contract constants, variables, functions, inheritance relationships and expressions in the contract basic analysis information code, and using this relationship as the contract advanced analysis information; Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rules are matched to obtain the first vulnerability detection result; Based on the advanced contract analysis information, the basic contract analysis information code is symbolically marked to obtain the symbolically marked basic contract analysis information code. The process involves verifying the security attributes of the symbol-marked contract basic analysis information code to obtain a second vulnerability detection result. This includes: executing the symbol-marked contract basic analysis information code and determining in real time whether the contract basic analysis information code satisfies the security attribute rules in the security attribute model library. If so, the contract basic analysis information code is considered vulnerability-free, and the second vulnerability detection result is determined to be vulnerability-free; otherwise, the code in the contract basic analysis information code that does not satisfy the security attribute rules is taken as the second vulnerability detection result. The security attribute model library includes at least one security attribute rule. During execution, the process involves determining in real time whether a symbol mark exists. If so, the symbol is interpreted, and execution continues; otherwise, the contract basic analysis information code is converted into blockchain platform target code and executed. The process also includes determining whether an execution condition is triggered. If so, the execution strategy corresponding to the execution condition is executed, and the contract basic analysis information code is executed using the execution strategy; otherwise, the contract basic analysis information code is executed. The execution conditions, execution strategies, and their relationships are all pre-stored data. Based on the first vulnerability detection result and the second vulnerability detection result, a vulnerability detection document is generated.

2. The method for improving the accuracy of smart contract code defect detection according to claim 1, characterized in that, After generating the vulnerability detection document based on the first vulnerability detection result and the second vulnerability detection result, it also includes: Based on the first vulnerability detection result and the second vulnerability detection result, mark the vulnerability location in the smart contract source code.

3. The method for improving the accuracy of smart contract code defect detection according to claim 2, characterized in that, Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rule matching is performed to obtain the first vulnerability detection result, including: Based on the advanced contract analysis information and the basic contract analysis information, vulnerability rules are matched in the vulnerability rule base. If there is a vulnerability rule that matches the advanced contract analysis information and the basic contract analysis information, the vulnerability corresponding to the vulnerability rule is taken as the first vulnerability detection result of the advanced contract analysis information and the basic contract analysis information. The vulnerability rule base contains multiple vulnerability rules.

4. The method for improving the accuracy of smart contract code defect detection according to claim 3, characterized in that, Based on the advanced contract analysis information, the contract basic analysis information code is symbolically marked to obtain the symbolically marked contract basic analysis information code, including: Based on the advanced contract analysis information, the variables in the basic contract analysis information code are marked as symbolic variables, resulting in the symbolically marked basic contract analysis information code.

5. The method for improving the accuracy of smart contract code defect detection according to claim 4, characterized in that, Perform symbol interpretation, including: Determine if a blockchain platform model library exists corresponding to the symbol. If it does, directly call the blockchain platform model library for symbol interpretation; otherwise, call the blockchain platform function interface for symbol interpretation. Determine if a corresponding symbolic expression exists in the blockchain platform function interface. If it does, directly call the symbolic expression for symbol interpretation; otherwise, perform symbol interpretation through the blockchain platform function interface, extract the symbolic expression corresponding to the symbol interpretation, and store it. The blockchain platform model library is used for symbol interpretation, and the blockchain platform model library is pre-stored data. The blockchain platform function interface is used to call functions on the blockchain platform for symbol interpretation.

6. A system for improving the accuracy of smart contract code defect detection, wherein the system is capable of executing the method for improving the accuracy of smart contract code defect detection as described in any one of claims 1 to 5, characterized in that, It includes a smart contract compiler, an abstract syntax tree parser, an intermediate language generator, a vulnerability detection module, a code analyzer, a hybrid execution heuristic module, a hybrid execution verification module, and a smart contract vulnerability detection document generator; The smart contract compiler is used to obtain the source code of the smart contract and to obtain the abstract syntax tree of the source code of the smart contract. The abstract syntax tree parser is used to parse the abstract syntax tree to obtain the basic analysis information of the smart contract code. The intermediate language generator is used to convert contract basic analysis information into target language code to obtain contract basic analysis information code. The code analyzer is used to analyze the basic analysis information code of the contract and obtain advanced analysis information of the contract. The vulnerability detection module is used to perform vulnerability rule matching based on the advanced contract analysis information and the basic contract analysis information to obtain the first vulnerability detection result. The hybrid execution heuristic strategy module is used to symbolically mark the contract basic analysis information code based on the contract advanced analysis information to obtain the symbolically marked contract basic analysis information code. The hybrid execution verification module is used to verify the security attributes of the contract basic analysis information code after symbol marking, and obtain the second vulnerability detection result; The smart contract vulnerability detection document generator is used to generate a vulnerability detection document based on the first vulnerability detection result and the second vulnerability detection result.

7. The system for improving the accuracy of smart contract code defect detection according to claim 6, characterized in that, It also includes a formal verification rule model library, which includes a security attribute model library and a blockchain platform model library; The hybrid execution heuristic strategy module is specifically used to execute the contract basic analysis information code after symbol marking, and to determine in real time whether the contract basic analysis information code meets the security attribute rules in the security attribute model library. If it does, the contract basic analysis information code has no vulnerabilities, and the second vulnerability detection result is determined to be no vulnerability. Otherwise, the code in the contract basic analysis information code that does not meet the security attribute rules is taken as the second vulnerability detection result. The security attribute model library includes at least one security attribute rule. During the execution process, it is determined in real time whether there are symbol markings. If so, the symbol is interpreted and execution continues. Otherwise, the contract basic analysis information code is converted into blockchain platform target code and executed. During execution, it is determined whether an execution condition is triggered. If so, the execution strategy corresponding to the execution condition is executed, and the contract basic analysis information code is executed again using the execution strategy. Otherwise, the contract basic analysis information code is executed again. The execution conditions, execution strategies and their relationships are all pre-stored data.

Citation Information

Patent Citations

  • Intelligent contract vulnerability detection method and device, equipment and storage medium

    CN114297663A