-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a fuzz target to the interpreter (#389)
- Loading branch information
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![no_main] | ||
use ckb_vm::cost_model::constant_cycles; | ||
use ckb_vm::machine::{DefaultCoreMachine, DefaultMachineBuilder, VERSION2}; | ||
use ckb_vm::memory::sparse::SparseMemory; | ||
use ckb_vm::memory::wxorx::WXorXMemory; | ||
use ckb_vm::{Bytes, ISA_A, ISA_B, ISA_IMC, ISA_MOP}; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
fn run(data: &[u8]) { | ||
let machine_memory = WXorXMemory::new(SparseMemory::<u64>::default()); | ||
let machine_core = DefaultCoreMachine::new_with_memory( | ||
ISA_IMC | ISA_A | ISA_B | ISA_MOP, | ||
VERSION2, | ||
200_000, | ||
machine_memory, | ||
); | ||
let mut machine = DefaultMachineBuilder::new(machine_core) | ||
.instruction_cycle_func(Box::new(constant_cycles)) | ||
.build(); | ||
let program = Bytes::copy_from_slice(data); | ||
if let Ok(_) = machine.load_program(&program, &[]) { | ||
let _ = machine.run(); | ||
} | ||
} | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
run(data); | ||
}); |