Intelligent contract threat transaction sequence generation method and system

Threat transaction sequences are generated through static analysis and dynamic behavior prediction technology, which solves dynamic security problems in the deployment and execution of smart contracts, improves security audit efficiency and the overall security of the contract, and enables in-depth analysis and analysis of complex interactive security challenges. deal with.

CN118709188AActive Publication Date: 2024-09-27GUANGZHOU INSTITUTE OF TECHNOLOY XIDIAN UNIVERSITY +3

Patent Information

Application Number
CN202410769995.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-27
Estimated Expiration
2044-06-14

AI Technical Summary

Technical Problem

Smart contracts face dynamic security issues during deployment and execution. Existing technologies are difficult to effectively handle complex transaction sequences and interactive behaviors, making security vulnerabilities difficult to identify and prevent.

Method used

Use static analysis and dynamic behavior prediction technology to generate threat transaction sequences, build function pools and transaction graphs through static code analysis and vulnerability detection, and combine to generate detailed threat transaction sequences to improve security audit efficiency and reduce security incidents.

Benefits of technology

Significantly improves the security and reliability of smart contracts. Through automated vulnerability detection and threat sequence generation, it reduces the burden of manual audits. It can complete security assessments of large-scale blockchain projects in a short time and conduct in-depth analysis of complex interactions. deep security challenges.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118709188A
    Figure CN118709188A
Patent Text Reader

Abstract

The invention provides a method and a system for generating a threat transaction sequence of an intelligent contract. Potential security holes in the intelligent contract are comprehensively identified and simulated by utilizing static analysis and dynamic behavior prediction technologies. According to the method, the targeted threat transaction sequence is generated, so that a possible attack path and actual utilization of contract vulnerabilities can be predicted and demonstrated, and developers are allowed to accurately repair and enhance the contract security. Through automatic vulnerability detection and threat sequence generation, the burden of manual auditing is greatly reduced, the auditing efficiency is remarkably improved, the security assessment of a large number of contracts can be completed in a short time, and the security requirements of large-scale block chain projects are effectively supported. In addition, the system designs a threat transaction sequence construction function especially for the complex interactivity of the smart contract, and can deeply analyze and solve deep security challenges occurring in contract interaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of blockchain technology and smart contract transactions, and relates to a method and system for generating a smart contract threat transaction sequence. Background Art

[0002] Smart contracts are programs based on blockchain technology that automatically execute, control or record legal events and actions registered on the blockchain according to preset conditions. The code of smart contracts is open, transparent, and cannot be tampered with. Once deployed, it cannot be changed, ensuring the automation of execution and the immutability of the contract. This technology is widely used in financial services, supply chain, law and other business fields because it can significantly reduce transaction costs and improve efficiency and security. Although smart contracts bring many benefits, their immutability also brings significant security risks. Any defects that initially exist in the contract code cannot be modified once deployed, which may lead to security vulnerabilities being maliciously exploited, resulting in economic losses or data leaks. In recent years, security vulnerabilities in smart contract platforms, such as The DAO attack and Parity wallet freezes, have demonstrated the severity of these problems.

[0003] Currently, the security of smart contracts is mainly tested through manual audits and automated security tools. Manual audits rely on the experience and knowledge of security experts, while automated tools such as static analysis tools identify common programming and logic errors by scanning contract code. Although these methods can identify potential security issues to a certain extent, they are mainly limited to static code analysis and it is difficult to effectively handle the complex behaviors of dynamic interactions when smart contracts are actually running in blockchain networks. The interaction between smart contracts and other contracts or external callers during execution may cause problems that are not predicted by static methods. For example, complex transaction sequences may trigger hidden contract behaviors, or external state changes that interact with contracts may change the results of contract execution. Summary of the invention

[0004] In order to solve the dynamic security problems that smart contracts may encounter in actual deployment and execution, a method is needed to generate possible threat transaction sequences. The purpose of the present invention is to provide a method and system for generating threat transaction sequences for smart contracts, which integrates static analysis and dynamic behavior prediction technology to identify security risks that smart contracts may encounter in actual operation and predict transaction sequences that may generate security risks, thereby improving the efficiency of security audits of smart contracts and reducing security incidents caused by vulnerabilities or design defects, especially in complex interactive environments.

