Smart contract security detection method and related device

Through the security detection methods of smart contracts, including source code collection, syntax analysis and fuzzy testing, the complexity and efficiency of smart contract security testing are solved, and efficient security and stability detection is achieved.

CN116861443BActive Publication Date: 2025-02-14JIANGXI KAICHUANG DIGITAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310898239.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-21
Publication Date
2025-02-14
Estimated Expiration
2043-07-21

AI Technical Summary

Technical Problem

The complexity and dynamic nature of smart contracts bring great challenges to security testing. Existing security testing methods and tools are difficult to fully cover various security issues of smart contracts, and the development cycle is short, so it requires quick response and resolution of security. question.

Method used

Provide a security detection method for smart contracts, including source code collection, token sequence recognition, syntax analysis, contract logic analysis, data sensitivity analysis, test case construction and fuzz testing, and comprehensive and in-depth security detection is carried out through these technical links.

Benefits of technology

Through comprehensive security detection links, the vulnerabilities and hidden dangers in the contract can be effectively discovered, the security and stability of the contract can be improved, and possible risk points and problems can be quickly identified, and the testing efficiency and accuracy can be improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116861443B_ABST
    Figure CN116861443B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of security technology, and discloses a security detection method and related devices for smart contracts, which are used to improve the accuracy and efficiency of smart contract security detection. The method includes: collecting source code of a target smart contract to obtain the source code of the target smart contract; identifying a token sequence of the source code to determine the target token sequence; performing syntax analysis on the source code through the target token sequence to generate syntax analysis results, performing contract logic analysis on the source code to generate contract logic; performing data sensitivity analysis on the target smart contract through the contract logic to generate sensitivity analysis results; matching sensitive data types through the sensitivity analysis results, and determining test targets through sensitive data types; constructing test cases through the test targets to generate corresponding test cases; performing fuzzy testing on the target smart contract through the test cases to generate fuzzy testing results, and generating a security detection report through the fuzzy testing results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of security technology, and in particular to a security detection method and related device for smart contracts. Background Art

[0002] At present, with the continuous development and application of blockchain technology and smart contracts, the security issues of smart contracts have gradually attracted people's attention. Faced with the ever-changing network environment and attack methods, traditional security testing methods are no longer sufficient to meet the security needs of smart contracts, so it is necessary to develop new smart contract security testing technologies. This solution includes multiple technical links such as source code collection, token sequence recognition, syntax analysis, contract logic analysis, sensitivity analysis, test case construction and fuzz testing, and combines the specific characteristics and security requirements of smart contracts for targeted processing.

[0003] At present, there are still some shortcomings in smart contract security testing technology. For example, the complexity and dynamism of smart contracts pose great challenges to security testing; existing security testing methods and tools are still difficult to fully cover various security issues of smart contracts; at the same time, the development cycle of smart contracts is short, and security issues need to be responded to and resolved quickly, so it is necessary to develop more efficient and faster security testing tools and technologies to ensure the security and reliability of smart contracts. In the future, with the continuous development and popularization of blockchain technology, smart contract security testing technology will continue to improve and improve to adapt to new security needs and challenges. Summary of the invention

[0004] The present invention provides a smart contract security detection method and related devices, which are used to improve the accuracy and efficiency of smart contract security detection.

[0005] A first aspect of the present invention provides a security detection method for a smart contract, which includes: collecting source code of a target smart contract to obtain the source code of the target smart contract; identifying a token sequence of the source code to determine a target token sequence; performing syntax analysis on the source code through the target token sequence to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed; when the syntax analysis result is verification passed, performing contract logic analysis on the source code to generate corresponding contract logic; performing data sensitivity analysis on the target smart contract through the contract logic to generate a sensitivity analysis result; matching the corresponding sensitive data type through the sensitivity analysis result, and at the same time, determining a test target through the sensitive data type; constructing a test case through the test target to generate a corresponding test case; performing fuzzy testing on the target smart contract through the test case to generate a fuzzy testing result, and generating a security detection report through the fuzzy testing result.

[0006] In combination with the first aspect, in a first implementation of the first aspect of the present invention, the source code collection of the target smart contract to obtain the source code of the target smart contract includes: analyzing the source code storage location of the target smart contract to obtain the source code storage location, and at the same time, performing hash value matching on the target smart contract to determine the target hash value; performing database matching based on the source code storage location to determine the source code database corresponding to the smart contract; and collecting the source code corresponding to the target smart contract from the source code database based on the target hash value.

[0007] In combination with the first aspect, in a second implementation of the first aspect of the present invention, the source code is parsed using the target token sequence to generate a grammatical analysis result, wherein the grammatical analysis result includes verification passed and verification failed, including: constructing a syntax tree using the target token sequence to generate an abstract syntax tree; performing root node analysis on the abstract syntax tree to obtain a syntax tree node set; performing syntax detection on each syntax tree node in the syntax tree node set to generate a grammatical analysis result, wherein the grammatical analysis result includes verification passed and verification failed.

[0008] In combination with the second implementation of the first aspect, in the third implementation of the first aspect of the present invention, when the syntax analysis result passes the verification, the source code is subjected to contract logic analysis to generate the corresponding contract logic, including: when the syntax analysis result passes the verification, the syntax tree node set is subjected to node traversal to generate the node type and node meaning corresponding to each syntax tree node; the source code is subjected to contract logic analysis according to the node type and node meaning corresponding to each syntax tree node to generate the corresponding contract logic.

[0009] In combination with the first aspect, in a fourth implementation of the first aspect of the present invention, the data sensitivity analysis is performed on the target smart contract through the contract logic to generate a sensitivity analysis result, including: performing data flow analysis on the contract logic to generate a data flow corresponding to the contract logic; extracting data application types from the data flow to obtain a data application type set; performing data attribute analysis on the data application type set to generate a data attribute set; performing data sensitivity analysis on the target smart contract through the data attribute set to generate a sensitivity analysis result.

[0010] In combination with the first aspect, in the fifth implementation of the first aspect of the present invention, the corresponding sensitive data type is matched through the sensitivity analysis result, and at the same time, the test target is determined through the sensitive data type, including: extracting sensitive data attributes through the sensitivity analysis result to determine the corresponding sensitive data attributes; performing sensitive data type analysis through the sensitive data attributes to determine the corresponding sensitive data type; matching the contract module of the target smart contract through the sensitive data type to obtain at least one contract module to be tested, and determining the test target through at least one of the contract modules to be tested.

[0011] In combination with the first aspect, in a sixth implementation of the first aspect of the present invention, the target smart contract is fuzz tested through the test case to generate a fuzz test result, and a security detection report is generated through the fuzz test result, including: constructing a test environment based on the test case to generate a target test environment; generating configuration information for a preset fuzz test tool through the target test environment to determine the target configuration information; configuring the fuzz test tool through the target configuration information to obtain the target fuzz test tool; and fuzz testing the test case through the target fuzz test tool to generate a fuzz test result.

[0012] A second aspect of the present invention provides a security detection system for a smart contract, the security detection system for a smart contract comprising:

[0013] A code collection module, used to collect source code of a target smart contract and obtain the source code of the target smart contract;

[0014] A sequence recognition module, used to perform token sequence recognition on the source code and determine a target token sequence;

[0015] A syntax analysis module, used to perform syntax analysis on the source code through the target token sequence to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed;

