A fuzz testing method for Ethereum virtual machine

Generate complex test cases through code instrumentation and random mutation to detect the state consistency of the Ethereum virtual machine. This solves the problem that existing technology cannot detect the underlying operation of the virtual machine and ignores the account status, and achieves more fine-grained vulnerability detection and Virtual machine state consistency check.

CN118409977BActive Publication Date: 2024-10-11ZHEJIANG UNIV
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410891441.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-10-11
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

The existing Ethereum virtual machine fuzz testing method cannot generate complex account status, cannot detect the correctness of the lower-level operations of the virtual machine, and only finds vulnerabilities by comparing fuel consumption and opcode sequence length, ignoring each account during execution and after completion. status, which may result in potential defects being missed.

Method used

Collect covered code execution paths through code instrumentation, build and sequence test cases, randomly mutate Ethereum transactions and account status, generate complex test cases, execute and compare the status of different Ethereum virtual machines, and detect vulnerabilities in virtual machine implementation .

Benefits of technology

Supports the generation of complex account status and transactions, detects the consistency of virtual machine execution results under complex account status, explores more potential vulnerabilities, implements more fine-grained bytecode level mutations, and effectively detects the correctness of the underlying operations of the virtual machine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409977B_ABST
    Figure CN118409977B_ABST
Patent Text Reader

Abstract

The present invention discloses a fuzzy testing method for an Ethereum virtual machine, comprising: inserting a code on the Ethereum virtual machine to collect the code execution path covered during the execution of a test case; constructing several seed test cases consisting of Ethereum transactions and account states before executing the transactions to form an initial test case set; selecting a top-ranked test case from the set and performing a random mutation operation on it; providing the mutated test case to different Ethereum virtual machines, which set the account state according to the test case and then execute the Ethereum transaction in the test case; adding the test case covering the new code path to the set, and discovering potential vulnerabilities by comparing whether the states generated by the execution processes of different virtual machines are consistent. The present invention solves the problem that the existing method cannot generate complex states and is prone to underreporting, and can effectively mine the vulnerabilities of the underlying implementations of different Ethereum virtual machines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software testing, and in particular to a fuzz testing method for an Ethereum virtual machine. Background Art

[0002] Blockchain is a decentralized distributed database technology that links data in the form of blocks to achieve the immutability and traceability of transaction information. Among them, Ethereum is an open source platform based on blockchain technology, designed to provide support for the deployment and execution of smart contracts. Compared with other blockchain platforms such as Bitcoin, the biggest feature of Ethereum is that it has a Turing-complete virtual machine, which allows developers to write complex smart contracts and decentralized applications.

[0003] Ethereum Virtual Machine (EVM) is the operating environment of smart contracts in the Ethereum network. It is a stack-based virtual machine that is specifically used to execute the bytecode of Ethereum smart contracts. EVM uses a simple and efficient instruction set to process data and perform calculations through a stack. Unlike the physical hardware virtual machine of a traditional computer, EVM is a completely virtual operating environment that exists on every node of the Ethereum network, ensuring the consistency of the execution results of smart contracts in the entire network.

[0004] The booming development of Ethereum has attracted the attention of other blockchain platforms. In order to reuse the rich tool chain of Ethereum ecosystem, avoid the high gas fees on the Ethereum main network and obtain faster transaction processing speed, some blockchains have implemented their own EVM to provide support for Ethereum smart contracts. If there are errors in the implementation of these virtual machines, it may cause the smart contract to be executed incorrectly, causing losses to the user's on-chain assets and even affecting the stable operation of the relevant blockchain platform.

[0005] Existing work only provides a fixed pre-state when executing the target contract, and cannot generate more complex account states, that is, except for the contract to be executed, the states of other accounts are fixed, which limits the ability to exploit vulnerabilities in the Ethereum virtual machine. At the same time, the existing Ethereum virtual machine fuzz testing method generates virtual machine bytecode based on mutations of the abstract syntax tree of the real smart contract. This method cannot perform more fine-grained, bytecode-level mutations, so it is impossible to detect whether the lower-level operations of the virtual machine are implemented correctly. In addition, existing work only discovers vulnerabilities by comparing the fuel consumption cost and the length of the opcode sequence, ignoring the state of the virtual machine during execution and the state of each account after the execution, which may cause potential defects to be missed. Summary of the invention

