Vulnerability detection method and system for Move smart contract

By converting the Move smart contract from stack-based bytecode to stack-free bytecode and conducting detailed code analysis, the complexity and insufficient accuracy of smart contract vulnerability detection in the existing technology is solved, and efficient vulnerability identification is achieved and security analysis, supporting detection of multiple defect types.

CN118965373APending Publication Date: 2024-11-15UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411160814.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The existing smart contract vulnerability detection methods have limitations in terms of complexity and irreversibility, especially the smart contracts in the Move language lack efficient automation, multi-defect type support and high-precision detection capabilities.

Method used

By converting the Move smart contract from stack-based bytecode to stack-free bytecode, an intermediate representation is generated and code analysis is performed, including building a control flow graph, generating a call graph across smart contracts, building a data dependency tree, and variable range Analyze, define defects and detection rules, design detectors to implement defect detection, and generate detection reports.

Benefits of technology

It realizes automation and supports the identification of multiple defect types, improves the efficiency and accuracy of security analysis of Move smart contracts, reduces human resource consumption and false alarm rates, and enhances the accuracy of vulnerability detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118965373A_ABST
    Figure CN118965373A_ABST
Patent Text Reader

Abstract

The invention discloses a vulnerability detection method and system for a Move smart contract, and relates to the field of computer network security. The vulnerability detection method comprises the following steps: converting a Move smart contract from a stack-based bytecode form into a stack-free bytecode form to obtain an intermediate representation of the Move smart contract; performing code analysis on the intermediate representation of the Move smart contract, wherein the code analysis comprises construction of a control flow graph, generation of a call graph across the smart contract, construction of a data dependence tree and variable range analysis; defects and defect detection rules are defined, then a detector is designed based on a metadata interface provided by code analysis to realize defect detection, and finally a detection report is generated. The method supports the recognition of various defect types, and through an automatic detection method and the design of a high-precision detector, potential vulnerabilities and errors in the smart contract can be effectively reduced, the efficiency and accuracy of security analysis of the Move smart contract are improved, human resources are saved, and the false alarm rate and the missing report rate are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer network security, and in particular to a vulnerability detection method and system for Move smart contracts. Background Art

[0002] Smart contracts are automated contracts that run on the blockchain, which enable transactions and data sharing between multiple parties. However, due to the complexity and irreversibility of smart contracts, they are vulnerable to various vulnerabilities and attacks. Therefore, smart contract defect detection has become a key research area. Move language is a new language for smart contract programming. The source code of smart contract modules in Move language is usually written in high-level programming languages. These modules are compiled to generate Move bytecode and executed in the Move virtual machine. Blockchain users can call deployed modules by initiating transactions.

[0003] Security analysis methods for Move smart contracts can be divided into three categories: formal methods, static analysis, and dynamic analysis. Formal methods are mainly represented by Move Prover, which is released together with the Move language and verifies the correctness of the project source code through a multi-step process of specification extraction, bytecode compilation, and SMT formula generation. The second method is MoveLint, which is the only static analysis tool available. It converts the source code into AST and identifies defects using predefined rules. The third method is Move Verifier, which is part of the Move VM and checks the bytecode before execution.

[0004] An intermediate representation is an intermediate form of a computer program, used to transfer and process information during different stages of compilation or analysis. It is a bridge between source code and target code, and can help compilers and analysis tools optimize, transform, and check. Static code analysis is a technique for analyzing code without executing it. It detects potential problems such as errors, vulnerabilities, or bad practices by examining the structure, semantics, and properties of the code. Static analysis is usually performed based on the intermediate representation of the code and can be applied to different levels of the program, including source code, abstract syntax tree, and bytecode.

[0005] However, each method has its own advantages and limitations, such as the limitations of formal methods on specification understanding, the challenges faced by static analysis tools such as bytecode incompatibility and local support, and the dynamic analysis method requires modifying the virtual machine to support new defects and only supports the inspection of deployed modules. Summary of the invention

