Bitcoin Core 28.99.0
P2P Digital Currency
check_globals.cpp
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <test/util/random.h>
8#include <util/time.h>
9
10#include <iostream>
11#include <memory>
12#include <optional>
13#include <string>
14
17 {
18 g_used_g_prng = false;
20 g_used_system_time = false;
21 SetMockTime(0s);
22 }
24 {
26 std::cerr << "\n\n"
27 "The current fuzz target used the global random state.\n\n"
28
29 "This is acceptable, but requires the fuzz target to call \n"
30 "SeedRandomStateForTest(SeedRand::ZEROS) in the first line \n"
31 "of the FUZZ_TARGET function.\n\n"
32
33 "An alternative solution would be to avoid any use of globals.\n\n"
34
35 "Without a solution, fuzz instability and non-determinism can lead \n"
36 "to non-reproducible bugs or inefficient fuzzing.\n\n"
37 << std::endl;
38 std::abort(); // Abort, because AFL may try to recover from a std::exit
39 }
40
42 std::cerr << "\n\n"
43 "The current fuzz target accessed system time.\n\n"
44
45 "This is acceptable, but requires the fuzz target to call \n"
46 "SetMockTime() at the beginning of processing the fuzz input.\n\n"
47
48 "Without setting mock time, time-dependent behavior can lead \n"
49 "to non-reproducible bugs or inefficient fuzzing.\n\n"
50 << std::endl;
51 std::abort();
52 }
53 }
54};
55
56CheckGlobals::CheckGlobals() : m_impl(std::make_unique<CheckGlobalsImpl>()) {}
std::atomic< bool > g_used_system_time
Definition: time.cpp:23
std::atomic< bool > g_used_g_prng
Definition: random.cpp:674
std::atomic< bool > g_seeded_g_prng_zero
Definition: random.cpp:15
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:39