AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 22 Bitcoin

coinselection: rewrite BnB in CoinGrinder-style

Public commit record

What the developer wrote

Authored by Murch

78/100 · Adequate
coinselection: rewrite BnB in CoinGrinder-style

In the original implementation of BnB, the state of the search is
backtracked by explicitly walking back to the omission branch and then
testing again. This retests an equivalent candidate set as before, e.g.,
after backtracking from {ABC}, it would evaluate {AB_}, before trying
{AB_D}, but {AB_} is equivalent to {AB} which was tested before.

CoinGrinder tracks the state of the search instead by remembering which
UTXO was last added and explicitly shifting from that UTXO directly to
the next, so after {ABC}, it will immediately move on to {AB_D}. We
replicate this approach here.

The description of the two optimizations is removed from the
documentation as they will only be implented in a later commit.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit rewrites an internal Bitcoin wallet algorithm called Branch-and-Bound (BnB) coin selection so it works more like another existing algorithm, CoinGrinder. The change removes two documented speed optimizations (lookahead pruning and skipping equivalent input sets) and adjusts how the search backtracks. It is a code-quality/refactoring change in wallet coin selection, not a consensus or networking change. There is no indication in the commit that this fixes a security vulnerability.

Recommended action

Treat as a normal code review item. Verify that the new BnB still terminates within TOTAL_TRIES, still respects max_selection_weight, and still finds the same optimal or near-optimal solutions as before. Re-introduce the removed lookahead and equivalent-input-set optimizations in a follow-up as the commit message indicates is planned. No security-specific action is required based on this commit alone.

Security signals we found

01

Removal of two BnB optimizations (lookahead pruning and equivalent-input-set skipping) without immediate replacement

02

Change from assert() to Assume() for positive UTXO effective value

03

Algorithmic refactor of wallet coin selection with adjusted test attempt counts

04

No consensus, P2P, or cryptographic code touched

Risk score

Why this scored 22/100

Our methodology →
Potential impact 5/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 5/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.