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

fuzz: add target for LocalAddress from string #227

Merged
merged 2 commits into from
Sep 3, 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
26 changes: 26 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[workspace]
resolver = "2"
members = [
"florestad",
"fuzz",
"crates/floresta",
"crates/floresta-chain",
"crates/floresta-cli",
"crates/floresta-common",
"crates/floresta-compact-filters",
"crates/floresta-electrum",
"crates/floresta-watch-only",
"crates/floresta-wire",
]

default-members = [
"florestad",
"crates/floresta",
"crates/floresta-chain",
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ If you want to use `libfloresta` to build your own Bitcoin application, you can

### ToC

- [Community](#community)
- [Building](#building)
- [(Prerequisites)](#prerequisites)
- [Building with nix](#building-with-nix)
- [Running](#running)
- [Assume Utreexo](#assume-utreexo)
- [Compact Filters](#compact-filters)
- [Getting help](#getting-help)
- [Wallet](#wallet)
- [Running the tests](#running-the-tests)
- [Contributing](#contributing)
- [Using Nix](#using-nix)
- [License](#license)
- [Acknowledgments](#acknowledgments)
- [Consensus implementation](#consensus-implementation)
- [Running](#running)
- [Assume Utreexo](#assume-utreexo)
- [Compact Filters](#compact-filters)
- [Getting help](#getting-help)
- [Wallet](#wallet)
- [Running the tests](#running-the-tests)
- [Requirements](#requirements)
- [Fuzzing](#fuzzing)
- [Contributing](#contributing)
- [Using Nix](#using-nix)
- [License](#license)
- [Acknowledgments](#acknowledgments)
- [Consensus implementation](#consensus-implementation)

### Community

Expand Down Expand Up @@ -203,6 +205,15 @@ pip3 install -r tests/requirements.txt
python tests/run_tests.py
```

### Fuzzing

This project uses `cargo-fuzz` (libfuzzer) for fuzzing, you can run a fuzz target with:
```bash
cargo +nightly fuzz run local_address_str
```

You can replace `local_address_str` with the name of any other target you want to run.

brunoerg marked this conversation as resolved.
Show resolved Hide resolved
### Contributing
Contributions are welcome, feel free to open an issue or a pull request.

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
coverage
20 changes: 20 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "floresta-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
bitcoin = { version = "0.31", features = ["serde", "std"] }
floresta-wire = { path = "../crates/floresta-wire" }

[[bin]]
name = "local_address_str"
path = "fuzz_targets/local_address_str.rs"
test = false
doc = false
bench = false
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/local_address_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]

use core::str;
use std::str::FromStr;

use floresta_wire::address_man::LocalAddress;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let _ = match str::from_utf8(data) {
Ok(s) => LocalAddress::from_str(s),
Err(_) => return,
};
});
Loading