[0016] A logic generation module, used for performing contract logic analysis on the source code to generate corresponding contract logic when the syntax analysis result passes the verification;

[0017] A data analysis module, used to perform data sensitivity analysis on the target smart contract through the contract logic and generate a sensitivity analysis result;

[0018] A type matching module, used to match the corresponding sensitive data type through the sensitivity analysis result, and at the same time, determine the test target through the sensitive data type;

[0019] A test case generation module, used to construct test cases through the test targets and generate corresponding test cases;

[0020] The fuzz testing module is used to perform fuzz testing on the target smart contract through the test case, generate fuzz testing results, and generate a security detection report through the fuzz testing results.

[0021] The third aspect of the present invention provides a security detection device for a smart contract, comprising: a memory and at least one processor, wherein instructions are stored in the memory; the at least one processor calls the instructions in the memory so that the security detection device for the smart contract executes the above-mentioned security detection method for the smart contract.

[0022] A fourth aspect of the present invention provides a computer-readable storage medium, which stores instructions that, when executed on a computer, enable the computer to execute the above-mentioned smart contract security detection method.

[0023] In the technical solution provided by the present invention, source code collection is performed on the target smart contract to obtain the source code of the target smart contract; token sequence recognition is performed on the source code to determine the target token sequence; syntax analysis is performed on the source code through the target token sequence to generate syntax analysis results, contract logic analysis is performed on the source code to generate contract logic; data sensitivity analysis is performed on the target smart contract through the contract logic to generate sensitivity analysis results; sensitive data types are matched through sensitivity analysis results, and test targets are determined through sensitive data types; test cases are constructed through test targets to generate corresponding test cases; fuzzy testing is performed on the target smart contract through test cases to generate fuzzy test results, and a security detection report is generated through the fuzzy test results. In an embodiment of the present invention, by performing comprehensive security detection links such as source code collection, syntax analysis, contract logic analysis, data sensitivity analysis and fuzzy testing on smart contracts, loopholes and hidden dangers in the contract can be effectively discovered, and the security and stability of the contract can be improved. By performing comprehensive scanning and analysis on smart contracts, possible risk points and problems can be quickly identified, test efficiency and accuracy can be improved, and any possible security issues can be avoided from being missed. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 A schematic diagram of an embodiment of a security detection method for a smart contract in an embodiment of the present invention;

[0025] Figure 2 This is a flow chart of performing syntax analysis on source code through a target token sequence in an embodiment of the present invention;

[0026] Figure 3 This is a flow chart of performing contract logic analysis on source code in an embodiment of the present invention;

[0027] Figure 4 This is a flow chart of performing data sensitivity analysis on a target smart contract in an embodiment of the present invention;

[0028] Figure 5 A schematic diagram of an embodiment of a security detection system for a smart contract in an embodiment of the present invention;

[0029] Figure 6 Schematic diagram of an embodiment of a security detection device for a smart contract in an embodiment of the present invention. DETAILED DESCRIPTION

[0030] The embodiments of the present invention provide a security detection method and related devices for smart contracts, which are used to improve the circulation planning efficiency and distribution efficiency of rural logistics. The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0031] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the security detection method of the smart contract in the embodiment of the present invention includes:

[0032] S101. Collect source code of the target smart contract to obtain the source code of the target smart contract;

[0033] It is understandable that the execution subject of the present invention can be a security detection system of a smart contract, or a terminal or a server, which is not limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.

[0034] Specifically, the target smart contract source code acquisition refers to obtaining the original code of the target smart contract. A smart contract is an automated protocol executed on a blockchain that can define and execute specific rules and conditions. Smart contract source code acquisition can be performed in a variety of ways. Several common methods are described in detail below: 1. Blockchain browser: Many blockchain platforms provide blockchain browsers that can be used to view transactions and smart contracts. Through the browser, you can retrieve the transaction history of the contract and obtain its source code. Usually, the source code of a smart contract is publicly visible, but there may also be private contracts that require specific permissions to access. 2. Code repository: Smart contracts are usually stored in code repositories such as GitHub, GitLab, etc. in the form of source code. These repositories can be found through search engines or links shared by developers in the blockchain community. Once the repository is found, the source code of the contract can be browsed and downloaded. 3. API call: Some blockchain platforms provide APIs to obtain information about smart contracts, including source code. By calling the corresponding API, the source code of the contract can be obtained. This requires authentication and authorization using appropriate API documents and access keys. 4. Contract publisher or developer: If the smart contract is published by a specific entity or developer, you can contact them directly to request the source code.

[0035] S102, performing token sequence recognition on the source code to determine the target token sequence;

[0036] Specifically, token sequence recognition in source code refers to the process of identifying and determining the target token sequence in the source code. In programming, a token is the smallest unit in the source code, which can be a keyword, identifier, operator, separator or constant. By identifying and extracting the token sequence, the server obtains the specific grammatical structure and logical information in the source code. The token sequence recognition of the source code requires the following steps: 1. Lexical Analysis: Lexical analysis is the process of decomposing the source code into independent tokens. In this step, the source code is divided into a series of tokens, and each token is assigned a corresponding lexical unit. These lexical units can be keywords (such as if, for, while, etc.), identifiers (variable names, function names, etc.), operators (+, -, *, etc.), separators (brackets, semicolons, etc.) and constants (numbers, strings, etc.). 2. Syntax Analysis: Syntax analysis is the process of building a syntax tree based on the token sequence. The syntax tree represents the grammatical structure and relationship in the source code. Through syntax analysis, the server identifies different syntax elements in the source code (such as functions, classes, loops, etc.) and the nesting and dependency relationships between them. 3. Determination of target token sequence: During the syntax analysis process, the server defines and identifies specific syntax rules to determine the target token sequence. These rules can be matched and filtered based on keywords, identifiers, operators, etc. By defining appropriate rules, the server filters out token sequences that meet specific conditions to obtain the target token sequence. After determining the target token sequence, the server further analyzes and processes these sequences. This includes but is not limited to the following aspects: 1. Semantic analysis: By analyzing the target token sequence, the server performs semantic analysis to understand the meaning and logic in the source code. This can involve the definition and use of variables, function calls, control flow statements, etc. Through semantic analysis, the server verifies the correctness of the code, detects potential errors and vulnerabilities, and optimizes and improves it. 2. Code generation and execution: After determining the target token sequence, the server uses it for code generation and execution. According to the target token sequence, the corresponding machine code or intermediate code can be generated and then run in the appropriate execution environment. This enables us to actually execute the source code and verify its behavior and functionality. 3. Code optimization and refactoring: By analyzing the target token sequence, the server performs code optimization and refactoring. This includes reducing redundant code, improving performance, and improving readability. By analyzing the target token sequence, potential problems and improvement points in the code can be identified, and corresponding optimization and refactoring operations can be performed. This helps improve the efficiency, maintainability and scalability of the code. 4. Security analysis: By analyzing the target token sequence, the server performs security analysis.This involves identifying potential security vulnerabilities, risks, and attack surfaces. By performing security analysis on the target token sequence, appropriate security measures and protection mechanisms can be taken to ensure the security and reliability of the code. 5. Code understanding and debugging: After determining the target token sequence, the server better understands the structure and logic of the code. This helps debug the code and solve potential errors and problems. By analyzing the target token sequence, bugs in the code can be located and fixed more quickly, and better code readability and maintainability can be provided. It should be noted that token sequence recognition of source code is a complex and critical process. It requires good lexical analysis and syntax analysis skills, and needs to consider the grammatical rules and semantics of the programming language. Different programming languages ​​may have different lexical and syntax rules, so specific programming languages ​​need to be processed when performing token sequence recognition.