[0006] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a vulnerability detection method and system for Move smart contracts to achieve automation, support bytecode, support more defect types and high-precision detection.

[0007] The objective of the present invention is achieved through the following technical solutions: A vulnerability detection method for Move smart contracts, comprising the following steps: S1: Convert the Move smart contract from stack-based bytecode form to stackless bytecode form to obtain the intermediate representation of the Move smart contract; S2: Code analysis of the intermediate representation of the Move smart contract, including building a control flow graph, generating a call graph across smart contracts, building a data dependency tree, and variable scope analysis; S3: Define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.

[0008] Furthermore, the step S1 specifically includes: S11: Compile the input Move source code using the Move compiler to generate bytecode; S12: Use the bytecode parsing function of the Move compiler to parse all bytecode Move smart contracts to generate CompiledModules. Each CompiledModule includes the global variables, structure definitions, function definitions, and string information of some source codes of the Move smart contract. S13: For all functions in CompiledModule, perform intermediate representation conversion one by one. The specific process is: use a temporary stack to simulate the operation of the bytecode based on the stack in the function, and define temporary variables to record the intermediate results, so as to realize the conversion from stack-based bytecode to stackless bytecode.

[0009] Furthermore, the string information of the source code includes a function name and a smart contract name.

[0010] Furthermore, constructing the control flow graph specifically includes: dividing the intermediate representation code of the Move smart contract into multiple basic blocks according to the definition of the control flow graph, each basic block starts with the target address of the first instruction or the jump instruction, and ends with the jump instruction or the program end instruction, thereby generating a control flow graph.

[0011] Furthermore, the generating of a call graph across smart contracts specifically includes: Identify all function call instructions in the intermediate representation, and divide function calls into intra-smart contract function calls and cross-smart contract function calls based on whether the smart contract of the called function belongs to the current smart contract; Create a node for each function and establish a directed edge from the function to the called function to construct the call graph of the smart contract; Link multiple smart contracts to generate a cross-smart contract call graph.

[0012] Furthermore, the constructing of the data dependency tree specifically includes: identifying the variable assignment statement in the intermediate representation of the Move smart contract, extracting the dependency relationship between the left value of the assignment statement and the right value of the assignment statement, taking each variable as a tree node, and the lines between the nodes represent the dependency relationship, thereby constructing the data dependency tree.

[0013] Furthermore, the variable range analysis specifically includes: Collect all variables and variable types from the intermediate representation of the Move smart contract, and set the initial legal scope of the variables according to their types; The data dependency tree is traversed, and constraints are further added to the range of the variables according to the arithmetic operation relationship between the variables, wherein the arithmetic operation relationship includes addition, subtraction, multiplication, division, modulus, bit operation and type conversion.

[0014] Furthermore, the definition of defects and defect detection rules specifically include: Formal definition of defects based on three dimensions: code quality standards, common error patterns, and project-specific requirements; Manually extract the features of defined defect codes, and design defect detection rules based on the features of defect codes. The detection rules include declaration usage rules, operation validity rules, structural condition rules, calculation result rules, and function return value rules.

[0015] Furthermore, the metadata interface design detector provided based on code analysis implements defect detection and finally generates a detection report, which specifically includes: Traverse the code after code analysis and extract the feature data of the code; Record the usage of feature data; Analyze the characteristic data of the code according to the predefined defects and defect detection rules, and identify defects based on the usage of the characteristic data; Report the location of the defect from the intermediate representation level and locate the function corresponding to the defective code in the bytecode.

[0016] The present invention also provides a vulnerability detection system for Move smart contracts, comprising: The intermediate representation module is used to convert the Move smart contract from a stack-based bytecode form to a stackless bytecode form to obtain the intermediate representation of the Move smart contract; Code analysis module, which is used to perform code analysis on the intermediate representation of Move smart contracts, including building control flow graphs, generating call graphs across smart contracts, building data dependency trees, and variable scope analysis; The defect detection module is used to define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.

