Smart contract threat transaction sequence generation method and system

By integrating static analysis and dynamic behavior prediction technology to generate smart contract threat transaction sequences, the problem of difficulty in identifying dynamic interaction security risks of smart contracts in existing technologies is solved, efficient security audits and vulnerability repairs are achieved, and the security and reliability of contracts are improved.

CN118709188BActive Publication Date: 2025-10-21GUANGZHOU INSTITUTE OF TECHNOLOY XIDIAN UNIVERSITY +3
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively identify and predict potential security risks during the dynamic interaction of smart contracts within blockchain networks, while static analysis methods are insufficient to cover hidden behaviors arising from complex transaction sequences.

Method used

By integrating static analysis and dynamic behavior prediction technology, smart contract threat transaction sequences are generated, including preprocessing, static code analysis, building function pools and function transaction graphs, identifying potential security risks and generating threat transaction sequences.

Benefits of technology

It improves the efficiency of smart contract security audits, can identify and repair potential security vulnerabilities in a short time, and enhance the security and reliability of contracts, especially in complex interactive environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118709188B_ABST
    Figure CN118709188B_ABST
Patent Text Reader

Abstract

The application provides a smart contract threat transaction sequence generation method and system, which comprehensively identifies and simulates potential security vulnerabilities in smart contracts by using static analysis and dynamic behavior prediction technology. This method generates targeted threat transaction sequences, which not only predict and demonstrate possible attack paths and their actual exploitation of contract vulnerabilities, but also allow developers to make precise repairs and enhance contract security. Automated vulnerability detection and threat sequence generation significantly reduces the burden of manual audits, significantly improves audit efficiency, and can complete security evaluation of a large number of contracts in a short time, effectively supporting the security needs of large-scale blockchain projects. In addition, the system designs a threat transaction sequence construction function specifically for the complex interactivity of smart contracts, which can deeply analyze and solve deep-seated security challenges 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 blockchain-based programs that automatically execute, control, or record legal events and actions registered on the blockchain, based on pre-set conditions. The code of smart contracts is transparent, tamper-proof, and once deployed, cannot be altered, ensuring automated execution and the immutability of the contract. This technology is widely used in financial services, supply chains, law, and other business sectors because it can significantly reduce transaction costs and improve efficiency and security. While smart contracts offer many benefits, their immutability also poses significant security risks. Any initial flaws in the contract code, once deployed, cannot be corrected, potentially leading to malicious exploitation and resulting in financial losses or data breaches. Recent incidents involving security vulnerabilities in smart contract platforms, such as The DAO attack and the Parity wallet freeze, have demonstrated the severity of these issues.

[0003] Currently, the security of smart contracts is primarily monitored 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, scan contract code to identify common programming and logic errors. While these methods can identify potential security issues to a certain extent, they are primarily limited to static code analysis and struggle to effectively address the complex dynamic interactions of smart contracts during actual operation in blockchain networks. During execution, interactions between smart contracts and other contracts or external callers can lead to issues unforeseen by static methods. For example, complex transaction sequences can trigger hidden contract behavior, or external state changes interacting with the contract can alter the outcome of contract execution. Summary of the Invention

[0004] To address the dynamic security issues that smart contracts may encounter during their actual deployment and execution, a method is needed to generate possible threat transaction sequences. This invention aims to provide a method and system for generating threat transaction sequences for smart contracts. By integrating static analysis and dynamic behavior prediction techniques, these methods are used to identify security risks that smart contracts may encounter during actual operation and predict transaction sequences that may generate security risks. This approach improves the efficiency of smart contract security audits and reduces security incidents caused by vulnerabilities or design flaws, particularly 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 required by the user 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] Based on the analysis and detection results, three 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, a 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 preprocessing of the smart contract source code 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 the AST, the dependency relationship between global variables and functions is 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] Accordingly, the parsing of the smart contract source code to generate the corresponding abstract syntax tree specifically involves performing a 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 split; after the conversion is completed, a syntax analysis is performed, and the converted character stream is analyzed by using the constructed syntax rule set, that is, the syntax rules are applied to the source program, thereby parsing the smart contract source code into an abstract syntax tree.

[0023] Accordingly, 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 usage in the entire contract; when traversing to the function definition node, analyzing the function name, return type and parameters and the usage 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 size 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 identified through 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 construction of the function transaction graph using the dynamic behavior prediction technology specifically includes the following steps:

[0028] Define behavioral rules, including 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 preprocessing the smart contract code, static code analysis, vulnerability detection, and generating 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, location (row and column), related vulnerability rules, detailed description and recommended repair measures.

[0036] Accordingly, the client includes a static rule base management module that enables 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 rule import and export functions, allowing administrators to import externally written rules or export existing rules for sharing or backup.