[0037] S103, performing syntax analysis on the source code through the target token sequence to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed;

[0038] Specifically, parsing the source code through the target token sequence refers to the process of parsing the source code using the target token sequence as input. Parsing is one of the important steps in the compilation process. It is responsible for verifying the grammatical correctness of the code and generating parsing results. This result includes the parts that pass the verification and the parts that fail the verification. When performing parsing, the server uses different methods and technologies, such as context-free grammar, parsing tree, and parser. The following will describe the parsing process and the generated parsing results in detail: 1. Definition of context-free grammar: Before parsing, it is necessary to define an appropriate context-free grammar (CFG) to describe the grammatical rules of the programming language. The context-free grammar consists of a set of production rules that define legal grammatical structures and grammatical rules. 2. Lexical analysis: Before parsing, lexical analysis is usually performed to decompose the source code into a series of tokens. These tokens are the basic units of parsing and are used to build parsing trees. The lexical analyzer divides the source code into different token types, such as keywords, identifiers, operators, constants, etc., according to predefined lexical rules. 3. Syntax analyzer: The syntax analyzer is the component responsible for performing syntax analysis. It constructs a syntax analysis tree based on the definition of the context-free grammar and the token sequence generated in the lexical analysis phase. Common syntax analysis algorithms include LL(k) analysis, LR(k) analysis, and syntax-directed translation. 4. Syntax analysis tree: The syntax analysis tree is a tree structure that represents the syntax structure of the source code. It consists of non-terminal symbols and terminal symbols. The non-terminal symbol represents the left side of the grammar rule, and the terminal symbol represents the actual code fragment or token. The process of building a syntax analysis tree involves the process of applying production rules and matching token sequences until a complete syntax analysis tree is generated. 5. Syntax analysis results: The syntax analysis results are the output after the source code is syntax verified. It includes the part that passes the verification and the part that fails the verification. The part that passes the verification indicates the part of the source code that conforms to the grammar rules, and the part that fails the verification indicates that there are syntax errors or parts that do not conform to the grammar rules. Different strategies can be adopted when generating syntax analysis results. A common strategy is to detect syntax errors during syntax analysis and report error information immediately. Another strategy is to perform a complete syntax analysis, and then mark or separate the parts that pass the verification and the parts that fail the verification to generate the syntax analysis results. The parts that pass the verification can be used for further compilation or execution, while the parts that fail the verification need to be fixed or prompted to the developer.

[0039] S104. When the syntax analysis result is verified, the contract logic is analyzed on the source code to generate the corresponding contract logic;

[0040] Specifically, when the grammatical analysis result passes the verification, the server performs contract logic analysis to generate the corresponding contract logic. Contract logic analysis is the process of deeply understanding and deducing the source code to identify the behavior, function and interaction logic of the contract. The purpose of contract logic analysis is to understand the business logic of the contract and convert it into a formal description or model. This helps to verify the correctness of the contract, detect potential logic errors and design test cases for the contract. The following will explain in detail the process of contract logic analysis and the generated results: 1. Business understanding: Before performing contract logic analysis, you need to have an in-depth understanding of the business involved in the contract. This includes understanding the goals, functions, roles and interaction processes of the contract. Through communication and research with business domain experts, you can obtain background knowledge and business requirements about the contract. 2. Contract logic derivation: Based on business understanding and the grammatical structure of the source code, the logical behavior of the contract can be deduced. This includes identifying the state, events, functions, conditional statements, loop structures, etc. of the contract. By deeply analyzing the source code, you can understand the behavior and execution process of the contract in different situations. 3. State transition analysis: Contracts usually have different states, and there may be a transition relationship between states. In contract logic analysis, it is necessary to identify the state of the contract and the transition conditions between states. This helps to understand the state machine behavior of the contract and check the logical correctness of the contract in different states. 4. Interaction analysis: Contracts usually involve interactions with other parties (such as users, other contracts, etc.). In the contract logic analysis, it is necessary to analyze the interaction logic between the contract and other parties, including event triggering, data transmission, permission verification, etc. By analyzing the interaction logic, the correct execution of the contract and the expected interaction behavior can be ensured. 5. Logical model generation: The results of the contract logic analysis can be converted into a formal description or model. This can be a model of the contract created using a formal specification language (such as Solidity, UML, etc.), or a logical expression, state diagram, flow chart, etc. to represent the logical behavior of the contract. The generated logical model can be used to verify the correctness of the contract, perform simulation, and generate tests.

[0041] S105. Perform data sensitivity analysis on the target smart contract through contract logic to generate sensitivity analysis results;

[0042] Specifically, the server performs data sensitivity analysis on the target smart contract through the contract logic, which means analyzing the data in the contract to determine which data is sensitive to the behavior and security of the contract. Sensitivity analysis is intended to help discover data privacy risks, data leakage vulnerabilities, and data protection needs that may exist in the contract. The following will detail the process of data sensitivity analysis and the sensitivity analysis results generated: 1. Data identification: First, the data in the target smart contract needs to be identified. This includes variables, parameters, stored data, and data used in the contract. By analyzing the source code of the contract, the data elements involved in the contract can be determined. 2. Data classification: Classify the identified data according to the nature and sensitivity of the data. For example, the data can be divided into different categories such as personal identity information, financial data, and transaction records. This helps to better understand the sensitivity of the data and the degree of impact on privacy. 3. Data flow analysis: Analyze the data flow in the contract and track the transmission and processing of data in the contract. By analyzing operations such as reading, writing, transmitting, and manipulating data, the changes and flow of data during the execution of the contract can be determined. This helps to understand how the data is used and how sensitive data is handled. 4. Sensitivity assessment: Perform a sensitivity assessment on the identified sensitive data. The sensitivity level of the data can be assessed by considering the value, privacy, sensitivity, and possible risks of the data. Sensitivity assessment can be qualitative, such as marking the data as highly sensitive, medium sensitive, or low sensitive; or it can be quantitative, scoring the data based on sensitivity indicators. 5. Data access and control analysis: Analyze the access and control mechanisms for sensitive data in the contract. This includes permission control, access restrictions, and security mechanisms such as data encryption and desensitization for data read, write, and update operations. By analyzing these mechanisms, the degree of protection and security of sensitive data in the contract can be determined. 6. Sensitivity analysis results: The sensitivity analysis results provide information and recommendations about sensitive data in the contract. It can include a sensitivity level assessment for each data element, a summary of the data access and control analysis, and possible risks and security recommendations. The sensitivity analysis results can help developers and security experts understand the sensitivity of data in the contract and take appropriate protective measures.

[0043] S106. Match the corresponding sensitive data type according to the sensitivity analysis result, and determine the test target according to the sensitive data type;