[0006] In order to solve the problems existing in the above work, the present invention provides a fuzz testing method for an Ethereum virtual machine. The method can more effectively explore vulnerabilities in different Ethereum virtual machine implementations by generating complex Ethereum transactions and the Ethereum state before executing the transactions.

[0007] The purpose of the present invention is achieved through the following technical solutions:

[0008] A fuzz testing method for an Ethereum virtual machine comprises the following steps:

[0009] Step 1: Instrument the Ethereum virtual machine to collect the code execution paths covered during the execution of the test case;

[0010] Step 2: Build seed test cases to form an initial test case set, and sort the test cases according to the covered code paths and execution time:

[0011] The test case includes a description of an Ethereum transaction and the Ethereum account status before the transaction is executed; the Ethereum account status before the transaction is executed includes multiple Ethereum accounts, each Ethereum account corresponds to a unique address, and its status includes balance, random number, storage and deployed code;

[0012] The test case sorting rules in the test case set are as follows: sort from high to low according to the number of covered code paths; for test cases with exactly the same number of covered code paths, sort from short to long according to the execution time;

[0013] Step 3: Select a test case with a higher ranking from the test case set, and perform a random mutation operation on it to modify the content of the selected test case;

[0014] Step 4: Provide the mutated test case to different Ethereum virtual machines as input, and different Ethereum virtual machines set the state of the relevant Ethereum account before executing the transaction according to the test case, and then execute the Ethereum transaction in the test case; collect the code paths covered during the execution of the Ethereum virtual machine and the state for comparison;

[0015] Step 5: If the test case covers a new code path during execution, it is added to the test case collection; then the states collected on all Ethereum virtual machines are compared. If there are differences, it means that there is a problem with the implementation of the virtual machine being tested. The current test case is output and the test is terminated; otherwise, return to step 3.

[0016] Furthermore, the mutation operation in step three includes:

[0017] Randomly modify fields in Ethereum transactions;

[0018] Randomly add or delete an Ethereum account;

[0019] Randomly modify the balance of an Ethereum account;

[0020] Randomly modify the random number of an Ethereum account;

[0021] Randomly modify the storage of an Ethereum account;

[0022] Randomly modify the code deployed by an Ethereum account.

[0023] Furthermore, when randomly modifying fields in Ethereum transactions, the semantics of the Ethereum virtual machine and the current Ethereum account status are combined for mutation;

[0024] For the gas limit field in the transaction, a value is randomly generated within a certain range. This range ensures that the virtual machine will neither reject the transaction due to too little gas nor enter an infinite loop due to too much gas.

[0025] For the recipient and block creator fields in the transaction, randomly select one from the addresses of all Ethereum accounts in the current test case as its new value;

[0026] For the input field in the transaction, if the current transaction is a contract creation transaction, the input is considered as a piece of account code for mutation, otherwise it is considered as a random byte array for mutation;

[0027] For the access list field, it is randomly generated based on all Ethereum account addresses and storages existing in the current test case;

[0028] For other fields, a random number generator is used to generate them directly.

[0029] Furthermore, the access list field is randomly generated based on the addresses and storage of all Ethereum accounts in the current test case, including:

[0030] Randomly add a tuple containing an address and a list of multiple storage key values;

[0031] Randomly copy a tuple;

[0032] Randomly delete a tuple;

[0033] Randomly select a tuple and randomly add a storage key value to the storage key value list;

[0034] Randomly select a tuple and randomly copy a storage key value in the storage key value list;

[0035] Randomly select a tuple and remove a random storage key value from the storage key value list.

[0036] Furthermore, when randomly modifying the code deployed by an Ethereum account, the bytecode is first converted into a linear intermediate representation using the simulation execution technology, and then mutation is performed based on the linear intermediate representation. After the mutation is completed, the linear intermediate representation is converted back into bytecode.

[0037] Furthermore, the bytecode is converted into a linear intermediate representation using simulation execution technology, including:

[0038] The bytecode to be mutated needs to be executed based on a simulated stack according to the Ethereum virtual machine bytecode specification. During the execution process, a corresponding instruction is generated for all bytecodes that are not PUSH, POP, DUP or SWAP, and the corresponding number of elements at the top of the stack are popped out as parameters of the instruction according to the specification. If the bytecode generates a return value, a new variable is generated as the return value of the instruction and pushed to the top of the stack. During the execution process, all instructions are added to a list in sequence. After the execution is completed, the list is the generated linear intermediate representation.

