Skip to content

Commit

Permalink
feat: Add fuzzers for BTreeMap and MinHeap (#217)
Browse files Browse the repository at this point in the history
- Added two fuzzers `stable_btreemap_multiple_ops_persistent` and
`stable_minheap_multiple_ops_persistent`
- Added a CI job to check if the fuzzers can be built. However, the
fuzzers are not run on CI yet.

To run a fuzzer locally, 
```sh
rustup toolchain install nightly
cargo install cargo-fuzz
cargo +nightly fuzz run stable_btreemap_multiple_ops_persistent
```
  • Loading branch information
venkkatesh-sekar authored May 24, 2024
1 parent f2cde61 commit a62501e
Show file tree
Hide file tree
Showing 8 changed files with 741 additions and 0 deletions.
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

0 comments on commit a62501e

Please sign in to comment.