[0044] Specifically, the server matches the corresponding sensitive data type through the sensitivity analysis results, and determines the test target through the sensitive data type, which means matching the identified sensitive data with the predefined sensitive data type according to the sensitivity analysis results, and determining the focus and target of the test according to the matching results. The steps and functions of this process are described in detail below: 1. Sensitive data type definition: First, a set of sensitive data types need to be predefined. These sensitive data types can be defined according to general data protection requirements and privacy regulations, such as personal identity information, financial data, medical records, etc. Each sensitive data type should contain corresponding sensitive data attributes and protection requirements. 2. Sensitive data matching: Through the results of sensitivity analysis, the identified sensitive data is matched with the predefined sensitive data types. According to the attributes, content and context of the sensitive data, it is associated with the most matching sensitive data type. The matching process can be based on methods such as keyword matching, data structure matching or rule matching. 3. Test target determination: According to the matching results of the sensitive data types, the focus and target of the test are determined. For each successfully matched sensitive data type, a corresponding test plan and test strategy can be formulated. For example, for sensitive data types that contain personally identifiable information, the goal of the test may be to verify whether the encryption and protection mechanisms of the data are effective; for sensitive data types that contain financial data, the goal of the test may be to verify the access rights and anti-tampering mechanisms of the data, etc. 4. Test design and execution: Based on the determined test objectives, design corresponding test cases and test plans. Test cases should cover different sensitive data types and possible test scenarios. Test plans should consider all aspects of data protection and security, including data reading, writing, transmission, and processing. When executing the test, focus on the operations and processes involving sensitive data, and verify whether the protection and security mechanisms of the data meet the expected requirements. 5. Test result analysis: Based on the test execution results, analyze the test coverage and security assessment. Check whether all successfully matched sensitive data types are covered, and evaluate the effectiveness and feasibility of the test. Based on the analysis results, determine further testing and remediation measures.

[0045] S107, constructing test cases through test targets, and generating corresponding test cases;

[0046] Specifically, the server constructs test cases through test targets, and generating corresponding test cases means designing and constructing specific test cases for the target smart contract according to the determined test targets. These test cases are designed to cover different functions, boundary conditions and possible exceptions of the contract to verify the correctness, security and stability of the contract. The following will explain in detail the process of test case construction and the importance of the corresponding test cases generated: 1. Understand the test objectives: First, have a deep understanding of the determined test objectives. Test objectives may include verifying specific functions of the contract, testing boundary conditions, detecting potential security vulnerabilities or error handling situations, etc. Ensuring a clear understanding of the test objectives is the basis for test case construction. 2. Determine test requirements: Based on the test objectives, determine the corresponding test requirements. Test requirements are a specific description and refinement of the test objectives, including the functional points that need to be covered, the range of input data, expected outputs and expected behaviors, etc. This helps to clarify the scope and objectives of the test and provide guidance for the subsequent test case construction. 3. Design test strategies: Develop test strategies based on test objectives and requirements. Test strategies include selecting appropriate test technologies, defining test environments, determining test data, and designing test methods. The goal of the test strategy is to ensure the comprehensiveness, effectiveness and repeatability of the test. 4. Generate test cases: Based on the test requirements and test strategies, start generating test cases. Test cases should cover various functional modules, boundary conditions and abnormal situations. According to different test objectives, different test design techniques, such as equivalence class partitioning, boundary value analysis, decision tables, etc., can be used to generate specific test cases. 5. Test case writing: Convert the generated test cases into actual test scripts or test case documents. Test cases should contain detailed steps, input data and expected results. Ensure that the test cases are readable and easy to execute so that testers can perform the tests accurately. 6. Cover the test scope: Ensure that the test cases can cover the entire scope of the test. According to the test objectives and test requirements, check whether the generated test cases cover all functional modules, different input situations, boundary conditions and abnormal situations. This helps to ensure the comprehensiveness and effectiveness of the test. 7. Test case review: Review the generated test cases to ensure their completeness, accuracy and feasibility. Test case review can be conducted by the test team internally or in collaboration with the development team. During the review process, the test cases can be reviewed and discussed to obtain different perspectives and feedback. Through the test case review, potential defects, missing test scenarios or test cases that need further optimization can be found. 8. Execute test cases: In the test environment, execute the written test cases. According to the steps and expected results of the test cases, execute the test step by step, and record the actual results and observed behaviors. Ensure the accuracy and repeatability of the test, and record any problems or abnormalities during the test execution. 9. Result analysis and repair: According to the results of the test execution, analyze the results and locate the problems.If the test case execution finds errors, abnormal behaviors, or unexpected results, record the problems and communicate with the development team. The development team can fix the problems or vulnerabilities in the contract based on the test results. 10. Repeat testing and iteration: Repeat the test case based on the repaired contract version. Through repeated testing, verify the effectiveness of the repair and ensure that the functionality, security, and stability of the contract in multiple aspects are verified. If there are still problems, iteration is required, update the test case or adopt other testing strategies.

[0047] S108. Perform fuzz testing on the target smart contract through test cases, generate fuzz testing results, and generate a security detection report through the fuzz testing results.

[0048] Specifically, the server performs fuzz testing on the target smart contract through test cases, generates fuzz testing results, and generates a security detection report through the fuzz testing results. This refers to the process of using fuzz testing technology to simulate malicious inputs and abnormal situations to perform security assessment and vulnerability detection on the target smart contract. The steps and functions of this process are described in detail below. 1. Understand the target smart contract: First, deeply understand the functions, data flows, and security requirements of the target smart contract. Understanding the design and implementation details of the contract, as well as possible security risks and vulnerabilities, helps guide the subsequent fuzz testing design and evaluation process. 2. Design fuzz test cases: Design fuzz test cases based on the understanding of the target smart contract. Fuzz test cases simulate the behavior of attackers by constructing exceptions, boundary conditions, and illegal inputs. Test cases should cover different functions and data types of contracts, including various transactions, state transitions, and contract calls. 3. Execute fuzz testing: According to the designed fuzz test cases, start executing fuzz testing. Testing tools and frameworks can generate random, mutated, and deformed inputs based on predefined test cases to trigger potential vulnerabilities and security issues in the contract. During the test execution, record the test inputs, operations, and observed behaviors. 4. Generate fuzz test results: Generate fuzz test results based on the execution of fuzz testing and observed behaviors. The results include successfully triggered vulnerabilities, abnormal behaviors, crashes or denial of service, etc. These results can be used to evaluate the security of the contract and provide reference for subsequent vulnerability fixes and improvements. 5. Analyze fuzz test results: Analyze and organize the generated fuzz test results. Assess the severity and scope of impact of each triggered vulnerability and abnormal situation. This helps to determine the priority security issues and provide repair suggestions and improvement measures. 6. Generate security detection report: Generate a security detection report based on the analysis of fuzz test results. The report should include an overall security assessment of the contract, a detailed description of the vulnerabilities and problems found, repair suggestions and improvement measures. The goal of the report is to provide comprehensive information and guidance on contract security to operation and maintenance personnel. 7. Vulnerability repair and improvement: Perform vulnerability repair and contract improvement based on the recommendations and guidance in the security detection report. The development team should prioritize each vulnerability based on the vulnerability and problem descriptions provided in the report and develop a corresponding repair plan. The repair measures may involve modification of contract code, enhancement of input validation, improvement of exception handling, etc. After the fix is ​​complete, a second round of fuzz testing is performed to verify the effectiveness of the vulnerability fix and to ensure that no new security issues have been introduced. When performing the second round of fuzz testing, you can focus on testing the previously discovered vulnerabilities and issues to verify whether the fix was successful.

