Skip to content

Commit 2e23779

Browse files
committed
fuzz: interpreter
1 parent 61bf7fa commit 2e23779

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

crates/polkavm-common/src/program.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4303,6 +4303,13 @@ impl ProgramBlob {
43034303
&self.bitmask
43044304
}
43054305

4306+
#[cfg(feature = "export-internals-for-testing")]
4307+
#[doc(hidden)]
4308+
pub fn set_bitmask(&mut self, bitmask: ArcBytes) {
4309+
self.bitmask = bitmask;
4310+
}
4311+
4312+
/// Returns the import offsets and symbols.
43064313
pub fn imports(&self) -> Imports {
43074314
Imports {
43084315
offsets: &self.import_offsets,
@@ -4363,7 +4370,7 @@ impl ProgramBlob {
43634370
}
43644371
}
43654372

4366-
/// Visits every instrution in the program.
4373+
/// Visits every instruction in the program.
43674374
#[cfg_attr(not(debug_assertions), inline(always))]
43684375
pub fn visit<T>(&self, dispatch_table: T, visitor: &mut T::State)
43694376
where

fuzz/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ libfuzzer-sys = "0.4"
1515
path = "../crates/polkavm"
1616
features = ["export-internals-for-testing"]
1717

18+
[dependencies.polkavm-common]
19+
path = "../crates/polkavm-common"
20+
features = ["export-internals-for-testing"]
21+
1822
[[bin]]
1923
name = "fuzz_shm_allocator"
2024
path = "fuzz_targets/fuzz_shm_allocator.rs"

fuzz/fuzz_targets/fuzz_interpreter.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![no_main]
22

33
use libfuzzer_sys::fuzz_target;
4+
use polkavm::Engine;
45
use polkavm::InterruptKind;
56
use polkavm::ModuleConfig;
6-
use polkavm::ProgramBlob;
77
use polkavm::ProgramCounter;
8-
use polkavm::{ArcBytes, Engine};
8+
use polkavm_common::program::ProgramBlob;
99

1010
fn harness(data: &[u8]) {
1111
// configure the polkavm engine
@@ -21,15 +21,12 @@ fn harness(data: &[u8]) {
2121
module_config.set_step_tracing(true);
2222

2323
// create a polkavm program blob (eventually to be filled with the fuzzed data)
24-
let blob = ProgramBlob::default();
24+
let mut fuzzed_blob = ProgramBlob::default();
2525

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

28-
let fuzzed_blob = ProgramBlob {
29-
code: data.into(),
30-
bitmask: bitmask.into(),
31-
..blob
32-
};
28+
fuzzed_blob.set_code(data.into());
29+
fuzzed_blob.set_bitmask(bitmask.into());
3330

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

0 commit comments

Comments
 (0)