Merge bitcoin/bitcoin#31521: fuzz: Fix misplaced SeedRand::ZEROS
Some checks are pending
CI / Win64 native fuzz, VS 2022 (push) Waiting to run
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run
CI / test each commit (push) Waiting to run
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Waiting to run
CI / macOS 14 native, arm64, fuzz (push) Waiting to run
CI / Win64 native, VS 2022 (push) Waiting to run

fadd568931 fuzz: Fix misplaced SeedRand::ZEROS (MarcoFalke)

Pull request description:

  After commit fae63bf130 this must be placed even before test_setup. This is nice, because it makes the usage consistently appear in the first line.

  The change is moving a `SeedRandomForTest(SeedRand::ZEROS)` to happen earlier. This is fine, because it will either have no effect, or make the code more deterministic, because after commit fae63bf, no other re-seeding other than `ZEROS` can happen in fuzz tests.

ACKs for top commit:
  marcofleon:
    Re ACK fadd568931
  brunoerg:
    code review ACK fadd568931
  hodlinator:
    ACK fadd568931

Tree-SHA512: 54eadf19a1e850157a280fb252ece8797f37a9a50d3b0a01aa2c267bacbe8ef4ddea6cf3faadcbaa4ab9f53148edf08e3cee5dfb3eae928db582adf8373a5206
This commit is contained in:
Ryan Ofsky 2024-12-19 10:06:17 -05:00
commit bb57017b29
No known key found for this signature in database
GPG key ID: 46800E30FC748A66
2 changed files with 4 additions and 4 deletions

View file

@ -24,12 +24,12 @@ struct CheckGlobalsImpl {
"The current fuzz target used the global random state.\n\n"
"This is acceptable, but requires the fuzz target to call \n"
"SeedRandomStateForTest(SeedRand::ZEROS) at the beginning \n"
"of processing the fuzz input.\n\n"
"SeedRandomStateForTest(SeedRand::ZEROS) in the first line \n"
"of the FUZZ_TARGET function.\n\n"
"An alternative solution would be to avoid any use of globals.\n\n"
"Without a solution, fuzz stability and determinism can lead \n"
"Without a solution, fuzz instability and non-determinism can lead \n"
"to non-reproducible bugs or inefficient fuzzing.\n\n"
<< std::endl;
std::abort(); // Abort, because AFL may try to recover from a std::exit

View file

@ -21,6 +21,7 @@ using node::BlockAssembler;
FUZZ_TARGET(utxo_total_supply)
{
SeedRandomStateForTest(SeedRand::ZEROS);
/** The testing setup that creates a chainman only (no chainstate) */
ChainTestingSetup test_setup{
ChainType::REGTEST,
@ -28,7 +29,6 @@ FUZZ_TARGET(utxo_total_supply)
.extra_args = {"-testactivationheight=bip34@2"},
},
};
SeedRandomStateForTest(SeedRand::ZEROS); // Can not be done before test_setup
// Create chainstate
test_setup.LoadVerifyActivateChainstate();
auto& node{test_setup.m_node};