[0039] Further, mutation is performed based on the linear intermediate representation, specifically including:

[0040] Generate a random instruction;

[0041] Randomly copy an instruction;

[0042] Randomly delete an instruction;

[0043] Randomly replace an instruction with another instruction with the same return value type;

[0044] Randomly modify the parameters of an instruction according to the instruction's specification;

[0045] Furthermore, in step 4, the states used for comparison include: the values ​​of the stack, memory, program counter, and bytecode during the execution of the virtual machine, and the states of each Ethereum account after the execution is completed.

[0046] A fuzz testing device for an Ethereum virtual machine comprises one or more processors for implementing a fuzz testing method for the Ethereum virtual machine.

[0047] An electronic device, comprising:

[0048] one or more processors;

[0049] A storage device is used to store one or more programs, and when the one or more programs are executed by the electronic device, the electronic device implements a fuzz testing method for an Ethereum virtual machine.

[0050] The beneficial effects of the present invention are as follows:

[0051] The present invention supports the generation of complex account states and transactions to test whether the execution results of various virtual machines under complex account states are consistent, thereby excavating more potential vulnerabilities. The present invention generates the underlying bytecode of the Ethereum virtual machine based on the intermediate representation, supports more fine-grained mutations, and can more effectively detect whether the underlying operations of the virtual machine are implemented correctly. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 Schematic diagram of a fuzzy testing method for an Ethereum virtual machine according to an embodiment of the present invention.

[0053] Figure 2 It is a schematic diagram of using named pipes to improve the execution efficiency of virtual machines.

[0054] Figure 3 It is a flowchart of using the fork system call to improve the execution efficiency of the virtual machine.

[0055] Figure 4 This is the flowchart for step five.

[0056] Figure 5 Schematic diagram of a fuzzy testing device for an Ethereum virtual machine according to an embodiment of the present invention. DETAILED DESCRIPTION

[0057] The present invention will be described in detail below based on the accompanying drawings and preferred embodiments, and the purpose and effects of the present invention will become more clear. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0058] The present invention is a fuzzy testing method for an Ethereum virtual machine. By randomly mutating Ethereum account states and transactions, new test cases are obtained, which are run on multiple different virtual machine implementations to compare the results, thereby testing the Ethereum virtual machine more comprehensively.

[0059] Figure 1 The schematic diagram of the fuzzy testing method of the Ethereum virtual machine of the present invention is as follows:

[0060] Step 1: Instrument the Ethereum virtual machine to collect the code execution paths covered during the test case execution. In this embodiment, the sanitizerCoverage module of llvm can be used to automatically instrument the code, which inserts instructions for collecting covered code paths at all basic blocks and edge levels of the code. In order to optimize the execution efficiency of the Ethereum virtual machine during the test, the virtual machine to be tested can communicate with the fuzz test program through a named pipe. Figure 2It is a schematic diagram of using named pipes. The virtual machine directly reads the test case file through the named pipe, and the fuzz test program also directly collects the status of the virtual machine during execution through the named pipe, thus avoiding the overhead caused by directly reading and writing hard disk files.

[0061] Figure 3 This is a flowchart of using the fork system call to improve the execution efficiency of the virtual machine. For Ethereum virtual machine implementations with a long startup time, the execution process of the virtual machine can be manually modified so that it executes a fork system call after running the startup code. This call will create a child process that is exactly the same as the current process. Since the child process has already executed the startup code, the virtual machine can execute test cases directly in the child process. Whenever the child process is executed, the parent process of the virtual machine immediately reclaims the resources of the child process, and then creates the child process again through the fork system call. Using the fork system call, the virtual machine can avoid executing the startup code multiple times during the test process. At the same time, each time the test case is executed, the image of the child process is just in the stage of executing the initialization code, which can significantly improve the test efficiency.

[0062] Step 2: Build seed test cases to form an initial set of test cases, and sort the test cases according to the covered code paths and execution time.

[0063] The test case includes a description of an Ethereum transaction and the status of the Ethereum account before the transaction is executed; the status of the Ethereum account before the transaction is executed includes multiple Ethereum accounts, each Ethereum account corresponds to a unique address, and its status includes balance, random number, storage and deployed code.

[0064] The test case sorting rule in the test case set is: sort from high to low according to the number of covered code paths; for test cases with exactly the same number of covered code paths, sort from short to long according to the execution time.

