Intelligent contract entrusted call vulnerability detection method and system based on read-write data stream capture

By constructing a smart contract abstract syntax tree and a contract control flow graph, combined with symbolic execution, the smart contract delegation call vulnerability is detected, which solves the problem of fuzzy detection logic of existing tools and improves the security and reliability of smart contracts.

CN118709192APending Publication Date: 2024-09-27Chinese People's Liberation Army Cyberspace Force Information Engineering University
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410813510.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-24
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection tools have fuzzy logic for delegate call vulnerability detection, resulting in a high false positive rate and inability to effectively determine whether the main contract has modified vulnerabilities, affecting the security of the smart contract.

Method used

Using a method based on reading and writing data flow capture, by constructing a smart contract abstract syntax tree, generate a contract control flow graph, track the data flow direction, obtain suspicious attack data, verify the authenticity of the suspicious attack path through symbolic execution, and extract functions and variables related Information to verify the read and write status of vulnerability variables.

Benefits of technology

It improves the security and reliability of smart contracts, can accurately detect delegation call vulnerabilities, reduces the false positive rate, and enhances the security of application deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118709192A
    Figure CN118709192A
Patent Text Reader

Abstract

The invention relates to the technical field of network security, in particular to an intelligent contract delegation calling vulnerability detection method and system based on read-write data stream capture, and the method comprises the steps: building an intelligent contract abstract syntax tree according to an intelligent contract source code, and extracting the related information of functions and variables in an intelligent contract based on the intelligent contract abstract syntax tree; a contract control flow graph is generated through the intelligent contract abstract syntax tree, the data flow direction in the intelligent contract is tracked based on the contract control flow graph, suspicious attack data are obtained, and the suspicious attack data comprise suspicious attack paths and vulnerability variables; and symbolizing parameters in the suspicious attack data based on symbolic execution and executing related transactions, obtaining variable read-write change information according to an execution result, and verifying the authenticity of a suspicious attack path. According to the method and the system, while vulnerabilities are searched, possible attack paths and read-write variables can be found, potential vulnerabilities in entrusted calling are solved, and the security and the reliability of the smart contract in real application can be enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network security technology, and in particular to a smart contract delegate call vulnerability detection method and system based on read-write data stream capture. Background Art

[0002] A smart contract is a program that runs on a blockchain network. It automatically executes pre-set logic through multiple institutions. After the program is executed, the final state on the network will be immutable. Smart contract programs can be implemented in programming languages ​​such as Solidity or Vyper and stored on the blockchain. On the public chain network, anyone can access and execute deployed smart contracts. Since smart contracts are a piece of program code, they may also have defects or errors that lead to fatal security vulnerabilities. There are many risks in the execution process, and it cannot be guaranteed to be completely safe.

[0003] The delegate call function in Solidity has the advantages of simplifying contract logic and reducing gas consumption. Before some contract writers fully understand the relevant logic of the delegate call function, they use the delegate call function to call contracts with delegate call vulnerabilities, such as the Parity Wallet incident. This may cause functions that can abnormally elevate user permissions and destroy the function execution path of the original contract execution process in the contract, resulting in delegate call vulnerabilities. As one of the most cunning vulnerabilities, the delegate call function vulnerability has caused great trouble to the development of smart contracts. After the attacker discovered the delegate call vulnerability, he wrote an attack contract to attack, resulting in serious problems such as property loss. At present, the detection logic of the smart contract vulnerability detection tool for the delegate call vulnerability is relatively vague. The detection logic mostly uses whether the contract address of the delegate call can be modified as the basis for judging whether the vulnerability exists. This detection method will inhibit the flexibility of the delegate call function. Even if the main contract cannot modify the external contract, that is, there is no delegate call vulnerability, the false positive rate of the detection result is high. Therefore, there is an urgent need for a method that can determine whether the main contract has a vulnerability that may be modified from an external contract to improve the security of smart contract application deployment. Summary of the invention

