Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

[Coin Selection Chapter] Add outline and initial notes #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions y.coin-selection/coin-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Intro
Coin Selection refers to the process of picking inputs from a wallet's Unspent Transaction Output (UTXO) Pool to fund a transaction.

# Problem Description
First and foremost, the selected input set must provide sufficient funds to pay for the transaction's intended outputs at the determined fee rate.
The selection hereby has a bit of recursive feedback on the selection target in that it determines the necessity of change outputs, additional witness bytes to the transaction header, and inputs need to pay for their own inclusion.
After achieving these requirements, other considerations come into play.

# Dimensions of the Problem

## Smallest transaction pays lowest fees
Generally, the smallest possible transaction is the cheapest to get included in a block.
So, it may seem obvious that one could save fees by always building transactions with a single input.
However, this would likely require the creation of a change ouput which would mean that the sending wallet's UTXO count would remain constant, while new UTXO get created for the recipients.
If the wallet also frequently receives incoming transactions, optimizing for this dimension exclusively can lead to a quickly bloating UTXO pool.

## Every UTXO has to be spent eventually
Given that Bitcoin balance is only accessible[^1] by spending the corresponding UTXO, every UTXO must be spent eventually.
Assuming that there will be some periods of time in the future in which block inclusion remains continuously restricted to high fee rates, it may be preferable to spend low-value UTXO at earlier low-fee periods.
Otherwise, low-value UTXO may become economically unspendable for the duration of such a fee rate spike when the cost to spend a UTXO exceeds the UTXO's value.
Strategies to pre-empt this situation include consolidating UTXO periodically, using different coin selection strategies at different fee rate levels, or simply prioritizing the consumption of low-value UTXO.

## Privacy
While Bitcoin has some nice privacy property in the sense that payments are associated only with a pseudonym of the owner rather than their identity immediately, it is far from anonymous.
Where people are concerned to limit their traceability and improve their privacy, they may have vastly different requirements for their coin selection.
Chainalysis has generally been doing well to assume that any UTXO used together in one transaction indicate being owned by the same wallet.
[Coinjoin with 100 participants via Wasabi]
[Spend everything from same address.]
[Address reuse.]
[Manual selection.]
[Separation of funds by concerns.]
[Coinjoin with recipient.]

## Individual Usage Pattern
- Small UTXO Pools for end-users
- Large incoming to outgoing imbalance for merchants

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure this bullet point is capturing what I think it is, we plan to write about the 2nd point in Jameson's post, "For high volume wallets that send more than one transaction every few blocks it’s important to keep plenty of confirmed UTXOs available."

https://medium.com/@lopp/the-challenges-of-optimizing-unspent-output-selection-a3e5d05d13ef

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was mostly based on the notion that every transaction performs only a single payment. Wallets that batch payments can subsist on way fewer UTXOs.

- High frequency of sending makes batching viable and attractive
- Sending frequency correlated with trading activity corresponds to times of high fees (-> consolidations)

## Global UTXO Set
- CONOP influence of large UTXO Set

## Significance of omitting change outputs

# Simple workable solution: Random Selection

# Heuristic-based UTXO Management, e.g. Branch and Bound

# Coin Control

# Do nots
## Largest First Selection

# Additional UTXO Management Strategies (link to consolidation and batching)
# Outlook: New Address formats

[^1]: Barring direct transfer of UTXO ownership e.g. per hardware wallets or layer-two constructions such as state-chains.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention needing to refresh timelocks? For example, the Green wallet considers this in their coin selection algorithm.