Coin selection is the process of choosing which UTXOs (or “coins”) to fund a Bitcoin transaction with (inputs1) when making an on-chain payment. Since a wallet contains multiple coins to arrive at a balance, these are retrieved by an algorithm to fulfill the payment amount for outgoing transactions.
There are two types of coin selection strategies that are used in Bitcoin applications:
- Automatic Coin Selection (wallet is delegated to control coin selection on behalf of user)
- Manual Coin Selection (user controls coin selection)
There are a few constraints that you should have in mind when considering the coin-selection strategy for your product.
First, the transaction must have sufficient funding. For example, to send X, the transaction inputs must at least equate to X.
Second, as blockspace is limited, miners prioritize transactions by fee per byte to maximize revenue. The minimum relay fee must accompany transactions for confirmation (therefore, inputs must equal X + fee).
Third, transaction outputs must have a value of 500 sats or more. Anything less than this value is considered a “dust” output, and these transactions are often not relayed and confirmed by most nodes and miners in the network.
Finally, wallet owners need to label their incoming and outgoing (change) coins. Labels provide context to a wallet’s transaction history and coin provenance, making it easier to successfully employ coin control for privacy optimization.
Whether an automated or manual process, coin selection is important when understanding how to optimize our Bitcoin payments for either cost, speed, or privacy. Below is a breakdown of the three most common effects of coin selection.
Miners select transactions based on their fee, measured by the fee rate of satoshis per byte. Therefore, it is cost-effective for users to minimize transaction size by minimizing the number of inputs.
Higher fees will increase the likelihood of your transaction being prioritized by miners and included in the next block, thereby increasing the speed of your transaction. This can be optimized by either increasing the fee rate or selecting a higher number of transaction inputs.
Because each UTXO can be traced backward on a public ledger, we can unearth the digital footprints of Bitcoin payments. Privacy is often lost due to the exposure of unknown coins, addresses, balances, and economic activity to unrecognized trading partners. Privacy can be optimized by selecting transaction inputs from an anonymity set (CoinJoins or mixers) or a recognized label or cluster or reducing the size of change outputs.
Automatic coin selection #
This strategy has arguably become the most popular form of coin selection used in Bitcoin wallets and applications. The application selects the coins on behalf of users to fulfill a payment request. As mentioned above, “fractions (of bitcoins) are retrieved by an algorithm to fulfill the payment amount”. This algorithm varies from wallet to wallet, and is dependent upon the desired outcome of optimisation.
Automatic selection strategies can provide a near frictionless user experience and are suitable for most introductory level Bitcoin wallets.
How it works #
A user chooses to send a payment to one of their contacts. They enter the amount of bitcoin they wish to send, select their transaction fee rate, and approve the outgoing payment request. During this process, their wallet automatically selects which coins to use to fund the transaction’s inputs, making sure it can fulfill the payment request.
A few popular algorithms currently implemented by Bitcoin wallets:
- First In First Out (FIFO) / Last In, First Out (LIFO)
The default strategy spends the oldest/youngest coins first.
- Pruned FIFO
Similiar to FIFO, but smallest coins filtered out in post-selection step.
- High Priority First
Coins selected by priority (calculated by value x age). Up until February 2016, a portion of each block (50kB) was reserved for high-priority transactions by default. This algorithm therefore optimised for transaction speed.
- Minimize Fees (Optimize Size)
Spending the lowest number of coins to reduce the byte size of the transaction, resulting in a lower fee.
- Minimize Future Fees (Merge Coins)
Spending the maximum number of inputs to merge coins as a single change output for future use. This strategy can optimise for speed as the transaction size (and therefore cost) is increased. However, merging coins can also lead to a loss of privacy as coins, their addresses, balances, and historical transaction data are intertwined.
A few more, optimising for privacy
- Target Sized Change
Wallet aims to minimize the value difference of target input and change output.
- Branch & Bound (BnB)/Exact Change
Wallet finds an input set that is equal in value to the target, avoiding change outputs. If the wallet cannot find an exact match, it refers back to a “knapsack” solver which selects inputs that minimise the change output to within 0.01 BTC.
Accumulates inputs until the target value (+fees) is matched, does not accumulate inputs that go over the target value (within a threshold).
Accumulates inputs until the target value (+fees) is reached, skipping detrimental inputs.
- Freezing Coins
Freezes certain coins or clusters from their wallet’s UTXO pool to either prioritize or avoid using when funding outgoing payment requests. This technique aids automatic selection strategies to become more private but also relies on the practice of successfully labeling coins.
- Low friction: easy for end-user, doesn’t have to play around with manual coin selection
- Wallets can choose to optimize for cost, speed, or privacy (byte size of transaction, fee, change outputs) depending upon their targeted user group.
- Minimizing change outputs and decreases balance exposure and the chance of tracing future transactions from that address.
- Doesn’t optimize for all three features (speed, cost, privacy)
- Automatic selection strategies may select UTXOs associated with targeted dusting attacks, resulting in privacy loss
- UTXOs selected from unrecognized clusters can expose private data of wallet addresses, balances, and contact payment information (UTXO derivation paths and data).
- Reducing the inputs (byte size) of bitcoin transactions doesn’t usually optimise for minimal change outputs, exposing larger amounts of sensitive wallet data.
- Freezing certain coins reduces the size of a wallet’s UTXO pool, and may hinder an automatic algorithm’s ability to optimise for speed, cost, or privacy.
Best practice #
When to use #
- New users or introductory level wallets
- Wallets specifically optimizing for either cost, speed, or privacy
When not to use #
- When privacy is a top priority to users
- When wanting to provide a more custom experience for Bitcoin transactions
Products that use this scheme #
Manual coin selection (a.k.a coin control) #
Manual coin selection gives users full control over exactly which coins or clusters they use to fund a transaction input for an outgoing payment request.
Manual coin control is often an “opt-in” strategy, agreed to by users as they enter “Private Mode” or select “Manual Coin Selection” when creating an outgoing payment request. However, it is also possible for Bitcoin wallets to use manual coin control as their default coin selection strategy.
This strategy gives users the ability to choose what they wish to optimize for in Bitcoin transactions (cost, speed, or privacy). However, it’s worth noting that manual coin control, whilst beneficial to many, could also lead to expensive, slow, or revealing transactions if misused. Manual coin selection is an advanced feature and should be used (and designed) with caution.
How it works #
A user chooses to send a payment to one of their contacts. They enter the amount of bitcoin they wish to send, select their transaction fee rate, “opt-in” for manual coin selection (or by default), select which UTXOs will fund the transaction input, and finally approve the outgoing payment request.
- Gives user full control over coin selection. They can choose to optimize for privacy, cost, or speed, and delegate risk accordingly.
- Good labeling of coins allows users to prioritize recognized clusters, thereby minimizing the exposure of historical transaction data, balances, and addresses associated with certain coins.
- Has potential to reduce dust attacks (avoiding choosing minute or unknown UTXOs for payment inputs)
- Inexperienced users may end up making mistakes that result in higher fees, slower transactions, or a loss of privacy
- Can lead to dust attacks if not careful selecting sizes of UTXO inputs
- Bad labeling of contacts and clusters can lead to sensitive information being exposed
Best practise #
When to use #
- Wallets oriented towards advanced, privacy focused bitcoiners
- When wanting to give users full control of selecting transaction inputs
- When paired with good labeling practises
When not to use #
- Introductory level bitcoin wallets
Products that use this scheme #