[0049] In an embodiment of the present invention, source code collection is performed on the target smart contract to obtain the source code of the target smart contract; token sequence recognition is performed on the source code to determine the target token sequence; syntax analysis is performed on the source code through the target token sequence to generate syntax analysis results, contract logic analysis is performed on the source code to generate contract logic; data sensitivity analysis is performed on the target smart contract through the contract logic to generate sensitivity analysis results; sensitive data types are matched through sensitivity analysis results, and test targets are determined through sensitive data types; test cases are constructed through test targets to generate corresponding test cases; fuzzy testing is performed on the target smart contract through test cases to generate fuzzy test results, and a security detection report is generated through the fuzzy test results. In an embodiment of the present invention, by performing comprehensive security detection links such as source code collection, syntax analysis, contract logic analysis, data sensitivity analysis and fuzzy testing on smart contracts, loopholes and hidden dangers in the contract can be effectively discovered, and the security and stability of the contract can be improved. By performing comprehensive scanning and analysis on smart contracts, possible risk points and problems can be quickly identified, test efficiency and accuracy can be improved, and any possible security issues can be avoided from being missed.

[0050] In a specific embodiment, the process of executing step S101 may specifically include the following steps:

[0051] (1) Analyze the source code storage location of the target smart contract to obtain the source code storage location. At the same time, match the hash value of the target smart contract to determine the target hash value;

[0052] (2) Perform database matching based on the source code storage location to determine the source code database corresponding to the smart contract;

[0053] (3) Based on the target hash value, collect the source code corresponding to the target smart contract from the source code database.

[0054] Specifically, (1) Analyze the source code storage location of the target smart contract to obtain the source code storage location. At the same time, perform hash value matching on the target smart contract to determine the target hash value: When analyzing the source code storage location of the target smart contract, we need to determine the location where the source code file of the contract is stored. This can be in the local file system, code hosting platform (such as GitHub, GitLab, etc.), version control system or other code repository. By analyzing the contract deployment process, contract metadata or configuration files related to the contract, clues to the source code storage location can be found. At the same time, by performing hash value matching on the target smart contract, the server determines the unique identifier of the contract, that is, the target hash value. The hash value is a fixed-length string obtained by performing a hash function calculation on the source code file. It is unique, that is, the hash values ​​generated by different source code files must be different. By performing hash value calculation on the source code file of the target contract, the hash value of the target contract can be obtained. (2) Perform database matching based on the source code storage location to determine the source code database corresponding to the smart contract: Once the source code storage location of the target smart contract is determined, the next step is to perform database matching based on this location to determine the source code database corresponding to the smart contract. The source code database can be a centralized code hosting platform or a local or private code repository. By matching the source code storage location, the server determines which database contains the source code of the target contract. Database matching may involve analyzing and comparing the storage structure, directory structure, naming rules, etc. in the database. In addition, factors such as the contract version information and timestamp may need to be considered to ensure that the source code obtained is consistent with the version of the target contract. (3) Based on the target hash value, collect the source code corresponding to the target smart contract from the source code database: After determining the source code database corresponding to the smart contract, the server then collects the source code of the target smart contract from the database based on the target hash value. By using the hash value of the target contract as an index or keyword, query and retrieve in the source code database to obtain the source code file of the target contract. This may involve database query language, API call or other query mechanism to obtain the source code file that matches the target hash value from the database. Once the source code file of the target contract is obtained, the server further analyzes, reviews and verifies it. This ensures that the obtained source code is consistent with the target contract and provides a basis for contract auditing, security assessment, version management, etc.

[0055] In a specific embodiment, if Figure 2 As shown, the process of executing step S103 may specifically include the following steps:

[0056] S201, constructing a syntax tree through a target token sequence to generate an abstract syntax tree;

[0057] S202, analyzing the root node of the abstract syntax tree to obtain a syntax tree node set;

[0058] S203: Perform syntax check on each syntax tree node in the syntax tree node set respectively to generate syntax analysis results, wherein the syntax analysis results include verification pass and verification fail.

[0059] Specifically, (1) The syntax tree is constructed through the target token sequence to generate an abstract syntax tree: Before performing syntax analysis, the target code or input must first be converted into a series of tokens. Token is the basic unit of syntax analysis and represents the lexical unit in the code, such as keywords, identifiers, operators, etc. The target token sequence is obtained by segmenting the code or input according to certain rules. Based on the target token sequence, the server constructs a syntax tree. A syntax tree is a tree structure used to describe the structure and syntax relationship of the code. It consists of nodes and edges, each node represents a syntax unit, and the edges represent the relationship between syntax units. The target token sequence is parsed and organized through syntax rules and context information to gradually construct an abstract syntax tree. The abstract syntax tree is an abstract representation of the code structure, removing specific details and syntax redundancy, and highlighting the logical structure and semantics of the code. (2) The root node of the abstract syntax tree is analyzed to obtain a set of syntax tree nodes: Once the abstract syntax tree is generated, the server analyzes its root node. The root node is the top-level node of the syntax tree, which represents the starting point of the entire code. By analyzing the root node, the server obtains the node set of the entire syntax tree. Root node analysis involves traversing and parsing the abstract syntax tree to identify and extract each node in the syntax tree. During the traversal process, the server classifies and summarizes the nodes in the syntax tree into different sets according to the type, attribute or other characteristics of the node. Through root node analysis, the server obtains all node sets including the root node to form an ordered node structure. This node set will provide the basis for subsequent syntax detection. (3) Perform syntax detection on each syntax tree node in the syntax tree node set and generate a syntax analysis result, where the syntax analysis result includes verification pass and verification fail: Once the syntax tree node set is obtained, the server performs syntax detection on each syntax tree node in it. Syntax detection refers to verifying the syntax rules of the code to ensure that the code complies with the predefined syntax specifications and syntax constraints. For each syntax tree node, the server checks its matching degree with the rules according to the predefined syntax rules. If the structure and attributes of the node meet the requirements of the syntax rules, then the node passes the syntax detection and generates a syntax analysis result of verification pass. On the contrary, if the structure or attributes of the node do not meet the requirements of the syntax rules, then the node fails the syntax detection and generates a syntax analysis result of verification fail. The grammatical analysis result is a summary of the verification results of each syntax tree node. It can include the verification status, error information, location information, etc. of each node. For nodes that pass the verification, their location in the code and corresponding semantic information can be recorded for subsequent program processing and analysis. Through the grammatical analysis results, the server obtains an assessment of the overall grammatical correctness of the target code or input.The syntax tree nodes that pass the verification indicate that the code is grammatically compliant, while the nodes that fail the verification indicate the syntax errors or non-compliant parts in the code. The syntax analysis results are very important for software development and code review processes. It can help developers find and fix potential syntax errors in a timely manner and improve the readability, maintainability and reliability of the code. At the same time, the syntax analysis results can also be used for the construction, integration and testing of automated tools and systems to ensure the correctness and quality of the code.

[0060] In a specific embodiment, if Figure 3 As shown, the process of executing step S104 may specifically include the following steps:

[0061] S301, when the syntax analysis result is verified, perform node traversal on the syntax tree node set to generate a node type and node meaning corresponding to each syntax tree node;

[0062] S302. Perform contract logic analysis on the source code based on the node type and node meaning corresponding to each syntax tree node, and generate corresponding contract logic.