[0017] The beneficial effects of the present invention are: In the first stage, the embodiment of the present invention converts bytecode into an intermediate representation to facilitate the effective extraction of Move smart contract metadata. In the second stage, a control flow graph and a cross-smart contract call graph are constructed to better analyze defects involving cross-smart contract calls. Then, metadata required for detecting defects is collected based on the constructed data dependency tree and variable range constraints. In the third stage, defects are identified by designing a detector and a detection report is generated. The present invention supports the identification of multiple defect types. Through automated detection methods and the design of high-precision detectors, potential vulnerabilities and errors in smart contracts can be effectively reduced, the efficiency and accuracy of Move smart contract security analysis can be improved, human resources can be saved, and false positives and false negatives can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A flowchart of a vulnerability detection method for a Move smart contract provided by an embodiment of the present invention; Figure 2 A schematic diagram of the intermediate representation conversion process of a Move smart contract provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0019] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0020] See also Figure 1-Figure 2 , the present invention provides a technical solution: Embodiment 1: like Figure 1 As shown in the figure, a vulnerability detection method for Move smart contract includes the following steps: S1: Convert the Move smart contract from stack-based bytecode form to stackless bytecode form to obtain the intermediate representation of the Move smart contract; S2: Code analysis of the intermediate representation of the Move smart contract, including building a control flow graph, generating a call graph across smart contracts, building a data dependency tree, and variable scope analysis; S3: Define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.

[0021] As an implementation of the embodiment of the present invention, step S1 specifically includes: S11: Compile the input Move source code using the Move compiler to generate bytecode; S12: Use the bytecode parsing function of the Move compiler to parse all bytecode Move smart contracts to generate CompiledModules. Each CompiledModule includes the global variables, structure definitions, function definitions, and string information of some source codes of the Move smart contract. The string information of the source code includes the function name and the smart contract name. S13: For all functions in CompiledModule, perform intermediate representation conversion one by one. The specific process is: use a temporary stack to simulate the operation of the bytecode based on the stack in the function, and define temporary variables to record the intermediate results, so as to realize the conversion from stack-based bytecode to stackless bytecode.

[0022] During the intermediate representation conversion process of step S1, the conversion diagram of the smart contract's Move source code from stack-based bytecode to stackless bytecode is as follows: Figure 2 shown.

[0023] As an implementation method of an embodiment of the present invention, constructing a control flow graph in step S2 specifically includes: dividing the intermediate representation code of the Move smart contract into multiple basic blocks according to the definition of the control flow graph, each basic block starts with the target address of the first instruction or the jump instruction, and ends with a jump instruction or a program end instruction, thereby generating a control flow graph.

[0024] As an implementation method of an embodiment of the present invention, generating a call graph across smart contracts in step S2 specifically includes: Identify all function call instructions in the intermediate representation, and divide function calls into intra-smart contract function calls and cross-smart contract function calls based on whether the smart contract of the called function belongs to the current smart contract; Create a node for each function and establish a directed edge from the function to the called function to construct the call graph of the smart contract; Link multiple smart contracts to generate a cross-smart contract call graph.

[0025] As an implementation of an embodiment of the present invention, building a data dependency tree in step S2 specifically includes: identifying variable assignment statements in the intermediate representation of the Move smart contract, extracting the dependency relationship between the left value of the assignment statement and the right value of the assignment statement, taking each variable as a tree node, and the lines between the nodes represent the dependency relationship, thereby building a data dependency tree. For example, for the statement a=b op c, the dependency relationship between the left value a and the right value b and c can be extracted.

[0026] As an implementation of an embodiment of the present invention, the variable range analysis in step S2 specifically includes: Collect all variables and variable types from the intermediate representation of the Move smart contract, and set the initial legal scope of the variables according to their types; The data dependency tree is traversed, and constraints are further added to the range of the variables according to the arithmetic operation relationship between the variables, wherein the arithmetic operation relationship includes addition, subtraction, multiplication, division, modulus, bit operation and type conversion. The addition of constraints can maintain the legal range of each variable.