[0004] To this end, the present invention provides a smart contract delegate call vulnerability detection method and system based on read and write data stream capture to remedy the problem of broad detection of existing delegate call functions and enhance the security and reliability of smart contracts in real applications.

[0005] According to the design scheme provided by the present invention, on the one hand, a smart contract delegation call vulnerability detection method based on read-write data stream capture is provided, comprising:

[0006] Construct a smart contract abstract syntax tree based on the smart contract source code, and extract information related to functions and variables in the smart contract based on the smart contract abstract syntax tree;

[0007] Generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph and obtain suspicious attack data, the suspicious attack data includes suspicious attack paths and vulnerability variables;

[0008] Based on symbolic execution, the parameters in the suspicious attack data are symbolized and related transactions are executed. The variable read and write change information is obtained based on the execution results, and the authenticity of the suspicious attack path is verified.

[0009] As a smart contract delegation call vulnerability detection method based on read-write data stream capture of the present invention, further, a smart contract abstract syntax tree is constructed according to the smart contract source code, including:

[0010] Compile the smart contract source code and convert it into an abstract syntax tree through lexical and grammatical analysis;

[0011] Convert the grammatical structure in the source code into the node object of the abstract syntax tree, build the relationship between the nodes according to the abstract syntax tree node type and grammatical structure, and form the tree structure of the smart contract abstract syntax tree.

[0012] As a smart contract delegation call vulnerability detection method based on read-write data stream capture of the present invention, further, extracting related information of functions and variables in the smart contract based on the smart contract abstract syntax tree includes:

[0013] Read the smart contract abstract syntax tree, and obtain the function signatures and function entries of all functions in the smart contract through the function selector. The function signature is a function identifier composed of the function name and function parameters.

[0014] The function modifier and the calling relationship are obtained through the function name, the read and write operations on the state variables inside each function are extracted, and the names of the state variables being read and written are obtained. The calling relationship includes a direct calling relationship and an indirect calling relationship.

[0015] As a smart contract delegate call vulnerability detection method based on read-write data stream capture of the present invention, further, a contract control flow graph is generated through a smart contract abstract syntax tree, including:

[0016] Generate three-address instructions according to the smart contract abstract syntax tree, and construct the three-address instructions into basic blocks;

[0017] Taking the basic blocks as control flow graph nodes, traverse the smart contract abstract syntax tree to obtain the path set containing all basic blocks to form the contract control flow graph.

[0018] As a smart contract delegation call vulnerability detection method based on read-write data flow capture of the present invention, further, based on the contract control flow graph, the data flow in the smart contract is tracked and suspicious attack data is obtained, including:

[0019] According to the data flow in the control flow graph, the flow direction of relevant variables in the smart contract in the function is tracked, and the preferred target function of the attack in the data flow is searched and obtained, and the preferred target function of the attack includes the smart contract self-destruction function and the smart contract transfer function;

[0020] Obtain suspicious attack data based on the attack preferred target function.

[0021] As a smart contract delegation call vulnerability detection method based on read-write data stream capture of the present invention, further, based on symbolic execution, the parameters in the suspicious attack data are symbolized and related transactions are executed, including:

[0022] Obtain key information of suspicious attack data in the smart contract source code, including contract functions, function modifiers, function parameters, and function signatures;

[0023] The key information of suspicious attack data is symbolized according to the Ethereum contract interaction standard, and transactions related to suspicious attack data are executed in a virtual Ethereum environment to deduce the changes in function variables during correct execution.

[0024] As a smart contract delegation call vulnerability detection method based on read-write data stream capture of the present invention, further, executing suspicious attack data related transactions in a virtual Ethereum environment includes:

[0025] Compile the smart contract source code into a binary file and deploy it in a virtual Ethernet environment. Allocate slots for each state variable in the source code so that when a function call is executed to modify the state variable, the real value pointed to by the state variable is obtained by reading the state variable slot and the corresponding offset.