[0037] The present invention has the following advantages and effects compared to the prior art:

[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 errors in the contract. 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, thereby enhancing 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, it ensures that the transaction sequence can accurately trigger potential risk points in the contract, thereby maximizing the security and reliability of smart contracts.

[0039] (2) In the smart contract threat transaction sequence generation method 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 the security audit. By deeply analyzing the potential vulnerabilities in the contract and the relationship between these vulnerabilities and the contract functions, a series of carefully designed transaction sequences can be generated to verify and trigger specific vulnerabilities. This method greatly optimizes resource utilization, 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 for 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] This invention provides a method and system for generating threat transaction sequences for smart contracts, leveraging static analysis and dynamic behavior prediction techniques to comprehensively identify and simulate potential security vulnerabilities in smart contracts. By generating targeted threat transaction sequences, this method not only predicts and demonstrates possible attack paths and their actual exploitation of contract vulnerabilities, but also allows developers to precisely repair and enhance contract security. Automated vulnerability detection and threat sequence generation significantly reduces the burden of manual audits, significantly improves audit efficiency, and can complete security assessments for a large number of contracts in a relatively short period of time, effectively supporting the security requirements of large-scale blockchain projects. Furthermore, the system incorporates a threat transaction sequence construction function specifically designed to address the complex interactivity of smart contracts, enabling in-depth analysis and resolution of deep-seated security challenges arising from contract interactions. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] 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 pre-processing 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 by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] To provide a deeper understanding of the objectives, technical solutions, and advantages of the present invention, the following sections will provide a detailed description of embodiments of the present invention with reference to the accompanying drawings. It should be understood that the embodiments discussed herein represent only some, and not all, implementations of the present invention. The illustrations and descriptions contained herein generally illustrate various components of the embodiments, which may be arranged in various configurations and designs.

[0047] See attached Figure 1 This is a schematic diagram of the overall process 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 the smart contract source code written in Solidity for which a threat transaction sequence needs to be generated through a client.

[0048] In the above-mentioned embodiment, the method for generating threat transaction sequences for smart contracts takes as input the source code of a smart contract written in Solidity, an object-oriented programming language created for implementing smart contracts. This method uses a one-click, fully automated process to receive user-provided smart contract source code and automatically performs a series of security audit steps, including preprocessing, static code analysis, and vulnerability detection. This automated process significantly improves the efficiency and reliability of smart contract security analysis, reducing the risks introduced by manual errors or omissions. The preprocessing step ensures the code is up-to-date and clean, static analysis reveals potential weaknesses in the code, and vulnerability detection leverages the latest security knowledge base to identify known and potential security threats. Furthermore, this method not only discovers and reports issues in smart contracts but also simulates and predicts potential threat patterns in contract interaction scenarios by constructing function transaction graphs. The generated threat transaction sequences are further used to guide security testing, dynamically predicting potential attacker actions 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 with undeclared access types to public types to enhance the transparency of the contract; and deleting unused parameters in contract functions to further simplify the contract structure.

[0050] After preprocessing is completed, the generated information will be stored, mainly including: the initial smart contract source code passed 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 This is a contract preprocessing flow chart for a method for generating a smart contract threat transaction sequence, as provided by an embodiment of the present invention. This method implements contract upgrades and syntax error repairs through continuous automated error repair, while also setting a repair limit to prevent continued program execution and the occurrence of unrepairable situations. Error and warning messages may be empty when the user's contract code is standard.

[0052] The above embodiment proposes an automated workflow for optimizing and validating smart contract source code written in Solidity. Starting with user-uploaded source code, this workflow enhances code security and efficiency through a series of preprocessing steps. First, the source code is upgraded to the latest stable version of Solidity, 0.8.0 or later. This ensures that the code leverages Solidity's latest security measures and performance improvements. Next, the contract code is automatically cleaned up, removing unused comments, blank lines, and obsolete code sections, simplifying the code structure and reducing potential security risks. Subsequently, the source code is compiled using the smart contract command-line compiler, solc. Errors and warnings generated during the compilation process are captured and parsed by the system, enabling rapid identification and resolution of issues. This iterative compilation process continues until the source code generates no new compilation errors or a predetermined number of iterations is reached. Finally, the user-uploaded smart contract source code, preprocessed contract code, and any error and warning messages generated during the compilation process are saved for final delivery to the user. This approach provides smart contract developers with a clear path to ensure their code meets high security standards while also streamlining the development process. Automated compilation and error detection processes reduce reliance on specialized knowledge and accelerate the transition of code from development to production environments. This way, developers can ensure their smart contracts have been rigorously tested and optimized before deployment to prevent future security vulnerabilities. By displaying the comparison results, problems with the contract can be intuitively identified, making it easier for users to interpret and modify them.