[0027] Defining defects and defect detection rules specifically include: S311: Formalize the definition of defects based on three dimensions: code quality standards, common error patterns, and project-specific requirements; To define defects, we must first clarify the target to be detected, including code patterns that may cause program errors, performance problems, or maintainability problems, so as to formally define defects. The evaluation criteria of the three dimensions are as follows: (1) Code quality standards: based on common coding standards and best practices, such as variable naming standards, code readability, and invalid code; (2) Common error patterns: common programming errors summarized based on historical data or experience, such as unchecked function return values, integer overflow, etc.; (3) Project-specific requirements: Based on the needs and characteristics of the specific project, such as specific performance optimization requirements, security requirements, etc.

[0028] S312: Manually extract features of defined defect codes, and design defect detection rules based on the features of the defect codes. The detection rules include declaration usage rules, operation validity rules, structural condition rules, operation result rules, and function return value rules.

[0029] After the defect definition is completed, the code with defects is manually analyzed through the metadata extracted in the code analysis phase to determine the characteristics of the relevant code, and the defect detection rules are designed based on the characteristics of the defective code. The specific detection rules are: Declaration usage rules: detect unused declarations, duplicate declarations, etc.

[0030] Operation validity rules: detect invalid operations, unnecessary operations, etc.

[0031] Structural conditional rules: detect dead loops, unnecessary conditions, etc.

[0032] Operation result rules: detect meaningless operations, potentially risky operations, etc.

[0033] Function return value rules: detect unhandled return values, unchecked errors, etc.

[0034] As an implementation method of the embodiment of the present invention, in step S3, the metadata interface design detector provided by the code analysis implements defect detection, and finally generates a detection report, which specifically includes: S321: traverse the code after code analysis and extract feature data of the code; S322: Record usage of feature data; S323: Analyze the feature data of the code according to the predefined defects and defect detection rules, and identify the defects in combination with the usage of the feature data; S324: Report the location of the defect from the intermediate representation layer, and locate the function corresponding to the defective code in the bytecode.

[0035] In addition, the interface allows users to develop new detectors to enhance their support for emerging defects.

[0036] Embodiment 2: The present invention also provides a vulnerability detection system for Move smart contracts, comprising: The intermediate representation module is used to convert the Move smart contract from a stack-based bytecode form to a stackless bytecode form to obtain the intermediate representation of the Move smart contract; Code analysis module, which is used to perform code analysis on the intermediate representation of Move smart contracts, including building control flow graphs, generating call graphs across smart contracts, building data dependency trees, and variable scope analysis; The defect detection module is used to define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.

[0037] In summary, the embodiment of the present invention converts bytecode into an intermediate representation in the first stage, which is convenient for effectively extracting Move smart contract metadata; in the second stage, a control flow graph and a cross-smart contract call graph are constructed to better analyze defects involving cross-smart contract calls, and then the metadata required for detecting defects is collected based on the constructed data dependency tree and variable range constraints; in the third stage, defects are identified by designing a detector and a detection report is generated. The present invention supports the identification of multiple defect types. Through automated detection methods and the design of high-precision detectors, it can effectively reduce potential vulnerabilities and errors in smart contracts, improve the efficiency and accuracy of Move smart contract security analysis, save human resources and reduce false positives and false negatives.

[0038] The above is only a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art do not deviate from the spirit and scope of the present invention, and should be within the scope of protection of the claims attached to the present invention.

Claims

1. A vulnerability detection method for Move smart contracts, characterized in that: The following steps are involved: S1: Convert the Move smart contract from stack-based bytecode form to stackless bytecode form to obtain the intermediate representation of the Move smart contract; S2: Code analysis of the intermediate representation of the Move smart contract, including building a control flow graph, generating a call graph across smart contracts, building a data dependency tree, and variable scope analysis; S3: Define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.