[0063] Specifically, (1) when the grammatical analysis result is verified, the set of grammar tree nodes is traversed to generate the node type and node meaning corresponding to each grammar tree node: Once the grammar analysis result is verified, the server traverses the set of grammar tree nodes to obtain the node type and node meaning of each grammar tree node. Node traversal refers to visiting the nodes in the grammar tree one by one according to a certain traversal strategy. Common traversal methods include depth-first traversal (DFS) and breadth-first traversal (BFS). During the node traversal process, the server checks and analyzes each node and records its node type and node meaning. The node type represents the classification or category of the grammar tree node. It can be a type defined in a predefined grammar rule, such as a variable declaration, function call, assignment statement, etc. The node type can be used to identify and distinguish different types of grammar units, thereby facilitating subsequent contract logic analysis. The node meaning represents the semantics or meaning represented by the grammar tree node. It describes the role, function or purpose of the node in the code. The node meaning can be deduced and analyzed through grammar rules and context information. By understanding the meaning of each node, the server has a deep understanding of the logical structure and semantics of the code. By traversing the nodes of the syntax tree node set, the server determines the node type and node meaning for each node and records them. This provides a basis for the subsequent contract logic analysis. (2) Perform contract logic analysis on the source code based on the node type and node meaning corresponding to each syntax tree node to generate the corresponding contract logic: Once the node type and node meaning of the syntax tree node are determined, the server performs contract logic analysis on the source code based on this information to generate the corresponding contract logic. Contract logic analysis is a process of in-depth understanding and analysis of the functions and behaviors of the contract code. By analyzing the node type and node meaning, the server understands the role and function of each syntax tree node in the code, and then derives the logical relationship, state transition and business logic of the contract. During the contract logic analysis process, the server performs pattern recognition and rule matching based on the node type and node meaning. By identifying specific node combinations, grammatical structures and code patterns, the specific behavior and logic of the contract can be determined. Contract logic analysis can also include analysis of control flows such as conditional statements, loop statements and function calls, as well as analysis of variable usage, state transitions and data processing. By analyzing the contract logic of the source code, the server deeply understands the functions and behaviors of the contract and discovers potential logic errors, security loopholes, and business logic problems. Contract logic analysis can help us identify potential errors and defects, optimize the logical structure and performance of the code, and ensure the correctness and security of the contract. In the process of contract logic analysis, the server uses relevant analysis tools and technologies, such as static code analysis, symbolic execution, model checking, etc. These tools and technologies can automatically analyze the contract code, discover potential problems and vulnerabilities, and provide corresponding repair suggestions.The results of contract logic analysis can be presented in a variety of forms, such as structure diagrams, flow charts, state transition diagrams, etc. These graphical representations can more intuitively display the logical relationship and behavior of the contract. At the same time, contract logic analysis can also generate corresponding analysis reports, providing detailed analysis results and suggestions for developers to refer to and apply.

[0064] In a specific embodiment, if Figure 4 As shown, the process of executing step S105 may specifically include the following steps:

[0065] S401. Perform data flow analysis on the contract logic to generate data flow corresponding to the contract logic;

[0066] S402, extracting data application types from the data stream to obtain a data application type set;

[0067] S403, performing data attribute analysis on the data application type set to generate a data attribute set;

[0068] S404: Perform data sensitivity analysis on the target smart contract through a data attribute set to generate a sensitivity analysis result.

[0069] Specifically, (1) Data flow analysis is performed on the contract logic to generate the data flow corresponding to the contract logic: Data flow analysis is a static analysis technique that aims to analyze the flow and conversion of data in a program. Based on the contract logic analysis, data flow analysis can help us understand the source, transmission and use of data in the contract. By performing data flow analysis on the contract logic, the server builds a data flow graph, in which nodes represent data sources, variables, functions, etc., and edges represent the flow path of data. The data flow graph reflects the transmission and dependency of data in the contract. Data flow analysis can help us identify the input and output points of data, determine the flow path of data in the contract, and find potential data errors and unsafe data operations. It can also be used to detect problems such as data leakage, data competition and data dependency. Through data flow analysis, the server generates the data flow corresponding to the contract logic, providing a basis for subsequent data application type extraction and data attribute analysis. (2) Data application type extraction is performed on the data flow to obtain a data application type set: Based on the data flow analysis, the server performs data application type extraction on the data flow to obtain a data application type set. Data application type refers to the specific purpose or application scenario of data in the contract. For example, data can be used as input parameters, state variables, transaction information, etc. By identifying the application type of data, the server can better understand the purpose and role of data in the contract. Data application type extraction of data streams can be achieved through static analysis technology and rule matching. The server determines the application type of data based on the grammatical rules of the contract, function call relationships, variable declarations and other information, and classifies and records it. Data application type extraction can help us build a data application model and provide a basis for subsequent data attribute analysis and data sensitivity analysis. (3) Perform data attribute analysis on the data application type set to generate a data attribute set: After obtaining the data application type set, the server performs data attribute analysis on it to generate a data attribute set. Data attributes refer to the characteristics, properties or features of data. By analyzing the data application type set, the server identifies the attributes of the data, such as the type, range, constraints, etc. of the data. Data attribute analysis can be achieved through static analysis technology, type inference, constraint analysis and other methods. The server extracts the attributes of the data from the declaration statements, assignment statements, function calls and other information of the contract, and infers and analyzes them. The results of the data attribute analysis can include information such as data type, data range, validity check, boundary conditions, etc. These attributes can help us understand the nature and behavior of data, so as to conduct subsequent data sensitivity analysis and security analysis. Perform data sensitivity analysis on the target smart contract through the data attribute set and generate sensitivity analysis results: After obtaining the data attribute set, the server uses these attributes to perform data sensitivity analysis on the target smart contract to evaluate the sensitivity of the contract to different types of data.Data sensitivity analysis aims to determine the protection level and risk level of different data in the contract. By analyzing the data attributes, the server identifies which data is critical to the correctness, security and privacy of the contract. Data sensitivity analysis can be carried out based on the following aspects: 1. Sensitive data type identification: Identify the sensitive data types involved in the contract through the type information in the data attribute set. For example, personal identity information, payment-related data, etc. are all sensitive data types. 2. Data access rights: Analyze the access rights and control mechanisms for different data in the contract. Determine which data can be publicly accessed and which data requires access control and permission verification. 3. Data transmission and storage security: Analyze the transmission and storage methods of data in the contract and evaluate its security. Ensure that the data is encrypted and protected during transmission, and is properly kept and access controlled during storage. 4. Data processing and operation security: Analyze the contract's processing and operation methods for data, and check whether there are potential data risks and vulnerabilities. For example, check whether there are security issues such as data injection, overflow, and replay. 5. Data leakage and privacy protection: Evaluate the risks and privacy protection measures for sensitive data leakage in the contract. Ensure that the contract does not accidentally leak sensitive data, and take appropriate privacy protection measures, such as data desensitization and anonymization. Through data sensitivity analysis, the server determines the strengths and weaknesses of the target smart contract in processing and protecting sensitive data, and provides corresponding improvement suggestions and security measures. The results of sensitivity analysis can help operation and maintenance personnel understand the data risks in the contract, thereby enhancing the security and credibility of the contract.

[0070] In a specific embodiment, the process of executing step S106 may specifically include the following steps:

[0071] (1) Extract sensitive data attributes based on sensitivity analysis results and determine the corresponding sensitive data attributes;

[0072] (2) Analyze sensitive data types through sensitive data attributes and determine the corresponding sensitive data types;

[0073] (3) Match the contract modules of the target smart contract by sensitive data types to obtain at least one contract module to be tested, and determine the test target through at least one contract module to be tested.