[0065] When mutating, test cases that cover new code paths and have shorter execution times are preferred. This allows the fuzz testing tool to explore based on newly discovered code paths, making it more likely that the mutated test cases will cover other unexplored code paths and shorten the execution time of the test cases.

[0066] Step 3: Select a top-ranked test case from the test case set and perform a random mutation operation on it to modify the content of the selected test case.

[0067] Mutation operations include:

[0068] Randomly modify fields in Ethereum transactions;

[0069] Randomly add or delete an Ethereum account;

[0070] Randomly modify the balance of an account;

[0071] Randomly modify the random number of an account;

[0072] Randomly modify the storage of an account;

[0073] Randomly modify the code deployed by an account.

[0074] When randomly modifying fields in Ethereum transactions, mutations are performed in combination with the semantics of the Ethereum virtual machine and the current account status. For the fuel limit field in the transaction, a value is randomly generated within a certain range, which ensures that the virtual machine will neither reject the transaction due to too little fuel nor enter an infinite loop due to too much fuel; for the recipient and block creator fields in the transaction, a random value is selected from the addresses of all Ethereum accounts in the current test case as its new value; for the input field in the transaction, if the current transaction belongs to a contract creation transaction, the input is treated as a piece of account code for mutation, otherwise it is treated as a random byte array for mutation; for the access list field, it is randomly generated based on all Ethereum account addresses and storage in the current test case; for other fields, they are directly generated using a random number generator.

[0075] When mutating the access list fields, they are randomly generated based on the addresses and storage of all Ethereum accounts in the current test case, including:

[0076] Randomly add a tuple containing an address and a list of multiple storage key values;

[0077] Randomly copy a tuple;

[0078] Randomly delete a tuple;

[0079] Randomly select a tuple and randomly add a storage key value to the storage key value list;

[0080] Randomly select a tuple and randomly copy a storage key value in the storage key value list;

[0081] Randomly select a tuple and remove a random storage key value from the storage key value list.

[0082] When randomly modifying the code deployed by an account, the bytecode is first converted into a linear intermediate representation using simulated execution technology, and then mutation is performed based on the linear intermediate representation. After the mutation is completed, the linear intermediate representation is converted back into bytecode.

[0083] The bytecode is converted into a linear intermediate representation using simulated execution technology. Specifically, the bytecode to be mutated needs to be executed based on a simulated stack according to the Ethereum virtual machine bytecode specification. During the execution process, a corresponding instruction is generated for all bytecodes that are not PUSH, POP, DUP or SWAP, and the corresponding number of elements at the top of the stack are popped out as parameters of the instruction according to the specification. If the bytecode will generate a return value, a new variable must be generated as the return value of the instruction and pushed to the top of the stack. During the execution process, all instructions are added to a list in sequence, and after the execution is completed, the list is the generated linear intermediate representation.

[0084] Mutation based on linear intermediate representation includes: randomly generating an instruction; randomly copying an instruction; randomly deleting an instruction; randomly replacing an instruction with another instruction with the same return value type; and randomly modifying the parameters of an instruction according to the specification of the instruction. Compared with mutation directly at the bytecode level, the use of linear intermediate representation can combine the semantics of the current bytecode and Ethereum account status to mutate more effectively, thereby covering more code paths and edge cases.

[0085] When randomly generating an instruction or randomly modifying the parameters of an instruction, you can refer to the parameter type of the instruction in the specification, use the executed instructions that return the same type, or generate reasonable parameters based on the current Ethereum account status. For example, when mutating the STATICCALL instruction, when you need to generate the second parameter of the STATICCALL instruction, according to the specification, you know that the type of the parameter is an Ethereum address, so you can choose an instruction whose return value type is an address, such as the return value of the CREATE2 instruction.

[0086] Step 4: Provide the mutated test case to different Ethereum virtual machines as input. Different Ethereum virtual machines set the status of the relevant Ethereum accounts before executing the transaction according to the test case, and then execute the Ethereum transaction in the test case; collect the code paths covered during the execution of the Ethereum virtual machine and the status for comparison. The status used for comparison includes: the value of the stack, memory, program counter, bytecode during the execution of the virtual machine, and the status of each Ethereum account after the execution. By comparing the status during the execution and the status of all Ethereum accounts after the execution, the possibility of virtual machine implementation defects being ignored can be reduced.