[0005] The technical solution of the present invention is as follows: a method for generating a smart contract threat transaction sequence, the method comprising:

[0006] Obtain the smart contract source code that the user needs to pass and generate an ordered transaction sequence;

[0007] Preprocessing the smart contract source code, including cleaning, formatting and contract version upgrade;

[0008] Perform static code analysis and static vulnerability detection;

[0009] According to the analysis and detection results, three major function pools are constructed, including a write-only function pool, a read-write function pool, and a read-only function pool;

[0010] Based on the read-write function pool, the function transaction graph is constructed using dynamic behavior prediction technology;

[0011] Derive a complete and ordered transaction sequence pool from the function transaction graph, merge the function pool, and generate a threat transaction sequence;

[0012] Send detailed reports to users based on threat transaction sequences.

[0013] Accordingly, the smart contract source code is written in Solidity.

[0014] Accordingly, the smart contract source code preprocessing includes upgrading the contract code to the latest version of Solidity 0.8.0 and above to take advantage of the latest security features and language optimizations; deleting comments, blank lines, and outdated code segments in the contract to streamline the code; merging function modifiers and functions in the contract to simplify the code logic; setting variables whose access types are not explicitly declared to be public types; and deleting unused parameters in contract functions to further simplify the contract structure.

[0015] Accordingly, the static code analysis includes the following steps:

[0016] Based on the Solidity language specification, a smart contract syntax rule set is built to guide the parsing of source code;

[0017] Parse the smart contract source code and generate the corresponding abstract syntax tree (AST) to structure the various statements and expressions in the contract;

[0018] Traverse the abstract syntax tree to identify and extract key programming components such as function declarations, variable assignments, and control flow structures;

[0019] By analyzing the connections between nodes in AST, the dependencies between global variables and functions are determined, and potential threat functions are identified.

[0020] Accordingly, the static vulnerability detection adopts a general method that is applicable to all versions of smart contracts and is not limited to a specific Solidity version.

[0021] Accordingly, the elements of the smart contract grammar rules include keywords, data types, expressions, control structures, function declarations and contract structures.

[0022] Correspondingly, the parsing of the smart contract source code to generate the corresponding abstract syntax tree specifically involves performing lexical analysis on the smart contract source code, that is, scanning the source file from left to right and converting the character stream therein into characters that can no longer be divided; performing syntax analysis after the conversion is completed, and analyzing the converted character stream by using the constructed syntax rule set, that is, applying the syntax rules to the source program, thereby parsing the smart contract source code into an abstract syntax tree.

[0023] Correspondingly, the traversal of the abstract syntax tree is specifically to generate a listener base class based on the constructed syntax rules, analyze the contract syntax tree, and obtain various properties of the contract, including: when traversing to the variable declaration node, recording the scope, type and initialization information of the variable, tracking the declaration of all global variables and their use in the entire contract; when traversing to the function definition node, analyzing the function name, return type and parameters and the use of variables, identifying and classifying various functions in the contract.

[0024] Accordingly, the static vulnerability detection method includes a set of comprehensive detection rules and a static rule base based on these rules for comprehensive security assessment. The static rule base includes but is not limited to: reentrancy vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegated call vulnerability detection, randomness source vulnerability detection, phishing vulnerability detection, block timestamp vulnerability detection, contract scale detection bypass vulnerability detection, and signature replay vulnerability detection.

[0025] Accordingly, the threat transaction sequence generation is to further refine the read-write function pool and construct a detailed function transaction graph based on the dependencies between functions and potential security threats. The threat transaction sequence is formed by merging the read-only and write-only function sequences with the newly constructed valid sequence to form a comprehensive threat transaction sequence pool.

