fuzz: Use FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION for pow checks #29305

pull dergoegge wants to merge 1 commits into bitcoin:master from dergoegge:2024-01-fuzz-unsafe-pow changing 3 files +27 −2
  1. dergoegge commented at 2:18 PM on January 24, 2024: member

    Alternative to the mocking of CheckProofOfWork in #28043 for avoiding fuzzers to be blocked on proof-of-work checks.

    More on FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION: https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode

  2. fuzz: Use FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION for pow checks
    Unless we are fuzzing `CheckProofOfWork` itself, it makes little sense
    to have it be a blocker when fuzzing. We therefore use
    `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` (only defined for fuzz builds
    by e.g. clang with -fsanitize=fuzzer, afl-clang-lto, etc.) to replace
    the actual proof-of-work checks with checking if the first bit on
    `nNonce` is set. This allows the fuzzer to create PoW (in)valid blocks
    by controling that one bit instead of having to grind for actual PoW.
    
    Checking for a bit in `nNonce` is preferable over checking for a bit in
    the block hash as `nNonce` is chosen by the fuzzer and when whole chains
    of blocks are created during fuzzing a change in an old block won't
    invalidate the fake PoW on newer blocks.
    37e5ebe60b
  3. DrahtBot commented at 2:18 PM on January 24, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

  4. DrahtBot added the label Tests on Jan 24, 2024
  5. dergoegge marked this as a draft on Jan 24, 2024
  6. dergoegge commented at 3:07 PM on January 24, 2024: member

    Using clang with -fsanitize=fuzzer does actually not define FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION by default.

  7. dergoegge closed this on Jan 24, 2024

  8. bitcoin locked this on Jan 23, 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: 2026-04-28 21:13 UTC

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