@@ -45,6 +45,24 @@ static void GroupCoins(FuzzedDataProvider& fuzzed_data_provider, const std::vect
45
45
if (valid_outputgroup) output_groups.push_back (output_group);
46
46
}
47
47
48
+ static CAmount CreateCoins (FuzzedDataProvider& fuzzed_data_provider, std::vector<COutput>& utxo_pool, CoinSelectionParams& coin_params, int & next_locktime)
49
+ {
50
+ CAmount total_balance{0 };
51
+ LIMITED_WHILE (fuzzed_data_provider.ConsumeBool (), 10000 )
52
+ {
53
+ const int n_input{fuzzed_data_provider.ConsumeIntegralInRange <int >(0 , 10 )};
54
+ const int n_input_bytes{fuzzed_data_provider.ConsumeIntegralInRange <int >(41 , 10000 )};
55
+ const CAmount amount{fuzzed_data_provider.ConsumeIntegralInRange <CAmount>(1 , MAX_MONEY)};
56
+ if (total_balance + amount >= MAX_MONEY) {
57
+ break ;
58
+ }
59
+ AddCoin (amount, n_input, n_input_bytes, ++next_locktime, utxo_pool, coin_params.m_effective_feerate );
60
+ total_balance += amount;
61
+ }
62
+
63
+ return total_balance;
64
+ }
65
+
48
66
// Returns true if the result contains an error and the message is not empty
49
67
static bool HasErrorMsg (const util::Result<SelectionResult>& res) { return !util::ErrorString (res).empty (); }
50
68
@@ -67,20 +85,8 @@ FUZZ_TARGET(coinselection)
67
85
coin_params.change_output_size = fuzzed_data_provider.ConsumeIntegralInRange <int >(10 , 1000 );
68
86
coin_params.m_change_fee = effective_fee_rate.GetFee (coin_params.change_output_size );
69
87
70
- // Create some coins
71
- CAmount total_balance{0 };
72
88
int next_locktime{0 };
73
- LIMITED_WHILE (fuzzed_data_provider.ConsumeBool (), 10000 )
74
- {
75
- const int n_input{fuzzed_data_provider.ConsumeIntegralInRange <int >(0 , 10 )};
76
- const int n_input_bytes{fuzzed_data_provider.ConsumeIntegralInRange <int >(100 , 10000 )};
77
- const CAmount amount{fuzzed_data_provider.ConsumeIntegralInRange <CAmount>(1 , MAX_MONEY)};
78
- if (total_balance + amount >= MAX_MONEY) {
79
- break ;
80
- }
81
- AddCoin (amount, n_input, n_input_bytes, ++next_locktime, utxo_pool, coin_params.m_effective_feerate );
82
- total_balance += amount;
83
- }
89
+ CAmount total_balance{CreateCoins (fuzzed_data_provider, utxo_pool, coin_params, next_locktime)};
84
90
85
91
std::vector<OutputGroup> group_pos;
86
92
GroupCoins (fuzzed_data_provider, utxo_pool, coin_params, /* positive_only=*/ true , group_pos);
0 commit comments