Skip to content

Commit

Permalink
tests: add a cargo-fuzz-powered fuzz test
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Apr 7, 2022
1 parent 52cfe85 commit f499a72
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
Cargo.lock
28 changes: 28 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "snarkos-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
bytes = "1"
libfuzzer-sys = "0.4"
tokio-util = { version = "0.7", features = [ "codec" ] }

[dependencies.snarkos-environment]
path = "../environment"
features = [ "network" ]

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false
15 changes: 15 additions & 0 deletions fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use bytes::BytesMut;
use snarkos_environment::{network::MessageCodec, Client, CurrentNetwork};
use tokio_util::codec::Decoder;

fuzz_target!(|messages: Vec<&[u8]>| {
let mut codec = MessageCodec::<CurrentNetwork, Client<CurrentNetwork>>::default();

for message in messages {
let mut bytes = BytesMut::from(message);
let _ = codec.decode(&mut bytes);
}
});

0 comments on commit f499a72

Please sign in to comment.