Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #389 #390

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion fuzz/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
spike-sys = "0.1.1"
spike-sys = "0.1.2"

[dependencies.ckb-vm]
path = ".."
Expand All @@ -26,6 +26,12 @@ path = "fuzz_targets/asm.rs"
test = false
doc = false

[[bin]]
name = "interpreter"
path = "fuzz_targets/interpreter.rs"
test = false
doc = false

[[bin]]
name = "isa_a"
path = "fuzz_targets/isa_a.rs"
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/asm.rs
@@ -1,12 +1,12 @@
#![no_main]
use ckb_vm::cost_model::constant_cycles;
use ckb_vm::machine::asm::{AsmCoreMachine, AsmMachine};
use ckb_vm::machine::{DefaultMachineBuilder, VERSION0};
use ckb_vm::{Bytes, ISA_IMC};
use ckb_vm::machine::{DefaultMachineBuilder, VERSION2};
use ckb_vm::{Bytes, ISA_A, ISA_B, ISA_IMC, ISA_MOP};
use libfuzzer_sys::fuzz_target;

fn run(data: &[u8]) {
let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION0, 200_000);
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION2, 200_000);
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
.instruction_cycle_func(Box::new(constant_cycles))
.build();
Expand Down
26 changes: 26 additions & 0 deletions fuzz/fuzz_targets/interpreter.rs
@@ -0,0 +1,26 @@
#![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_core = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
VERSION2,
200_000,
);
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);
});