Skip to content

Commit

Permalink
Add fuzz support and update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ChosunOne committed Mar 3, 2019
1 parent 1fcb0e8 commit 3e81619
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
serde for serialization, though a number of serde schemes are implemented as their own features (see below).
* Separate bincode from ```default_tree```. To use bincode with the default tree, you only need to use the "use_bincode" feature
ex. ```cargo build --features "use_bincode"```
## New serialization schemes
* Add JSON support through ```use_json``` feature
* Add CBOR support through ```use_cbor``` feature
* Add YAML support through ```use_yaml``` feature
* Add Pickle support through ```use_pickle``` feature
* Add RON support through ```use_ron``` feature
* Fixed issue with getting values when supplied keys were not all in the tree
* Inputs to get and insert no longer need to be sorted (sorting is done internally)
* Fixed issue when using stored split index values on inserts.
## New hashing schemes
* You can now use different hashing schemes with the different serialization features.
* Add Blake2b support through ```use_blake2b``` feature
* Add Groestl support through ```use_groestl``` feature
* Add Groestl support through ```use_groestl``` feature (note: Groestl is much slower compared to the other hashing algorithms)
* Add SHA-2 (SHA256) support through ```use_sha2``` feature
* Add SHA-3 support through ```use_sha3``` feature
* Add Keccak256 support through ```use_keccak``` feature
## Bug Fixes
* Fixed issue with getting values when supplied keys were not all in the tree
* Fixed issue when using stored split index values on inserts.
* Inputs to get and insert no longer need to be sorted (sorting is done internally)
## Development Improvements
* Added benchmarking via ```cargo bench```
* Added fuzzing via ```cargo +nightly fuzz <fuzz_target_name>```. Requires installation of ```cargo-fuzz``` and ```nightly``` toolchain.


# 1.2.1
* Add serde support for default tree implementation
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rand = "0.6.5"
rocksdb = "0.11.0"
serde = { version = "1.0.89", features = ["derive"] }
criterion = "0.2.10"
afl = "0.4.3"

[dependencies]
bincode = { version = "1.1.2", optional = true }
Expand Down
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
22 changes: 22 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

[package]
name = "starling-fuzz"
version = "0.0.1"
authors = ["Automatically generated"]
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies.starling]
path = ".."
[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"

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

[[bin]]
name = "round_trip_empty_tree"
path = "fuzz_targets/round_trip_empty_tree.rs"
22 changes: 22 additions & 0 deletions fuzz/fuzz_targets/round_trip_empty_tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate starling;

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
let key_and_value = get_key_and_value(data);
let mut key = key_and_value.0.iter().map(|x| x.as_slice()).collect::<Vec<_>>();
let mut val = key_and_value.1.iter().collect::<Vec<_>>();
let mut bmt = starling::tree::HashTree::new(16);
let root = bmt.insert(None, &mut key, &mut val).unwrap();
let items = bmt.get(&root, &mut key).unwrap();
assert_eq!(items, vec![Some(key_and_value.1[0].clone())]);
});

fn get_key_and_value(data: &[u8]) -> (Vec<Vec<u8>>, Vec<Vec<u8>>) {
if data.is_empty() || data.len() < 2 {
return (vec![vec![0]], vec![vec![0]])
}
let split = data.split_at(data.len() / 2);
(vec![split.0.to_vec()], vec![split.1.to_vec()])
}
21 changes: 21 additions & 0 deletions src/merkle_bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,19 @@ pub mod tests {
assert_eq!(item, expected_item);
}

#[test]
fn the_fuzz_test_function_works() {
let rand_data = vec![];
let data = &rand_data[..];
let key_and_value = get_key_and_value(data);
let mut key = key_and_value.0.iter().map(|x| x.as_slice()).collect::<Vec<_>>();
let mut val = key_and_value.1.iter().collect::<Vec<_>>();
let mut bmt = HashTree::new(16);
let root = bmt.insert(None, &mut key, &mut val).unwrap();
let items = bmt.get(&root, &mut key).unwrap();
assert_eq!(items, vec![Some(key_and_value.1[0].clone())]);
}

fn prepare_inserts(num_entries: usize, rng: &mut StdRng) -> (Vec<Vec<u8>>, Vec<Vec<u8>>, Vec<Option<Vec<u8>>>) {
let mut keys = Vec::with_capacity(num_entries);
let mut data = Vec::with_capacity(num_entries);
Expand Down Expand Up @@ -1922,4 +1935,12 @@ pub mod tests {
}
}
}

fn get_key_and_value(data: &[u8]) -> (Vec<Vec<u8>>, Vec<Vec<u8>>) {
if data.is_empty() || data.len() < 2 {
return (vec![vec![0]], vec![vec![0]])
}
let split = data.split_at(data.len() / 2);
(vec![split.0.to_vec()], vec![split.1.to_vec()])
}
}

0 comments on commit 3e81619

Please sign in to comment.