[0053] Static analysis is a key step in generating threat transaction sequences for smart contracts. Its purpose is to identify potential security vulnerabilities and design flaws before code execution. This process includes several steps: building a set of grammatical rules for the smart contract; parsing the preprocessed source code to generate an abstract syntax tree (AST); and traversing the AST to analyze the code structure.

[0054] The construction of the smart contract syntax rule set involves developing a comprehensive set of rules based on the latest Solidity language specification. This includes syntax rules for keywords, data types, expressions, control structures, function declarations, contract structure, and other elements. For example, keywords such as "function" and "contract" help identify the main structure of the code, while data types such as "uint" and "string" ensure the correctness of variable operations. Control structures such as "if-else" and "loop" statements define the flow of control in the code, while function and contract declarations describe the functionality and composition of the contract.

[0055] Secondly, the preprocessed source code is parsed to generate an abstract syntax tree (AST). Lexical analysis is performed on the smart contract source code, which involves scanning the source file from left to right and segmenting the character stream into indivisible characters (tokens), similar to words in English or Chinese. After the conversion is complete, syntactic analysis is performed. The converted token stream is analyzed using a constructed set of grammatical rules, applying the grammatical rules to the source program, thereby parsing the smart contract source code into an abstract syntax tree (AST).

[0056] Finally, the AST is traversed to analyze the code structure. A listener base class based on the constructed grammatical rules is generated to analyze the contract syntax tree and obtain various properties of the contract. These include: when traversing to a variable declaration node, the scope, type, and initialization information of the variable can be recorded, and the declaration of all global variables and their usage throughout the contract can be tracked; when traversing to a function definition node, the function name, return type, parameters, and variable usage can be analyzed to identify and classify various functions in the contract, such as view functions, pure functions, payment functions, etc.

[0057] A static rule library is also used to perform vulnerability detection on the syntax tree during traversal of the abstract syntax tree. This static rule library includes, but is not limited to, detection of reentrancy vulnerabilities, self-destruction vulnerabilities, hidden code vulnerabilities, delegated call vulnerabilities, randomness source vulnerabilities, phishing vulnerabilities, block timestamp vulnerabilities, contract size detection bypass vulnerabilities, and signature replay vulnerabilities. A detailed detection report is also generated, including the functions hit by the detection, the detection rules, vulnerability descriptions, and solutions.

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

[0059] See attached Figure 3, a flowchart for generating a threat transaction sequence pool for a method for generating a threat transaction sequence for a smart contract provided by an embodiment of the present invention. The function pool construction, based on the classification and management of different types of functions in a smart contract and based on the results of static analysis, can construct three major function pools: a write-only function pool, a read-write function pool, and a read-only function pool. The write-only function pool contains functions that only modify the blockchain state during execution. These functions are typically used for updating contract status, performing transfer operations, etc. The read-write function pool contains functions that both read and modify the state. These functions typically first read the current state of the contract, then perform operations based on the current state, and ultimately update the state. The read-only function pool contains functions that only read the blockchain state during execution without modifying it. These functions are typically used for querying contract status, returning information to users, etc.

[0060] Based on the read-write function pool constructed based on analysis and vulnerability detection results, a function transaction graph is constructed using dynamic behavior prediction technology. Using the collected static analysis data, static vulnerability detection data, and the constructed read-write function pool, a dynamic behavior prediction model is then used to predict the threat transaction sequence between each function. If a 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] The dynamic behavior prediction model, based on a detailed set of behavioral rules and logical reasoning, can predict potential threats and performance issues before contract execution. First, a comprehensive set of behavioral rules is defined. These rules are tailored to the specific characteristics and interaction patterns of smart contracts, covering key factors such as contract state changes and transaction sequence dependencies. Next, by integrating static analysis results and static vulnerability detection results, this static data provides the necessary support for logical reasoning. Finally, using logical reasoning, the most likely transaction sequences between two functions, as well as independent functions, are constructed—dynamic behavior sequences and single behavior sequences—and added to the prediction pool. The resulting prediction pool is merged and simplified to reduce loops in subsequent graphs. The dynamic behavior sequence constructs the most likely transaction sequence between functions, taking into account all dependencies and potential execution paths. The single behavior sequence determines independently executed functions—those that do not depend on the outputs of other functions.

[0062] Based on the prediction pool, a function transaction graph is constructed. A directed acyclic transaction graph structure is constructed, and data from the prediction pool is continuously added. Graph nodes are functions, and transaction graph edges are directed edges pointing to the next function. Each piece of data in the transaction pool is represented as: the beginning is the head, the middle is the nodes passed through, and the end is the tail. By analyzing the connections between the head and tail, as well as the connections involved in the intermediate paths, the graph is continuously improved and supplemented until all data is added, thus constructing a complete directed transaction graph, which is also a directed acyclic graph (DAG).