[0026] Rewrite the callback function. In the virtual execution of the smart contract, the callback function is used to capture the read and write change information of the state variables of the suspicious attack data in the symbolic execution and the instructions currently executed by the smart contract. The callback function and the current execution instructions are compared with the layout information of the state variables of the smart contract source code to verify and determine the truth of the suspicious attack path and the read and write status of the vulnerability variables.

[0027] On the other hand, the present invention also provides a smart contract delegation call vulnerability detection system based on read-write data flow capture, comprising: an information extraction module, a path search module and a path verification module, wherein:

[0028] The information extraction module is used to construct an abstract syntax tree of the smart contract based on the smart contract source code, and extract information related to functions and variables in the smart contract based on the abstract syntax tree of the smart contract;

[0029] A path search module is used to generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph, and obtain suspicious attack data, wherein the suspicious attack data includes suspicious attack paths and vulnerability variables;

[0030] The path verification module is used to symbolize the parameters in the suspicious attack data based on symbolic execution and execute related transactions, obtain the variable read and write change information based on the execution results, and verify the authenticity of the suspicious attack path.

[0031] Beneficial effects of the present invention:

[0032] The present invention combines pattern matching and symbolic execution to infer the attack path of delegate call vulnerabilities. Starting from the various problems that may be caused by delegate calls, the present invention warns of existing vulnerabilities by analyzing the called contracts. While searching for vulnerabilities, it can also discover possible attack paths and read and write variables, and resolve potential vulnerabilities in delegate calls, thereby enhancing the security and reliability of smart contracts in real applications, and has good application prospects. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a schematic diagram of the smart contract delegation call vulnerability detection process based on read and write data stream capture in the embodiment;

[0034] Figure 2 This is a schematic diagram of the vulnerability triggering process in the embodiment;

[0035] Figure 3 This is an example of capturing read and write information in the embodiment;

[0036] Figure 4 This is a schematic diagram of the Delegate Tracker architecture in the embodiment. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.

[0038] Although the delegate call function of smart contracts is powerful, it also has potential security threats. Delegated calls allow one contract to execute code as another contract. Although this mechanism is flexible, it may lead to security vulnerabilities if not managed properly. In the field of vulnerability detection tools, the detection logic of most tools is relatively vague and cannot ensure contract security while ensuring flexibility. For this reason, the embodiments of the present invention, see Figure 1As shown, a smart contract delegation call vulnerability detection method based on read-write data stream capture is provided, including:

[0039] S101. Construct a smart contract abstract syntax tree according to the smart contract source code, and extract information related to functions and variables in the smart contract based on the smart contract abstract syntax tree.

[0040] The target of the delegate call vulnerability detection is the external contract. When the main contract calls the external contract, the function logic of the external contract will be used to operate the variable storage space of the main contract. If there is code in the external contract that may modify the state variable (storage type), the main contract may modify the state variable in the main contract after executing the code. If the main contract then uses the modified state variable when executing other code, the accidentally modified state variable will directly affect the contract state, causing unexpected effects.

[0041] After modifying the state variables in the contract, the attacker will use certain state variables to obtain special permissions, improve their own permissions, operate the contract funds for transfer, self-destruction, etc.; or some state variables of the contract are modified abnormally, resulting in abnormal judgments, loops, and call statements, with serious consequences, etc. Abnormal modifications of different state variables within the contract may lead to different unexpected results, which can be roughly divided into contract self-destruction anomalies, currency sending anomalies, and judgment condition disorder anomalies. Among them, the contract self-destruction anomaly and currency sending anomaly trigger process are as follows Figure 2 The judgment condition disorder exception is similar.