[0026] Accordingly, through the contract function transaction graph algorithm, a complete ordered transaction sequence is derived from the constructed function transaction graph; these transaction sequences are specially designed to cover as many potential security risk points as possible determined by static analysis and vulnerability detection; it also includes sorting and optimizing the generated transaction sequences to reduce the errors and deviations inherent in the static analysis process and ensure the accuracy and effectiveness of the transaction sequences; the sorting and optimization process involves adjusting the priority of the transaction sequences, giving priority to those transaction sequences involving high risks or critical vulnerabilities; the optimization strategy also includes optimizing the consumption caused by redundant transaction sequences by reducing redundant tests and merging similar test paths.

[0027] Furthermore, the use of dynamic behavior prediction technology to construct a function transaction graph specifically includes the following steps:

[0028] Define behavior rules, which include contract state changes, transaction sequence dependencies, and function call relationships, and determine the order in which functions interact with each other;

[0029] Use static analysis and static detection results to construct dynamic behavior sequences and single behavior sequences;

[0030] Add all behavior sequences to the prediction pool, merge similar transaction sequences to reduce redundancy;

[0031] Construct a directed acyclic graph to eliminate circular dependencies, thereby generating a directed acyclic transaction graph of contract functions.

[0032] In addition, in order to achieve the above-mentioned purpose, the present invention also proposes a smart contract threat transaction sequence generation system, including a client and a server;

[0033] Among them, the client is responsible for providing a user interface that allows users to upload and manage smart contract source code; and can receive transaction sequence analysis results and related reports returned by the server.

[0034] Server side: It includes a data processing module, which is responsible for the preprocessing of smart contract code, static code analysis, vulnerability detection and generation of transaction sequences; an analysis module, which performs static analysis and vulnerability detection based on the smart contract code uploaded by the client, and builds a function pool and function transaction graph; a transaction sequence optimization module, which is responsible for sorting and optimizing the generated transaction sequence to ensure test efficiency and accuracy; and a result feedback module, which returns the analysis report and optimized transaction sequence to the client.

[0035] Accordingly, the generated results include syntax error information resolved after preprocessing, warning information, detailed static vulnerability detection results, and generated threat transaction sequences; static vulnerability detection results include the function where the vulnerability is located, the location (row and column), the relevant vulnerability rules, a detailed description, and the recommended repair measures.

[0036] Accordingly, the client includes a static rule base management module, which implements visual management and editing of static detection rules; the static rule base management module of the client allows administrators to add, modify or delete static analysis and vulnerability detection rules through a graphical user interface; the module also supports the import and export functions of rules, allowing administrators to import externally written rules or export existing rules for sharing or backup;

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

[0038] (1) In the method for generating a threat transaction sequence for a smart contract of the present invention, after obtaining the input smart contract source code, the contract version is upgraded, merged and simplified, and the contract is compiled to locate the errors in the contract, and the contract errors are repaired according to the error information to obtain the latest high-version contract code without syntax errors. As can be seen from the above, this preprocessing process is the basis for ensuring the analysis and testing of smart contracts, so that subsequent security audits and the generation of threat transaction sequences are based on a stable and reliable code foundation. This step not only improves the quality of smart contracts, but also reduces security vulnerabilities that may be caused by code defects, and enhances overall security protection. Furthermore, this method allows smart contract developers and security auditors to more effectively identify and prevent potential security threats, by eliminating syntax and logic errors in advance, ensuring that the transaction sequence can accurately trigger potential risk points in the contract, and maximizing the security and reliability of smart contracts.

[0039] (2) In the method for generating threat transaction sequences for smart contracts of the present invention, the vulnerability-oriented threat sequence generation scheme uses the vulnerability information obtained from static analysis and static vulnerability detection to accurately construct transaction sequences that may trigger these vulnerabilities. This process not only improves the pertinence of the test, but also significantly enhances the effectiveness of security audits. By deeply analyzing the potential vulnerabilities in the contract and the relationship between these vulnerabilities and contract functions, a series of carefully designed transaction sequences can be generated to verify and trigger specific vulnerabilities. This method greatly optimizes resource usage, reduces redundant testing activities, and ensures that all key security risk points can be covered through testing. Therefore, vulnerability-oriented threat sequence generation is a key point in enhancing the security of smart contracts, providing smart contract developers with an efficient and systematic way to discover and fix possible security issues in advance, thereby significantly improving the overall security protection level of smart contracts.

