Skip to content

feat: add initial fuzz testing #271

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

oleonardolima
Copy link
Contributor

@oleonardolima oleonardolima commented Jun 24, 2025

Description

It's an initial work towards the goal of #61, it adds a new fuzz crate to the project which is meant to be used to add new fuzz target in order to increase the fuzz coverage.

It's built on top of and with inspiration from previous Antoine's work through the most recent BDK Audit.

So far, this PR:

  • creates a new fuzz crate with cargo fuzz relying on LibFuzzer engine.
  • adds an initial fuzz target, which builds and applies an Update to Wallet.
  • adds both initial fuzzed_data_provider and fuzz_utils with common used fns to build BDK's-specific types from fuzzed bytes.

Still to be done by this PR:

  • write-up the README.md with instructions for other users.
  • add helpful bash scripts, to build the environment, and run the existing fuzz targets.
  • add a new CI step, to briefly run the existing fuzz targets at a certain schedule.
  • add remaining: (i) persist ; (ii) tx creation fuzz targets (by Antoine's existing target).
  • add other fuzz targets.

Notes to the reviewers

Are there any other BDK usage scenarios you'd like to see covered by a fuzz target ? Let's discuss it either on the issue or under this PR comments.

Changelog notice

TBD

Checklists

All Submissions:

@coveralls
Copy link

coveralls commented Jun 24, 2025

Pull Request Test Coverage Report for Build 16808127177

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.912%

Totals Coverage Status
Change from base Build 16786013135: 0.0%
Covered Lines: 6669
Relevant Lines: 7854

💛 - Coveralls

@oleonardolima oleonardolima force-pushed the feat/add-initial-fuzz-testing branch 2 times, most recently from 31f422f to 2b885dc Compare June 25, 2025 19:15
@oleonardolima oleonardolima self-assigned this Jun 25, 2025
@oleonardolima oleonardolima added the tests New or improved tests label Jun 25, 2025
@oleonardolima oleonardolima moved this to In Progress in BDK Wallet Jun 25, 2025
@oleonardolima oleonardolima added this to the Wallet 3.0.0 milestone Jun 25, 2025
@evanlinjin
Copy link
Member

Could you include the rationale for having a separate crate for fuzzing? Is it because we need to use nightly cargo?

@TheBlueMatt
Copy link

Rather than requiring use of libFuzzer, it might make sense to build a generic fuzz wrapper, possibly based on the LDK fuzz infra at https://github.com/lightningdevkit/rust-lightning/tree/main/fuzz or the rust-bitcoin fuzz infra. libFuzzer is great and one of the more actively maintained fuzz harnesses, but honggfuzz is in many cases easier to run, so we've found it quite useful to offer both (plus AFL, for those who want that).

@oleonardolima oleonardolima force-pushed the feat/add-initial-fuzz-testing branch 3 times, most recently from 1166295 to 8422bc6 Compare July 24, 2025 00:04
@oleonardolima oleonardolima force-pushed the feat/add-initial-fuzz-testing branch from 8422bc6 to f309e1d Compare July 24, 2025 00:18
persist-credentials: false

- name: Install the nightly Rust channel
uses: actions-rs/toolchain@v1

Check failure

Code scanning / zizmor

action is not pinned to a hash (required by blanket policy) Error

action is not pinned to a hash (required by blanket policy)
@oleonardolima oleonardolima force-pushed the feat/add-initial-fuzz-testing branch from f309e1d to 3b70fa6 Compare July 24, 2025 00:54
- creates a new `fuzz` crate, it's meant to run fuzz testing over
  bdk_wallet targets, with `cargo fuzz` (libFuzzer).
- creates an initial `wallet_update` fuzz target for `bdk_wallet`.
- creates an initial `fuzzed_data_provider` and `fuzz_utils` files with
  useful methods to consume the fuzzed data into `bdk_wallet` API-specific types.
- renames the fuzz target to `bdk_wallet`.
- add the `WalletAction` enum, in order to fuzz test different
  behaviors: wallet update, persistance/load, and tx creation.
- use macros (e.g `try_consume_*`) in `fuzzed_data_provider` and
  `fuzz_utils` in order to properly handle an exhausted fuzzer byte
stream, returning early.
- update `Wallet::ApplyUpdate` target to use the newly added macros.
- update `bdk_wallet_fuzz` to use `rusqlite` feature.
- update the created wallet in `bdk_wallet` fuzz target to use an
  in-memory sqlite database connection, initializing wallet with
persistance.
- add the `PersistAndLoad` scenario to `bdk_wallet` fuzz target.
- add the `CreateTx` scenario to `bdk_wallet` fuzz target.
- add two new macros: `try_consume_tx_builder` and
  `try_consume_sign_options`, in order to build the specific structures
and types required for tx creation, signing and applying to wallet.
- adds a new daily CI fuzz job, it runs every day at 5am UTC and uploads
  the artifacts on failures.
- it currently only uses the `cargo fuzz`, as it's the only supported
  harness at the moment.
@oleonardolima oleonardolima force-pushed the feat/add-initial-fuzz-testing branch from 47ecc5f to 7f1fa74 Compare August 7, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests New or improved tests
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants