mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 20:22:44 +02:00
util: Add ConsumeArithUInt256InRange fuzzing helper
This commit is contained in:
@@ -180,6 +180,22 @@ template <typename WeakEnumType, size_t size>
|
||||
return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline arith_uint256 ConsumeArithUInt256InRange(FuzzedDataProvider& fuzzed_data_provider, const arith_uint256& min, const arith_uint256& max) noexcept
|
||||
{
|
||||
assert(min <= max);
|
||||
const arith_uint256 range = max - min;
|
||||
const arith_uint256 value = ConsumeArithUInt256(fuzzed_data_provider);
|
||||
arith_uint256 result = value;
|
||||
// Avoid division by 0, in case range + 1 results in overflow.
|
||||
if (range != ~arith_uint256(0)) {
|
||||
const arith_uint256 quotient = value / (range + 1);
|
||||
result = value - (quotient * (range + 1));
|
||||
}
|
||||
result += min;
|
||||
assert(result >= min && result <= max);
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
||||
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
Reference in New Issue
Block a user