Merge bitcoin/bitcoin#31548: fuzz: Abort when global PRNG is used before SeedRand::ZEROS

fa3c787b62 fuzz: Abort when global PRNG is used before SeedRand::ZEROS (MarcoFalke)

Pull request description:

  This adds one more check to abort when global PRNG is used before SeedRand::ZEROS in fuzz tests. This is achieved by carving out the two remaining uses. First, `g_rng_temp_path_init`, and second the random fallback for `RANDOM_CTX_SEED`, which isn't used in fuzz tests anyway.

  Requested in https://github.com/bitcoin/bitcoin/pull/31521#issuecomment-2554669015

  Can be tested by reverting fadd568931 and observing an abort when running the `utxo_total_supply` fuzz target.

ACKs for top commit:
  marcofleon:
    ACK fa3c787b62
  hodlinator:
    re-ACK fa3c787b62
  ryanofsky:
    Code review ACK fa3c787b62. This adds a new check to make that sure that RNG is never seeded during fuzzing after the RNG has been used. Together with existing checks which ensure RNG can only be seeded with zeroes during fuzzing, and that RNG must was seeded at some point if used after fuzzing, this implies it must have been seeded by zeros before being used.

Tree-SHA512: 2614928d31c310309bd9021b3e5637b35f64196020fbf9409e978628799691d0efd3f4cf606be9a2db0ef60b010f890c2e70c910eaa2934a7fbf64cd1598fe22
This commit is contained in:
Ryan Ofsky
2025-01-22 12:29:08 -05:00
3 changed files with 10 additions and 6 deletions

View File

@@ -78,7 +78,9 @@ constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes
static FastRandomContext g_rng_temp_path;
static const bool g_rng_temp_path_init{[] {
// Must be initialized before any SeedRandomForTest
Assert(!g_used_g_prng);
(void)g_rng_temp_path.rand64();
g_used_g_prng = false;
return true;
}()};