[0040] The beneficial effects of the present invention are:

[0041] The present invention provides a method and system for generating threat transaction sequences for smart contracts, which use static analysis and dynamic behavior prediction technology to comprehensively identify and simulate potential security vulnerabilities in smart contracts. By generating targeted threat transaction sequences, this method can not only predict and demonstrate possible attack paths and their actual use of contract vulnerabilities, but also allow developers to accurately repair and enhance contract security. Automated vulnerability detection and threat sequence generation greatly reduce the burden of manual audits, significantly improve audit efficiency, and can complete security assessments of a large number of contracts in a relatively short period of time, effectively supporting the security needs of large-scale blockchain projects. In addition, the system has designed a threat transaction sequence construction function specifically for the complex interactivity of smart contracts, which can deeply analyze and solve the deep-level security challenges that arise in contract interactions. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to facilitate understanding by those skilled in the art, the present invention is further described below with reference to the accompanying drawings.

[0043] Figure 1 A schematic diagram of the overall process of a method for generating a smart contract threat transaction sequence provided by an embodiment of the present invention;

[0044] Figure 2 A contract preprocessing flow chart of a method for generating a smart contract threat transaction sequence provided by an embodiment of the present invention;

[0045] Figure 3 A flowchart of a threat transaction sequence pool generation method for a smart contract threat transaction sequence generation method provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to more deeply understand the purpose, technical solutions and advantages of the present invention, the following part will be described in detail through the drawings of the embodiments of the present invention. It should be understood that the embodiments discussed here only represent some implementation methods of the present invention, not all. The illustrations and descriptions contained herein generally show various components of the embodiments, which can be arranged according to different configurations and designs.

[0047] See attached Figure 1 The present invention provides an overall flow chart of a method for generating a threat transaction sequence for a smart contract provided by an embodiment of the present invention. Specifically, a user transmits a smart contract source code written in Solidity for which a threat transaction sequence needs to be generated through a client.

[0048] In the above embodiment, the input target of the method for generating threat transaction sequences for smart contracts is: Solidity, an object-oriented programming language created for implementing smart contracts, and the smart contract source code written in it. The method receives the smart contract source code provided by the user through a one-click fully automated process, and automatically performs a series of security audit steps such as preprocessing, static code analysis, and vulnerability detection. The automation of this process greatly improves the efficiency and reliability of smart contract security analysis and reduces the risks introduced by manual errors or omissions. The preprocessing step ensures the latest and cleanliness of the code, static analysis reveals potential weaknesses in the code, and vulnerability detection uses the latest security knowledge base to identify known and potential security threats. In addition, the method can not only discover and report problems in smart contracts, but also simulate and predict possible threat patterns in contract interaction scenarios by constructing function transaction graphs. The generated threat transaction sequence is further used to guide security testing, dynamically predicting the actions that attackers may take to ensure that the contract can robustly protect assets and data when attacked.

[0049] The preprocessing includes: upgrading the contract code to the latest version of Solidity 0.8.0 and above to take advantage of the latest security features and language optimizations; deleting comments, blank lines, and outdated code segments in the contract to streamline the code; merging function modifiers and functions in the contract to simplify the code logic; setting variables whose access types are not explicitly declared to public types to enhance the transparency of the contract; deleting unused parameters in contract functions to further simplify the contract structure.

[0050] After the preprocessing is completed, the information generated by the processing will be stored, mainly including: the initial smart contract source code transmitted by the user, the preprocessed smart contract code, the smart contract syntax errors detected during the preprocessing process, and syntax warning information.

[0051] See attached Figure 2 , is a contract preprocessing flow chart of a smart contract threat transaction sequence generation method provided by an embodiment of the present invention, which realizes contract upgrade and syntax error repair through continuous automated error repair, and sets a repair upper limit to prevent the continuous execution of the program and the occurrence of unrepairable situations. The error message and warning message may be empty when the user's contract code is standard.

