Skip to content

feat(fuzz): add fuzzing harness for LocalChain with CI job - #2239

Open
erickcestari wants to merge 2 commits into
bitcoindevkit:masterfrom
erickcestari:fuzz-bdk
Open

feat(fuzz): add fuzzing harness for LocalChain with CI job#2239
erickcestari wants to merge 2 commits into
bitcoindevkit:masterfrom
erickcestari:fuzz-bdk

Conversation

@erickcestari

@erickcestari erickcestari commented Jul 9, 2026

Copy link
Copy Markdown

Description

Adds an initial fuzzing harness for bdk_chain and a CI job that runs it.

Two fuzz targets in a new fuzz/ crate:

  • local_chain_apply_update: builds a LocalChain<BlockHash> and applies random sequences of apply_update, insert_block, disconnect_from, apply_header(_connected_to), including updates derived from the chain's own tip to hit the merge_chains eq_ptr fast path.
  • local_chain_apply_update_header: fuzzes LocalChain<Header>, exercising placeholder resolution in apply_update and CheckPoint::entry_iter via a virtual chain of linked headers with random reorgs.

After every operation, the harness asserts that a successful op's changeset reconstructs the post-state from the pre-state, a failed op leaves the chain untouched, and chain invariants hold (strictly decreasing heights, genesis present, is_block_in_chain consistency).

Supports AFL, honggfuzz, and libFuzzer via cargo features. The CI job runs each fuzzer on each target for 5 minutes as a smoke test.

Notes to the reviewers

  • The fuzz crate is its own workspace (publish = false) so fuzzer deps don't affect the main workspace.

Changelog notice

  • Added a fuzzing harness for LocalChain (AFL, honggfuzz, libFuzzer) with a CI job.

Coverage report

image

cc @oleonardolima

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.31%. Comparing base (5108b5c) to head (8f4d293).

Files with missing lines Patch % Lines
crates/chain/src/local_chain.rs 16.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2239      +/-   ##
==========================================
- Coverage   78.36%   78.31%   -0.05%     
==========================================
  Files          30       30              
  Lines        5945     5950       +5     
  Branches      281      283       +2     
==========================================
+ Hits         4659     4660       +1     
- Misses       1210     1213       +3     
- Partials       76       77       +1     
Flag Coverage Δ
rust 78.31% <16.66%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@luisschwab luisschwab moved this to Needs Review in BDK Chain Jul 9, 2026
@oleonardolima oleonardolima moved this from Needs Review to In Progress in BDK Chain Jul 10, 2026
@oleonardolima

Copy link
Copy Markdown
Contributor

It's still missing an updated CI, fixing the conflicts and running each target+harness for an x cycles instead of time, also it requires a proper README.md for users on how to run the fuzzer, and how to add new targets.

Comment thread fuzz/fuzz_targets/local_chain_apply_update.rs
@luisschwab

Copy link
Copy Markdown
Member

@erickcestari needs rebase

erickcestari and others added 2 commits August 17, 2026 11:14
Co-authored-by: Leonardo Lima <oleonardolima@users.noreply.github.com>
Co-authored-by: Leonardo Lima <oleonardolima@users.noreply.github.com>
@luisschwab

Copy link
Copy Markdown
Member

Put bdk_chain targets under a chain folder so we can keep it neat when adding targets from other crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants