1
- // Copyright (c) 2023 The Bitcoin Core developers
1
+ // Copyright (c) 2023-present The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
@@ -24,7 +24,8 @@ void SeedRandomStateForTest(SeedRand seedtype)
24
24
// MakeRandDeterministicDANGEROUS is called, the output of GetRandHash is
25
25
// no longer truly random. It should be enough to get the seed once for the
26
26
// process.
27
- static const uint256 ctx_seed = []() {
27
+ static const auto g_ctx_seed = []() -> std::optional<uint256> {
28
+ if constexpr (G_FUZZING) return {};
28
29
// If RANDOM_CTX_SEED is set, use that as seed.
29
30
if (const char * num{std::getenv (RANDOM_CTX_SEED)}) {
30
31
if (auto num_parsed{uint256::FromUserHex (num)}) {
@@ -41,8 +42,9 @@ void SeedRandomStateForTest(SeedRand seedtype)
41
42
g_seeded_g_prng_zero = seedtype == SeedRand::ZEROS;
42
43
if constexpr (G_FUZZING) {
43
44
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)
44
46
}
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};
46
48
LogInfo (" Setting random seed for current tests to %s=%s\n " , RANDOM_CTX_SEED, seed.GetHex ());
47
49
MakeRandDeterministicDANGEROUS (seed);
48
50
}
0 commit comments