Bitcoin Core
28.99.0
P2P Digital Currency
src
test
fuzz
util
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
5
#include <
test/fuzz/util/check_globals.h
>
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
15
struct
CheckGlobalsImpl
{
16
CheckGlobalsImpl
()
17
{
18
g_used_g_prng
=
false
;
19
g_seeded_g_prng_zero
=
false
;
20
g_used_system_time
=
false
;
21
SetMockTime
(0
s
);
22
}
23
~CheckGlobalsImpl
()
24
{
25
if
(
g_used_g_prng
&& !
g_seeded_g_prng_zero
) {
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
41
if
(
g_used_system_time
) {
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
56
CheckGlobals::CheckGlobals
() : m_impl(
std
::make_unique<
CheckGlobalsImpl
>()) {}
57
CheckGlobals::~CheckGlobals
() =
default
;
check_globals.h
g_used_system_time
std::atomic< bool > g_used_system_time
Definition:
time.cpp:23
std
Definition:
setup_common.h:270
test_vectors_musig2_generate.s
tuple s
Definition:
test_vectors_musig2_generate.py:72
g_used_g_prng
std::atomic< bool > g_used_g_prng
Definition:
random.cpp:674
CheckGlobals::~CheckGlobals
~CheckGlobals()
CheckGlobals::CheckGlobals
CheckGlobals()
Definition:
check_globals.cpp:56
CheckGlobalsImpl
Definition:
check_globals.cpp:15
CheckGlobalsImpl::CheckGlobalsImpl
CheckGlobalsImpl()
Definition:
check_globals.cpp:16
CheckGlobalsImpl::~CheckGlobalsImpl
~CheckGlobalsImpl()
Definition:
check_globals.cpp:23
g_seeded_g_prng_zero
std::atomic< bool > g_seeded_g_prng_zero
Definition:
random.cpp:15
random.h
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition:
time.cpp:39
time.h
Generated on Sat Jan 18 2025 20:00:13 for Bitcoin Core by
1.9.4