Skip to content

Commit

Permalink
fuzz: interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
subotic committed Nov 25, 2024
1 parent d997e96 commit 0f5dc7b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions fuzz/fuzz_targets/fuzz_interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use polkavm::Engine;
use polkavm::InterruptKind;
use polkavm::ModuleConfig;
use polkavm::ProgramBlob;
use polkavm::ProgramCounter;
use polkavm::{ArcBytes, Engine};

fn harness(_data: &[u8]) {
fn harness(data: &[u8]) {
// configure the polkavm engine
let mut config = polkavm::Config::new();
config.set_backend(Some(polkavm::BackendKind::Interpreter));
Expand All @@ -22,10 +22,17 @@ fn harness(_data: &[u8]) {

// create a polkavm program blob (eventually to be filled with the fuzzed data)
let blob = ProgramBlob::default();
blob.code()

let bitmask = vec![0xff; data.len() / 8 + 1];

let fuzzed_blob = ProgramBlob {
code: data.into(),
bitmask: bitmask.into(),
..blob
};

// create a polkavm module from the engine, module config, and program blob
let module = polkavm::Module::from_blob(&engine, &module_config, blob).unwrap();
let module = polkavm::Module::from_blob(&engine, &module_config, fuzzed_blob).unwrap();

let initial_pc = ProgramCounter(0);
let mut final_pc = initial_pc;
Expand Down

0 comments on commit 0f5dc7b

Please sign in to comment.