[0074] It should be noted that (1) Extract sensitive data attributes through sensitivity analysis results and determine the corresponding sensitive data attributes: In the sensitivity analysis process, we have obtained the sensitivity analysis results of the target smart contract. These results indicate which data has high sensitivity and risk in the contract. By further analyzing the sensitivity analysis results, the server extracts the attributes of sensitive data. Sensitive data attributes can include information such as data type, range, validity check, boundary conditions, etc. For example, if the sensitivity analysis results indicate that a certain variable stores the user's personal identity information in the contract, the server extracts the data type of the variable as a string, the range is a specific length, and requires validity check and encrypted storage. By extracting the attributes of sensitive data, the server better understands the characteristics and requirements of sensitive data and provides a basis for subsequent sensitive data type analysis. (2) Perform sensitive data type analysis through sensitive data attributes to determine the corresponding sensitive data type: After obtaining the sensitive data attributes, the server further performs sensitive data type analysis to determine the specific type of sensitive data. Sensitive data types are the result of classification and induction based on the attributes and characteristics of sensitive data. By analyzing sensitive data attributes, the server identifies different sensitive data types, such as personal identity information, financial data, health records, etc. Through the analysis of sensitive data types, the server classifies and identifies the sensitive data involved in the contract. This helps us better understand the characteristics and importance of sensitive data in the contract, and provides a basis for the subsequent contract module matching and test target determination. (3) Match the contract module of the target smart contract through the sensitive data type to obtain at least one contract module to be tested, and determine the test target through at least one contract module to be tested: After determining the sensitive data type, the server uses this type information to match the contract module of the target smart contract. Contract modules refer to specific functional units or modules in a contract, which usually involve a set of related functions or operations. Through the matching of contract modules, the server determines which modules are associated with sensitive data types, thereby determining the contract modules to be tested. Through the matching of contract modules, the server selects at least one contract module to be tested, which is closely related to the sensitive data type and may have an impact on the processing and use of sensitive data. By selecting the contract module to be tested, the server clarifies the test objectives and scope, and constructs and executes test cases in a targeted manner. In this way, the efficiency and coverage of the test can be improved. After determining the contract module to be tested, the server determines the test objectives based on its functions and operations. The test objectives can include the following aspects: 1. Data operations: determine the data operations related to sensitive data in the contract module, such as reading, writing, modifying, deleting, etc. These operations involve the processing and transmission of sensitive data, and need to focus on their correctness, security and compliance. 2. Logical flow: Analyze the logical flow in the contract module and determine the conditional judgments, loops and branch statements related to sensitive data.These logical processes may affect the access and use rights of sensitive data, and their logical correctness and security need to be verified. 3. Exception handling: Determine the abnormal situations and error handling mechanisms that may occur in the contract module for sensitive data operations. This includes exception handling, error code return, logging, etc. It is necessary to verify whether the contract module handles abnormal situations of sensitive data reasonably and safely. 4. Interface interaction: Analyze the interaction between the contract module and the external interface, and determine the interface calls and data transmission related to sensitive data. These interfaces may involve the transmission and storage of sensitive data, and their security and protection measures need to be verified. By determining the test objectives, the server constructs test cases in a targeted manner to cover the functions and operations related to sensitive data in the contract module to be tested. Test cases should include normal scenarios, boundary conditions, and abnormal situations to verify the correctness and security of the contract when processing sensitive data.

[0075] In a specific embodiment, the process of executing step S108 may specifically include the following steps:

[0076] (1) Build a test environment based on test cases and generate a target test environment;

[0077] Generate configuration information for the preset fuzz testing tool through the target test environment to determine the target configuration information;

[0078] (2) configuring the fuzz testing tool through the target configuration information to obtain the target fuzz testing tool;

[0079] (3) Perform fuzz testing on the test cases through the target fuzz testing tool and generate fuzz testing results.

[0080] Specifically, (1) Build a test environment based on test cases and generate a target test environment: Before fuzz testing, we need to build an environment suitable for testing, namely the target test environment. The target test environment is designed to simulate the actual operating environment and provide the necessary conditions and resources to execute test cases. Based on the test cases, the server analyzes the environmental requirements required in the test cases, such as the operating system, dependent libraries, network configuration, etc. According to these requirements, the server builds the corresponding test environment to ensure that the test cases can run in the correct environment. The construction of the test environment can include the following steps: installing and configuring the operating system, installing necessary dependent libraries and software, setting up the network environment, configuring the database, etc. The purpose of these steps is to meet the running requirements of the test cases and ensure the accuracy and reliability of the tests. By building the target test environment, the server provides a stable and controllable execution environment for subsequent fuzz testing. (2) Generate configuration information for the preset fuzz testing tools through the target test environment and determine the target configuration information: Before fuzz testing, we need to configure the preset fuzz testing tools to ensure that they can correctly execute the test cases and generate valid fuzz testing results. According to the characteristics and requirements of the target test environment, the server generates configuration information suitable for the target environment. This configuration information includes but is not limited to the following: the version and settings of the test tool, the path and parameters of the target contract, the input generation strategy, the test case generation rules, etc. By generating configuration information according to the target test environment, the server ensures that the fuzz test tool is configured in the correct environment so that the test case can be accurately executed. (3) The fuzz test tool is configured with the target configuration information to obtain the target fuzz test tool: According to the target configuration information, the server performs corresponding information configuration on the preset fuzz test tools to ensure that they can execute the test cases according to the target requirements. Information configuration includes but is not limited to the following aspects: setting the parameters and options of the test tool, specifying the path and parameters of the target contract, defining the input generation strategy and generation rules, etc. By configuring the fuzz test tool, the server ensures that the test tool can perform fuzz testing according to the requirements of the target configuration information and generate corresponding fuzz test results. The configuration of the fuzz test tool is to ensure the accuracy and effectiveness of the test. By correctly configuring the fuzz test tool, the server ensures that the test case is fuzz tested according to the target requirements and produces meaningful test results.

[0081] The above describes the security detection method of the smart contract in the embodiment of the present invention. The following describes the security detection system of the smart contract in the embodiment of the present invention. Figure 5 , an embodiment of the security detection system of the smart contract in the embodiment of the present invention includes:

[0082] The code collection module 501 is used to collect source code of the target smart contract and obtain the source code of the target smart contract;

[0083] A sequence recognition module 502 is used to perform token sequence recognition on the source code to determine a target token sequence;

[0084] A syntax analysis module 503, configured to perform syntax analysis on the source code through the target token sequence to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed;

[0085] A logic generation module 504, configured to perform contract logic analysis on the source code and generate corresponding contract logic when the syntax analysis result passes verification;

[0086] A data analysis module 505, configured to perform data sensitivity analysis on the target smart contract through the contract logic and generate a sensitivity analysis result;

[0087] A type matching module 506, configured to match a corresponding sensitive data type according to the sensitivity analysis result, and determine a test target according to the sensitive data type;

[0088] A test case generation module 507 is used to construct a test case through the test target and generate a corresponding test case;

[0089] The fuzz testing module 508 is used to perform fuzz testing on the target smart contract through the test case, generate a fuzz testing result, and generate a security detection report through the fuzz testing result.