[0042] Contract self-destruction exception, that is, the modification of state variables can cause the contract to self-destruct abnormally. The detection logic is that if there is an attack path<A,B> , where the vulnerable variable is X, and function B is a self-destruct function, then the attack path is the contract self-destruction exception attack path. If functions A and B are executed in sequence, a certain value of variable X may trigger the contract to self-destruct abnormally. The specific manifestation of the contract self-destruction exception is that the modification of the state variable causes the contract function execution logic to change. The attacker can upgrade his own user authority level by attacking the contract, thereby forcibly triggering the function to self-destruct, and sending the currency to the attacker's specified address during self-destruction; or it causes an error in the contract function execution logic, which may cause the contract to automatically self-destruct.

[0043] Currency sending anomaly, that is, the modification of state variables can lead to some abnormal way of sending currency. The detection logic is that if there is an attack path<A,B> , where the vulnerable variable is X, and function B can send currency, then the attack path is the currency sending abnormal attack path. If functions A and B are executed in sequence, a certain value of variable X may trigger a currency sending abnormality. Specifically, the abnormal modification of the state variable causes the contract function execution logic to change. The attacker can easily modify his own user permission level by attacking the contract and send currency to the user's own address; or cause errors in the contract function execution logic, and the transaction requests related to the contract by external users will be abnormal.

[0044] The judgment condition disorder exception, that is, the modification of the state variable can cause the assertion statement in the function to be abnormal. The detection logic is that if there is an attack path<A,B> , where the vulnerable variable is X, and function B has assertion statements and loop statements that use the variable, then the attack path is a judgment condition disorder exception attack path. If functions A and B are executed in sequence, a certain value of variable X may trigger a judgment condition disorder exception. Specifically, the assertion statement and loop statement in the function have abnormal branch directions, and the normal execution function logic is modified.

[0045] In order to obtain possible attack paths, it is necessary to analyze the contract and find out the state variables that may be modified when executing the function. The reading and writing operations of the contract function on the state variables are the main implementation methods for changing the contract state. The state variables store the state information of the contract and can affect the behavior and function of the contract. By modifying the value of the state variable, various functions such as recording events and updating the state function will be triggered. For example, changing the conditional judgment jump target, contract self-destruction, and permission escalation.

[0046] Specifically, when analyzing the smart contract, the smart contract abstract syntax tree is constructed based on the smart contract source code, which can be designed to include:

[0047] Compile the smart contract source code and convert it into an abstract syntax tree through lexical and grammatical analysis;

[0048] Convert the grammatical structure in the source code into the node object of the abstract syntax tree, build the relationship between the nodes according to the abstract syntax tree node type and grammatical structure, and form the tree structure of the smart contract abstract syntax tree.

[0049] By extracting the modification and reading of state variables in the contract, function calls, and contract protection information, we can find out the state variables that may be modified when executing the function. First, we need to compile the contract in advance to obtain the contract's abstract syntax tree AST (Abstract Syntax Tree). In solc, we provide an interface for compiling the contract AST to facilitate the generation of the contract AST. AST is an abstract representation of the grammatical structure of the contract code, ignoring some code details, and does not rely on the specific syntax and contract code of Solidity to analyze the contract, which improves the analysis efficiency and facilitates the detection of anomalies. Each node in the AST represents a grammatical structure or statement of the contract code, and different types of nodes. In order to obtain information such as the function protection, function variable reading and writing, and function calls of the contract, it is necessary to extract the nodes in the AST, analyze the data flow and control flow of the AST, and obtain the contract structure information such as contract state variables, functions, visibility, etc., control information such as conditional judgment, loops, exception handling, logical processing information such as assignment operations and arithmetic operations, and type information of variables and expressions, providing the data required for searching the attack path.

[0050] Among them, the extraction of related information of functions and variables in smart contracts based on the smart contract abstract syntax tree can be designed to include:

[0051] Read the smart contract abstract syntax tree, and obtain the function signatures and function entries of all functions in the smart contract through the function selector. The function signature is a function identifier composed of the function name and function parameters.

