fuzz: Add fuzz target for block index tree and related validation events #31533

pull mzumsande wants to merge 1 commits into bitcoin:master from mzumsande:202412_fuzz_checkblockindex_pr changing 5 files +217 −3
  1. mzumsande commented at 5:53 pm on December 18, 2024: contributor

    This adds a fuzz target for the block index and various events in validation that interact with it.

    It can create arbitrary tree-like structure of block indexes, simulating (so far) the following events:

    • Adding a header
    • Receiving the full block (may be valid or not)
    • ActivateBestChain() - Reorging the chain to a new chain tip (possibly encountering invalid blocks on the way)
    • Pruning

    It might be interesting / possible to extend this to more events, such as dealing with more than one chainstate (assumeutxo).

    The test skips all actual validation of header/ block / transaction data by just simulating the outcome, and also doesn’t interact with the data directory. The main goal is to ensure the integrity of the block index tree in all fuzzed constellations, by calling CheckBlockIndex() at the end of each iteration.

    Compared to #29158 this approach has a more limited scope (by skipping all actual validation), but it is fast - it doesn’t do a full init sequence on each iteration, but “cleans up” after itself by resetting the global validation state after each iteration. One downside of this approach is that it needs to have public access to a few members / functions in Chainstate(Manager) / BlockManager.

    Looking for conceptual feedback for now, so will leave as draft for a bit - this was helpful while working on #31405 and found the problem described in #31512.

  2. DrahtBot commented at 5:53 pm on December 18, 2024: 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/31533.

    Reviews

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

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Tests on Dec 18, 2024
  4. mzumsande marked this as a draft on Dec 18, 2024
  5. DrahtBot added the label Needs rebase on Jan 22, 2025
  6. mzumsande force-pushed on Jan 23, 2025
  7. DrahtBot removed the label Needs rebase on Jan 23, 2025
  8. in src/test/fuzz/block_index_tree.cpp:57 in 98d68e00c2 outdated
    51+        CallOneOf(
    52+            fuzzed_data_provider,
    53+            [&] {
    54+                // Receive a header building on an existing one. This assumes headers are valid, so PoW is not relevant here.
    55+                LOCK(cs_main);
    56+                CBlockIndex* prev_block = PickValue(fuzzed_data_provider, blocks);
    


    stratospher commented at 4:46 am on February 5, 2025:

    98d68e0: shouldn’t we have a blocks.push_back(index) in this block of code?

    right now, only genesis block gets inserted into std::vector<CBlockIndex*> blocks and we don’t enter into the interesting test cases.


    mzumsande commented at 8:47 pm on February 5, 2025:
    Good point - fixed, and also cleared blocks in the end! While working /testing this branch I directly did picked a value from blockman.m_block_index and introduced blocks right before pushing because picking from a std::unordered_map mad runs non-deterministic.
  9. mzumsande force-pushed on Feb 5, 2025
  10. DrahtBot added the label Needs rebase on Feb 5, 2025
  11. fuzz: Add fuzzer for block index
    This fuzz target creates arbitrary tree-like structure of indices,
    simulating the following events:
    - Adding a header to the block tree db
    - Receiving the full block (may be valid or not)
    - Reorging to a new chain tip (possibly encountering invalid blocks on
      the way)
    - pruning
    The test skips all actual validation of header/ block / transaction data
    by just simulating the outcome, and also doesn't interact with the data directory.
    
    The main goal is to test the integrity of the block index tree in
    all fuzzed constellations, by calling CheckBlockIndex()
    at the end of each iteration.
    7dd613b268
  12. mzumsande force-pushed on Feb 6, 2025
  13. DrahtBot removed the label Needs rebase on Feb 6, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-02-22 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me