coinselection
fuzz harness into 3 targets (coinselection_bnb
, coinselection_knapsack
, coinselection_srd
). The goal is to be able to fuzz each algorithm separately (to avoid performance issues) and also all of them together.
coinselection
harness
#31870
coinselection
fuzz harness into 3 targets (coinselection_bnb
, coinselection_knapsack
, coinselection_srd
). The goal is to be able to fuzz each algorithm separately (to avoid performance issues) and also all of them together.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31870.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
Stale ACK | zaidmstrr, marcofleon |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
SetBumpFeeDiscount
by brunoerg)add_excess_to_recipient_position
for changeless txs with excess that would be added to fees by remyers)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
220-{
221+enum class CoinSelectionAlgorithm {
222+ BNB,
223+ SRD,
224+ KNAPSACK,
225+ ALL
nit: missing trailing comma.
Also, what is the point of combining them, when they are handled completely separate anyway?
ALL
option. I don’t see anything that needs all of them combined.
224+ KNAPSACK,
225+ ALL
226+};
227+
228+template<CoinSelectionAlgorithm Algorithm>
229+void FuzzCoinSelectionAlgorithm(const uint8_t* buffer, size_t size) {
std::span
for new code
302- auto result_knapsack = KnapsackSolver(group_all, target, change_target, fast_random_context, max_selection_weight);
303- if (result_knapsack) {
304- assert(result_knapsack->GetSelectedValue() >= target);
305- assert(result_knapsack->GetWeight() <= max_selection_weight);
306- result_knapsack->RecalculateWaste(coin_params.min_viable_change, coin_params.m_cost_of_change, coin_params.m_change_fee);
307- (void)result_knapsack->GetShuffledInputVector();
350+FUZZ_TARGET(coinselection_srd) {
351+ FuzzCoinSelectionAlgorithm<CoinSelectionAlgorithm::SRD>(std::span<const uint8_t>(buffer.data(), buffer.size()));
352+}
353+
354+FUZZ_TARGET(coinselection_knapsack) {
355+ FuzzCoinSelectionAlgorithm<CoinSelectionAlgorithm::KNAPSACK>(std::span<const uint8_t>(buffer.data(), buffer.size()));
0 FuzzCoinSelectionAlgorithm<CoinSelectionAlgorithm::KNAPSACK>(buffer);
nit: it is already a span,no?
coinselection_bnb
, coinselection_knapsack
, coinselection_srd
) which is fine, but for the combined test I can’t find any fuzz target there like coinselection
.
Hey, I’m reviewing this PR, as the description says that we can test each target separately, (
coinselection_bnb
,coinselection_knapsack
,coinselection_srd
) which is fine, but for the combined test I can’t find any fuzz target there likecoinselection
.
I just updated the description. I removed the coinselection
target, so there are 3 ones.
Code review ACK 9b293d031c941dc6af0c4274e43388c57c702047
Knapsack is quite a bit slower than the other two, so separating them out is probably a good idea.
Coverage for the three targets: coinselection_bnb coinselection_srd coinselection_knapsack
344+ (void)result_knapsack->GetShuffledInputVector();
345+ (void)result_knapsack->GetInputSet();
346+ // If the total balance is sufficient for the target and we are not using
347+ // effective values, Knapsack should always find a solution (unless the selection exceeded the max tx weight).
348+ if (total_balance >= target && subtract_fee_outputs && !HasErrorMsg(result_knapsack)) {
349+ assert(result_knapsack);
if
statement.
Previously the assert was exposed, now it is guarded by the same condition, making it dead code that the compiler will remove.
In other words: { if (a) assert(a); }
is equivalent to { }
.