[0052] The function modifier and the calling relationship are obtained through the function name, the read and write operations on the state variables inside each function are extracted, and the names of the state variables being read and written are obtained. The calling relationship includes a direct calling relationship and an indirect calling relationship.

[0053] When writing contracts, contract writers usually consider the access control of functions and impose necessary access control restrictions on functions. By setting the visibility of the function to external, internal calls can be avoided, and internal to avoid external calls, etc. In addition, writers can use modifier functions to limit the access control of functions while improving code readability. The modifier can design the location where the function is inserted, so that the function can only execute the function subject logic if the modifier restrictions are met. In order to find function vulnerabilities that attackers may exploit, it is necessary to first extract the modifier of the function, find out the functions that the attacker can access, and get the modifier encountered by the attacker when executing the function.

[0054] The function signature is the unique identifier of the function, in the form of the concatenation of the function name and the function parameters. Find the function signature through the function selector, and then directly obtain the function element through the function signature. After reading the contract AST, use the function selector to obtain all functions, function signatures, and function entries in the contract. Then find the modifiers of each function, the direct call relationship, and the indirect call relationship of the function through the function name. Modifying the state variable will change the state of the contract and change the judgment of the contract execution condition. Reading the state variable can obtain the state of the contract at this time. Therefore, after obtaining the function through the function selector, in order to find the attack path that the attacker may exploit, it is also necessary to extract the modification and reading operations of the state variables inside the function, and search for the names of the modified and read state variables.

[0055] After obtaining the read and write information of the function state variables, the read and write status of the state variables in the function can be obtained. If the calling relationship between functions can be known, the suspected attack path can be deduced in combination with the read and write information of the function state variables.

[0056] S102. Generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph and obtain suspicious attack data, wherein the suspicious attack data includes suspicious attack paths and vulnerability variables.

[0057] Specifically, the contract control flow graph is generated through the smart contract abstract syntax tree, which can be designed to include:

[0058] Generate three-address instructions according to the smart contract abstract syntax tree, and construct the three-address instructions into basic blocks;

[0059] Taking the basic blocks as control flow graph nodes, traverse the smart contract abstract syntax tree to obtain the path set containing all basic blocks to form the contract control flow graph.

[0060] Among them, tracking the data flow in the smart contract based on the contract control flow graph and obtaining suspicious attack data may include:

[0061] According to the data flow in the control flow graph, the flow direction of relevant variables in the smart contract in the function is tracked, and the preferred target function of the attack in the data flow is searched and obtained, and the preferred target function of the attack includes the smart contract self-destruction function and the smart contract transfer function;

[0062] Obtain suspicious attack data based on the attack preferred target function.

[0063] When it comes to attacking contracts, self-destruct functions and transfer functions are usually the attacker's first choice, so calculating how to successfully trigger these functions after executing a series of functions and modifying state variables is the key to detecting attack paths.

[0064] For the self-destruct function, Solidity has a built-in suicide function to implement the self-destruct function of the contract, which can be called without explicit declaration. After solc-0.5.0, it was changed to selfdestruct, and the calling method is suicide(address_to) or selfdestruct(address_to). The address type variable _to can be any address, which means that the self-destruct function enables developers to delete smart contracts from Ethereum and transfer ether to the account with address _to.

[0065] For transfer functions, Solidity supports three types of transfer operations, namely call, transfer and send functions. The calling methods are address.call.value(uint_n), address.transfer(uint_n), address.send(uint_n), where address is the address of the transfer recipient and _n is the transfer amount. When the smart contract executes these three types of transfer operations, the Ethereum virtual machine will send the ether stored in the contract to the recipient's account address. The main differences between the three come from the gas setting problem and security problem of the function itself, but the same thing is that they can all transfer money to the address by providing the address parameter.

[0066] Therefore, based on the algorithm for extracting the direct call relationship of functions, we start from the contract self-destruction function and the transfer function to find possible attack paths.<A,B> , find the contract self-destruction function, transfer function or function B with judgment logic.