[0090] Through the cooperation of the above-mentioned components, the source code of the target smart contract is collected to obtain the source code of the target smart contract; the token sequence of the source code is identified to determine the target token sequence; the source code is parsed by the target token sequence to generate the grammatical analysis result, the contract logic analysis of the source code is performed to generate the contract logic; the data sensitivity analysis of the target smart contract is performed by the contract logic to generate the sensitivity analysis result; the sensitive data type is matched by the sensitivity analysis result, and the test target is determined by the sensitive data type; the test case is constructed by the test target to generate the corresponding test case; the target smart contract is fuzzy tested by the test case to generate the fuzzy test result, and the security detection report is generated by the fuzzy test result. In the embodiment of the present invention, by performing comprehensive security detection links such as source code collection, grammatical analysis, contract logic analysis, data sensitivity analysis and fuzzy testing on the smart contract, the loopholes and hidden dangers in the contract can be effectively discovered, and the security and stability of the contract can be improved. By performing comprehensive scanning and analysis on the smart contract, possible risk points and problems can be quickly identified, the test efficiency and accuracy can be improved, and any possible security issues can be avoided from being missed.

[0091] above Figure 5 The security detection system of the smart contract in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The security detection device of the smart contract in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0092] Figure 6 6 is a schematic diagram of the structure of a security detection device for a smart contract provided by an embodiment of the present invention. The security detection device 600 for the smart contract may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) storing application programs 633 or data 632. Among them, the memory 620 and the storage medium 630 may be short-term storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the security detection device 600 for the smart contract. Furthermore, the processor 610 may be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the security detection device 600 for the smart contract.

[0093] The smart contract security detection device 600 may also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 660, and / or one or more operating systems 631, such as Windows Serve, MacOS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 6 The structure of the security detection device for the smart contract shown does not constitute a limitation on the security detection device for the smart contract, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.

[0094] The present invention also provides a security detection device for a smart contract, which includes a memory and a processor. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor executes the steps of the security detection method for the smart contract in the above-mentioned embodiments.

[0095] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the smart contract security detection method.

[0096] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0097] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0098] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments are still modified, or some of the technical features thereof are replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A security detection method for a smart contract, characterized in that: The security detection method of the smart contract includes: Collect source code of the target smart contract to obtain the source code of the target smart contract; Performing token sequence recognition on the source code to determine a target token sequence; The source code is parsed by the target token sequence to generate a grammatical analysis result, wherein the grammatical analysis result includes verification passed and verification failed; specifically comprising: constructing a grammatical tree by the target token sequence to generate an abstract grammatical tree; performing root node analysis on the abstract grammatical tree to obtain a grammatical tree node set; performing grammatical detection on each grammatical tree node in the grammatical tree node set to generate a grammatical analysis result, wherein the grammatical analysis result includes verification passed and verification failed; When the syntax analysis result passes the verification, the source code is subjected to contract logic analysis to generate the corresponding contract logic; specifically comprising: when the syntax analysis result passes the verification, the syntax tree node set is subjected to node traversal to generate the node type and node meaning corresponding to each syntax tree node; the source code is subjected to contract logic analysis according to the node type and node meaning corresponding to each syntax tree node to generate the corresponding contract logic; Performing data sensitivity analysis on the target smart contract through the contract logic to generate a sensitivity analysis result; specifically comprising: performing data flow analysis on the contract logic to generate a data flow corresponding to the contract logic; extracting data application types from the data flow to obtain a data application type set; performing data attribute analysis on the data application type set to generate a data attribute set; performing data sensitivity analysis on the target smart contract through the data attribute set to generate a sensitivity analysis result; Matching the corresponding sensitive data type through the sensitivity analysis result, and determining the test target through the sensitive data type; Construct test cases through the test targets to generate corresponding test cases; The target smart contract is fuzz tested through the test case, a fuzz test result is generated, and a security detection report is generated through the fuzz test result.

2. The security detection method of smart contract according to claim 1 is characterized in that: The collecting source code of the target smart contract to obtain the source code of the target smart contract includes: Analyze the source code storage location of the target smart contract to obtain the source code storage location, and at the same time, match the hash value of the target smart contract to determine the target hash value; Perform database matching based on the source code storage location to determine the source code database corresponding to the smart contract; Based on the target hash value, source code corresponding to the target smart contract is collected from the source code database.

3. The security detection method of smart contract according to claim 1 is characterized in that: The matching of the corresponding sensitive data type by the sensitivity analysis result and determining the test target by the sensitive data type include: Extract sensitive data attributes based on the sensitivity analysis results to determine corresponding sensitive data attributes; Perform sensitive data type analysis based on the sensitive data attributes to determine the corresponding sensitive data type; The target smart contract is matched with a contract module by using the sensitive data type to obtain at least one contract module to be tested, and a test target is determined by using at least one contract module to be tested.

4. The security detection method of smart contract according to claim 1 is characterized in that: The step of performing fuzz testing on the target smart contract through the test case, generating a fuzz testing result, and generating a security detection report through the fuzz testing result includes: Build a test environment based on the test case to generate a target test environment; Generating configuration information for a preset fuzzy testing tool through the target testing environment to determine target configuration information; Performing information configuration on the fuzz testing tool through the target configuration information to obtain a target fuzz testing tool; The test case is fuzz tested by the target fuzz testing tool to generate a fuzz testing result.

5. A security detection system for smart contracts, characterized in that: The security detection system of the smart contract includes: A code collection module, used to collect source code of a target smart contract and obtain the source code of the target smart contract; A sequence recognition module, used to perform token sequence recognition on the source code and determine a target token sequence; A syntax analysis module is used to perform syntax analysis on the source code through the target token sequence to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed; specifically comprising: constructing a syntax tree through the target token sequence to generate an abstract syntax tree; performing root node analysis on the abstract syntax tree to obtain a syntax tree node set; performing syntax detection on each syntax tree node in the syntax tree node set to generate a syntax analysis result, wherein the syntax analysis result includes verification passed and verification failed; A logic generation module, for performing contract logic analysis on the source code to generate corresponding contract logic when the syntax analysis result is verified; specifically comprising: performing node traversal on the syntax tree node set to generate a node type and node meaning corresponding to each syntax tree node when the syntax analysis result is verified; performing contract logic analysis on the source code according to the node type and node meaning corresponding to each syntax tree node to generate corresponding contract logic; A data analysis module, used to perform data sensitivity analysis on the target smart contract through the contract logic and generate a sensitivity analysis result; specifically comprising: performing data flow analysis on the contract logic to generate a data flow corresponding to the contract logic; performing data application type extraction on the data flow to obtain a data application type set; performing data attribute analysis on the data application type set to generate a data attribute set; performing data sensitivity analysis on the target smart contract through the data attribute set to generate a sensitivity analysis result; A type matching module, used to match the corresponding sensitive data type through the sensitivity analysis result, and at the same time, determine the test target through the sensitive data type; A test case generation module, used to construct test cases through the test targets and generate corresponding test cases; The fuzz testing module is used to perform fuzz testing on the target smart contract through the test case, generate fuzz testing results, and generate a security detection report through the fuzz testing results.

6. A security detection device for smart contracts, characterized in that: The security detection device of the smart contract includes: a memory and at least one processor, wherein the memory stores instructions; The at least one processor calls the instructions in the memory so that the security detection device of the smart contract executes the security detection method of the smart contract as described in any one of claims 1-4.

7. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by the processor, the security detection method of the smart contract as described in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Ethereum intelligent contract vulnerability detection method, device and system and medium

    CN115033896A

  • Intelligent contract vulnerability detection method and system and electronic equipment

    CN115828264A