Skip to content

Commit 9f243cd

Browse files
committed
Introduce g_fuzzing global for fuzzing checks
1 parent b95adf0 commit 9f243cd

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ if(BUILD_FOR_FUZZING)
240240
set(BUILD_GUI_TESTS OFF)
241241
set(BUILD_BENCH OFF)
242242
set(BUILD_FUZZ_BINARY ON)
243-
244-
target_compile_definitions(core_interface INTERFACE
245-
ABORT_ON_FAILED_ASSUME
246-
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
247-
)
248243
endif()
249244

250245
include(ProcessConfigurations)

src/pow.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <chain.h>
1010
#include <primitives/block.h>
1111
#include <uint256.h>
12+
#include <util/check.h>
1213

1314
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
1415
{
@@ -138,11 +139,8 @@ bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t heig
138139
// the most signficant bit of the last byte of the hash is set.
139140
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
140141
{
141-
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
142-
return (hash.data()[31] & 0x80) == 0;
143-
#else
142+
if (g_fuzzing) return (hash.data()[31] & 0x80) == 0;
144143
return CheckProofOfWorkImpl(hash, nBits, params);
145-
#endif
146144
}
147145

148146
bool CheckProofOfWorkImpl(uint256 hash, unsigned int nBits, const Consensus::Params& params)

src/test/fuzz/fuzz.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ void ResetCoverageCounters() {}
102102

103103
void initialize()
104104
{
105+
g_fuzzing = true;
106+
105107
// By default, make the RNG deterministic with a fixed seed. This will affect all
106108
// randomness during the fuzz test, except:
107109
// - GetStrongRandBytes(), which is used for the creation of private key material.

src/util/check.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <string>
1515
#include <string_view>
1616

17+
bool g_fuzzing = false;
18+
1719
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
1820
{
1921
return strprintf("Internal bug detected: %s\n%s:%d (%s)\n"

src/util/check.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <string_view>
1414
#include <utility>
1515

16+
extern bool g_fuzzing;
17+
1618
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func);
1719

1820
class NonFatalCheckError : public std::runtime_error
@@ -42,7 +44,7 @@ void assertion_fail(std::string_view file, int line, std::string_view func, std:
4244
template <bool IS_ASSERT, typename T>
4345
constexpr T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* file, [[maybe_unused]] int line, [[maybe_unused]] const char* func, [[maybe_unused]] const char* assertion)
4446
{
45-
if (IS_ASSERT || std::is_constant_evaluated()
47+
if (IS_ASSERT || std::is_constant_evaluated() || g_fuzzing
4648
#ifdef ABORT_ON_FAILED_ASSUME
4749
|| true
4850
#endif

0 commit comments

Comments
 (0)