[0052] In the above embodiment, an automated workflow is proposed for optimizing and verifying the source code of smart contracts written in Solidity. This workflow starts with the source code uploaded by the user and improves the security and efficiency of the code through a series of preprocessing steps. First, the source code is upgraded to the latest stable version of Solidity 0.8.0 or above. This step ensures that the code can take advantage of Solidity's latest security measures and performance improvements. Next, the contract code is automatically cleaned up to remove useless comments, blank lines, and obsolete code segments, simplifying the code structure and reducing potential security risks. Subsequently, the smart contract command line compiler-solc is used to compile the source code. Errors and warning messages generated during the compilation process are captured and parsed by the system for rapid identification and resolution of problems. This iterative compilation process continues until the source code no longer generates new compilation errors or reaches a predetermined number of iterations. Finally, the smart contract source code uploaded by the user, the preprocessed contract code, error messages during the processing, and warning messages are all saved and sent to the user at the end. This method provides a clear path for smart contract developers to ensure that their code meets high security standards while also optimizing the development process. The automated compilation and error detection process reduces the reliance on expertise and accelerates the transition of code from development to production environments. In this way, developers can ensure that their smart contracts have been rigorously tested and optimized before deployment to prevent possible security vulnerabilities in the future. Through the comparison display, problems with the contract can be intuitively discovered, making it easier for users to interpret and modify them.

[0053] The static analysis is a key step in generating threat transaction sequences for smart contracts, and its purpose is to identify potential security vulnerabilities and design flaws before the code is executed. This process includes several steps: building a grammar rule set for smart contracts; parsing the preprocessed source code to generate an abstract syntax tree (AST); and traversing the AST to analyze the code structure.

[0054] Among them, the construction of the smart contract syntax rule set is to develop a complete set of syntax rule sets based on the latest language specification of Solidity. This includes syntax rules for elements such as keywords, data types, expressions, control structures, function declarations, and contract structures. For example, keywords such as function and contract help identify the main structure of the code, while data types such as uint or string ensure the correctness of variable operations. Control structures such as if-else and loop statements define the flow control of the code, while function and contract declarations describe the function and composition of the contract.

[0055] Secondly, parse the preprocessed source code to generate an abstract syntax tree (AST). Perform lexical analysis on the smart contract source code, that is, scan the source file from left to right and split the character stream into characters (tokens) that cannot be split any further, similar to words in English or Chinese. After the conversion is completed, perform grammatical analysis, and analyze the converted token stream using the constructed grammar rule set, that is, apply the grammar rules to the source program, so as to parse the smart contract source code into an abstract syntax tree (AST).

[0056] Finally, traverse the AST to analyze the code structure. Generate a listener base class based on the constructed syntax rules, analyze the contract syntax tree, and obtain various properties of the contract, including: when traversing to the variable declaration node, you can record the scope, type, and initialization information of the variable, track the declaration of all global variables and their use in the entire contract; when traversing to the function definition node, you can analyze the function name, return type and parameters, and the use of variables, identify and classify various functions in the contract, such as view functions, pure functions, payment functions, etc.

[0057] At the same time, static rule libraries are used to detect vulnerabilities in the syntax tree by traversing the abstract syntax tree. These static rule libraries include but are not limited to: reentry vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegate call vulnerability detection, random source vulnerability detection, phishing vulnerability detection, block timestamp vulnerability detection, contract size detection bypass vulnerability detection, and signature replay vulnerability detection. At the same time, a detailed detection report is generated, including the detection hit function and the detection hit rule, vulnerability description, and solution.

[0058] In the above embodiment, the operation of static analysis of smart contracts covers the whole process from building a grammar rule set, parsing the source code to generate AST, to in-depth analysis by traversing AST. Static analysis can identify potential security vulnerabilities and design flaws before the smart contract is deployed. By discovering problems before the code is executed, the subsequent potential security risks and economic losses can be greatly reduced, especially in the blockchain environment, where contracts are difficult to modify once deployed. By generating and traversing AST, the analysis process is not limited to surface code review, but can go deep into the structure and logic level of the code. Such systematic analysis helps to ensure the quality of the code and improve the stability and reliability of the contract. Using a static rule base for vulnerability detection can cover a wide range of security issues, including but not limited to reentry attacks, abuse of self-destruction functions, hidden malicious code, etc. These rules can effectively identify known and potential security threats.