[0087] Step 5: If the test case covers a new code path during execution, add it to the test case collection; then compare the states collected on all Ethereum virtual machines. If there are differences, it means that there is a problem with the implementation of the virtual machine being tested. Output the current test case and then end the test; otherwise return to step 3.

[0088] The flowchart of step five is as follows Figure 4 As shown in the figure, the test case generator uses the above mutation method to generate test cases. The differential test engine runs the test cases on different Ethereum virtual machines and compares the generated states to discover virtual machine implementation vulnerabilities. At the same time, it feeds back the code execution path to the previous component to guide it to generate new test cases.

[0089] By applying the fuzz testing method of the embodiment of the present invention to multiple Ethereum virtual machine implementations, multiple vulnerabilities have been successfully discovered and submitted. These virtual machine implementations include: Aurora Engine, an EVM-compatible implementation on the Near blockchain; Neon-EVM, an EVM-compatible implementation on the Solana blockchain; Moonbeam, an EVM-compatible chain in the Polkadot ecosystem; Evmos, an EVM-compatible chain in the Cosmos ecosystem; Fevm, an EVM-compatible implementation on the Filecoin blockchain; and Polygon-zkEVM, an Ethereum expansion implementation based on zero-knowledge proof.

[0090] On the other hand, corresponding to the embodiment of the fuzzy testing method of the Ethereum virtual machine described above, the present invention also provides an embodiment of the fuzzy testing device of the Ethereum virtual machine.

[0091] A fuzzy testing device for an Ethereum virtual machine provided in an embodiment of the present invention includes one or more processors for implementing the fuzzy testing method for the Ethereum virtual machine in the above embodiment.

[0092] The embodiments of the fuzzy testing device for the Ethereum virtual machine of the present invention can be applied to any device with data processing capabilities, and the device with data processing capabilities can be a device or apparatus such as a computer. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of any device with data processing capabilities in which it is located to read the corresponding computer program instructions in the non-volatile memory into the memory and run them. From a hardware perspective, any device with data processing capabilities in which the fuzzy testing device for the Ethereum virtual machine of the present invention is located, except for Figure 5 In addition to the processor, memory, network interface, and non-volatile memory shown, any device with data processing capabilities in which the apparatus in the embodiments is located may also include other hardware, generally based on the actual functions of the device with data processing capabilities, which will not be described in detail.

[0093] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0094] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.

[0095] An embodiment of the present invention also provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the fuzz testing method of the Ethereum virtual machine in the above embodiment is implemented.

