|
| 1 | +#include <arith_uint256.h> |
1 | 2 | #include <blockencodings.h> |
2 | 3 | #include <net.h> |
3 | 4 | #include <net_processing.h> |
@@ -89,10 +90,23 @@ CBlockHeader ConsumeHeader(FuzzedDataProvider& fuzzed_data_provider, const uint2 |
89 | 90 | { |
90 | 91 | CBlockHeader header; |
91 | 92 | header.nNonce = 0; |
92 | | - // Either use the previous difficulty or let the fuzzer choose |
93 | | - header.nBits = fuzzed_data_provider.ConsumeBool() ? |
94 | | - prev_nbits : |
95 | | - fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0x17058EBE, 0x1D00FFFF); |
| 93 | + // Either use the previous difficulty or let the fuzzer choose. The upper target in the |
| 94 | + // range comes from the bits value of the genesis block, which is 0x1d00ffff. The lower |
| 95 | + // target comes from the bits value of mainnet block 840000, which is 0x17034219. |
| 96 | + // Calling lower_target.SetCompact(0x17034219) and upper_target.SetCompact(0x1d00ffff) |
| 97 | + // should return the values below. |
| 98 | + // |
| 99 | + // RPC commands to verify: |
| 100 | + // getblockheader 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f |
| 101 | + // getblockheader 0000000000000000000320283a032748cef8227873ff4872689bf23f1cda83a5 |
| 102 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 103 | + header.nBits = prev_nbits; |
| 104 | + } else { |
| 105 | + arith_uint256 lower_target = UintToArith256(uint256{"0000000000000000000342190000000000000000000000000000000000000000"}); |
| 106 | + arith_uint256 upper_target = UintToArith256(uint256{"00000000ffff0000000000000000000000000000000000000000000000000000"}); |
| 107 | + arith_uint256 target = ConsumeArithUInt256InRange(fuzzed_data_provider, lower_target, upper_target); |
| 108 | + header.nBits = target.GetCompact(); |
| 109 | + } |
96 | 110 | header.nTime = ConsumeTime(fuzzed_data_provider); |
97 | 111 | header.hashPrevBlock = prev_hash; |
98 | 112 | header.nVersion = fuzzed_data_provider.ConsumeIntegral<int32_t>(); |
|
0 commit comments