2. A vulnerability detection method for Move smart contracts according to claim 1, characterized in that: The step S1 specifically includes: S11: Compile the input Move source code using the Move compiler to generate bytecode; S12: Use the bytecode parsing function of the Move compiler to parse all bytecode Move smart contracts to generate CompiledModules. Each CompiledModule includes the global variables, structure definitions, function definitions, and string information of some source codes of the Move smart contract. S13: For all functions in CompiledModule, perform intermediate representation conversion one by one. The specific process is: use a temporary stack to simulate the operation of the bytecode based on the stack in the function, and define temporary variables to record the intermediate results, so as to realize the conversion from stack-based bytecode to stackless bytecode.

3. A vulnerability detection method for Move smart contracts according to claim 2, characterized in that: The string information of the source code includes the function name and the smart contract name.

4. A vulnerability detection method for Move smart contracts according to claim 1, characterized in that: The construction of the control flow graph specifically includes: dividing the intermediate representation code of the Move smart contract into multiple basic blocks according to the definition of the control flow graph, each basic block starts with the target address of the first instruction or the jump instruction, and ends with the jump instruction or the program end instruction, thereby generating a control flow graph.

5. A vulnerability detection method for Move smart contracts according to claim 1, characterized in that: The generating of a cross-smart contract call graph specifically includes: Identify all function call instructions in the intermediate representation, and divide function calls into intra-smart contract function calls and cross-smart contract function calls based on whether the smart contract of the called function belongs to the current smart contract; Create a node for each function and establish a directed edge from the function to the called function to construct the call graph of the smart contract; Link multiple smart contracts to generate a cross-smart contract call graph.

6. A vulnerability detection method for Move smart contracts according to claim 1, characterized in that: The constructing of the data dependency tree specifically includes: identifying the variable assignment statement in the intermediate representation of the Move smart contract, extracting the dependency relationship between the left value of the assignment statement and the right value of the assignment statement, taking each variable as a tree node, and the lines between the nodes represent the dependency relationship, thereby constructing the data dependency tree.

7. A vulnerability detection method for Move smart contracts according to claim 6, characterized in that: The variable range analysis specifically includes: Collect all variables and variable types from the intermediate representation of the Move smart contract, and set the initial legal scope of the variables according to their types; The data dependency tree is traversed, and constraints are further added to the range of the variables according to the arithmetic operation relationship between the variables, wherein the arithmetic operation relationship includes addition, subtraction, multiplication, division, modulus, bit operation and type conversion.

8. A vulnerability detection method for Move smart contracts according to claim 1, characterized in that: The definition of defects and defect detection rules specifically include: Formal definition of defects based on three dimensions: code quality standards, common error patterns, and project-specific requirements; Manually extract the features of defined defect codes, and design defect detection rules based on the features of defect codes. The detection rules include declaration usage rules, operation validity rules, structural condition rules, calculation result rules, and function return value rules.

9. A vulnerability detection method for Move smart contracts according to claim 8, characterized in that: The metadata interface design detector provided by the code analysis implements defect detection and finally generates a detection report, specifically including: Traverse the code after code analysis and extract the feature data of the code; Record the usage of feature data; Analyze the characteristic data of the code according to the predefined defects and defect detection rules, and identify defects based on the usage of the characteristic data; Report the location of the defect from the intermediate representation level and locate the function corresponding to the defective code in the bytecode.

10. A vulnerability detection system for Move smart contracts, characterized by: include: The intermediate representation module is used to convert the Move smart contract from a stack-based bytecode form to a stackless bytecode form to obtain the intermediate representation of the Move smart contract; Code analysis module, which is used to perform code analysis on the intermediate representation of Move smart contracts, including building control flow graphs, generating call graphs across smart contracts, building data dependency trees, and variable scope analysis; The defect detection module is used to define defects and defect detection rules, then design a detector based on the metadata interface provided by code analysis to implement defect detection, and finally generate a detection report.