Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#31213: fuzz: Fix difficulty target generation i…
…n `p2p_headers_presync` a6ca8f3 fuzz: Fix difficulty target generation in p2p_headers_presync (marcofleon) fa327c7 util: Add ConsumeArithUInt256InRange fuzzing helper (marcofleon) Pull request description: In the `p2p_headers_presync` fuzz target, this assertion failed: ``` assert(total_work < chainman.MinimumChainWork()); ``` Input that triggered the failure: [p2ppresync_crash.txt](https://github.com/user-attachments/files/17620203/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`][setcompact-link] 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 bitcoin/bitcoin#30918. [setcompact-link]: https://github.com/bitcoin/bitcoin/blob/6463117a29294f6ddc9fafecfd1e9023956cc41b/src/arith_uint256.h#L251-L271 ACKs for top commit: instagibbs: ACK bitcoin/bitcoin@a6ca8f3 dergoegge: Code review ACK a6ca8f3 brunoerg: code review ACK a6ca8f3 Tree-SHA512: 92013d9d37bd3f11992ee678ba9745196efbdc4d773fd14994116629260bea46ffc9fa3923d443af7b623d39c6211900ce98a349c62ad1976e12312c37ef9df0
- Loading branch information