Root cause detection method and device for ethereum virtual machine defects
By generating Ethereum Virtual Machine test cases based on a target large language model and combining it with a differential testing engine, the problem of generating semantically valid and diverse test cases in existing technologies is solved, and the automated identification of Ethereum Virtual Machine defects and root cause localization are achieved.
Patent Information
- Application Number
- CN202411742485.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2044-11-29
AI Technical Summary
Existing technologies cannot generate semantically valid and diverse Ethereum Virtual Machine (EVM) test cases, nor can they automatically identify and locate defects in the EVM implementation, resulting in an inability to effectively cover boundary conditions and defective parts during the execution of the EVM.
Test cases for the Ethereum Virtual Machine are generated based on the target large language model. Combined with a pre-built differential testing engine, execution process information and results are obtained. The target defect identification index is used to determine whether there are defects in the source code. The root cause of the defects is determined through the target large language model.
It enables the generation of semantically valid and diverse test cases, which can quickly locate the root cause of defects in the Ethereum Virtual Machine and improve the automation and accuracy of defect detection.
Smart Images

Figure CN119668913B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Ethereum Virtual Machine (EVM) defect detection technology, and in particular to a method and apparatus for detecting the root cause of EVM defects. Background Technology
[0002] In recent years, blockchain technology has received widespread attention from academia, industry, and governments worldwide. Ethereum, as the world's second-largest blockchain platform, has experienced rapid growth, supporting the operation of smart contracts, the processing of cross-shard transactions in sharded blockchains, and upper-layer applications such as non-fungible tokens, decentralized finance, and games. Ethereum's smart contracts rely on the underlying Ethereum Virtual Machine (EVM); however, some flaws exist in the implementation of the EVM, leading to vulnerabilities that affect the security and availability of the blockchain system.
[0003] In related technologies, Ethereum Virtual Machine defect detection can be performed by relying on bytecode generated by smart contract compilers; NeoDiff or go evmlab can be used to generate bytecode based on predefined templates, and a template-based bytecode-level test case generation method can be used for defect detection.
[0004] However, in related technologies, because smart contract compilers cannot generate semantically invalid test cases, directly using the bytecode generated by the smart contract compiler for Ethereum Virtual Machine (EVM) defect detection cannot detect the logic in the EVM implementation that handles semantically invalid bytecode, resulting in an inability to effectively cover boundary cases during EVM execution. In addition, the bytecode generated by the smart contract compiler contains a large number of opcodes, and finding the opcodes that cause defects requires manual analysis, which is inefficient and prone to errors. NeoDiff and goevmlab use bytecode-level test case generation methods that rely on predefined templates to generate bytecode, requiring manual template writing, resulting in poor scalability of the generated bytecode, an inability to cover more EVM code implementations, and an inability to identify the specific defective parts in the opcode implementation. Summary of the Invention
[0005] This application provides a method and apparatus for detecting the root cause of Ethereum Virtual Machine (EVM) defects, in order to solve the problems in related technologies, such as the inability to generate semantically valid and diverse EVM test cases, and the inability to automatically identify defects in the EVM implementation and locate the root cause of the defects.
[0006] The first aspect of this application provides a method for detecting the root cause of defects in the Ethereum Virtual Machine (EVM), comprising the following steps: generating test cases for the EVM based on a target large language model; obtaining execution process information and execution results of the EVM based on the test cases and a pre-built differential testing engine; determining whether the source code of the EVM's implementation of the opcode has defects based on the execution process information and the execution results, combined with a target defect identification index; and determining the root cause of the defect based on the source code of the opcode implementation and the target large language model if the source code of the EVM's implementation of the opcode has defects.
[0007] Optionally, in one embodiment of this application, the step of generating test cases for the Ethereum Virtual Machine based on the Target Large Language Model includes: determining a first hint word for the opcode in the Ethereum Virtual Machine based on the Ethereum Execution Layer Specification; obtaining a first seed generator for implementing the opcode using the Target Large Language Model based on the first hint word; obtaining an inter-process control flow graph of the opcode implementation function; determining a second hint word for the opcode implementation function based on the seed output by the first seed generator, the mnemonic word of the seed, and the inter-process control flow graph; obtaining a second seed generator for implementing the opcode using the Target Large Language Model based on the second hint word, and obtaining the test cases using the second seed generator.
[0008] Optionally, in one embodiment of this application, the step of generating test cases for the Ethereum Virtual Machine based on the target large language model further includes: determining whether the seed output by the second seed generator needs to be mutated; if the seed needs to be mutated, randomly obtaining the boundary value of the operand of the opcode, and using the boundary value to replace the operand of the seed to obtain the test cases.
[0009] Optionally, in one embodiment of this application, before obtaining the execution process information and execution result of the Ethereum Virtual Machine based on the test cases and the pre-built differential testing engine, the method further includes: obtaining the network fork of the Ethereum Virtual Machine; obtaining the account status of the Ethereum Virtual Machine; obtaining the global status of the Ethereum Virtual Machine; and building the differential testing engine based on the same network fork, the same account status, and the same global status.
[0010] Optionally, in one embodiment of this application, the target defect identification indicator may include, but is not limited to, at least one of the Ethereum Virtual Machine's return value, gas consumption, and storage.
[0011] Optionally, in one embodiment of this application, if the source code of the Ethereum Virtual Machine's implementation of the opcode has a defect, determining the root cause of the defect based on the source code of the opcode implementation and the target large language model includes: obtaining the corresponding opcode implementation function based on the source code of the Ethereum Virtual Machine implementation; and analyzing the opcode implementation function corresponding to the defect in conjunction with the target large language model to obtain the root cause based on the analysis results.
[0012] A second aspect of this application provides a root cause detection device for Ethereum Virtual Machine (EVM) defects, comprising: a first generation module for generating test cases for the EVM based on a target large language model; a second generation module for obtaining execution process information and execution results of the EVM based on the test cases and a pre-built differential testing engine; a judgment module for determining whether the source code of the EVM's implementation of the opcode has defects based on the execution process information and the execution results, combined with a target defect identification index; and a determination module for determining the root cause of the defect based on the source code of the opcode implementation and the target large language model when the source code of the EVM's implementation of the opcode has defects.
[0013] Optionally, in one embodiment of this application, the first generation module includes: a first determining unit, configured to determine a first prompt word for the opcode in the Ethereum Virtual Machine based on the Ethereum Execution Layer Specification; a first generation unit, configured to obtain a first seed generator for implementing the opcode based on the first prompt word using the Target Large Language Model; an acquisition unit, configured to acquire the inter-process control flow graph of the opcode implementation function; a second determining unit, configured to determine a second prompt word for the opcode implementation function based on the seed output by the first seed generator, the mnemonic word of the seed, and the inter-process control flow graph; and a second generation unit, configured to obtain a second seed generator for implementing the opcode based on the second prompt word using the Target Large Language Model, and obtain the test case using the second seed generator.
[0014] Optionally, in one embodiment of this application, the first generation module further includes: a judgment unit, configured to judge whether the seed output by the second seed generator needs to be mutated; and a third generation unit, configured to, when the seed needs to be mutated, randomly obtain the boundary value of the operand of the opcode, so as to use the boundary value to replace the operand of the seed to obtain the test case.
[0015] Optionally, in one embodiment of this application, it further includes: a first acquisition module, configured to acquire the network fork of the Ethereum Virtual Machine before acquiring the execution process information and execution result of the Ethereum Virtual Machine based on the test cases and the pre-built differential test engine; a second acquisition module, configured to acquire the account status of the Ethereum Virtual Machine; a third acquisition module, configured to acquire the global status of the Ethereum Virtual Machine; and a construction module, configured to construct the differential test engine based on the same network fork, the same account status, and the same global status.
[0016] Optionally, in one embodiment of this application, the target defect identification indicator may include, but is not limited to, at least one of the Ethereum Virtual Machine's return value, gas consumption, and storage.
[0017] Optionally, in one embodiment of this application, the determining module includes: a fourth generation unit, used to obtain the corresponding opcode implementation function based on the source code implemented by the Ethereum Virtual Machine; and an analysis unit, used to analyze the opcode implementation function corresponding to the defect in conjunction with the target large language model, so as to obtain the root cause based on the analysis results.
[0018] A third aspect of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the root cause detection method for Ethereum Virtual Machine defects as described in the above embodiments.
[0019] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned root cause detection method for Ethereum Virtual Machine defects.
[0020] A fifth aspect of this application provides a computer program product, including a computer program that, when executed, implements the root cause detection method for Ethereum Virtual Machine defects as described above.
[0021] This application's embodiments can generate test cases for the Ethereum Virtual Machine (EVM) based on a target large language model. Based on these test cases and a pre-built differential testing engine, it obtains execution process information and results for the EVM. Then, combined with target defect identification indicators, it determines whether the EVM's opcode implementation source code has defects. If defects are found, it identifies the root cause of the defects based on the opcode implementation source code and the target large language model. Through the target large language model, semantically valid and diverse test cases are obtained. Using the pre-built differential testing engine and target defect identification indicators, the root cause of defects can be quickly located. Therefore, this solves the problems in related technologies, such as the inability to generate semantically valid and diverse EVM test cases and the inability to automatically identify and locate the root cause of EVM implementation defects.
[0022] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0023] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0024] Figure 1 This is a flowchart of a root cause detection method for Ethereum Virtual Machine defects according to an embodiment of this application;
[0025] Figure 2 A flowchart illustrating the working principle of a root cause detection method for Ethereum Virtual Machine defects according to an embodiment of this application;
[0026] Figure 3 A block diagram of an Ethereum Virtual Machine defect root cause detection device provided according to an embodiment of this application;
[0027] Figure 4 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0028] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0029] The following describes a method and apparatus for detecting the root cause of Ethereum Virtual Machine (EVM) defects according to embodiments of this application, with reference to the accompanying drawings. Addressing the problems mentioned in the background art, such as the inability to generate semantically valid and diverse EVM test cases and the inability to automatically identify and locate the root cause of EVM implementation defects, this application provides a method for detecting the root cause of EVM defects. In this method, test cases for the EVM can be generated based on a target large language model. Based on the test cases and a pre-built differential testing engine, the execution process information and execution results of the EVM are obtained. Then, combined with target defect identification indicators, it is determined whether there are defects in the source code of the EVM's opcode implementation. If defects are found, the root cause of the defects is determined based on the opcode implementation source code and the target large language model. Through the target large language model, semantically valid and diverse test cases are obtained. Through the pre-built differential testing engine and target defect identification indicators, the root cause of the defects can be quickly located. Thus, the problems of the related art, such as the inability to generate semantically valid and diverse EVM test cases and the inability to automatically identify and locate the root cause of EVM implementation defects, are solved.
[0030] Specifically, Figure 1 This is a flowchart of a root cause detection method for Ethereum Virtual Machine defects according to an embodiment of this application.
[0031] like Figure 1 As shown, the root cause detection method for this Ethereum Virtual Machine defect includes the following steps:
[0032] In step S101, test cases for the Ethereum Virtual Machine are generated based on the target large language model.
[0033] Those skilled in the art will understand that the embodiments of this application can select a suitable target large language model to generate test cases for the Ethereum Virtual Machine. The target large language model possesses powerful natural language processing capabilities, enabling it to understand and generate code and instructions related to the Ethereum Virtual Machine. The specific settings can be configured by those skilled in the art according to actual circumstances, and this application does not impose any specific limitations.
[0034] Optionally, in one embodiment of this application, generating test cases for the Ethereum Virtual Machine based on a target large language model includes: determining a first prompt word for the opcode in the Ethereum Virtual Machine based on the Ethereum Execution Layer Specification; obtaining a first seed generator for implementing the opcode using the target large language model based on the first prompt word; obtaining the inter-process control flow graph of the opcode implementation function; determining a second prompt word for the opcode implementation function based on the seed output by the first seed generator, the mnemonic word of the seed, and the inter-process control flow graph; obtaining a second seed generator for implementing the opcode using the target large language model based on the second prompt word, and obtaining test cases using the second seed generator.
[0035] As one possible implementation, embodiments of this application can generate semantically valid and diverse Ethereum Virtual Machine test cases based on the Ethereum execution layer specification, combined with static analysis techniques and a target large language model. The main content of these test cases may include:
[0036] In some embodiments, the Ethereum Execution Layer Specification of this application defines the functionality that Ethereum Virtual Machine opcodes should implement. To achieve a developer-friendly specification, the Ethereum Execution Layer Specification is implemented using the Python programming language and includes semantically rich natural language annotations. To generate semantically valid test cases for Ethereum Virtual Machine opcodes, this application can leverage the natural language processing and code generation capabilities of a target large oracle model. It can construct a first prompt word using the opcode implementation function in the Ethereum Execution Layer Specification, and call the target large oracle model based on the first prompt word. This allows the target large oracle model to understand the Ethereum Execution Layer Specification and generate a first seed generator for Ethereum Virtual Machine opcodes. The execution of the first seed generator then yields semantically valid test cases for a given Ethereum Virtual Machine opcode.
[0037] Furthermore, since function calls exist in the Ethereum execution layer specification of this application embodiment, the definition function of the opcode alone cannot cover the entire control flow in the opcode definition. Therefore, static analysis technology can be used to obtain the inter-process control flow graph of the opcode implementation function in the Ethereum execution layer specification.
[0038] Furthermore, it should be noted that, considering the potential lack of diversity in the seeds output by the first seed generator, this application embodiment designs a control flow-oriented mutation method, which can be understood as follows: using the opcode name, the seed output by the first seed generator, the mnemonic phrase of the seed, and the obtained inter-process control flow graph to construct a second prompt word for the opcode implementation function, and calling the target large language model based on the second prompt word to generate a second seed generator for the Ethereum Virtual Machine opcode, and executing the second seed generator to obtain test cases that can cover all paths in the control flow of the opcode implementation function.
[0039] Optionally, in one embodiment of this application, generating test cases for the Ethereum Virtual Machine based on the target large language model further includes: determining whether the seed output by the second seed generator needs to be mutated; if the seed needs to be mutated, randomly obtaining the boundary values of the opcode operands to replace the operands of the seed with the boundary values to obtain test cases.
[0040] It is understandable that in the test cases obtained by the second seed generator in this application embodiment, since specific branches in the control flow of the function implementing the opcode require operands with specific boundary values, the target large language model may not be able to generate seed mutations. Therefore, in order to cover test cases for all paths, a parameter-oriented mutation method is designed. By determining whether the seed output by the second seed generator needs mutation, if the seed needs mutation, the boundary values of the opcode operands are randomly obtained to replace the operands of the seed, thereby obtaining test cases, increasing the possibility of test cases covering boundary situations, and improving the diversity of test cases. The mutation seeds involved in the embodiments of this application are described below with reference to Table 1. Table 1 is a comparison table of mutation seeds provided according to an embodiment of this application.
[0041] Table 1
[0042]
[0043] Optionally, in one embodiment of this application, before obtaining the execution process information and execution results of the Ethereum Virtual Machine based on test cases and a pre-built differential testing engine, the method further includes: obtaining the network fork of the Ethereum Virtual Machine; obtaining the account status of the Ethereum Virtual Machine; obtaining the global status of the Ethereum Virtual Machine; and building a differential testing engine based on the same network fork, the same account status, and the same global status.
[0044] It is understood that, in this embodiment of the application, since specific branches in the opcode execution path require different execution environments to be configured for triggering, this embodiment of the application will randomly execute the environment in each round of differential testing while ensuring consistency of the execution environment. That is, it will construct the differential test engine using the same network fork, the same account state, and the same global state. Specifically, its main content can be:
[0045] (1) Network Forks: Ethereum uses network forks to introduce new technical features. Different network forks within the Ethereum Virtual Machine (EVM) may contain different instruction sets, meaning the number of supported opcodes or functionalities may differ. Therefore, to avoid false positives, this application embodiment can set the Ethereum Virtual Machine for differential testing under the same network fork; this application does not impose specific limitations.
[0046] (2) Account Status: Ethereum transaction execution may affect changes in account status. Therefore, in order to avoid false alarms caused by different account statuses, this application embodiment can set the addresses involved in the Ethereum Virtual Machine test to addresses containing the same balance and code. This application does not impose specific restrictions.
[0047] (3) Global state: The execution of the Ethereum Virtual Machine may require reading some global state on the chain, such as fields such as "timestamp" and "block number". Therefore, in differential testing, the embodiments of this application can unify the global state. This application does not impose specific restrictions.
[0048] In step S102, based on test cases and a pre-built differential testing engine, the execution process information and execution results of the Ethereum Virtual Machine are obtained.
[0049] As one possible approach, in order to perform defect detection on the Ethereum Virtual Machine based on differential testing, this application embodiment can call Ethereum Virtual Machines implemented in different programming languages based on a pre-built differential testing engine, prepare the same execution environment for the execution of the Ethereum Virtual Machine, and collect execution process information and execution results during execution.
[0050] Additionally, it should be noted that in this embodiment, the input to the pre-built differential testing engine is the test cases generated above, and the output is the execution process information and execution results after the Ethereum Virtual Machine executes the test cases. The execution process information and execution results may include, but are not limited to, information such as the program counter, memory, stack, and consumed gas; this application does not impose specific limitations.
[0051] In step S103, based on the execution process information and execution results, and in conjunction with the target defect identification indicators, it is determined whether there are defects in the source code of the Ethereum Virtual Machine's opcode implementation. The target defect identification indicators may include, but are not limited to, at least one of the Ethereum Virtual Machine's return values, gas consumption, and storage.
[0052] It is understood that after collecting the execution process information and execution results, the embodiments of this application can design target defect identification indicators to determine whether there are inconsistencies and potential defects in the execution of the Ethereum Virtual Machine. In the embodiments of this application, the target defect identification indicators may include, but are not limited to, at least one of the return value of the Ethereum Virtual Machine, gas consumption, and storage.
[0053] Among them, the return value: The return value of the Ethereum Virtual Machine is usually used as the return value of a function call, which represents the result of the current execution.
[0054] Gas Consumption: The Ethereum Virtual Machine (EVM) uses the concept of gas to limit the consumption of physical resources. Inconsistent gas consumption across EVMs indicates a flaw in the opcode implementation or that the EVMs are executing different control flows.
[0055] Storage: Storage refers to the impact of the Ethereum Virtual Machine on persistent storage on the blockchain. After executing storage-related opcodes (SSTORE, TSTORE, CREATE, CREATE2, SELFDESTRUCT, REVERT, etc., which are not specifically limited in this application), the embodiments of this application can record the impact of the Ethereum Virtual Machine's execution on storage.
[0056] As one possible implementation method, embodiments of this application can determine whether the source code of the opcode implementation has defects based on the target defect identification index after collecting execution process information and execution results.
[0057] In step S104, if the source code of the Ethereum Virtual Machine's opcode implementation has defects, the root cause of the defects is determined based on the source code of the opcode implementation and the target large language model.
[0058] In actual implementation, when there are defects in the source code of the Ethereum Virtual Machine's opcode implementation, this application embodiment can design a root cause localization algorithm based on the source code of the opcode implementation and the target large language model to determine the root cause of the defect.
[0059] Optionally, in one embodiment of this application, if the source code of the Ethereum Virtual Machine's opcode implementation has defects, the root cause of the defects is determined based on the source code of the opcode implementation and the target large language model, including: obtaining the corresponding opcode implementation function based on the source code of the Ethereum Virtual Machine implementation; and analyzing the opcode implementation function corresponding to the defects in conjunction with the target large language model, so as to obtain the root cause based on the analysis results.
[0060] In some embodiments, the present application's implementation determines the root cause of a defect based on a designed root cause localization algorithm. The main content includes: comparing execution process information of different Ethereum Virtual Machines (EVMs) during execution, comparing line by line to find the opcodes causing inconsistencies, then finding the corresponding opcode implementation functions in the source code of the EVM implementation, and based on analysis of the Ethereum execution layer specification, locating the opcode defect to different stages within the opcode implementation function, thereby obtaining the root cause. Table 2 is an implementation table of a root cause localization algorithm according to one embodiment of the present application.
[0061] Table 2
[0062]
[0063] The working principle of the root cause detection method for Ethereum Virtual Machine defects proposed in this application will be described in detail below with reference to a specific embodiment.
[0064] in, Figure 2 This is a flowchart illustrating the working principle of a root cause detection method for Ethereum Virtual Machine defects according to an embodiment of this application.
[0065] like Figure 2 As shown in the figure, the root cause detection method for Ethereum Virtual Machine defects proposed in this application mainly includes three parts. The first part is the generation of test cases assisted by the target large language model, mainly including steps S201-S205; the second part is the pre-construction of a differential testing engine, mainly including steps S206 and S207; and the third part is the automatic identification and root cause localization of Ethereum Virtual Machine defects, mainly including steps S208-S210. The input to the second part is the test cases generated in the first part, and the input to the third part is the execution process information and execution results obtained in the second part. The three parts will be described in detail below.
[0066] Step S201: Obtain the Ethereum Execution Layer Specification.
[0067] Step S202: Construct a seed generator.
[0068] Step S203: Obtain the inter-process control flow graph.
[0069] It can be understood that, in the first part of the embodiments of this application, based on the Ethereum execution layer specification, the natural language processing capabilities and code generation capabilities of the target big language model can be used to construct the first prompt word by utilizing the opcode implementation function in the Ethereum execution layer specification, and the target big language model can be called based on the first prompt word, so that the target big oracle model can understand the Ethereum execution layer specification and generate the first seed generator of the Ethereum virtual machine opcode, and then execute the first seed generator to obtain a semantically valid test case of a certain Ethereum virtual machine opcode.
[0070] Furthermore, since function calls exist in the Ethereum execution layer specification of this application embodiment, the definition function of the opcode alone cannot cover the entire control flow in the opcode definition. Therefore, static analysis technology can be used to obtain the inter-process control flow graph of the opcode implementation function in the Ethereum execution layer specification.
[0071] Step S204: Design a mutation method oriented towards control flow.
[0072] Step S205: Design a parameter-oriented mutation method.
[0073] It can be understood that, considering the potential lack of diversity in the seeds output by the first seed generator, this application embodiment designs a control flow-oriented mutation method and a parameter-oriented mutation method, the details of which are as described above and will not be elaborated further here.
[0074] Step S206: Initialize a consistent execution environment.
[0075] Step S207: Differential test.
[0076] It can be understood that in the second part of the embodiments of this application, a differential test engine can be built using the same network fork, the same account state, and the same global state, and the execution environment can be randomly executed under the premise of ensuring that the execution environment is consistent, so as to carry out differential testing.
[0077] Step S208: Defect identification.
[0078] Step S209: Root cause identification.
[0079] Step S210: Root cause.
[0080] This can be understood as follows: In the third part of this application embodiment, after collecting execution process information and execution results, a target defect identification index can be designed to determine whether there are inconsistencies and potential defects in the execution of the Ethereum Virtual Machine. Furthermore, if there are defects in the source code of the Ethereum Virtual Machine's opcode implementation, a root cause localization algorithm is designed based on the opcode implementation source code and the target large language model to determine the root cause of the defect. The implementation table of the root cause localization algorithm is shown in Table 2.
[0081] The root cause detection method for Ethereum Virtual Machine (EVM) defects proposed in this application can generate test cases for the EVM based on a target large language model. Based on these test cases and a pre-built differential testing engine, it obtains the execution process information and results of the EVM. Then, combined with target defect identification indicators, it determines whether there are defects in the source code implementing the opcodes of the EVM. If defects are found, the root cause of the defects is determined based on the source code implementing the opcodes and the target large language model. Through the target large language model, semantically valid and diverse test cases are obtained. Using the pre-built differential testing engine and target defect identification indicators, the root cause of the defects can be quickly located. This solves the problems in related technologies, such as the inability to generate semantically valid and diverse EVM test cases and the inability to automatically identify and locate the root cause of defects in the EVM implementation.
[0082] Next, referring to the accompanying drawings, a root cause detection device for Ethereum Virtual Machine defects proposed according to an embodiment of this application is described.
[0083] Figure 3 This is a block diagram of a root cause detection device for Ethereum Virtual Machine defects provided according to an embodiment of this application.
[0084] like Figure 3 As shown, the root cause detection device 10 for Ethereum Virtual Machine defects includes: a first generation module 100, a second generation module 200, a judgment module 300, and a determination module 400.
[0085] The first generation module 100 is used to generate test cases for the Ethereum Virtual Machine based on the target large language model.
[0086] The second generation module 200 is used to obtain the execution process information and execution results of the Ethereum Virtual Machine based on test cases and a pre-built differential testing engine.
[0087] The judgment module 300 is used to determine whether there are defects in the source code of the Ethereum Virtual Machine's opcode implementation based on the execution process information and execution results, combined with the target defect identification index.
[0088] The determination module 400 is used to determine the root cause of defects in the source code of the opcode implementation of the Ethereum Virtual Machine based on the source code of the opcode implementation and the target large language model when defects exist in the source code of the opcode implementation.
[0089] Optionally, in one embodiment of this application, the first generation module 100 includes: a first determining unit, a first generation unit, an acquisition unit, a second determining unit, and a second generation unit.
[0090] The first determining unit is used to determine the first prompt word of the opcode in the Ethereum Virtual Machine based on the Ethereum execution layer specification.
[0091] The first generation unit is used to obtain the first seed generator for implementing the opcode based on the first prompt word and using the target large language model.
[0092] The acquisition unit is used to acquire the inter-process control flow graph of the opcode implementation function.
[0093] The second determining unit is used to determine the second prompt word of the opcode implementation function based on the seed output by the first seed generator, the seed's mnemonic word, and the inter-process control flow graph.
[0094] The second generation unit is used to obtain a second seed generator for implementing the opcode based on the second prompt word using the target large language model, and to obtain test cases using the second seed generator.
[0095] Optionally, in one embodiment of this application, the first generation module 100 further includes a judgment unit and a third generation unit.
[0096] The judgment unit is used to determine whether the seed output by the second seed generator needs to be mutated.
[0097] The third generation unit is used to randomly obtain the boundary values of the operands of the opcode when the seed needs to be mutated, so as to use the boundary values to replace the operands of the seed and obtain test cases.
[0098] Optionally, in one embodiment of this application, it further includes: a first acquisition module, a second acquisition module, a third acquisition module, and a construction module.
[0099] The first acquisition module is used to acquire the network fork of the Ethereum Virtual Machine before acquiring the execution process information and execution results of the Ethereum Virtual Machine based on test cases and a pre-built differential testing engine.
[0100] The second acquisition module is used to obtain the account status of the Ethereum Virtual Machine.
[0101] The third acquisition module is used to acquire the global state of the Ethereum Virtual Machine.
[0102] The building block is used to build a differential testing engine based on the same network fork, the same account state, and the same global state.
[0103] Optionally, in one embodiment of this application, the target defect identification metric may include, but is not limited to, at least one of the Ethereum Virtual Machine return value, gas consumption, and storage.
[0104] Optionally, in one embodiment of this application, the determining module 400 includes: a fourth generation unit and an analysis unit.
[0105] The fourth generation unit is used to obtain the corresponding opcode implementation function based on the source code implemented by the Ethereum Virtual Machine.
[0106] The analysis unit is used to combine the target large language model to analyze the opcode implementation function corresponding to the defect, so as to obtain the root cause based on the analysis results.
[0107] It should be noted that the explanation of the aforementioned method embodiment for detecting the root cause of Ethereum Virtual Machine defects also applies to the Ethereum Virtual Machine defect root cause detection device of this embodiment, and will not be repeated here.
[0108] The root cause detection device for Ethereum Virtual Machine (EVM) defects proposed in this application can generate test cases for the EVM based on a target large language model. Based on these test cases and a pre-built differential testing engine, it obtains execution process information and results of the EVM. Then, combined with target defect identification indicators, it determines whether there are defects in the source code implementing the opcodes of the EVM. If defects are found, it determines the root cause of the defects based on the opcode implementation source code and the target large language model. Through the target large language model, semantically valid and diverse test cases are obtained. Through the pre-built differential testing engine and target defect identification indicators, the root cause of the defects can be quickly located. This solves the problems in related technologies, such as the inability to generate semantically valid and diverse EVM test cases and the inability to automatically identify and locate the root cause of defects in the EVM implementation.
[0109] Figure 4 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application. The electronic device may include:
[0110] The memory 401, the processor 402, and the computer program stored on the memory 401 and capable of running on the processor 402.
[0111] When processor 402 executes the program, it implements the root cause detection method for Ethereum Virtual Machine defects provided in the above embodiments.
[0112] Furthermore, electronic devices also include:
[0113] Communication interface 403 is used for communication between memory 401 and processor 402.
[0114] The memory 401 is used to store computer programs that can run on the processor 402.
[0115] The memory 401 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0116] If the memory 401, processor 402, and communication interface 403 are implemented independently, then the communication interface 403, memory 401, and processor 402 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized into address buses, data buses, control buses, etc. For ease of representation, Figure 4 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0117] Optionally, in a specific implementation, if the memory 401, processor 402, and communication interface 403 are integrated on a single chip, then the memory 401, processor 402, and communication interface 403 can communicate with each other through an internal interface.
[0118] Processor 402 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0119] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for detecting the root cause of Ethereum Virtual Machine defects.
[0120] This application also provides a computer program product, including a computer program that, when executed, implements the above-described root cause detection method for Ethereum Virtual Machine defects.
[0121] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0122] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0123] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0124] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0125] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. If implemented in hardware, as in another embodiment, it can be implemented using any one or more of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0126] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0127] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0128] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
Claims
1. A method for detecting the root cause of defects in the Ethereum Virtual Machine, characterized in that, Includes the following steps: Test cases for the Ethereum Virtual Machine are generated based on the target large language model; Based on the test cases and the pre-built differential testing engine, obtain the execution process information and execution results of the Ethereum Virtual Machine; Based on the execution process information and the execution result, and in conjunction with the target defect identification indicators, it is determined whether there are defects in the source code of the Ethereum Virtual Machine's opcode implementation; wherein, the target defect identification indicators include at least one of the Ethereum Virtual Machine's return value, gas consumption, and storage; If the source code of the Ethereum Virtual Machine's implementation of the opcode has defects, the corresponding opcode implementation function is obtained based on the source code of the opcode implementation, and the root cause of the defects is determined in conjunction with the target large language model. The test cases for generating the Ethereum Virtual Machine based on the target large language model include: Based on the Ethereum Execution Layer Specification, the first prompt word of the opcode in the Ethereum Virtual Machine is determined; Based on the first prompt word, a first seed generator for implementing the opcode is obtained using the target large language model; Obtain the inter-procedural control flow graph of the opcode implementation function; The second prompt word for the opcode implementation function is determined based on the seed output by the first seed generator, the mnemonic word of the seed, and the inter-process control flow graph. Based on the second prompt word, a second seed generator for implementing the opcode is obtained using the target large language model, and the test case is obtained using the second seed generator; The test cases for generating the Ethereum Virtual Machine based on the target large language model also include: Determine whether the seed output by the second seed generator needs to be mutated; If the seed needs to be mutated, the boundary value of the operand of the opcode is randomly obtained, and the boundary value is used to replace the operand of the seed to obtain the test case; Before obtaining the execution process information and execution results of the Ethereum Virtual Machine based on the test cases and the pre-built differential testing engine, the process also includes: Obtain the network fork of the Ethereum Virtual Machine; Obtain the account status of the Ethereum Virtual Machine; Obtain the global state of the Ethereum Virtual Machine; The differential testing engine is built based on the same network fork, the same account state, and the same global state.
2. The method according to claim 1, characterized in that, If the Ethereum Virtual Machine's implementation of the opcode has a defect in its source code, the root cause of the defect is determined based on the source code of the opcode implementation and the target large language model, including: The corresponding opcode implementation function is obtained based on the source code implemented by the Ethereum Virtual Machine. Based on the target large language model, the opcode implementation function corresponding to the defect is analyzed to obtain the root cause based on the analysis results.
3. A root cause detection device for Ethereum Virtual Machine defects, characterized in that, The root cause detection method for Ethereum Virtual Machine defects as described in claim 1 is adopted, wherein the apparatus comprises: The first generation module is used to generate test cases for the Ethereum Virtual Machine based on the target large language model; The second generation module is used to obtain the execution process information and execution results of the Ethereum Virtual Machine based on the test cases and the pre-built differential testing engine. The judgment module is used to determine whether there are defects in the source code of the Ethereum Virtual Machine's opcode implementation based on the execution process information and the execution result, combined with the target defect identification index. The determination module is used to determine the root cause of the defect based on the source code of the opcode implementation and the target large language model when the source code of the Ethereum Virtual Machine's implementation of the opcode has defects.
4. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to implement the root cause detection method for Ethereum Virtual Machine defects as described in any one of claims 1-2.
5. A computer-readable storage medium having a computer program stored thereon, characterized in that, The program is executed by the processor to implement the root cause detection method for Ethereum Virtual Machine defects as described in any one of claims 1-2.
6. A computer program product, characterized in that, Includes a computer program, which, when executed, is used to implement the root cause detection method for Ethereum Virtual Machine defects as described in any one of claims 1-2.
Citation Information
Patent Citations
Fuzzy testing method for Ethereum virtual machine
CN118409977A