[0063] In the above embodiments, by constructing write-only function pools, read-write function pools, and read-only function pools, different types of functions in smart contracts are classified and managed, enhancing understanding and analysis of each function's behavior. This classification helps accurately identify functions that may introduce security risks, particularly those that may become targets of attack due to state modifications. Furthermore, the dynamic behavior prediction model introduced in the embodiments is based on behavioral rules and logical deduction. This approach can predict potential threats and performance issues before contract execution, improving predictability and security. Furthermore, using this predicted information, a function transaction graph is constructed, revealing the interaction patterns and execution order between functions.

[0064] As described above, the valid sequence pool is finally generated. In a directed acyclic graph, start nodes are nodes with an in-degree of 0, meaning they do not depend on the outputs or states of other functions in the contract. These start nodes are the starting point for the transaction sequence pool generation process and typically 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 node access order starting from the start 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, the transaction sequence pool is generated. Each sequence begins from one or more start nodes and gradually expands along the directed edges until it reaches the terminal node in the graph. These sequences represent possible execution paths in the contract, each path arranged according to the logical order of function calls.

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

[0066] Based on 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 a 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, location (row and column), related vulnerability rules, detailed description and recommended repair measures; and generated threat transaction sequence.

[0072] The static rule base management described above implements visual management of static detection rules through a graphical user interface. Real-time detection rule updates and additions are possible through the user interface. Currently, these include but are not limited to reentrancy vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegate call vulnerability detection, randomness 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-mentioned embodiments, the static rule base management system is designed as an efficient, user-friendly tool specifically for enhancing the security of smart contracts. By visually managing static detection rules through a graphical user interface, the system provides an intuitive way to manage, update, and maintain the rule set used for smart contract security analysis. This design allows administrators to easily add or update detection rules in real time through the interface, enabling rapid response to emerging security threats and vulnerabilities.

[0074] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing module, each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.

[0075] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been disclosed as above in terms of a preferred embodiment, it is not intended to limit the present invention. Any person skilled in the art can, without departing from the scope of the technical solution of the present invention, make some changes or modifications to equivalent embodiments using the technical contents disclosed above. 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 required by the user and generate an ordered transaction sequence; Preprocess the smart contract source code. This includes upgrading the contract code to the latest version of Solidity, 0.8.0 or later, to take advantage of the latest security features and language optimizations; removing comments, blank lines, and outdated code snippets from the contract; and merging function decorators and functions in the contract to simplify the code logic. Set variables without explicitly declared access types to public types; delete unused parameters in contract functions to further simplify the contract structure; Perform static code analysis and static vulnerability detection; Based on 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, a function transaction graph is constructed using dynamic behavior prediction technology; The method of constructing a function transaction graph using dynamic behavior prediction technology specifically includes the following steps: Define behavioral rules, including 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. Based on the dependencies between functions and potential security threats, generate a directed acyclic transaction graph of contract functions, i.e., a function transaction graph. 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. The 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 an 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 dependency relationship between global variables and functions is determined, and potential threat functions are identified.

4. The 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 a lexical analysis on the smart contract source code, i.e., scanning the source file from left to right and converting the character stream therein into characters that can no longer be split; after the conversion is completed, a syntax analysis is performed, in which the converted character stream is analyzed by using a constructed syntax rule set, i.e., the syntax rules are applied to the source program, thereby parsing the smart contract source code into an abstract syntax tree.

6. The method for generating a smart contract threat transaction sequence according to claim 3, characterized in that: The traversal of the abstract syntax tree specifically generates a listener base class based on the constructed syntax rules, analyzes the contract syntax tree, and obtains various properties of the contract, including: when traversing to a variable declaration node, recording the scope, type, and initialization information of the variable, tracking the declaration of all global variables and their usage in the entire contract; when traversing to a function definition node, analyzing the function name, return type and parameters, and the usage of variables, and 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 reentrancy vulnerability detection, self-destruction vulnerability detection, hidden code vulnerability detection, delegate call vulnerability detection, randomness source vulnerability detection, phishing vulnerability detection, block timestamp vulnerability detection, contract size detection bypass vulnerability detection and signature replay vulnerability detection.

8. A system for generating a smart contract threat transaction sequence, applied to a method for generating a smart contract threat transaction sequence according to any one of claims 1 to 7, 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 sequences to ensure testing efficiency and accuracy; The result feedback module returns the analysis report and the optimized transaction sequence to the client.

9. The smart contract threat transaction sequence generation system according to claim 8, 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, supporting 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