[0059] See attached Figure 3, a flowchart of a threat transaction sequence pool generation method for a smart contract threat transaction sequence generation method provided by an embodiment of the present invention. The function pool construction, for the classification and management of different types of functions in smart contracts, can construct three major function pools according to the static analysis results: a write-only function pool, a read-write function pool, and a read-only function pool. The write-only function pool contains those functions that only modify the blockchain state during execution. These functions are usually used to update the contract state, perform transfer operations, etc. The read-write function pool contains those functions that both read and modify the state. These functions usually read the current state of the contract first, then perform some operations based on the current state, and finally update the state. The read-only function pool contains those functions that only read the blockchain state without modifying the state during execution. These functions are usually used to query the contract state, return information to the user, etc.

[0060] Based on the read-write function pool constructed according to the analysis results and vulnerability detection results, the function transaction graph is constructed using dynamic behavior prediction technology. Through the collected static analysis data, static vulnerability detection data and the constructed read-write function pool, the dynamic behavior prediction model is used to predict and generate the threat transaction sequence between two functions. When the target is detected as a single behavior, it is directly added to the prediction pool. If not, a dynamic behavior sequence is constructed and then added to the prediction pool.

[0061] Among them, the dynamic behavior prediction model, this method is based on a set of detailed behavior rules and logical deduction, which can predict potential threats and performance issues before the contract is executed. First, a series of detailed behavior rules are defined. These rules are formulated according to the specific characteristics and interaction patterns of smart contracts, covering key factors such as contract state changes and transaction order dependencies. Then, by integrating the results of static analysis and static vulnerability detection results, these static data provide necessary support for logical deduction. Finally, using logical deduction, the most likely transaction sequence between two functions, as well as independent functions, that is, dynamic behavior sequence and single behavior sequence are constructed and added to the prediction pool. The generated prediction pool is merged and simplified to reduce the appearance of loops in subsequent graphs. Among them, the dynamic behavior sequence is the most likely transaction sequence between constructed functions, taking into account all dependencies and potential execution paths. The single behavior sequence is to determine the functions that are executed independently, that is, those that do not depend on the output of other functions.

[0062] Based on the prediction pool, a function transaction graph is constructed. A directed acyclic transaction graph structure is constructed, and the data constructed by the prediction pool is continuously added, where the graph nodes are functions, the edges of the transaction graph are directed edges pointing to the next function, and each piece of data in the transaction pool is represented as: the beginning is the head, the middle is the passed node, and the end is the tail. By analyzing the association between the head and the tail, as well as the association involved in the middle path, the graph is continuously improved and supplemented until the data is added, thereby constructing a complete directed transaction graph, which is also a directed acyclic graph (DAG).

[0063] In the above embodiment, by constructing: write-only function pool, read-write function pool and read-only function pool, different types of functions in smart contracts are classified and managed, which enhances the understanding and analysis of the behavior of each function. This classification helps to accurately identify functions that may introduce security risks, especially those functions that may become targets of attack due to state modification. In addition, the dynamic behavior prediction model introduced in the embodiment is based on behavioral rules and logical deduction. This method can predict potential threats and performance issues before the contract is executed, improving predictability and security. Furthermore, through this prediction information, a function transaction graph is constructed to reveal the interaction pattern and execution order between functions.

[0064] As described above, the final generation of the valid sequence pool. In a directed acyclic graph, the starting nodes are nodes with an in-degree of 0, which means that they do not depend on the output or state of other functions in the contract. These starting nodes are the starting point of the transaction sequence pool generation process, and usually correspond to functions that can be directly called by external parties (such as users or other contracts). A topological sorting algorithm is applied to determine the order of node access starting from the starting node, where for any directed edge uv from node u to node v, u appears before v in the sorting. This ensures that each function is called after its dependent functions, thus complying with the logical and execution order. Following the results of the topological sorting, a transaction sequence pool is generated. Each sequence starts from one or more starting nodes and gradually expands along the directed edges until it reaches the end node in the graph. These sequences represent possible execution paths in the contract, and each path is arranged according to the logical order of function calls.

