In the p2p_headers_presync
fuzz target, this assertion failed:
0 assert(total_work < chainman.MinimumChainWork());
Input that triggered the failure: p2ppresync_crash.txt
The test previously used ConsumeIntegralInRange
to generate header difficulty targets within a hardcoded range. The fuzzer found specific values in that range that correspond to very low thresholds due to how SetCompact
works. The total work of a long enough test chain ended up exceeding MinimumChainWork
.
Fix this by adding a new ConsumeArithUInt256InRange
helper function and use it in the fuzz test to generate target values within the originally intended range. The target is then converted to an nBits
value using GetCompact()
.
For some more context, see #30918.