[0067] Through the pre-processing of information extraction, the data reading and writing, function calling, function protection and other situations in the contract can be obtained. First, the contract source code is parsed to generate AST, and then the contract control flow graph (CFG) is constructed through AST. CFG contains all possible paths, and each node represents the basic code block in the program. CFG well displays the call relationship or loop branch between functions, and identifies the scope, life cycle and possible references of variables, so as to obtain the call relationship of functions. CFG is used to perform data flow analysis, track the flow of data in the contract in the function, and obtain a possible attack path and vulnerability variables when the self-destruction and transfer functions are found.

[0068] S103. Symbolize the parameters in the suspicious attack data based on symbolic execution and execute related transactions, obtain variable read and write change information based on the execution results, and verify the authenticity of the suspicious attack path.

[0069] Specifically, symbolizing parameters in suspicious attack data based on symbolic execution and executing related transactions may include:

[0070] Obtain key information of suspicious attack data in the smart contract source code, including contract functions, function modifiers, function parameters, and function signatures;

[0071] The key information of suspicious attack data is symbolized according to the Ethereum contract interaction standard, and transactions related to suspicious attack data are executed in a virtual Ethereum environment to deduce the changes in function variables during correct execution.

[0072] Among them, executing suspicious attack data related transactions in the virtual Ethereum environment may include:

[0073] Compile the smart contract source code into a binary file and deploy it in a virtual Ethernet environment. Allocate slots for each state variable in the source code so that when a function call is executed to modify the state variable, the real value pointed to by the state variable is obtained by reading the state variable slot and the corresponding offset.

[0074] Rewrite the callback function. In the virtual execution of the smart contract, the callback function is used to capture the read and write change information of the state variables of the suspicious attack data in the symbolic execution and the instructions currently executed by the smart contract. The callback function and the current execution instructions are compared with the layout information of the state variables of the smart contract source code to verify and determine the truth of the suspicious attack path and the read and write status of the vulnerability variables.

[0075] By performing symbolic execution on the attack path and vulnerability variables output by the path matching part, the authenticity of the attack path can be verified.

[0076] In order to verify the attack path using symbolic execution, it is necessary to re-acquire contract-related information, including contract functions, function modifiers, function parameters, and function signatures. The ABI of a contract is the standard way of contract interaction in Ethereum. It defines how to call functions in smart contracts and get return values. External accounts calling contracts or contract accounts calling contracts are all implemented through ABI. ABI specifies the format information required for EVM to execute a specified function, including function name, parameter list, return type, etc. By compiling the contract with solc, you can get a JSON format file of the contract ABI, or you can use the ABI library provided by manticore to more conveniently implement symbolic transaction data. For the attack path output in the previous section, symbolize the parameters and execute the transaction in turn, and deduce the variable values ​​and related information that can correctly execute the two functions.

[0077] In order to capture whether the variable is modified or read during function execution, the callback function needs to be rewritten to output key information during symbolic execution. The contract file will run in the virtual Ethereum environment created by Manticore, which can simulate the execution of smart contracts and the basic functions of the Ethereum blockchain. The information related to the contract file variables will be captured by Manticore, including runtime status (slots, offsets), contract addresses, and owners. During operation, ManticoreEVM will compile the contract source code into a binary file and deploy it on the virtual Ethereum environment. The state variables in the contract have unique slots. When calling a function to modify the variable, the slot and offset corresponding to the variable will be read to find the real value pointed to by the variable.

[0078] Combining the variable slot information used during contract execution with the contract state variable layout information automatically analyzed by solc or hardhat will allow us to know which variables are modified or read during function execution, and thus determine the true or false nature of the attack path. By using the write callback function and the read callback function, we can capture the read and write change information of variables during symbolic execution, and automatically output the variable slot information and offset information when the state variable is modified or read. For example, Figure 3 As shown, by comparing the slot and offset information with the previously automatically analyzed contract state variable layout information, it will be possible to find out whether the vulnerable variable is modified in function A and read in function B.