[0065] The threat transaction sequence, by merging the read-only and write-only function sequences with the newly constructed valid sequences, forms a comprehensive threat transaction sequence pool, which can fully reflect all interactive actions and potential vulnerabilities of the contract.

[0066] According to the contract preprocessing results, static detection and threat transaction sequence construction results, a comprehensive threat transaction sequence generation result is finally formed and output to the user.

[0067] To achieve the above objectives, the present invention also implements a system for generating a smart contract threat transaction sequence, the system comprising a client and a server:

[0068] Client: Responsible for providing a user interface, allowing users to upload and manage smart contract source code, and receiving analysis results and reports returned by the server;

[0069] Server side: Data processing module, responsible for smart contract code preprocessing, static code analysis, vulnerability detection and transaction sequence generation; analysis module, performs static analysis and vulnerability detection based on the uploaded smart contract code, and builds function pool and function transaction graph; transaction sequence optimization module, responsible for sorting and optimizing the generated transaction sequence; result feedback module, returns the analysis report and optimized transaction sequence to the client.

[0070] The smart contract source code delivered by the user is written in Solidity.

[0071] Accordingly, the generated results include: syntax error information and warning information resolved after preprocessing; detailed static vulnerability detection results, including the function where the vulnerability is located, the location (row and column), the relevant vulnerability rules, a detailed description and suggested repair measures; and the generated threat transaction sequence.

[0072] The static rule base management described above realizes the visual management of static detection rules through a graphical user interface. Real-time detection rule updates and additions are realized through the user interface, which currently include but are not limited to reentry vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegated call vulnerability detection, random source vulnerability detection, phishing vulnerability detection, block timestamp vulnerability detection, contract size detection bypass vulnerability detection, and signature replay vulnerability detection.

[0073] In the above embodiment, the static rule base management system is designed as an efficient and user-friendly tool specifically for enhancing the security of smart contracts. Through the graphical user interface, the system realizes the visual management of static detection rules, and provides an intuitive way to process, update and maintain the rule set for smart contract security analysis. This design allows administrators to easily add or update detection rules in real time through the interface, so as to quickly respond to emerging security threats and vulnerabilities.

[0074] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0075] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not used to limit the present invention. Any technical personnel in this field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any brief modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the technical solution of the present invention.

Claims

1. A method for generating a smart contract threat transaction sequence, characterized by: The following steps are involved: Obtain the smart contract source code that the user needs to pass and generate an ordered transaction sequence; Preprocess the smart contract source code, including upgrading the contract code to the latest version of Solidity 0.8.0 and above to take advantage of the latest security features and language optimizations; deleting comments, blank lines, and outdated code segments in the contract; merging function decorators and functions in the contract to simplify code logic; Set variables whose access types are not explicitly declared to public types; delete unused parameters in contract functions to further simplify the contract structure; Perform static code analysis and static vulnerability detection; According to the analysis and detection results, a write-only function pool, a read-write function pool, and a read-only function pool are constructed; Based on the read-write function pool, the function transaction graph is constructed using dynamic behavior prediction technology; Derive a complete and ordered transaction sequence pool from the function transaction graph, and merge it with the read-only function pool and write-only function pool sequences to generate a comprehensive threat transaction sequence; Send detailed reports to users based on threat transaction sequences.

2. A method for generating a smart contract threat transaction sequence according to claim 1, characterized in that: The smart contract source code is written in Solidity.

