1- // Copyright (c) 2023 The Bitcoin Core developers
1+ // Copyright (c) 2023-present The Bitcoin Core developers
22// Distributed under the MIT software license, see the accompanying
33// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
@@ -24,7 +24,8 @@ void SeedRandomStateForTest(SeedRand seedtype)
2424 // MakeRandDeterministicDANGEROUS is called, the output of GetRandHash is
2525 // no longer truly random. It should be enough to get the seed once for the
2626 // process.
27- static const uint256 ctx_seed = []() {
27+ static const auto g_ctx_seed = []() -> std::optional<uint256> {
28+ if constexpr (G_FUZZING) return {};
2829 // If RANDOM_CTX_SEED is set, use that as seed.
2930 if (const char * num{std::getenv (RANDOM_CTX_SEED)}) {
3031 if (auto num_parsed{uint256::FromUserHex (num)}) {
@@ -41,8 +42,9 @@ void SeedRandomStateForTest(SeedRand seedtype)
4142 g_seeded_g_prng_zero = seedtype == SeedRand::ZEROS;
4243 if constexpr (G_FUZZING) {
4344 Assert (g_seeded_g_prng_zero); // Only SeedRandomStateForTest(SeedRand::ZEROS) is allowed in fuzz tests
45+ Assert (!g_used_g_prng); // The global PRNG must not have been used before SeedRandomStateForTest(SeedRand::ZEROS)
4446 }
45- const uint256& seed{seedtype == SeedRand::FIXED_SEED ? ctx_seed : uint256::ZERO};
47+ const uint256& seed{seedtype == SeedRand::FIXED_SEED ? g_ctx_seed. value () : uint256::ZERO};
4648 LogInfo (" Setting random seed for current tests to %s=%s\n " , RANDOM_CTX_SEED, seed.GetHex ());
4749 MakeRandDeterministicDANGEROUS (seed);
4850}
0 commit comments