[0079] By rewriting various callback functions, in addition to capturing the contract state variables being read and written, you can also capture the instruction information being executed by the contract file, such as ADD, DUP, PUSH, etc. These instructions are close to the underlying logic, and you can more clearly view the current execution logic of the contract file. Combined with the write and read callback functions, you can capture the current state of the contract file and the currently executed instructions when there are important changes in the contract.

[0080] Based on the above, this solution also provides a delegate call vulnerability detection tool Delegate Tracker. The specific framework is as follows: Figure 4As shown in the figure, it is based on the capture of read and write data flow and is implemented through two stages: attack path search and attack path verification. The attack path search stage uses the established pattern to match the possible attack path. The attack path verification stage uses the dynamic symbolic execution method to capture the read and write information of the variable during function execution, and tries to verify the suspected attack path output by the pattern matching. It can focus on detecting delegate call vulnerabilities; taking the contract source code as input, the attack path search stage stores the read contract information, and uses the information extraction to obtain the function and variable related information, matches the established pattern in the vulnerability trigger logic, finds the possible attack path, and sends it as a new input to the attack path verification stage; in the attack path verification stage, the given attack path is symbolically executed, and it is determined whether the vulnerability variable output with the attack path is modified and read. If the match is successful, the abnormal result that the final output vulnerability may cause (such as contract self-destruction abnormality and currency sending abnormality, etc.), as well as the delegate call vulnerability attack path, the vulnerability variable name and its slot information. For more than one abnormal situation that may be caused by the vulnerability variable, Delegate Tracker will output the specific attack path.

[0081] By matching the three modes of contract self-destruction exception, currency sending exception, and judgment condition disorder exception, a more accurate path is obtained compared to the symbolic execution traversal path before the constraint, reducing the number of paths that need to be tested for symbolic execution, avoiding symbolic execution from traversing irrelevant paths for a long time, curbing the possibility of false alarms and path explosions, and then capturing the function variable status information at runtime to obtain accurate variable reading information, thereby knowing whether the attack path has the possibility of modifying the key variables of the contract, and obtaining an efficient and high-precision testing tool.

[0082] Furthermore, based on the above method, an embodiment of the present invention also provides a smart contract delegation call vulnerability detection system based on read-write data stream capture, comprising: an information extraction module, a path search module and a path verification module, wherein:

[0083] The information extraction module is used to construct an abstract syntax tree of the smart contract based on the smart contract source code, and extract information related to functions and variables in the smart contract based on the abstract syntax tree of the smart contract;

[0084] A path search module is used to generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph, and obtain suspicious attack data, wherein the suspicious attack data includes suspicious attack paths and vulnerability variables;

[0085] The path verification module is used to symbolize the parameters in the suspicious attack data based on symbolic execution and execute related transactions, obtain the variable read and write change information based on the execution results, and verify the authenticity of the suspicious attack path.

[0086] Unless otherwise specifically stated, the relative steps, numerical expressions and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present invention.

[0087] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0088] The units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods to implement the described functions for each specific application, but such implementation is not considered to be beyond the scope of the present invention.

[0089] Those skilled in the art will appreciate that all or part of the steps in the above method can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more integrated circuits, and accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of software function modules. The present invention is not limited to any specific form of combination of hardware and software.

[0090] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A smart contract delegate call vulnerability detection method based on read-write data stream capture, characterized in that: Include: Construct a smart contract abstract syntax tree based on the smart contract source code, and extract information related to functions and variables in the smart contract based on the smart contract abstract syntax tree; Generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph and obtain suspicious attack data, the suspicious attack data includes suspicious attack paths and vulnerability variables; Based on symbolic execution, the parameters in the suspicious attack data are symbolized and related transactions are executed. The variable read and write change information is obtained based on the execution results, and the authenticity of the suspicious attack path is verified.

2. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 1 is characterized in that: Construct the smart contract abstract syntax tree based on the smart contract source code, including: Compile the smart contract source code and convert it into an abstract syntax tree through lexical and grammatical analysis; Convert the grammatical structure in the source code into the node object of the abstract syntax tree, build the relationship between the nodes according to the abstract syntax tree node type and grammatical structure, and form the tree structure of the smart contract abstract syntax tree.

3. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 1 or 2 is characterized in that: Extract relevant information about functions and variables in smart contracts based on the smart contract abstract syntax tree, including: Read the smart contract abstract syntax tree, and obtain the function signatures and function entries of all functions in the smart contract through the function selector. The function signature is a function identifier composed of the function name and function parameters. The function modifier and the calling relationship are obtained through the function name, the read and write operations on the state variables inside each function are extracted, and the names of the state variables being read and written are obtained. The calling relationship includes a direct calling relationship and an indirect calling relationship.

4. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 1 is characterized in that: Generate a contract control flow graph through the smart contract abstract syntax tree, including: Generate three-address instructions according to the smart contract abstract syntax tree, and construct the three-address instructions into basic blocks; Taking the basic blocks as control flow graph nodes, traverse the smart contract abstract syntax tree to obtain the path set containing all basic blocks to form the contract control flow graph.

5. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 1 or 4 is characterized in that: Track the data flow in smart contracts based on the contract control flow graph and obtain suspicious attack data, including: According to the data flow in the control flow graph, the flow direction of relevant variables in the smart contract in the function is tracked, and the preferred target function of the attack in the data flow is searched and obtained, and the preferred target function of the attack includes the smart contract self-destruction function and the smart contract transfer function; Obtain suspicious attack data based on the attack preferred target function.

6. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 1 is characterized in that: Symbolize the parameters in the suspicious attack data based on symbolic execution and execute related transactions, including: Obtain key information of suspicious attack data in the smart contract source code, including contract functions, function modifiers, function parameters, and function signatures; The key information of suspicious attack data is symbolized according to the Ethereum contract interaction standard, and transactions related to suspicious attack data are executed in a virtual Ethereum environment to deduce the changes in function variables during correct execution.

7. The smart contract delegate call vulnerability detection method based on read-write data stream capture according to claim 6 is characterized in that: Execute suspicious attack data related transactions in a virtual Ethereum environment, including: Compile the smart contract source code into a binary file and deploy it in a virtual Ethernet environment. Allocate slots for each state variable in the source code so that when a function call is executed to modify the state variable, the real value pointed to by the state variable is obtained by reading the state variable slot and the corresponding offset. Rewrite the callback function. In the virtual execution of the smart contract, the callback function is used to capture the read and write change information of the state variables of the suspicious attack data in the symbolic execution and the instructions currently executed by the smart contract. The callback function and the current execution instructions are compared with the layout information of the state variables of the smart contract source code to verify and determine the truth of the suspicious attack path and the read and write status of the vulnerability variables.

8. A smart contract delegation call vulnerability detection system based on read-write data stream capture, characterized in that: It includes: information extraction module, path search module and path verification module, among which, The information extraction module is used to construct an abstract syntax tree of the smart contract based on the smart contract source code, and extract information related to functions and variables in the smart contract based on the abstract syntax tree of the smart contract; A path search module is used to generate a contract control flow graph through the smart contract abstract syntax tree, track the data flow in the smart contract based on the contract control flow graph, and obtain suspicious attack data, wherein the suspicious attack data includes suspicious attack paths and vulnerability variables; The path verification module is used to symbolize the parameters in the suspicious attack data based on symbolic execution and execute related transactions, obtain the variable read and write change information based on the execution results, and verify the authenticity of the suspicious attack path.

9. An electronic device, characterized in that: include: at least one processor, and a memory coupled to the at least one processor; The memory stores a computer program, and the computer program can be executed by the at least one processor to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 7 can be implemented.