ERC-20 contract backdoor detection method based on data flow analysis
Through the detection method based on data flow analysis, the two-level decompilation and optimization Datalog compilation method is used to identify the backdoor vulnerabilities in the ERC-20 smart contract, solving the limitations of traditional methods for detection, and improving the security of smart contracts and the stability of the blockchain ecosystem.
Patent Information
- Application Number
- CN202510015417.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-04-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The backdoor vulnerabilities present in the ERC-20 smart contract are difficult to fully cover by traditional static or limited dynamic analysis methods, resulting in limitations of security detection and potential asset losses.
The detection method based on data flow analysis is adopted, and the bytecode of the ERC-20 contract is converted into intermediate code through a two-level decompilation system, and the data flow analysis is performed using the optimized Datalog compilation method to identify backdoor vulnerabilities that are difficult to detect in traditional methods.
It realizes an in-depth analysis of the running behavior of ERC-20 contracts, and can quickly and accurately detect backdoor vulnerabilities, improving the security of smart contracts and the stability of the blockchain ecosystem.
Smart Images

Figure CN119808104A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain security, and in particular to an ERC-20 contract backdoor detection method based on data flow analysis. Background Art
[0002] As a token standard on Ethereum, ERC-20 manages the creation and issuance of smart contracts, supporting crowdfunding, token sales, and the development of decentralized applications (dApps). However, ERC-20 smart contracts have been plagued by security issues, especially integer overflow, improper permission control, and reentrancy attacks. These issues not only affect the economic model of tokens, but may also lead to the loss of user assets. More worryingly, there may be backdoor vulnerabilities in smart contracts, which may be maliciously exploited to bypass the normal logic of the contract and perform illegal operations, causing serious asset losses and trust crises. Traditional smart contract security detection methods, such as symbolic execution, formal verification, and fuzz testing, can detect security vulnerabilities to a certain extent, but they often rely on static analysis or limited dynamic analysis, and it is difficult to fully cover the runtime behavior of the contract, especially in the in-depth tracking and analysis of data flows. Summary of the invention
[0003] Purpose of the invention: The purpose of the present invention is to provide an ERC-20 contract backdoor detection method based on data flow analysis. It has important practical significance for improving the security of smart contracts and maintaining the stability of the blockchain ecosystem. The present invention can deeply analyze the runtime behavior of the contract, identify backdoor vulnerabilities that are difficult to find with traditional methods, and provide more comprehensive and in-depth technical support for the security audit of smart contracts.
[0004] Technical solution: The present invention provides an ERC-20 contract backdoor detection method based on data flow analysis, comprising the following steps:
[0005] Step 1: Through a two-level decompilation system, the bytecode of the ERC-20 contract is decompiled into ASM mnemonics, and then the ASM mnemonics are further decompiled into intermediate code representation;
[0006] Step 2: Classify the contract backdoors in the ERC-20 contract and design corresponding detection methods for each type of backdoor;
[0007] Step 3: Use the optimized Datalog compilation method to compile Soufle's Datalog source code into local machine code, and then perform data flow analysis on the intermediate code;
[0008] Step 4: Based on the results of steps 1 to 3, quickly detect possible backdoor risks in the ERC-20 contract.
[0009] Further, in step 1, the two-stage decompilation system includes:
[0010] A decompiler module to convert bytecode into ASM mnemonics;
[0011] An intermediate code conversion module is used to convert ASM mnemonics into intermediate code representation.
[0012] Furthermore, in step 2, the contract backdoors are classified into the following categories: amount manipulation, ownership acquisition, hidden ownership, contract self-destruction, transaction restrictions, complete sales restrictions, tax modifications, transaction cooling, inline assembly obfuscation checking of real jump flow, honeypot checking of overflow, external call checking of external call, and proxy contract.
[0013] Further, in step 2, the detection method includes:
[0014] Amount manipulation: By analyzing the transactions and balance modification operations in the contract, detect whether there is improper amount transfer or balance modification behavior, especially those operations that directly modify the user balance without going through normal business logic.
[0015] Ownership acquisition: Check whether there are inappropriate administrator permission settings in the contract, such as whether there are functions that can arbitrarily modify the administrator address or whether there are unlimited permission escalation mechanisms.
[0016] Hidden ownership: Analyze the contract code to find out whether there are hidden ownership transfers or control mechanisms, such as transferring control through complex conditionals or hidden call stacks.
[0017] Contract self-destruction: Detect whether there are self-destruct functions in the contract, especially those without proper permission control, which may be used for malicious purposes.
[0018] Trading restrictions: Checks whether the contract restricts the ability of certain addresses to trade, which could be used to manipulate the market, for example by checking if there are conditions in the contract that restrict trading to specific addresses.
[0019] Full sale restrictions: Analyze whether the contract restricts the sale of tokens, which may affect liquidity, such as checking whether there are lock-up periods or restrictions on trading pairs.
[0020] Tax modification: Check whether there are tax mechanisms in the contract that could be used maliciously to gain advantage, especially those that can arbitrarily modify tax rates or tax distribution.
[0021] Transaction Cooling: Analyze whether the contract contains transaction delay mechanisms that may be used to manipulate transactions, such as checking whether there are delayed transactions or conditional transaction delays.
[0022] Inline assembly obfuscation checks the real jump flow: By analyzing the inline assembly code in the contract, detect whether there is obfuscated or hidden real jump path, which may be used to hide malicious logic.
[0023] Honeypot check overflow: Detect whether there are honeypot patterns in the contract, which may be used to entrap user funds, such as checking whether there are abnormal high return promises or hidden conditional triggers.
[0024] External calls Check external calls: Analyze whether there are undisclosed functions called in the contract, which may be used for backdoor operations, especially those function calls that are not documented or invisible.
[0025] Proxy Contract: Checks whether a contract uses the proxy mode, which may be used to hide the real operation, such as checking whether a proxy contract exists and the permissions and behaviors of the proxy contract.
[0026] Furthermore, step 3 is specifically: compiling Soufle's Datalog source code into local machine code; and performing data flow analysis using the compiled machine code, which specifically includes the following steps:
[0027] Step 3.1: Compile Soufle's Datalog source code into native machine code
[0028] The Souflé compiler is used to convert the Datalog source code into an intermediate representation (IR). This step involves syntax analysis and semantic analysis to ensure the correctness of the Datalog code.
[0029] The intermediate representation is further compiled into the native machine code of the target platform, which involves code optimization and instruction selection to generate efficient native code.
[0030] Step 3.2:
[0031] Initialize the analysis environment: Set up the analysis environment, including defining the starting and ending points of the data flow analysis, and the types of data flows that need to be traced.
[0032] Build a control flow graph (CFG): Extract the control flow graph from the compiled machine code. CFG is the basis of data flow analysis, which defines the path of program execution.
[0033] Define rules for data flow analysis: Based on the characteristics of the ERC-20 contract backdoor, define rules for data flow analysis, such as tracking fund flows, permission changes, function calls, etc.
[0034] Perform data flow analysis: Based on CFG, apply the defined data flow analysis rules to track and analyze the flow of data in the program.
[0035] Detect abnormal data flows: Analyze the results of data flows and identify data flows that do not conform to the normal logic of the ERC-20 contract. These may be signs of backdoors.
[0036] Report and classify backdoors: Match detected anomalous data flows with known backdoor patterns, classify backdoors, and generate detailed detection reports.
[0037] Furthermore, step 4 is specifically as follows: write detection code using datalog language, design basic data structure, relationship type and basic rules; define behavior and backdoor standards for identification and detection.
[0038] The present invention also discloses a computer device, comprising a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method of the present invention.
[0039] The present invention also discloses a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of the method of the present invention are implemented.
[0040] The present invention also discloses a computer program product, comprising a computer program / instruction, which implements the steps of the method of the present invention when executed by a processor.
[0041] The present invention also discloses a smart contract security audit service, which provides an ERC-20 contract backdoor detection method based on data flow analysis as a service.
[0042] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages:
[0043] a) Detection method based on data flow analysis: This paper proposes an ERC-20 contract backdoor detection method based on data flow analysis. Compared with traditional contract backdoor detection methods, this scheme can detect the possible risks in ERC-20 contracts more quickly and accurately. By deeply analyzing the data flow, this method can effectively identify backdoor logic and hidden attack patterns, improving the comprehensiveness and accuracy of detection.
[0044] b) Two-level hierarchical decompilation scheme: The two-level hierarchical decompilation scheme designed by the present invention can not only decompile the contract bytecode more quickly and efficiently, but also significantly reduce memory and time overhead. This scheme improves the efficiency of the decompilation process by reducing unnecessary computing and storage requirements, saving valuable resources for subsequent security testing.
[0045] c) Data flow analysis technology, as a dynamic analysis method, can track the flow of data during program execution and help identify potential security vulnerabilities. In the field of smart contracts, data flow analysis can reveal the usage of variables, the legitimacy of function calls, and data dependencies, thereby discovering backdoor vulnerabilities and other security issues. The present invention has important practical significance for improving the security of smart contracts and maintaining the stability of the blockchain ecosystem. This method can deeply analyze the runtime behavior of the contract, identify backdoor vulnerabilities that are difficult to find with traditional methods, and provide more comprehensive and in-depth technical support for the security audit of smart contracts. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is the design drawing of the whole framework of the present invention;
[0047] Figure 2 Convert bytecode to ASM;
[0048] Figure 3 Convert to IR and CFG for ASM;
[0049] Figure 4 This is a comparison chart of the detection effect of the preset backdoor contract;
[0050] Figure 5 Comparison of detection results for real-world contracts;
[0051] Figure 6 For test speed comparison. DETAILED DESCRIPTION
[0052] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0053] The present invention designs an innovative two-level decompilation system, which first decompiles the bytecode of the ERC-20 contract into ASM mnemonics. This step takes advantage of the latest advances in decompilation technology, similar to jad and CFR tools, to improve the readability of the code. Subsequently, the system further decompiles the ASM mnemonics into an intermediate code representation, which not only improves the compatibility of the code, but also provides a more standardized basis for subsequent data flow analysis. Compared with traditional single-level decompilation, this two-level decompilation method can more accurately capture the logical structure and data flow of the contract, providing more precise input for backdoor detection.
[0054] The present invention has carefully classified the backdoors in ERC-20 contracts, including but not limited to known deformed bytecodes, self-destruction codes, and remote code calls. In view of these backdoor categories, the present invention deeply explores the possible risk points and designs corresponding detection methods. These methods not only include attention to high-risk instructions, such as SELFDESTRUCT, CALL, etc., but also cover deformation analysis of contract codes to identify hidden backdoors that may be maliciously exploited.
[0055] In terms of coding, the present invention proposes an optimized Datalog compilation method. The method first compiles the Soufle Datalog source code into local machine code, which significantly improves the execution efficiency. Subsequently, the compiled machine code is used for data flow analysis. Compared with the traditional interpretation execution method, this method can perform Datalog rule checks more quickly, thereby accelerating the security audit process of smart contracts.
[0056] Use datalog language to write detection code and design the following basic data structure:
[0057]
[0058] Design the following relationship types:
[0059]
[0060] Design the following basic rules:
[0061]
[0062]
[0063] The behavior and backdoor standards are defined as follows:
[0064]
[0065]
[0066]
[0067] This allows identification and detection.
[0068] Example
[0069] 1) Two-level decompilation system implementation
[0070] a) First, the bytecode of the ERC-20 contract is input into the decompilation system. The system uses the latest decompilation algorithm to convert the bytecode into ASM mnemonics. This step ensures the readability of the code and the accuracy of subsequent analysis.
[0071] b) Then, the system further converts the ASM mnemonics into intermediate code representation. This intermediate code is specially designed for data flow analysis, which can standardize the code structure of different contracts and facilitate subsequent automated analysis.
[0072] 2) Contract backdoor classification and detection implementation
[0073] a) Backdoor classification: Based on the predefined backdoor pattern library, the backdoors in the ERC-20 contract are divided into multiple categories, including but not limited to permission abuse, hidden calls, logic traps, etc.
[0074] b) Risk mining: For each category, use static analysis tools to deeply explore possible security risk points, including calls to high-risk functions, abnormal code structures, etc.
[0075] c) Detection method design: For each risk point, a corresponding detection method is designed. For example, for abuse of authority, check whether there are inappropriate administrator authority settings in the contract; for hidden calls, the present invention analyzes whether there are undisclosed functions called in the contract.
[0076] 3) Optimized Datalog compilation method implementation
[0077] a) Soufle Datalog compilation: The present invention compiles the Soufle Datalog source code into local machine code. This step utilizes modern compiler technology to improve the execution efficiency of the code.
[0078] b) Data flow analysis: The compiled machine code will be used to perform data flow analysis. This analysis process takes advantage of the efficiency of compilation to quickly check the Datalog rules of the ERC-20 contract and identify potential backdoors and security vulnerabilities.
[0079] Advantages of detection method implementation:
[0080] Fast detection: Through the above two-level decompilation and optimized Datalog compilation method, the detection method of the present invention can quickly perform backdoor detection on ERC-20 contracts, which greatly reduces the detection time compared with traditional methods.
[0081] Reduced overhead: The two-level decompilation scheme effectively reduces memory and time overhead, making large-scale contract auditing possible while maintaining high efficiency and accuracy.
[0082] In order to evaluate the backdoor detection solution of the present invention, the present invention conducted the following tests:
[0083] (i) Use 260 pre-designed test sets containing 13 preset backdoors to test the detection effect;
[0084] (ii) Use 3598 ERC-20 contracts in the real world to test the effect;
[0085] (iii) The detection speed of the scheme is tested using 5-group contractions of different sizes.
[0086] The pre-designed contract detection results are as follows. It completes all the preset types of detection and is better than similar solutions, such as Figure 4 shown.
[0087] We used 3598 ERC-20 contracts in the real world to test the results. Figure 5 As shown, this solution detected the most backdoor risks.
[0088] The detection speed of the scheme was tested using 5 groups of contracts of different sizes. The test results show that no matter what the bytecode of the contract is, the scheme always performs well in detection speed. Figure 6 As shown in Figure 2, when the bytecode length is less than 3500 bytes, the detection time gradually increases as the bytecode length increases. However, for contracts with bytecode lengths exceeding 3500 bytes, a clear divergence emerges. In this case, the detection time of other schemes increases significantly, while this scheme maintains its efficiency in three operating systems: Windows, Linux, and Android.
[0089] These results highlight the robustness and scalability of our scheme in handling smart contracts of varying complexity and size.
Claims
1. A method for detecting backdoors in ERC-20 contracts based on data flow analysis, characterized in that: The steps include: Step 1: Through a two-level decompilation system, the bytecode of the ERC-20 contract is decompiled into ASM mnemonics, and then the ASM mnemonics are further decompiled into intermediate code representation; Step 2: Classify the contract backdoors in the ERC-20 contract and design corresponding detection methods for each type of backdoor; Step 3: Use the optimized Datalog compilation method to compile Soufle's Datalog source code into local machine code, and then perform data flow analysis on the intermediate code in step 1; Step 4: Based on the results of steps 1 to 3, detect the backdoor risk in the ERC-20 contract.
2. According to claim 1, a method for detecting ERC-20 contract backdoor based on data flow analysis is characterized in that: In step 1, the two-stage decompilation system includes: A decompiler module to convert bytecode into ASM mnemonics; An intermediate code conversion module is used to convert ASM mnemonics into intermediate code representation.
3. According to claim 1, a method for detecting ERC-20 contract backdoor based on data flow analysis is characterized in that: In step 2, the contract backdoor is classified into: Amount manipulation: Check whether there is any improper amount transfer or balance modification in the contract; Ownership acquisition: Check whether there are inappropriate administrator permission settings in the contract, which may lead to illegal transfer of ownership; Hidden ownership: Analyze the contract code to find out if there are any hidden ownership transfers or control mechanisms; Contract self-destruction: Detect whether there is a self-destruction function in the contract for malicious purposes; Trading restrictions: Check if the contract restricts the address’s trading capabilities for market manipulation; Complete sales restrictions: Analyze whether the contract restricts the sale of tokens, affecting liquidity; Tax modification: Check whether there is a tax mechanism in the contract that is used maliciously to gain benefits; Transaction cooling: Analyze whether the contract contains a transaction delay mechanism to manipulate transactions; Inline assembly obfuscation checks the real jump flow: By analyzing the inline assembly code in the contract, detect whether there is an obfuscated or hidden real jump path; Honeypot check overflow: detect whether there is a honeypot mode in the contract to trap user funds; External calls Check external calls: Analyze whether undisclosed functions in the contract are called for backdoor operations; Proxy Contract: Checks whether the contract uses proxy mode to hide the real operation.
4. According to claim 3, a method for detecting ERC-20 contract backdoor based on data flow analysis is characterized in that: In step 2, the detection method comprises: Amount manipulation: By analyzing the transactions and balance modification operations in the contract, detect whether there is improper amount transfer or balance modification behavior, including operations that directly modify the user balance without going through normal business logic; Ownership acquisition: Check whether there are inappropriate administrator permissions in the contract, including whether there are functions that can arbitrarily modify the administrator address or whether there are unlimited permission escalation mechanisms; Hidden ownership: Analyze the contract code to find out whether there are hidden ownership transfers or control mechanisms, including transferring control through complex conditional judgments or hidden call stacks; Contract self-destruction: Detect whether there is a self-destruction function in the contract, including self-destruction functions without proper permission control for malicious purposes; Trading restrictions: Check if the contract restricts the address’s ability to trade, which can be used to manipulate the market, including by checking if there are conditions in the contract that restrict trading to a specific address; Complete sales restrictions: Analyze whether the contract restricts the sale of tokens, affecting liquidity, including checking whether there are lock-up periods or restrictions on trading pairs; Tax modification: Check whether there are tax mechanisms in the contract that are used maliciously to gain benefits, including mechanisms that arbitrarily modify tax rates or tax distribution; Transaction cooling: Analyze whether the contract contains a transaction delay mechanism used to manipulate transactions, including checking whether there are delayed transactions or conditional transaction delays; Inline assembly obfuscation checks the real jump flow: By analyzing the inline assembly code in the contract, detect whether there is an obfuscated or hidden real jump path to hide malicious logic; Honeypot check overflow: Detect whether there is a honeypot mode in the contract to trap user funds, including checking whether there are abnormal high return promises or hidden conditional triggers; External calls Check external calls: Analyze whether there are undisclosed functions in the contract that are called for backdoor operations, including missing documentation or invisible function calls; Proxy Contract: Checks whether the contract uses the proxy mode to hide the real operation, including checking whether there is a proxy contract and the permissions and behaviors of the proxy contract.
5. According to claim 1, a method for detecting ERC-20 contract backdoor based on data flow analysis is characterized in that: Step 3 is specifically: compile Soufle's Datalog source code into local machine code; use the compiled machine code to perform data flow analysis, which specifically includes the following steps: Step 3.1: Compile Soufle's Datalog source code into native machine code Use the Souflé compiler to convert Datalog source code into intermediate representation IR; this involves syntax analysis and semantic analysis to ensure the correctness of the Datalog code; The intermediate representation is further compiled into the native machine code of the target platform, which involves code optimization and instruction selection to generate efficient native code; Step 3.2: Initialize the analysis environment: Set up the analysis environment, including defining the starting and ending points of the data flow analysis, and the types of data flows that need to be tracked; Build a control flow graph (CFG): Extract the control flow graph from the compiled machine code. CFG is the basis of data flow analysis and defines the execution path of the program. Define the rules for data flow analysis: Based on the characteristics of the ERC-20 contract backdoor, define the rules for data flow analysis, including tracking fund flows, permission changes, and function calls; Perform data flow analysis: Based on CFG, apply the defined data flow analysis rules to track and analyze the flow of data in the program; Detect abnormal data flow: Analyze the results of data flow and identify data flow that does not conform to the normal logic of ERC-20 contract; Report and classify backdoors: Match detected anomalous data flows with known backdoor patterns, classify backdoors, and generate detailed detection reports.
6. According to claim 1, a method for detecting ERC-20 contract backdoor based on data flow analysis is characterized in that: Step 4 is as follows: Use the datalog language to write detection code, design basic data structures, relationship types, and basic rules; define behavior and backdoor standards for identification and detection.
7. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method of claim 1.
8. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.
9. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.
10. A smart contract security audit service, characterized in that: The ERC-20 contract backdoor detection method based on data flow analysis as described in claim 1 is provided as a service.