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

Added some more fuzzers in to the source #3003

Open
wants to merge 6 commits into
base: albatross
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ workspace = true
[dependencies]
afl = { version = "0.15.11", optional = true }

nimiq-account = { workspace = true }
nimiq-bls = { workspace = true }
nimiq-collections = { workspace = true }
nimiq-keys = { workspace = true }
nimiq-primitives = { workspace = true, features = ["key-nibbles", "serde-derive", "trie"] }
nimiq-serde = { workspace = true }
nimiq-transaction = { workspace = true }

[features]
fuzz = ["afl"]
Binary file added fuzz/in/keypair/examplekeys.bin
Binary file not shown.
Binary file added fuzz/in/normal_keypair/examplekeys.bin
Binary file not shown.
Binary file added fuzz/in/staking_contract/example_contract
Binary file not shown.
1 change: 0 additions & 1 deletion fuzz/src/bin/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn main() {
afl::fuzz!(|data: &[u8]| {
use nimiq_collections::BitSet;
use nimiq_serde::Deserialize as _;

let _ = BitSet::deserialize_from_vec(data);
})
}
8 changes: 8 additions & 0 deletions fuzz/src/bin/coin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::Deserialize as _;
use nimiq_primitives::coin::Coin;
let _ = Coin::deserialize_from_vec(data);
})
}
10 changes: 10 additions & 0 deletions fuzz/src/bin/htlc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::Deserialize as _;
use nimiq_account::{
HashedTimeLockedContract
};
let _ = HashedTimeLockedContract::deserialize_from_vec(data);
})
}
1 change: 0 additions & 1 deletion fuzz/src/bin/key_nibbles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn main() {
afl::fuzz!(|data: &[u8]| {
use nimiq_primitives::key_nibbles::KeyNibbles;
use nimiq_serde::Deserialize as _;

let _ = KeyNibbles::deserialize_from_vec(data);
})
}
8 changes: 8 additions & 0 deletions fuzz/src/bin/keypair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::Deserialize as _;
use nimiq_bls::{KeyPair};
let _ = KeyPair::deserialize_from_vec(data);
})
}
8 changes: 8 additions & 0 deletions fuzz/src/bin/normal_keypair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::Deserialize as _;
use nimiq_keys::KeyPair;
let _ = KeyPair::deserialize_from_vec(data);
})
}
21 changes: 21 additions & 0 deletions fuzz/src/bin/staking_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::{Deserialize, Serialize};
use nimiq_account::StakingContract;
let res = StakingContract::deserialize_from_vec(data); // err I think is of type DeserializeError
// Now check if contract exists. If it does (aka. the original data was a valid staking contract) then try to serialize it back to a vector, then check if the original vector and the new vector are the same, if they aren't then there is a bug in the parsing logic.
// The existence of error implies that contract does not exist.
match res {
Ok(v) => {
let serialized = StakingContract::serialize_to_vec(&v);
assert!((serialized.len() <= data.len()), "The size of the serialized version was bigger than the original vector! This shouldn't happen!");
let original_data_segment: &[u8] = data[..(serialized.len())].try_into().unwrap(); // This ugly stuff has to be done, because the serialization function ignores extra bytes at the end so we can not compare the byte vectors by themselves. Yuck!!!
assert_eq!(original_data_segment, serialized);
},
Err(e) => {
return;
},
}
})
}
8 changes: 8 additions & 0 deletions fuzz/src/bin/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
#[cfg(feature = "fuzz")]
afl::fuzz!(|data: &[u8]| {
use nimiq_serde::Deserialize as _;
use nimiq_transaction::{Transaction};
let _ = Transaction::deserialize_from_vec(data);
})
}
1 change: 0 additions & 1 deletion fuzz/src/bin/trie_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn main() {
afl::fuzz!(|data: &[u8]| {
use nimiq_primitives::trie::trie_node::TrieNode;
use nimiq_serde::Deserialize as _;

let _ = TrieNode::deserialize_from_vec(data);
})
}
Loading