3. The method for generating a smart contract threat transaction sequence according to claim 1, characterized in that: The static code analysis includes the following steps: Based on the Solidity language specification, a smart contract syntax rule set is built to guide the parsing of source code; Parse the smart contract source code and generate the corresponding abstract syntax tree to structure the various statements and expressions in the contract; Traversing the abstract syntax tree to identify and extract key programming constructs, including function declarations, variable assignments, and control flow structures; By analyzing the connections between nodes in the abstract syntax tree, the dependencies between global variables and functions are determined, and potential threat functions are identified.

4. A method for generating a smart contract threat transaction sequence according to claim 3, characterized in that: The elements of the smart contract grammar rules include keywords, data types, expressions, control structures, function declarations, and contract structures.

5. The method for generating a smart contract threat transaction sequence according to claim 3, characterized in that: The parsing of the smart contract source code to generate the corresponding abstract syntax tree specifically involves performing lexical analysis on the smart contract source code, that is, scanning the source file from left to right and converting the character stream therein into characters that cannot be split any more; performing syntax analysis after the conversion is completed, and analyzing the converted character stream by using the constructed syntax rule set, that is, applying the syntax rules to the source program, thereby parsing the smart contract source code into an abstract syntax tree.

6. A method for generating a smart contract threat transaction sequence according to claim 3, characterized in that: The traversal of the abstract syntax tree is specifically to generate a listener base class based on the constructed syntax rules, analyze the contract syntax tree, and obtain various properties of the contract, including: when traversing to the variable declaration node, recording the scope, type and initialization information of the variable, tracking the declaration of all global variables and their use in the entire contract; when traversing to the function definition node, analyzing the function name, return type and parameters and the use of variables, identifying and classifying various functions in the contract.

7. The method for generating a smart contract threat transaction sequence according to claim 1, characterized in that: The static vulnerability detection includes a set of comprehensive detection rules and a static rule base based on these rules. The static rule base includes reentry vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegated call vulnerability detection, randomness source vulnerability detection, phishing vulnerability detection, block timestamp vulnerability detection, contract scale detection bypass vulnerability detection and signature replay vulnerability detection.

8. The method for generating a smart contract threat transaction sequence according to claim 1, characterized in that: The use of dynamic behavior prediction technology to construct a function transaction graph specifically includes the following steps: Define behavior rules, which include contract state changes, transaction sequence dependencies, and function call relationships, and determine the order in which functions interact with each other; Use static analysis and static detection results to construct dynamic behavior sequences and single behavior sequences; Add all behavior sequences to the prediction pool, merge similar transaction sequences to reduce redundancy; Construct a directed acyclic graph to eliminate circular dependencies, thereby generating a directed acyclic transaction graph of contract functions.

9. A smart contract threat transaction sequence generation system, applied to a smart contract threat transaction sequence generation method as claimed in any one of claims 1 to 8, characterized in that: It includes client and server, where: The client is responsible for providing an interface for users to upload and manage smart contract source code, and receiving transaction sequence analysis results and related reports returned by the server; The server side includes a data processing module, an analysis module, a transaction sequence optimization module and a result feedback module; wherein: The data processing module is responsible for smart contract code preprocessing, static code analysis, static vulnerability detection and transaction sequence generation; The analysis module constructs a write-only function pool, a read-write function pool, a read-only function pool and a function transaction graph based on static code analysis and static vulnerability detection; The transaction sequence optimization module is responsible for sorting and optimizing the generated transaction sequence to ensure test efficiency and accuracy; The result feedback module returns the analysis report and the optimized transaction sequence to the client.

10. A smart contract threat transaction sequence generation system according to claim 9, characterized in that: The client also includes a management module for the static rule library, which is used for visual management and editing of static detection rules, and supports administrators to add, modify or delete static code analysis and static vulnerability detection rules through a graphical user interface; the management module also supports the import and export functions of rules, and supports administrators to import externally written rules or export existing rules for sharing or backup.

Citation Information

Patent Citations

  • Cross-contract reentry attack detection method and system

    CN115017515A

  • Intelligent contract reentry vulnerability detection method based on static and dynamic analysis

    CN115098863A

  • Ethereum smart contract security test method

    CN115114166A

Cited By

  • Intelligent contract vulnerability automatic repairing method and system based on vulnerability report

    CN119597326A