Skip to content

fuzz: Fuzzing harnesses for ActivateBestChainStep and ActivateBestChain - #34895

Closed
RobinDavid wants to merge 2 commits into
bitcoin:masterfrom
RobinDavid:fuzz-harness-activate-chains
Closed

RobinDavid wants to merge 2 commits into
bitcoin:masterfrom
RobinDavid:fuzz-harness-activate-chains

Conversation

@RobinDavid

Copy link
Copy Markdown
Contributor

Hi Bitcoin Core maintainers.

This PR is the second part of #34651 and provides the following two fuzzing harnesses:

  • activate_best_chain_step: Test the ActivateBestChainStep() function responsible of activating
    the most worked-chain (not selecting it). The harness is written in a way that enable the fuzzer
    triggering a chain reorganization if it generates two valid branches.
  • activate_best_chain: Test the ActivateBestChain() function responsible of selecting and activating
    the most worked-chain.

In the two later harnesses, some internal state cleaning is required to avoid non-reproducibility issues.
Also they might produce file artifacts on disk by means of writing blocks.

These two harnesses are built upon the connect_block harness thus the PR shall be merged first.

These harnesses enables improving function coverage on ActivateBestChainStep, removeForBlock and to
cover function uncovered by fuzzing at the time of fuzzing harness development (mid-2025).
Functions newly covered include DisconnectTip, DisconnectBlock, ApplyTxInUndo, MaybeUpdateMempoolForReorg, removeForReorg etc.

Authored by @RobinDavid and @nsurbay

(note shall be rebased on the other PR so that it only contains 1 commit)

@DrahtBot

DrahtBot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34895.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35906 (First steps towards a stateless, side-effect free validation library by purpleKarrot)
  • #35850 (fuzz: Implement connect_block harness by marcofleon)
  • #35570 (refactor: Change some validation.cpp methods to return BlockValidationState by optout21)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • // It intend to leave more space to craft complex transactions... -> // It is intended to leave more space... [Subject/verb agreement is incorrect (“intend” vs “intends/ is intended”), hurting readability.]
  • // It is exclusively used by ConsumeBlock to read transaction inside a block. -> // ... to read transactions inside a block. [Singular/plural mismatch (“transaction” → “transactions”).]
  • /** Vector of blocks to keep a references on blocks ... */ -> /** Vector of blocks to keep references on blocks ... */ [Incorrect article/plural (“a references”).]
  • /** Spending script for all UTXOs ... including not mature CoinBase and already spend one */ -> /** ... including immature coinbase and already spent one */ [Wording is grammatically broken (“not mature”, “CoinBase”, “already spend one”) and unclear without guessing intent.]
  • // ... is not read from the input per-se -> // ... is not read from the input per se [Typo: “per-se” → “per se”.]
  • // ... create the associated spending script to enable to be spent in later transactions. -> // ... create the associated spending script so that they can be spent in later transactions. [Broken grammar (“enable to be spent”), making the meaning awkward.]

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • ConsumeTransaction(fuzzed_data_provider, additionalUTXO, true, targetHeight) in src/test/fuzz/connect_block.cpp
  • active_chainstate.ConnectBlock(block, state, &new_index, active_coins, /* justCheck*/ true) in src/test/fuzz/connect_block.cpp
  • ConsumeBlock(fuzzed_data_provider, *currentBlock, active_tip->nHeight + 1 + i, additionalUTXO, true) in src/test/fuzz/connect_block.cpp
  • ConsumeBlock(fuzzed_data_provider, *currentBlock, originTip->nHeight + 1 + i, additionalUTXO, true) in src/test/fuzz/connect_block.cpp
  • csm.AcceptBlock(std::make_shared<CBlock>(block), state, &blockIndex, true, nullptr, &isNewBlock, true) in src/test/fuzz/connect_block.cpp
  • ConsumeBlock(fuzzed_data_provider, *currentBlock, originTip->nHeight + 1 + i, additionalUTXO, true) in src/test/fuzz/connect_block.cpp
  • ConsumeBlock(fuzzed_data_provider, *currentBlock, originTip->nHeight + 1 + i, additionalUTXO, true) in src/test/fuzz/connect_block.cpp

2026-04-08 21:45:47

@fanquake

fanquake commented Aug 6, 2026

Copy link
Copy Markdown
Member

@marcofleon were you planning to pick this up as well?

@marcofleon

Copy link
Copy Markdown
Contributor

Yes

@fanquake

fanquake commented Aug 6, 2026

Copy link
Copy Markdown
Member

Will close for now.

@fanquake fanquake closed this Aug 6, 2026
fanquake added a commit that referenced this pull request Aug 27, 2026
2777300 fuzz: Implement connect_block harness (Robin David)
40add91 test: Add reset to CuckooCache (Eugene Siegel)

Pull request description:

  Adds a fuzz target that directly calls `ConnectBlock` with `fJustCheck` set to true, so it hits block/transaction validation without writing undo data or updating the chainstate.

  This PR is essentially #34651 with some minor tweaks and style cleanups. Additional validation harnesses (e.g. #34895) could build on this test's setup.

ACKs for top commit:
  Crypt-iQ:
    ACK 2777300
  nervana21:
    tACK 2777300

Tree-SHA512: e2dc74154a6e29e0f3eaec9caeeec53d64bcc96adb0d1739281da97712dd931c3937eaf71f977bfc9c9330f26e35b3633f72788143b76e24e17c37b0a4258ba4
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 31, 2026
2777300c68f575565dabdcef4d0498ebc91a401e fuzz: Implement connect_block harness (Robin David)
40add915be5c5d204d85474a2704362cb635ef6d test: Add reset to CuckooCache (Eugene Siegel)

Pull request description:

  Adds a fuzz target that directly calls `ConnectBlock` with `fJustCheck` set to true, so it hits block/transaction validation without writing undo data or updating the chainstate.

  This PR is essentially bitcoin/bitcoin#34651 with some minor tweaks and style cleanups. Additional validation harnesses (e.g. bitcoin/bitcoin#34895) could build on this test's setup.

ACKs for top commit:
  Crypt-iQ:
    ACK 2777300c68f575565dabdcef4d0498ebc91a401e
  nervana21:
    tACK 2777300c68f575565dabdcef4d0498ebc91a401e

Tree-SHA512: e2dc74154a6e29e0f3eaec9caeeec53d64bcc96adb0d1739281da97712dd931c3937eaf71f977bfc9c9330f26e35b3633f72788143b76e24e17c37b0a4258ba4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants