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

feat: Add fuzzers for BTreeMap and MinHeap #217

Merged
merged 7 commits into from
May 24, 2024
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
rustup default ${{ matrix.rust }}
rustup component add rustfmt
rustup component add clippy
rustup toolchain install nightly

- name: Check Format
run: cargo fmt --all -- --check
Expand All @@ -39,6 +40,11 @@ jobs:
run: cargo test
env:
RUST_BACKTRACE: 1

- name: Build Fuzzers
run: |
cargo install cargo-fuzz
cargo +nightly fuzz build

examples:
runs-on: ubuntu-latest
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,19 @@ fn insert(key: u128, value: u128) -> Option<u128> {
If your project exclusively relies on stable structures, the memory can expand in size without the requirement of `pre_upgrade`/`post_upgrade` hooks.

However, it's important to note that if you also intend to perform serialization/deserialization of the heap data, utilizing the memory manager becomes necessary. To effectively combine both approaches, refer to the [Quickstart Example](https://github.com/dfinity/stable-structures/tree/main/examples/src/quick_start) for guidance.

## Fuzzing

Stable structures requires strong guarantees to work reliably and scale over millions of operations. To that extent, we use fuzzing to emulate such operations on the available data structures.

To run a fuzzer locally,
```sh
rustup toolchain install nightly
cargo install cargo-fuzz

# To list available fuzzer targets
cargo +nightly fuzz list

# To run a target
cargo +nightly fuzz run <TARGET_NAME>
```
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
coverage
304 changes: 304 additions & 0 deletions fuzz/Cargo.lock

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

37 changes: 37 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "ic-stable-structures-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
arbitrary = {version = "1.3.0", features = ["derive"]}
serde = {version = "1.0", features = ["derive"]}
serde_bytes = "0.11"
serde_cbor = "0.11.2"
tempfile = "3.3.0"

[dependencies.ic-stable-structures]
path = ".."

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

[[bin]]
name = "stable_btreemap_multiple_ops_persistent"
path = "fuzz_targets/stable_btreemap_multiple_ops_persistent.rs"
test = false
doc = false
bench = false

[[bin]]
name = "stable_minheap_multiple_ops_persistent"
path = "fuzz_targets/stable_minheap_multiple_ops_persistent.rs"
test = false
doc = false
bench = false
Loading