|
1 | 1 | #![no_main]
|
2 | 2 | use ckb_vm::cost_model::constant_cycles;
|
3 | 3 | use ckb_vm::machine::asm::{AsmCoreMachine, AsmMachine};
|
4 |
| -use ckb_vm::machine::{DefaultCoreMachine, DefaultMachineBuilder, VERSION2}; |
| 4 | +use ckb_vm::machine::trace::TraceMachine; |
| 5 | +use ckb_vm::machine::{DefaultCoreMachine, DefaultMachineBuilder, SupportMachine, VERSION2}; |
5 | 6 | use ckb_vm::memory::sparse::SparseMemory;
|
6 | 7 | use ckb_vm::memory::wxorx::WXorXMemory;
|
7 | 8 | use ckb_vm::{Bytes, Error, ISA_A, ISA_B, ISA_IMC, ISA_MOP};
|
8 | 9 | use libfuzzer_sys::fuzz_target;
|
9 | 10 |
|
10 |
| -fn run_asm(data: &[u8]) -> Result<i8, Error> { |
| 11 | +fn run_asm(data: &[u8]) -> Result<(i8, u64), Error> { |
11 | 12 | let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION2, 200_000);
|
12 | 13 | let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
|
13 | 14 | .instruction_cycle_func(Box::new(constant_cycles))
|
14 | 15 | .build();
|
15 | 16 | let mut machine = AsmMachine::new(core);
|
16 | 17 | let program = Bytes::copy_from_slice(data);
|
17 | 18 | machine.load_program(&program, &[])?;
|
18 |
| - machine.run() |
| 19 | + let exit_code = machine.run()?; |
| 20 | + let cycles = machine.machine.cycles(); |
| 21 | + Ok((exit_code, cycles)) |
19 | 22 | }
|
20 | 23 |
|
21 |
| -fn run_int(data: &[u8]) -> Result<i8, Error> { |
| 24 | +fn run_int(data: &[u8]) -> Result<(i8, u64), Error> { |
22 | 25 | let machine_memory = WXorXMemory::new(SparseMemory::<u64>::default());
|
23 | 26 | let machine_core = DefaultCoreMachine::new_with_memory(
|
24 | 27 | ISA_IMC | ISA_A | ISA_B | ISA_MOP,
|
25 | 28 | VERSION2,
|
26 | 29 | 200_000,
|
27 | 30 | machine_memory,
|
28 | 31 | );
|
29 |
| - let mut machine = DefaultMachineBuilder::new(machine_core) |
30 |
| - .instruction_cycle_func(Box::new(constant_cycles)) |
31 |
| - .build(); |
| 32 | + let mut machine = TraceMachine::new( |
| 33 | + DefaultMachineBuilder::new(machine_core) |
| 34 | + .instruction_cycle_func(Box::new(constant_cycles)) |
| 35 | + .build(), |
| 36 | + ); |
32 | 37 | let program = Bytes::copy_from_slice(data);
|
33 | 38 | machine.load_program(&program, &[])?;
|
34 |
| - machine.run() |
| 39 | + let exit_code = machine.run()?; |
| 40 | + let cycles = machine.machine.cycles(); |
| 41 | + Ok((exit_code, cycles)) |
35 | 42 | }
|
36 | 43 |
|
37 | 44 | fuzz_target!(|data: &[u8]| {
|
|
0 commit comments