[0096] The computer-readable storage medium may be an internal storage unit of any device with data processing capability described in any of the aforementioned embodiments, such as a hard disk or a memory. The computer-readable storage medium may also be an external storage device, such as a plug-in hard disk, a smart memory card (SmartMedia card, SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit of any device with data processing capability and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capability, and may also be used to temporarily store data that has been output or is to be output.

[0097] Those skilled in the art can understand that the above are only preferred examples of the invention and are not intended to limit the invention. Although the invention is described in detail with reference to the above examples, those skilled in the art can still modify the technical solutions recorded in the above examples or replace some of the technical features therein with equivalents. Any modification, equivalent replacement, etc. made within the spirit and principle of the invention shall be included in the protection scope of the invention.

Claims

1. A fuzz testing method for an Ethereum virtual machine, characterized in that: The following steps are involved: Step 1: Instrument the Ethereum virtual machine to collect the code execution paths covered during the execution of the test case; Step 2: Build seed test cases to form an initial test case set, and sort the test cases according to the covered code paths and execution time; The test case includes a description of an Ethereum transaction and the Ethereum account status before the transaction is executed; the Ethereum account status before the transaction is executed includes multiple Ethereum accounts, each Ethereum account corresponds to a unique address, and its status includes balance, random number, storage and deployed code; The test case sorting rules in the test case set are as follows: sort from high to low according to the number of covered code paths; for test cases with exactly the same number of covered code paths, sort from short to long according to the execution time; Step 3: Select a test case with a higher ranking from the test case set, and perform a random mutation operation on it to modify the content of the selected test case; Step 4: Provide the mutated test case to different Ethereum virtual machines as input. Different Ethereum virtual machines set the state of the relevant Ethereum accounts before executing the transaction according to the test case, and then execute the Ethereum transaction in the test case. Collect the code paths covered during the execution of the Ethereum virtual machine and the states used for comparison; the states used for comparison refer to the states of the virtual machine during the execution of the test case and the states of each Ethereum account after the execution; Step 5: If the test case covers a new code path when executed, add it to the test case set; Then compare the states collected on all Ethereum virtual machines. If there are differences, it means that there is a problem with the implementation of the tested virtual machine. Output the current test case and then end the test. Otherwise, return to step 3.

2. The fuzz testing method of the Ethereum virtual machine according to claim 1, characterized in that: The mutation operation in step three includes: Randomly modify fields in Ethereum transactions; Randomly add or delete an Ethereum account; Randomly modify the balance of an Ethereum account; Randomly modify the random number of an Ethereum account; Randomly modify the storage of an Ethereum account; Randomly modify the code deployed by an Ethereum account.

3. The fuzz testing method of the Ethereum virtual machine according to claim 2, characterized in that: When randomly modifying fields in Ethereum transactions, the mutation is performed in combination with the semantics of the Ethereum virtual machine and the current Ethereum account status; For the gas limit field in the transaction, a value is randomly generated within a certain range. This range ensures that the virtual machine will neither reject the transaction due to too little gas nor enter an infinite loop due to too much gas. For the recipient and block creator fields in the transaction, randomly select one from the addresses of all Ethereum accounts in the current test case as its new value; For the input field in the transaction, if the current transaction is a contract creation transaction, the input is considered as a piece of account code for mutation, otherwise it is considered as a random byte array for mutation; For the access list field, it is randomly generated based on all Ethereum account addresses and storages existing in the current test case; For other fields, a random number generator is used to generate them directly.

4. The fuzzy testing method of the Ethereum virtual machine according to claim 3, characterized in that: For the access list field, it is randomly generated based on the addresses and storage of all Ethereum accounts in the current test case, including: Randomly add a tuple containing an address and a list of multiple storage key values; Randomly copy a tuple; Randomly delete a tuple; Randomly select a tuple and randomly add a storage key value to the storage key value list; Randomly select a tuple and randomly copy a storage key value in the storage key value list; Randomly select a tuple and remove a random storage key value from the storage key value list.

5. The fuzz testing method of the Ethereum virtual machine according to claim 2, characterized in that: When randomly modifying the code deployed by an Ethereum account, the bytecode is first converted into a linear intermediate representation using simulated execution technology, and then mutation is performed based on the linear intermediate representation. After the mutation is completed, the linear intermediate representation is converted back into bytecode.

6. The fuzz testing method of the Ethereum virtual machine according to claim 5, characterized in that: The bytecode is converted into a linear intermediate representation using simulation execution technology, including: The bytecode to be mutated needs to be executed based on a simulated stack according to the Ethereum virtual machine bytecode specification. During the execution process, a corresponding instruction is generated for all bytecodes that are not PUSH, POP, DUP or SWAP, and the corresponding number of elements at the top of the stack are popped out as parameters of the instruction according to the specification. If the bytecode generates a return value, a new variable is generated as the return value of the instruction and pushed to the top of the stack. During the execution process, all instructions are added to a list in sequence. After the execution is completed, the list is the generated linear intermediate representation.

7. The fuzz testing method of the Ethereum virtual machine according to claim 5, characterized in that: Mutation is performed based on the linear intermediate representation, specifically including: Generate a random instruction; Randomly copy an instruction; Randomly delete an instruction; Randomly replace an instruction with another instruction with the same return value type; Randomly modify the parameters of an instruction according to the instruction's specification.

8. The fuzz testing method of the Ethereum virtual machine according to claim 1, characterized in that: In step 4, the states used for comparison include: the values ​​of the stack, memory, program counter, bytecode during the execution of the virtual machine, and the states of each Ethereum account after the execution is completed.

9. A fuzzy testing device for an Ethereum virtual machine, characterized in that: It includes one or more processors for implementing the fuzz testing method of the Ethereum virtual machine according to any one of claims 1 to 8.

10. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the electronic device, enables the electronic device to implement the fuzz testing method of the Ethereum virtual machine as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Ethereum virtual machine defect detection method and system

    CN110287002A

  • Coverage-guided intelligent contract test case generation method

    CN113971135A

  • Fuzzy testing method for block chain network

    CN116662207A

  • Ethereum reentry defect detection tool evaluation method based on variation test

    CN116881102A

  • Coverage-based fuzzing of interactive applications

    EP3657336A1