Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

A Survey on Coin Selection Algorithms in

UTXO-based Blockchains
Gholamreza Ramezan Manvir Schneider Mel McCann
IEEE Member Cardano Foundation Cardano Foundation
g2n@ieee.org manvir.schneider@cardanofoundation.org mel.mccann@cardanofoundation.org

Abstract—Coin selection algorithms are a fundamental compo-


nent of blockchain technology. In this paper, we present a compre-
arXiv:2311.01113v1 [cs.CR] 2 Nov 2023

hensive review of the existing coin selection algorithms utilized


in unspent transaction output (UTXO)-based blockchains. We
provide a list of the desired objectives and categorize existing
algorithms into three types: primitive, basic, and advanced
algorithms. This allows for a structured understanding of their Fig. 1: Example of new UTXOs created.
functionalities and limitations. We also evaluate the performance
of existing coin selection algorithms. The aim of this paper is to
provide system researchers and developers with a concrete view ∙ We categorize the various existing algorithms based on
of the current design landscape.
Keywords—Blockchain, Coin Selection, UTXO, Optimization their characteristics, allowing for a structured understand-
ing of their functionalities and limitations. This pro-
I. INTRODUCTION vides a valuable resource for researchers and developers
Coin selection algorithms play a fundamental role in the seeking to explore and compare different coin selection
functioning of blockchains. These algorithms determine which approaches.
coins or tokens are selected for a particular transaction, effec- ∙ We provide a comprehensive list of objectives that should
tively shaping the overall efficiency, privacy, and reliability be satisfied by coin selection algorithms.
of the blockchain systems. Coin selection is the algorithm of ∙ We conduct an in-depth performance analysis and study
choosing unspent transactions (UTXOs) from a user’s wallet in of existing algorithms, evaluating their effectiveness in
order to pay blockchain tokens to target recipients by forming terms of factors such as transaction fees, privacy, and
a transaction. The selected UTXOs set is the input of the overall user experience. The findings of this analysis
transaction while the transaction output includes the payment provide valuable insight into the practical implications
to the target recipient and the change which goes back to the and potential benefits of adopting the proposed method
user’s wallet. Fig. 1 shows a transaction sample with its inputs in UTXO-based blockchain systems.
and outputs. The UTXO model was first introduced in Bitcoin This paper is organized as follows. Section II introduces
[1] and Cardano proposed an extended version of UTXO that the terminology and provides a comprehensive list of the
is called Extended UTXO (EUTXO) [2]. objectives required for the coin selection algorithms. Existing
Although choosing a set of UTXOs to generate a transaction algorithms are reviewed in Section III. The performance of
looks like a simple task, following an effective UTXO selection the algorithms is evaluated and the results are provided in
algorithm is required to avoid long-term challenges. Every Section IV. Section V concludes.
time the user selects a set of UTXOs to form inputs for a
II. T ERMINOLOGY AND O BJECTIVES
transaction, the user’s wallet may receive some change back
as the output of the transaction. This has a smaller amount A. Terminology
than the input UTXOs. Over time, if the user continues to The inception of the Bitcoin era introduced the need for
pay bills and create transactions, the wallet can end up having cryptocurrency wallets. One of the main components of these
too many change UTXOs with small amounts that are called wallets is the coin selection algorithm, which refers to the
dust. A dust UTXO has a small amount that may cost more selection of a set of UTXOs, denoted 𝑆, to form an input
transaction fees to spend than what it is worth and hence, dust for a transaction. Every blockchain user keeps its tokens in
UTXOs are undesired. Dust is analyzed in [3] and [4]. the form of UTXOs inside the blocks of a blockchain. A
This paper presents a comprehensive review of the existing wallet software manages the user’s UTXO pool that keeps
coin selection algorithms utilized in UTXO-based blockchains. track of the UTXOs on the blockchain. Fig. 2 shows the UTXO
It is important to note that some established algorithms have pool of a blockchain user. Every transaction contains several
not been published formally in the context of coin selection existing UTXOs as input and new UTXOs as output. The
[5], [6], [7], [8], [9], [10]. Our contributions to this study are output UTXO has two main parts: the payment UTXO and the
threefold. change UTXO. The UTXO payment is the token that will be
transferred to the receiver’s wallet. The value of this UTXO is
called the target value and is denoted by 𝑇 . The UTXO change
is the token that will be sent back to the sender’s wallet. The
difference between the total values of the input UTXOs and
the total values of the output UTXOs is called the transaction
fee. Fig. 1 shows the payment and the change UTXOs in a
transaction. The transaction submitted to a blockchain network Fig. 2: User’s UTXO pool
will be processed by the block producers. The candidate block
producer that picks up a given transaction and includes its
UTXOs output into a new block will receive the transaction likelihood that a transaction is included in the next block,
fee as a part of its block generation reward. resulting in faster confirmation [11].
We introduce some notations about UTXOs and UTXO (O5) Increasing value range of the wallet’s UTXO pool:
pools. Let 𝑈 = {𝑢1 , ..., 𝑢𝑛 } be a pool of UTXOs with 𝑛 Having a wide value of UTXOs values in a UTXO pool
UTXOs. For any 𝑖 ∈ [𝑛]1 , 𝑢𝑣𝑖 is the value, 𝑢𝑠𝑖 the size and lets the user pay with higher granularity. We explain this
𝑢𝑎𝑖 the age (confirmation count) of 𝑢𝑖 . Note that we write 𝑈 𝑣 in Examples 1 and 2.
for the sum of the values of the UTXOs in the set 𝑈 , that Example 1. Assume that there are three users, each has 1

is, 𝑈 𝑣 = 𝑖∈[𝑛] 𝑢𝑣𝑖 . Furthermore, we denote 𝑈 𝑠 as the sum of token:

the sizes of the UTXO in the set 𝑈 , that is, 𝑈 𝑠 = 𝑖∈[𝑛] 𝑢𝑠𝑖 . ∙ User 1 with UTXO pool 𝑈 = {0.5, 0.5}.2
Furthermore, we denote 𝑈 𝑎 as the sum of the UTXO ages in
∑ ∙ User 2 with UTXO pool 𝑈 = {0.25, 0.25, 0.25, 0.25}
the set 𝑈 , that is, 𝑈 𝑎 = 𝑖∈[𝑛] 𝑢𝑎𝑖 . ∙ User 3 with UTXO pool 𝑈 = {0.1, 0.2, 0.3, 0.4}

B. Objectives Now, the set of the possible values of 𝑈 for each pool is:
∙ User 1, {0.5, 1}.
The coin selection algorithms employ various strategies
∙ User 2, {0.25, 0.5, 0.75, 1}.
to ensure efficient utilization of UTXOs while taking into
∙ User 3, {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}.
account parameters such as transaction fees, privacy, etc. In
this section, we will dive into the objectives that govern the As can be seen, User 3 has more options to pay for a wider
design and implementation of these algorithms. range of target values.
(O1) Minimizing Transaction Fee: Just pay enough transaction Example 2. Assume that there are two users, each has 1 token:
fees to get the transaction included in a block inside ∙ User 4 with UTXO pool 𝑈 = {0.5, 0.5}.
a blockchain. A good coin selection algorithm should ∙ User 5, with UTXO pool 𝑈 = {0.1, 0.2, 0.3, 0.4}.
not only reduce the transaction fee for the current
Now, to pay a target value of 0.6 token, the coin selection
transaction, but should also focus on minimizing the
algorithm can form the following UTXO sets as input for the
transaction fee in the long run [11]. The lowest number
transaction:
of inputs (UTXOs) is required to minimize transaction
∙ User 4, {0.5, 0.5}, change value = 0.4.
size [12]. The transaction fee may also contain an extra
∙ User 5, {0.1, 0.2, 0.3}, change value = 0.
incentive to encourage block producers to accelerate the
processing of transactions. As can be seen, for the requested payment from User 4, all
(O2) Enhancing Privacy: Everyone has access to every trans- of its funds would be used, there would be no confirmed
action. This may result in a breach of financial privacy. UTXOs left to send another transaction, and the recipient
Data miners and third-party observers should not be able would learn that the sender has an additional 0.4 token.
to get access to user data, such as the total balance However, User 5 has more options. A sufficient number of
or economic activity of a user. A good coin selection UTXOs in User 5’s pool results in not revealing all funds in the
algorithm should use a minimum number of UTXO wallet. Furthermore, the created transaction would leave the
addresses in the selected UTXO set. This is because data other UTXOs untouched in the wallet and would not require
miners may use the transaction information to reveal the the creation of a change output [10].
user’s identity [11], [13]. Another objective that we will not focus on in this work
(O3) Minimizing Pool Size: The size of the UTXO pool is maximizing the speed of execution of the coin selection
directly affects storage requirements as a way of how algorithm [12].
storing UTXO affects the processing speed of block
producers [14]. In addition, a small UTXO pool limits III. COIN SELECTION A LGORITHMS
the number of dust UTXOs in the pool. Various coin selection algorithms are currently employed in
(O4) Minimizing Confirmation Time: Block producers select wallet and blockchain software, as well as proposed in different
the transaction based on the fee per byte (token per byte) papers [15], [14], [16], [13], [12]. Each coin selection algo-
to maximize their revenue. A higher fee will increase the rithm selects a set of UTXO, denoted by 𝑆 alg ⊆ 𝑈 . The goal
1 Here we use the notation, [𝑛] = {1, ..., 𝑛}. 2 Note that in numerical examples, we write 𝑈 = {𝑢𝑣1 , ..., 𝑢𝑣𝑛 } for simplicity.
TABLE I: Coin Selection Algorithms Algorithm 1 Primitive Algorithms — 𝑃 (𝑈 )
Category Coin Selection Algorithm 𝑆 alg Input: Sorted UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 }
First In First Out (FIFO) 𝑆 FIFO Input: Target 𝑇 > 0
Last In First Out (LIFO) 𝑆 LIFO Output: Set of selected UTXOs 𝑆 alg
Highest Value First (HVF) 𝑆 HVF
Primitive
Lowest Value First (LVF) 𝑆 LVF
Require: 𝑈 𝑣 > 𝑇
Highest Priority First (HPF) 𝑆 HPF 1: 𝑆 𝑎𝑙𝑔 ← {}
Greedy 𝑆 Greedy 2: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑇
Random Draw [15] 𝑆 RndDrw 3: while 𝑟𝑒𝑚𝑎𝑖𝑛 > 0 do
Random-Improve [17] 𝑆 RndImp
Basic
Knapsack [15] 𝑆 Knp
4: for 𝑖 = 1 to 𝑛 do
Branch and Bound [15] 𝑆 BnB 5: 𝑆 𝑎𝑙𝑔 .add(𝑢𝑖 )
Optimization [14] 𝑆 Opt 6: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑟𝑒𝑚𝑎𝑖𝑛 − 𝑢𝑣𝑖
Advanced Knapsack with Leverage [16] 𝑆 KnpLv 7: end for
Myopic and Strategic Optimization [13] 𝑆 Myop , 𝑆 Strat
8: end while
Greedy and Genetic [12] 𝑆 GrGe
9: return 𝑆 alg

is to obtain the optimal value of 𝑆, which we denote as 𝑆 opt .


To effectively organize and present the gathered information, ranges of different transactions. Hence, it partially fulfills the
we categorize these algorithms into three distinct categories: second objective (O2). FIFO has two additional disadvantages:
Primitive, Basic, and Advanced. Each category represents a It minimizes neither the transaction fee (O1) nor the number
different level of complexity and sophistication in terms of the of transactions in the UTXO pool (O3). We run Algorithm 1
strategies used for coin selection. This classification provides as follows:
a clearer understanding of the evolution and progression of 𝑃 ({𝑢1 , ..., 𝑢𝑁 }) with 𝑢𝑎𝑖 ≥ 𝑢𝑎𝑖′ for 𝑖 < 𝑖′ .
coin selection algorithms, providing valuable information on
their effectiveness and potential areas for improvement. In this 2) Last In First Out (LIFO): The LIFO algorithm selects
section, we will dive into each category in detail, exploring UTXO in ascending confirmation count order, that is, the
the distinctive characteristics and features of the algorithms newer UTXO are picked first. Similar to FIFO, the input
within them. We summarize the coin selection algorithms in UTXO sets are neither small nor large. Therefore, it will not
Table I. reveal information about the composition of the UTXO pool.
However, there is hardly any consolidation of old UTXOs if
A. Primitive Algorithms the wallet’s funds are increasing over time. The objectives
The primitive category refers mainly to algorithms that (O1) and (O3) are not achieved. Furthermore, this algorithm
were discussed and conceptualized during the early stages will link up all of the recent activity in the wallet, since the
of the blockchain era. We start this section by providing a newest change output is always reused. We run Algorithm 1
comprehensive comparison of the primitive algorithms. All as follows:
primitive algorithms mentioned in Table I are commonly used 𝑃 ({𝑢1 , ..., 𝑢𝑁 }) with 𝑢𝑎𝑖 ≤ 𝑢𝑎𝑖′ for 𝑖 < 𝑖′ .
and known algorithms in computer science. These include First
In First Out (FIFO), Last In First Out (LIFO), Highest Value 3) Highest Value First (HVF): The HVF algorithm first
First (HVF), Lowest Value First (LVF), and Highest Priority picks the UTXO with the highest value. Therefore, only a mini-
First (HPF) algorithms. An informal analysis of some of the mal amount of input will be used, and therefore the transaction
algorithms is also presented in [9]. Primitive algorithms select fee is minimized (O1). HVF will likely increase the size of
a set of UTXOs until the total value of the selected UTXOs the UTXO pool, that is, it will not satisfy (O3). Furthermore,
reaches the target value. All algorithms in this category use only a few blockchain addresses are linked. This has a positive
the same approach with different sorting methods. The main impact on privacy (O2). However, there remain other privacy
approach is depicted in Algorithm 1 where 𝑃 (𝑈 ) denotes the issues, as it reveals the upper bound for the UTXO value in
alogrithm and 𝑈 is the sorted UTXO pool. the wallet and links consecutive transactions, while the change
1) First In First Out (FIFO): The FIFO algorithm picks output is still in the largest UTXO. The algorithm is used
UTXOs in order of decreasing the confirmation count, that is, in Cardano blockchain during Cardano Improvement Proposal
older UTXOs are picked first. FIFO has some nice properties, (CIP) 2. We run Algorithm 1 as follows:
such as the fact that small UTXOs will eventually be spent.
𝑃 ({𝑢1 , ..., 𝑢𝑁 }) with 𝑢𝑣𝑖 ≥ 𝑢𝑣𝑖′ for 𝑖 < 𝑖′ .
The input sets are neither small nor large and, therefore, will
not reveal information about the composition of the UTXO 4) Lowest Value First (LVF): The LVF algorithm selects
pool (O2). However, the date of the oldest UTXO in the wallet UTXO in ascending value order. Small UTXOs are consoli-
is revealed. Therefore, it can be guessed how long a user has dated as soon as possible, which reduces the wallet’s UTXO
been using the wallet. The total balance of the wallet might be pool (O3) and minimizes future spending costs. However,
estimated using the UTXO confirmation count values. It might the transaction fee will not be minimized (O1) since LVF
also be feasible to form a certain pattern using the timestamp maximizes the input sets. There are privacy concerns as the
TABLE II: Primitive Algorithms. A white circle ⚪ indicates Algorithm 2 Greedy Algorithm — 𝐺(𝑈 )
that the objective is not fulfilled, while a black circle ● is used Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 } with 𝑢𝑣𝑖 ≥ 𝑢𝑣𝑖′ for 𝑖 < 𝑖′
when the objective is fulfilled. Partial fulfillment is indicated Input: Target 𝑇 > 0
by ◑. Output: Set of selected UTXOs 𝑆 greedy
Objectives Require: 𝑈 𝑣 > 𝑇
Primitive algorithms
(O1) (O2) (O3) (O4) (O5) 1: 𝑆 greedy ← {}
FIFO ⚪ ◑ ⚪ ⚪ ⚪
2: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑇
LIFO ⚪ ◑ ⚪ ⚪ ⚪
HVF ● ◑ ⚪ ⚪ ⚪ 3: for 𝑖 = 1 to 𝑛 do
LVF ⚪ ⚪ ● ⚪ ⚪ 4: if 𝑢𝑣𝑖 ≤ 𝑟𝑒𝑚𝑎𝑖𝑛 and 𝑟𝑒𝑚𝑎𝑖𝑛 > 0 then
HPF ● ● ⚪ ⚪ ⚪
5: 𝑆 greedy .add(𝑢𝑖 )
6: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑟𝑒𝑚𝑎𝑖𝑛 − 𝑢𝑣𝑖
7: end if
lower bound for UTXO values in the wallet is revealed.
8: end for
Furthermore, it links consecutive transactions based on the
9: while 𝑟𝑒𝑚𝑎𝑖𝑛 > 0 do
lowest UTXO and also tends to over-consolidate the UTXO
10: 𝑆 greedy .add(min{𝑈 ⧵ 𝑆 greedy })3
pool, which degrades privacy. LVF also links many addresses
11: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑟𝑒𝑚𝑎𝑖𝑛 − (min{𝑈 ⧵ 𝑆 greedy })𝑣
and decreases the range of values of the UTXO pool of a
12: end while
wallet (O5). We run Algorithm 1 as follows:
13: return 𝑆 greedy
𝑃 ({𝑢1 , ..., 𝑢𝑁 }) with 𝑢𝑣𝑖 ≤ 𝑢𝑣𝑖′ for 𝑖 < 𝑖′ .
Algorithm 3 Random Draw — 𝑅𝐷(𝑈 )
5) Highest Priority First (HPF)- Combining FIFO/LIFO Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 }
with HVF/LVF: The HPF algorithm picks UTXOs in descend- Input: Target 𝑇 > 0
ing order of priority until the target is reached. The priority Output: Selected UTXOs’ set 𝑆 RndDrw
is calculated as a product of the UTXO values and their age Require: 𝑈 𝑣 > 𝑇
(i.e., the confirmation count). This will decrease transaction 1: 𝑆 RndDrw ← {}
fees (O1) and increase privacy as it links only a few addresses 2: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑇
(O2). However, this algorithm will not minimize the number 3: while 𝑟𝑒𝑚𝑎𝑖𝑛 > 0 do
of transactions in the UTXO pool (O3). We define the priority 4: 𝑟𝑎𝑛𝑑 ← (𝑅𝑎𝑛𝑑𝑜𝑚(𝑈 ⧵ 𝑆 RndDrw ))𝑣
of 𝑢𝑖 as 𝑢𝑝𝑖 ∶= 𝑢𝑣𝑖 𝑢𝑎𝑖 and run Algorithm 1 as follows: 5: 𝑆 RndDrw .add(𝑟𝑎𝑛𝑑)
6: 𝑟𝑒𝑚𝑎𝑖𝑛 ← 𝑟𝑒𝑚𝑎𝑖𝑛 − 𝑟𝑎𝑛𝑑
𝑃 ({𝑢1 , ..., 𝑢𝑁 }) with 𝑢𝑝𝑖 ≥ 𝑢𝑝𝑖′ for 𝑖 < 𝑖′ .
7: end while
6) A Summary of Primitive Algorithms: We summarize 8: return 𝑆 RndDrw
the primitive methods in Table II and what objectives they
achieve and to what extent. As mentioned, in the early days
of blockchain development, coin selection algorithms were minimize the number of inputs. We show this in the following
not extensively researched, and developers often resorted to example.
employing simple algorithms that we reviewed in the primitive Example 3. Let UTXO pool 𝑈 = {0.25, 0.2, 0.2, 0.1, 0.05} and
category. Although these initial approaches served their pur- target 𝑇 = 0.4. The greedy algorithm will find the solution
pose to some extent, they lacked the sophistication necessary 𝑆 Greedy = {0.25, 0.1, 0.05}, whereas the optimal solution that
to handle the complex and evolving demands of blockchain minimizes the number of inputs is 𝑆 opt = {0.2, 0.2}.
networks. In the next section, we review the basic algorithms.
2) Random Draw: The random draw algorithm picks
B. Basic Algorithms UTXOs randomly with equal probability. The implementation
of this method is easy and the method will enhance privacy
The basic category encompasses coin selection algorithms
(O2) as selected UTXOs have no consistent fingerprint like
that replaced their primitive counterparts due to their enhanced
age or value. Additionally, a random change output leads to
efficiency and improved performance. These algorithms rep-
an increased value diversity (O5). The transaction fee will not
resent a significant step forward in terms of usability and
be minimized (O1) and the random draw algorithm can select
effectiveness, meeting the growing demands and challenges
a UTXO set with an amount greater than the target value.
of the blockchain field.
The algorithm is described in Algorithm 3 and makes use of
1) Greedy: The greedy algorithm aims to reduce the
a function 𝑅𝑎𝑛𝑑𝑜𝑚(𝑈 ) that returns an element of the set 𝑈
number of transaction inputs. The algorithm takes UTXOs
randomly with a uniform distribution.
in descending order and selects UTXOs that are below the
remaining target. Once a UTXO is selected, its value is sub- 3 Note that, whenever we are using a min or max function, it is defined
tracted from the remaining target. The algorithm is described as follows: min(𝑈 ) = {𝑢 ∈ 𝑈 |𝑢𝑣 ≤ 𝑢̃ 𝑣 for all 𝑢̃ ∈ 𝑈 }. The max function is
in Algorithm 2. Note that the greedy algorithm cannot always defined analogously.
An alternative implementation for the random draw algo- Algorithm 4 Random Improve
rithm is the following. The input UTXO pool 𝑈 is randomly Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 }
reshuffled, and the UTXOs are selected starting with the first Input: Target 𝑇 > 0
element of 𝑈 until the total value of selected UTXOs reaches Input: MaxInputCount 𝑀𝐼𝐶
the target value. Output: Set of selected UTXOs 𝑆 RndImp
3) Random Improve: The random improve algorithm [17], Require: 𝑈 𝑣 > 𝑇
as the name suggests, aims at improving the random draw 1: 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 ← 𝑅𝐷(𝑈 )4
method. To achieve this goal, the algorithm consists of two 2: 𝑛𝑢𝑚𝑝𝑃 𝑜𝑠𝑠𝑖𝑏𝑙𝑒𝐴𝑑𝑑𝑖𝑡𝑖𝑜𝑛𝑠 ← min{𝑀𝐼𝐶, 𝑛} − |𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑|
phases. The first phase is a random draw until there is enough 3: for 𝑖 = 1 to 𝑛𝑢𝑚𝑃 𝑜𝑠𝑠𝑖𝑏𝑙𝑒𝐴𝑑𝑑𝑖𝑡𝑖𝑜𝑛𝑠 + 1 do
input value to pay for the output. The second phase focuses on 4: if 𝑖 == 𝑛𝑢𝑚𝑃 𝑜𝑠𝑠𝑖𝑏𝑙𝑒𝐴𝑑𝑑𝑖𝑡𝑖𝑜𝑛𝑠 + 1 then
improving the selected UTXO set. This is done by expanding 5: 𝑆 RndImp ← 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑
the set with additional UTXOs that are chosen one-by-one 6: break
randomly from the UTXO pool to get as close as possible 7: end if
to twice the target value, 2𝑇 . The reason is as follows. By 8: 𝑆 RndImp ← 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑
reaching a value close to twice the target value, we expect 9: 𝑟𝑎𝑛𝑑 ← 𝑅𝑎𝑛𝑑𝑜𝑚(𝑈 ⧵ 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑)
a change output with a value that is close to the original 10: 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑.add(𝑟𝑎𝑛𝑑)
𝑣
target. Unlike tiny change outputs, these “useful” outputs will 11: if |2𝑇 − 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑣 | > |2𝑇 − 𝑆 RndImp | then
help future transactions to be processed with a lower number 12: break
of inputs as the previous change outputs are of the value of 13: end if
typical payment requests. The rationale behind phase one is 14: if 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑣 > 3𝑇 then
dust management. In particular, if there is a large number of 15: break
dust UTXOs in the UTXO pool, then with a high probability, 16: end if
a large amount of dust will be selected as input. Therefore, it 17: end for
will reduce the amount of dust in the UTXO pool over time. 18: return 𝑆 RndImp
Instead of considering only the target 𝑇 , the random im-
prove algorithm considers a target range, consisting of (low,
ideal, high) = (𝑇 , 2𝑇 , 3𝑇 ). Phase two of the algorithm tries outputs the selected UTXOs. However, if the value exceeds
to get as close to the ideal value as possible. The algorithm the target, the algorithm attempts to replace the last selected
stops when there is no improvement. There is an improvement UTXO with a small UTXO to produce an even smaller set.
after adding a UTXO to the selected inputs if the value of the In the second phase, the same operations are performed with
selected UTXOs is closer to the ideal value than without the the difference that every unselected UTXO is considered as
additional UTXO. However, it is also necessary that the high an addition to the selected UTXO set. The procedure can be
value is not exceeded. In addition, there is a maximum input repeated iteratively to find better solutions. The algorithm is
count that has to be considered when adding UTXOs to the described in Algorithm 5. The Knapsack algorithm has several
selected inputs. The algorithm is described in Algorithm 4. advantages. In particular, it will decrease the size of the UTXO
Note that in the algorithm, it is required that the UTXO set is pool (O3) and increase privacy since only little information
not empty, and it is also allowed to add new UTXOs to the is revealed due to pseudo-randomly selected UTXOs (O2).
maximum number of input count. The original algorithm in However, rapid reduction in the pool of UTXO could be an
[17] throws an error if the maximum input count is exceeded or issue with respect to privacy (O2). Another disadvantage is
the UTXO balance is insufficient. If there are multiple targets that it will not minimize the transaction fee as it uses a larger
to be considered, the original algorithm imposes the constraint number of inputs (O1).
that each input can be used only for exactly one target value,
5) Branch and Bound: The branch and bound (BnB) coin
otherwise it throws an error. The algorithm will decrease the
selection algorithm was proposed by Erhardt [15] and ex-
size of the pool (O3) and reveal only small information about
plained in [7]. First, we need to introduce the concept of
the wallet, as it uses pseudo-randomly chosen inputs (O2). It
“effective value”. As mentioned before, having more inputs
will not minimize transaction fees (O1) but could improve the
and outputs in a transaction results in a higher transaction
value range of the UTXO pool, as it creates change outputs
fee. For every selected input UTXO, there is a fee to be
roughly the size of the target.
paid. We introduce the concept of effective value which is
4) Knapsack: The Knapsack algorithm for coin selection
the original UTXO’s value minus the transaction fee. More
was studied by Erhardt [15]. The algorithm consists of two
precisely, suppose that there is a UTXO 𝑢 and the transaction
phases. In the first phase, the algorithm runs through every
fee per byte is 𝑓 . Hence, the effective value of a UTXO is the
UTXO in the UTXO pool and adds them one by one with a
UTXO’s value 𝑢𝑣 minus the transaction fee per byte 𝑓 times
chance of 50% to the set of selected UTXOs. If the value of
the UTXO’s size 𝑢𝑠 . In other words,
the selected UTXOs matches the target, the algorithm ends and
4 Note that here we assume that |𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑| < 𝑀𝐼𝐶. 𝑒𝑓 𝑓 𝑉 𝑎𝑙(𝑢) ∶= 𝑢𝑣 − 𝑓 𝑢𝑠 .
Algorithm 5 Knapsack Algorithm 6 Branch and Bound — 𝐵𝑛𝐵(𝑈 , 𝑇 , 𝑚𝑐)
Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 } with 𝑢𝑣𝑖 ≥ 𝑢𝑣𝑖′ for 𝑖 < 𝑖′ Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 }
Input: Target 𝑇 > 0 Input: Target 𝑇 > 0
Output: Selected UTXOs’ set 𝑆 Knp Input: Minimum change 𝑚𝑐
Require: 𝑈 𝑣 > 𝑇 Input: Rounds 𝑟𝑜𝑢𝑛𝑑𝑠
1: 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 ← {} Output: Set of selected UTXOs 𝑆 BnB

2: 𝑆 Knp ← {} Require: 𝑖 𝑒𝑓 𝑓 𝑉 𝑎𝑙(𝑢𝑖 ) > 𝑇
3: 𝑏𝑒𝑠𝑡𝑉 𝑎𝑙 ← ∞ 1: 𝑐𝑢𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 ← {}
4: 𝑡𝑎𝑟𝑔𝑒𝑡𝑅𝑒𝑎𝑐ℎ𝑒𝑑 ← 𝑓 𝑎𝑙𝑠𝑒 2: 𝑟𝑜𝑢𝑛𝑑𝑠 ← 1000
5: for 𝑗 = 1 to 2 do 3: 𝑑 ← 0
6: if ¬𝑡𝑎𝑟𝑔𝑒𝑡𝑅𝑒𝑎𝑐ℎ𝑒𝑑 then 4: 𝑐𝑢𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 ← BnBRecursion(𝑑,𝑐𝑢𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛)
7: for 𝑢 ∈ 𝑈 ⧵ 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 do 5: if 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 == {} then
8: 𝑟𝑎𝑛𝑑𝐵𝑜𝑜𝑙 ← 𝑏𝑖𝑛𝑎𝑟𝑦𝑅𝑎𝑛𝑑𝑜𝑚() 6: 𝑈 ′ ← 𝑟𝑎𝑛𝑑𝑜𝑚𝑆ℎ𝑢𝑓 𝑓 𝑙𝑒(𝑈 )
9: if (𝑗 = 1 and 𝑟𝑎𝑛𝑑𝐵𝑜𝑜𝑙) or 𝑗 = 2 then 7: while 𝑒𝑓 𝑓 𝑉 𝑎𝑙𝑢𝑒(𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛) < 𝑇 + 𝑚𝑐 do
10: 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑.add(𝑢) 8: for 𝑢′ ∈ 𝑈 ′ do
11: if 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑣 == 𝑇 then 9: 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛.add(𝑢′ )
12: 𝑡𝑎𝑟𝑔𝑒𝑡𝑅𝑒𝑎𝑐ℎ𝑒𝑑 ← 𝑡𝑟𝑢𝑒 10: end for
13: 𝑆 Knp ← 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 11: end while
14: break 12: end if
15: end if 13: return 𝑐𝑢𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 as 𝑆 BnB
16: if 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑣 > 𝑇 then
17: 𝑡𝑎𝑟𝑔𝑒𝑡𝑅𝑒𝑎𝑐ℎ𝑒𝑑 ← 𝑡𝑟𝑢𝑒 TABLE III: Basic algorithms.
18: if 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑣 < 𝑏𝑒𝑠𝑡𝑉 𝑎𝑙 then Objectives
Basic Algorithms
19: 𝑆 Knp ← 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 (O1) (O2) (O3) (O4) (O5)
𝑣
20: 𝑏𝑒𝑠𝑡𝑉 𝑎𝑙 ← 𝑆 Knp Greedy ◑ ⚪ ⚪ ⚪ ⚪
Random Draw ⚪ ● ⚪ ⚪ ●
21: 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 ← 𝑆𝑒𝑙𝑒𝑐𝑡𝑒𝑑 ⧵ {𝑢} Random-Improve ⚪ ◑ ● ⚪ ◑
22: end if Knapsack ◑ ◑ ● ⚪ ⚪
23: end if Branch and Bound ◑ ● ⚪ ⚪ ⚪
24: end if
25: end for
26: end if as Bitcoin and Cardano. However, as blockchain technology
27: end for
matures and applications proliferate, the shortcomings of these
28: return 𝑆 Knp
early algorithms become evident. Consequently, increasing
emphasis has been placed on conducting thorough research
and developing more advanced coin selection algorithms that
The advantage of considering effective values of UTXOs is address critical issues. This shift towards more sophisticated
that it keeps the target fixed throughout the process. algorithms has played a crucial role in enhancing the overall
The BnB algorithm utilizes a depth-first search on a binary performance and functionality of blockchain systems to satisfy
tree, where each node represents the inclusion or omission of all the mentioned objectives.
a UTXO. UTXOs are sorted in descending order of effective C. Advanced Algorithms
values, and the tree is explored deterministically, prioritizing
We start this section by introducing basic terminologies.
the inclusion branch first.
Let  = {𝑇1 , ..., 𝑇𝑡 } 5 denote a set of payment requests.
Paths with a total effective value that exceeds the target are
Furthermore, let 𝑂 = {𝑜1 , ..., 𝑜𝑚 } ⊆  denote the set of outputs
cut. Finding an exact match results in one less output and one
and for any 𝑗 ∈ [𝑚], 𝑜v𝑗 is the value of 𝑜𝑗 and 𝑜s𝑗 the size of 𝑜𝑗 .
less input for future transactions. Indeed, if an exact match
There is a change output 𝑐 with value 𝑐 v and size 𝑐 s . We now
is found, there is no change output in the current transaction,
define a transaction as a 3-tuple (𝑆 alg , 𝑂, 𝑐). Furthermore, let
and this change output, in turn, does not need to be spent as
𝐷 > 0 denote the dust threshold.
input in future transactions. In total, we can save the cost of
1) Optimization Algorithm: This section introduces an ap-
an input plus the cost of an output. We call this summation
proach introduced primarily in [14]. The optimization algo-
“matchRange”. The algorithm is described in Algorithm 6 and
rithm consists of two phases. The first phase aims to optimize
Algorithm 7. If there is no match, there is a fallback logic that
the transaction size. The second phase focuses on minimizing
performs a random draw.
the pool size. Before formulating the optimization problems,
6) A Summary of Basic Algorithms: We summarize the
we start by introducing some notation.
basic methods in Table III and show the objectives they
achieve and to what extent. Basic algorithms are being used in 5 In the previous sections  = {𝑇 } was a singleton containing only one
different existing UTXO-based blockchain technologies such target 𝑇 .
Algorithm 7 Branch and Bound Recursion — 𝐷 > 0. Furthermore, the change size 𝑐 s = 𝛽 if 𝑐 v > 𝜖 and 0
𝐵𝑛𝐵𝑅𝑒𝑐𝑢𝑟𝑠𝑖𝑜𝑛(𝑑, 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛) otherwise. To minimize the transaction size in the first phase,
Input: Depth level in search 𝑑 the optimization problem is as follows:
Input: Current UTXO Selection 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛
min 𝑦
Output: New UTXOs Selection 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 𝑥𝑖 ,𝑦,𝑚
1: 𝑟𝑜𝑢𝑛𝑑𝑠 ← 𝑟𝑜𝑢𝑛𝑑𝑠 − 1 s.t. 𝑦≤𝑀
2: 𝑡𝑎𝑟𝑔𝑒𝑡𝐹 𝑜𝑟𝑀𝑎𝑡𝑐ℎ ← T + Cost_of_Header + ∑ ∑
𝑢𝑣𝑖 𝑥𝑖 = 𝑜𝑣𝑗 + 𝛼𝑦 + 𝑐 𝑣
Cost_per_Output
𝑖∈[𝑛] 𝑗∈[𝑚]
3: 𝑚𝑎𝑡𝑐ℎ𝑅𝑎𝑛𝑔𝑒 ← Cost_Per_Input + Cost_Per_Output ∑ (2)
4: 𝑢𝑡𝑥𝑜𝑆𝑜𝑟𝑡𝑒𝑑 ← 𝑠𝑜𝑟𝑡𝐷𝑒𝑠𝑐𝑒𝑛𝑑𝑖𝑛𝑔(𝑈 ⧵ 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛) 𝑜𝑣𝑗 ≥𝐷
∑ 𝑗∈[𝑚]
5: 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝐸𝑓 𝑓 𝑉 𝑎𝑙𝑢𝑒 = 𝑖∶𝑢 ∈𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 𝑒𝑓 𝑓 𝑉 𝑎𝑙(𝑢𝑖 )
𝑖
𝑐𝑣
6: if 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝐸𝑓 𝑓 𝑉 𝑎𝑙𝑢𝑒 > 𝑡𝑎𝑟𝑔𝑒𝑡𝐹 𝑜𝑟𝑀𝑎𝑡𝑐ℎ + 𝑚𝑎𝑡𝑐ℎ𝑅𝑎𝑛𝑔𝑒 𝑐𝑠 ≤ ⌊ ⌋𝛽
then 𝜖
7: return {} 𝑥𝑖 ∈ {0, 1} for all 𝑖 ∈ [𝑛]
8: else if 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝐸𝑓 𝑓 𝑉 𝑎𝑙𝑢𝑒 ≥ 𝑡𝑎𝑟𝑔𝑒𝑡𝐹 𝑜𝑟𝑀𝑎𝑡𝑐ℎ We denote 𝑦opt as a solution to the above optimization problem
9: return 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 which is the minimal transaction size. The second phase aims
10: else if 𝑟𝑜𝑢𝑛𝑑𝑠 ≤ 0 to minimize the size of the UTXO pool, that is, maximize the
11: return {} number of inputs in the transaction. The optimization problem
12: else if 𝑑 ≥ |𝑢𝑡𝑥𝑜𝑆𝑜𝑟𝑡𝑒𝑑| has another constraint in addition to the constraints of the first
13: return {} phase. Let 𝛾 ∈ (0, 1). The optimization problem is as follows:
14: else ∑ 𝑐𝑠
15: if 𝑏𝑖𝑛𝑎𝑟𝑦𝑅𝑎𝑛𝑑𝑜𝑚() == 𝑡𝑟𝑢𝑒 then max 𝑥𝑖 −
𝑥𝑖 ,𝑦,𝑚 𝛽
16: 𝑤𝑖𝑡ℎ𝑇 ℎ𝑖𝑠 ← 𝐵𝑛𝐵𝑅𝑒𝑐𝑢𝑟𝑠𝑖𝑜𝑛(𝑑 + 𝑖∈[𝑛]
1, 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 ∪ {𝑢𝑡𝑥𝑜𝑆𝑜𝑟𝑡𝑒𝑑[𝑑]}) s.t. 𝑦≤𝑀
17: if 𝑤𝑖𝑡ℎ𝑇 ℎ𝑖𝑠 ≠ {} then ∑ ∑
𝑢𝑣𝑖 𝑥𝑖 = 𝑜𝑣𝑗 + 𝛼𝑦 + 𝑐 𝑣
18: return 𝑤𝑖𝑡ℎ𝑇 ℎ𝑖𝑠 𝑖∈[𝑛] 𝑗∈[𝑚]
19: else ∑ (3)
𝑜𝑣𝑗 ≥𝐷
20: 𝑤𝑖𝑡ℎ𝑜𝑢𝑡𝑇 ℎ𝑖𝑠 ← 𝐵𝑛𝐵𝑅𝑒𝑐𝑢𝑟𝑠𝑖𝑜𝑛(𝑑 +
𝑗∈[𝑚]
1, 𝑐𝑢𝑟𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛)
𝑐𝑣
21: if 𝑤𝑖𝑡ℎ𝑜𝑢𝑡𝑇 ℎ𝑖𝑠 ≠ {} then 𝑐𝑠 ≤ ⌊ ⌋𝛽
𝜖
22: return 𝑤𝑖𝑡ℎ𝑜𝑢𝑡𝑇 ℎ𝑖𝑠
𝑥𝑖 ∈ {0, 1} for all 𝑖 ∈ [𝑛]
23: end if
24: end if 𝑦 ≤ (1 + 𝛾)𝑦opt
25: else Note that if 𝛾 is close to 0, we would like to keep the minimum
26: // As above but explore omission branch first transaction size obtained from the previous algorithm. If 𝛾 is
27: end if close to 1, a transaction of appropriate size is created by a
28: end if number of UTXOs as large as possible.
29: return 𝑐𝑢𝑟𝑒𝑛𝑡𝑆𝑒𝑙𝑒𝑐𝑡𝑖𝑜𝑛 2) Knapsack with Leverage: The problem of Knapsack
with leverage was studied by Diroff [16]. The concept behind
the standard Knapsack algorithm mentioned above involves
For any 𝑖 ∈ [𝑛], the binary variable 𝑥𝑖 is 1 if 𝑢𝑖 is chosen as finding a cost-effective and efficient transaction to handle a
input and 0 otherwise. The transaction fee will be a product specified collection of pay requests. However, attempting to
of a fixed fee rate 𝛼 ≥ 0 and the transaction size. Let 𝜖 denote find a feasible solution to the Knapsack problem may not
the minimum change output that is set to avoid creating a very always succeed due to various reasons, such as the absence of
small output. a solution or the algorithm’s inability to produce one within a
The transaction size 𝑦 can be calculated as follows: designated time frame. It aims to address the entire problem
∑ ∑ by first attempting to find a solution using the Knapsack
𝑦= 𝑢𝑠𝑖 𝑥𝑖 + 𝑜s𝑗 + 𝑐 s (1)
𝑖∈[𝑛] 𝑗∈[𝑚]
algorithm. If this attempt fails, it then resorts to utilizing the
∑ fallback solution.
𝑖∈[𝑛] 𝑢𝑖 𝑥𝑖 = |𝑆
Note that s Opt | which is the size of the
The leverage solution, on the other hand, does not im-
UTXOs set 𝑆 Opt selected by the optimization method. Our mediately rely on the fallback solution, but instead seeks to
objective is to minimize 𝑦 subject to the following constraints. take advantage of the fact that when the standard Knapsack
In particular, the transaction size should be less than the algorithm fails, there will be a change in the output of the
maximum transaction size denoted by 𝑀 > 0. Also, each transaction. The leverage solution strives to construct a trans-
UTXO must have a sufficient value for consumption and action in such a way that the change output becomes a useful
all UTXOs outputs must be larger than the dust threshold future UTXO. Essentially, it tries to create two transactions:
one for processing the current pay requests and the other for
handling a different set of pay requests. The goal is to ensure min (𝜏1s 𝛼 + 𝑟1 , 𝜏2s 𝛼 + 𝑟2 )
that the change output from the first transaction fits precisely
s.t. 𝜏1 is a good and valid transaction (5)
into the second transaction, resulting in a change-free process.
The paper studies the basic problem of two transactions and 𝜏2 is a good, change-free and valid transaction.
then extends it. In this work, we focus on the basic problem The advantage of the Knapsack with leverage algorithm is that
studied in [16]. the transaction fee is minimized (O1). It looks at several trans-
We expand the definition of a transaction by adding a tip actions and hence considers the long run, and also considers
denoted by 𝑟 ≥ 0 that will be paid to the block producers as an confirmation time. However, it does not focus on privacy (O2).
incentive to collect the transaction from the pool for the block 3) Myopic and strategic optimization: The myopic and
generation process. We assume that  is ordered by decreasing strategic optimization was studied in [13]. Given the initial
alg
values. In particular, a transaction is a 4-tuple (𝑆, 𝑂, 𝑐, 𝑟). The pool of UTXO 𝑈 , a subset 𝑆1 ⊆ 𝑈 of UTXO is selected to
size of the transaction is as follows: meet the target 𝑇1 in the first transaction in the first period.
In the second period, there is a target 𝑇2 that must be reached
alg alg
𝑥 + 𝑦|𝑆| + 𝑧|𝑂| + 𝑧(1 − 𝛿𝑐,0 ), by choosing a subset 𝑆2 ⊆ (𝑈 ⧵ 𝑆1 ) ∪ {𝑐1 } where 𝑐1 is the
change output of the first transaction. The article considers
where (𝑥, 𝑦, 𝑧) = (10, 148, 34) are constants denoting the two settings based on the information about 𝑇2 as follows.
number of bytes required for metadata6 , to record each input 1) Myopic optimization: There is no information about 𝑇2
and to record each output [16]. 𝛿𝑐,0 is the Kronecker delta. in the first period.
We now start with the standard Knapsack problem where we 2) Strategic optimization: 𝑇2 is known in the first period.
denote 𝑊 (𝑆 Knp , 𝑂, 𝑐, 𝑟) as the size of transaction generated The myopic optimization problem is as follows:
by the algorithm.
Myop
min |𝑆𝑖 |
𝑥𝑖

min 𝑊 (𝑆 Knp , 𝑂, 𝑐 = 0, 𝑟)𝛼 + 𝑟 s.t. 𝑇𝑖 ≤ 𝑢v𝑖 𝑥𝑖 for 𝑖 = 1, 2 (6)
Knp 𝑖∈[𝑛]
s.t. (𝑆 , 𝑂, 𝑐 = 0, 𝑟) is a good and valid transaction,
(4) 𝑥𝑖 ∈ {0, 1} for all 𝑖 ∈ [𝑛]
where 𝛼 is the market rate for the transaction fee per byte. For the strategic setting, we introduce 𝜆 ∈ [0, 1] as the
Transaction (𝑆 Knp , 𝑂, 𝑐, 𝑟) is a valid transaction if preference for privacy over lower transaction fees and 𝐴𝑖 as
{∑ ∑ the set of all UTXO addresses in the 𝑖 th transaction (𝑖 = 1, 2).
𝑢∈𝑆 Knp 𝑢 ≥ 𝑜 + 𝑊 (𝑆 Knp , 𝑂, 𝑐, 𝑟)𝛼 Furthermore, the strategic optimization problem is as follows:
∑ ∑𝑜∈𝑂 Knp , 𝑂, 𝑐 = 0, 𝑟)𝛼 + 𝑐 + 𝑟
𝑢∈𝑆 Knp 𝑢 = 𝑜∈𝑂 𝑜 + 𝑊 (𝑆
min (1 − 𝜆)|𝑆1Strat ∪ 𝑆2Strat | + 𝜆1(𝐴 Strat )
1 ∩𝐴2 ≠∅∨𝑐1 ∈𝑆2
and is a good transaction if (7)
s.t. 𝑇𝑖 ≤ (𝑆𝑖Strat )𝑣 for 𝑖 = 1, 2,
⎧𝑐 = 0 and 0 ≤ 𝑟 ≤ 𝐻 {
⎪ where ∅ refers to the empty set and
1, if 𝑥 holds
1𝑥 =
⎨or 0, otherwise.
⎪𝑐 ≥ 𝐷 and 𝑟 = 0
⎩ The myopic approach focuses on minimizing the transaction
size, and hence the transaction fee, whereas the strategic
where 𝐻 is the maximal overpayment amount.
approach additionally focuses on improving privacy.
The attempt at finding any feasible solution to the Knapsack
4) Greedy and genetic algorithm: Originally, the genetic
problem may fail for several reasons (e.g. there is no solution
algorithm was introduced in [18] and follows the evolution
or the algorithm fails to produce one in a certain allotted
of a population to solve the optimization problem using an
time period). Once the standard knapsack algorithm fails, it
exhaustive search. The algorithm was recently studied in the
is known that there will be a change output in the transaction.
context of coin selection [12]. The algorithm in [12] is as
In this case, the leverage solution attempts to construct two
follows. First, the least number of UTXOs as transaction inputs
transactions, one processing the current pay requests 𝑂1 and
is determined using the greedy algorithm. This number is then
the other one processing some other set 𝑂2 , so that the change
used in the objective function of the genetic algorithm. The
output of the first transaction fits precisely in the second, mak-
optimal solution is then searched using the genetic algorithm.
ing it change-free. This method is called the Knapsack with
KnpLv We summarize the procedure in the following way. For each
leverage and is defined in (5). Let 𝜏1 ∶= (𝑆1 , 𝑂1 , 𝑐1 , 𝑟1 ) 𝑢𝑣𝑖 ≥ 𝑢𝑣𝑖′ for 𝑖, 𝑖′ ∈ [𝑛] with 𝑖 < 𝑖′ where 𝑢𝑖 , 𝑢𝑖′ ∈ 𝑈 .
KnpLv
and 𝜏2 ∶= (𝑆2 ∪ {𝑐1 }, 𝑂2 ⊆  ⧵ 𝑂1 , 𝑐2 = 0, 𝑟2 ) be two Furthermore, the function 𝑟𝑎𝑛𝑑𝑜𝑚((𝑈 )) randomly selects
transactions. a subset of 𝑈 which is the summation of their values that
exceed the target. Possible solutions are compared using a
6 Metadata is data that is describing other data. It could contain information
about, e.g., an NFT or a transaction 7 Here we use the greedy algorithm 𝐺(𝑈 ) described in Algorithm 2.
Algorithm 8 Greedy and Genetic — 𝐺𝑟𝐺𝑒(𝑈 ) TABLE IV: Advanced algorithms.
Input: UTXO pool 𝑈 = {𝑢1 , ..., 𝑢𝑛 } with 𝑢𝑣𝑖 ≥ 𝑢𝑣𝑖′ for 𝑖 < 𝑖′ Objectives
Advanced Algorithms
Input: Target 𝑇 > 0 (O1) (O2) (O3) (O4) (O5)
Optimization ● ⚪ ● ⚪ ⚪
Input: Number of rounds 𝐾 > 0 Knapsack w/ Lev. ● ⚪ ⚪ ◑ ⚪
Input: Size 𝑀 > 0 Myopic and Str. Opt. ● ◑ ⚪ ⚪ ⚪
Output: Set of selected UTXOs 𝑆 GrGe Greedy and Genetic ● ⚪ ⚪ ⚪ ⚪
Require: 𝑈 𝑣 ≥ 𝑇
1: if 𝑈 𝑣 == 𝑇 then TABLE V: Summary of all coin selection algorithms.
2: return 𝑈 Objectives
Algorithm
3: end if (O1) (O2) (O3) (O4) (O5)
4: if 𝑈 𝑣 > 𝑇 and max(𝑈 ) > 𝑇 then First-In-First-Out (FIFO) ⚪ ◑ ⚪ ⚪ ⚪
Last-In-First-Out (LIFO) ⚪ ◑ ⚪ ⚪ ⚪
5: return min({𝑢 ∈ 𝑈 |𝑢𝑣 ≥ 𝑇 }) Highest Value First (HVF) ● ◑ ⚪ ⚪ ⚪
6: end if Lowest Value First (LVF) ⚪ ⚪ ● ⚪ ⚪
7:  ← {} Highest Priority First (HPF) ● ● ⚪ ⚪ ⚪
8: 𝑏𝑒𝑠𝑡 ← 𝐺(𝑈 )7 Greedy ◑ ⚪ ⚪ ⚪ ⚪
Random Draw ⚪ ● ⚪ ⚪ ●
9: .add(𝑏𝑒𝑠𝑡) Random Improve ⚪ ◑ ● ⚪ ◑
10: for 𝑖 = 1 to 𝑀 − 1 do Knapsack ◑ ◑ ● ⚪ ⚪
11: 𝐼 ← 𝑟𝑎𝑛𝑑𝑜𝑚((𝑈 )) Branch and Bound ◑ ● ⚪ ⚪ ⚪
12: .add(𝐼) Optimization ● ⚪ ● ⚪ ⚪
Knapsack with Leverage ● ⚪ ⚪ ◑ ⚪
13: if 𝑓 (𝐼) > 𝑓 (𝑏𝑒𝑠𝑡) then Myopic and Str. Opt. ● ◑ ⚪ ⚪ ⚪
14: 𝑏𝑒𝑠𝑡 ← 𝐼 Greedy and Genetic ● ⚪ ⚪ ⚪ ⚪
15: end if
16: end for
17: if 𝑏𝑒𝑠𝑡𝑣 == 𝑇 then have 𝑀 possible solutions. For each of the 𝑀 − 1 randomly
18: 𝑆 GrGe ← 𝑏𝑒𝑠𝑡 drawn subsets, we calculate the fitness and compare it to the
19: return 𝑆 GrGe fitness of the best initial solution. Whenever there is a subset
20: end if with better fitness, that subset will be the best. For the next
21: for 𝑘 = 1 to 𝐾 − 1 do 𝐾 −1 iterations, the initial 𝑀 subsets are changed by randomly
22: Generate new set  using randomness adding and removing the UTXOs, and again the fitness is
23: for 𝐼 ∈  do calculated and compared to the best. Once there is a subset
24: if 𝑓 (𝐼) > 𝑓 (𝑏𝑒𝑠𝑡) then with a value matching the target value, we stop or otherwise,
25: 𝑏𝑒𝑠𝑡 ← 𝐼 after all iterations, the best solution is returned. The algorithm
26: end if is described in Algorithm 8.
27: end for Note that when generating a new set , the randomness
28: if 𝑏𝑒𝑠𝑡𝑣 == 𝑇 then is created using three procedures. First, 𝐼 ∈  remains
29: 𝑆 GrGe ← 𝑏𝑒𝑠𝑡 in the next round with probability proportionally to fitness.
30: return 𝑆 GrGe Second, from every pair 𝐼, 𝐼 ′ ∈  generate a new pair
31: end if using randomness (called a single-point crossover). And lastly,
32: end for random invert digits in the binary string of each element with
33: return 𝑆 GrGe some probability (called mutation).
The advantage of this algorithm is that it minimizes trans-
action fees (O1) as it reduces the number of input UTXOs.
“fitness” function, which is defined as follows. Let 𝐵 ∈ (𝑈 ), However, it does not minimize the size of the UTXO pool.
then the fitness of 𝐵 is given by 5) A Summary of Advanced Algorithms: We summarize the
advanced algorithms in Table IV and describe the objectives
1 they achieve and to what extent.
𝑓 (𝐵) = .
𝐵 𝑣 − 𝑇 + |𝐵|
The greedy and genetic algorithm works as follows. Let IV. PERFORMANCE E VALUATION
𝑀, 𝐾 > 0 be given. First, it is checked whether there is In this section, we first summarize our findings in Table V
enough balance in the UTXO pool and whether the balance based on the previous discussions in Table II, Table III,
matches the target or not. If the balance does not match the and Table IV. Then, we review the performance of those
target, the algorithm performs the greedy algorithm to get an algorithms that are already deployed in existing blockchains.
initial best solution, that is, a subset of 𝑈 which has a balance To model the approximate real-world behavior of a wallet,
greater than or equal to the target value. The algorithm then we need to incorporate deposits and payments into our envi-
randomly draws 𝑀 − 1 additional subsets of 𝑈 such that the ronment. The deposit value, which we simply refer to as the
sum of their values exceeds the target value. In total, we now deposit, is added to the wallet’s UTXO balance. The payment
value, which we refer to as the target, is subtracted from the
wallet’s UTXO balance. Wallets usually involve a number of
incoming and outgoing transactions. This is taken care of by
incorporating deposits and targets.
The environment is set up as follows. We model the case
of a wallet with an initial UTXO value of 100,000 tokens. We
run 10,000 iterations for each of the different algorithms and
compare their performance. In each iteration, a random target
is drawn, and the input UTXOs are chosen according to the
underlying wallets’ algorithm. The change UTXO is added
to the wallet’s UTXO pool. Additionally, in each iteration,
three deposits are drawn and added to the UTXO pool. The
targets and deposits are the same for all algorithms, and the
deposit/target ratio is 3:1 [8], [15]. Note that when changing
the ratio, we need to make sure that the average of the deposits
and the targets are still balanced. Otherwise, the average of
deposits or targets will increase in the long run, which is not
desirable. We rather want to keep the balance almost the same
when investigating different coin selection algorithms.
We study the system considering two different distributions
for deposits and targets. First, the deposits and targets are
drawn from a Normal distribution [8], [15]. Specifically, the
deposits are drawn from a Normal distribution with a mean
of 1, 000 and a standard deviation of 250. Also, the targets
are drawn from a Normal distribution with a mean of 3, 000
and a standard deviation of 500. Note that the averages of
deposits and targets are equal and keep the wallets’ balances Fig. 3: The number of each UTXOs value in the UTXO pools
around the initial balance. Second, we consider the case of a for primitive and basic coin selection algorithms.
memoryless distribution. In particular, the deposits and targets
are drawn from a Poisson distribution with mean 1, 000 and
3, 000, respectively.
All algorithms start with a single initial UTXO of a value of The number of UTXOs in a wallet is depicted in Fig. 4.
100,000 tokens. Over time, the wallets accumulate a number According to the objective (O3), it is desired to have a low
of UTXOs of different values which come from the deposits number of UTXOs in the pool. We clearly observe that all
and from the change output after each iteration. Fig. 3 shows algorithms except HVF follow approximately the same trend.
the number of each UTXO value in the pool. According to Under the Poisson distribution, the pool size remains very low
the objective (O5), it is desired to have a wide range of for both Greedy and LVF, whereas for Normal distribution,
distributed UTXO values. Additionally, we would like UTXO it is more than double in size. In fact, under the Poisson
values that are not too small (i.e., dust). The range of values in distribution, both algorithms keep the pool size constantly low
Fig. 3 is depicted to be up to 2,000. However, there are single and lower than all other algorithms. For HVF, the number of
UTXOs of larger value for some algorithms. In particular, for UTXOs in the UTXO pool explodes compared to the other
the Normal (Poisson) distribution, LIFO, LVF, and Greedy algorithms for both distributions. For Knapsack we observe
have each one UTXO with a value of around 30,000 (90,000). that under Poisson distributed targets and deposits, the pool
Knapsack and Branch&Bound each have a UTXO with a value size fluctuates between 50 and 200 UTXOs. This is due to the
of around 20,000 (70,000), and the random improve algorithm fact that the number of input UTXOs is widely distributed and
has several UTXOs with a value of around 5,000 (4,000). close to 150. That is, for several transactions, approximately
Hence, qualitatively we have the same trends for both Normal 150 UTXOs are used as the input and therefore dramatically
and Poisson distributions. However, the interesting question shrink the pool size. The distribution of the number of input
is how many small UTXOs (dust) end up in a wallet. We UTXOs is depicted in Fig. 6. However, we represent it only
clearly see that the HVF accumulates the largest amount of up to 40 inputs to better compare it with other algorithms.
dust. In fact, while for the Normal distribution, the number of Fig. 5 shows the evolution of the pool size and we observe
small UTXOs is around 2,000, the number is twice as much that the pool size under HVF is more than 10 (20) times
under the Poisson distribution. The Greedy and Knapsack larger than the pool sizes of the other algorithm under Normal
algorithms also have many UTXOs of approximately the same (Poisson) distribution. Using HVF, the majority of UTXOs
size, instead of more distributed values, as is the case for the after 10,000 iterations are dust UTXOs, i.e. UTXOs with a
other algorithms. tiny value. All algorithms, other than HVF, seem to stabilize
Fig. 4: Size of the UTXO pools in different iterations for Fig. 6: Number of transactions versus the number of input
primitive and basic coin selection algorithms. UTXOs for primitive and basic coin selection algorithms.

all algorithms except Knapsack use a small number of inputs,


whereas Knapsack is widely distributed. In fact, Knapsack
also has transactions with more than 100 inputs. This trend
is observed under both distributions.
In general, we can conclude that the choice of a coin
selection algorithm requires a deep understanding of the de-
sired objectives. None of the coin-selection algorithms studied
meets all objectives. Therefore, it requires a careful choice
based on the underlying system and its requirements. For
example, if privacy is a desired objective, then Knapsack
would be the best choice, as the number of inputs is widely
distributed. However, Knapsack leads to higher transaction
fees as the transaction size increases with the number of input
UTXOs. These trade-offs are the basis of the choice of a coin
selection algorithm.
Fig. 5: Size of the UTXO pool in different iteration for the V. CONCLUSION
HVF algorithm. In this paper, we studied various coin selection algorithms
and defined their objectives, classifications, and performance
characteristics. Initially, we provided a list of the desired
the number of UTXOs in their pools. objectives for coin selection algorithms, such as minimiz-
Fig. 6 describes the number of input UTXOs needed to pay ing transaction fees and transaction size, improving privacy,
the target in each iteration. According to the objective (O1), minimizing pool size, and reducing confirmation time. We
the transaction fee should be minimized, which is the same as then reviewed the coin selection algorithms, classifying them
minimizing the number of inputs. In terms of privacy, a wider into three distinct categories: primitive, basic, and advanced.
distribution of the number of inputs is desired. We observe that The primitive category refers to algorithms discussed and
conceptualized during the early stages of the blockchain era. [16] D. J. Diroff, “Bitcoin Coin Selection with Leverage,” arXiv preprint
The basic category represents a significant advancement in arXiv:1911.01330, 2019.
[17] Cardano Foundation, “CIP 2 - Coin Selection Algorithms for Cardano.”
terms of usability and effectiveness, catering to the growing https://cips.cardano.org/cips/cip2/ (accessed July 25, 2023).
demands and complexities of the blockchain domain. The [18] J. H. Holland, Adaptation in Natural and Artificial Systems. Ann Arbor,
advanced category pivots to more sophisticated algorithms, MI: University of Michigan Press, 1975.
playing a crucial role in increasing the overall performance and
functionality of blockchain systems. However, these advanced
mechanisms have not yet seen widespread adoption in practical
software systems. Finally, we compared the performance of the
algorithms and discussed the advantages and disadvantages
of each, providing a comprehensive view of coin selection
algorithms within the blockchain space. This comparison not
only highlights the evolutionary trajectory of these algorithms,
but also serves as a guide for selecting the appropriate algo-
rithm based on specific requirements and constraints. The final
conclusion is that, at this moment, there is no coin selection
algorithm that meets all the required objectives. Consequently,
there is a significant gap in this area that future research needs
to address.

R EFERENCES
[1] S. Nakamoto, “Bitcoin: A Peer-to-Peer Electronic Cash System,”
https://bitcoin.org/bitcoin.pdf, 2008.
[2] M. M. T. Chakravarty, J. Chapman, K. MacKenzie, O. Melkonian,
M. Peyton Jones, and P. Wadler, “The Extended UTXO Model,” in
Financial Cryptography and Data Security (M. Bernhard, A. Bracciali,
L. J. Camp, S. Matsuo, A. Maurushat, P. B. Rønne, and M. Sala, eds.),
(Cham), pp. 525–539, Springer, 2020.
[3] C. Pérez-Solà, S. Delgado-Segura, G. Navarro-Arribas, and J. Herrera-
Joancomart, “Another Coin Bites the Dust: An Analysis of Dust in
UTXO Based Cryptocurrencies.” Cryptology ePrint Archive, Paper
2018/513, 2018. https://eprint.iacr.org/2018/513.
[4] S. Delgado-Segura, C. Pérez-Solà, G. Navarro-Arribas, and J. Herrera-
Joancomartí, “Analysis of the Bitcoin UTXO Set,” in Financial Cryp-
tography and Data Security (A. Zohar, I. Eyal, V. Teague, J. Clark,
A. Bracciali, F. Pintore, and M. Sala, eds.), (Berlin, Heidelberg), pp. 78–
91, Springer Berlin Heidelberg, 2019.
[5] “Bitcoin Design – Coin Selection.” https://bitcoin.design/guide/how-i
t-works/coin-selection/ (accessed July 25, 2023).
[6] “What is the Coin Selection Algorithm?.” https://bitcoin.stackexcha
nge.com/questions/1077/what-is-the-coin-selection-algorithm#29962
(accessed July 25, 2023).
[7] “Coin Selection for Dummies: Part 2 — Branch and Bound Coin Selec-
tion.” https://blog.summerofbitcoin.org/coin-selection-for-dummies-2/
(accessed July 25, 2023).
[8] E. de Vries, “Self Organisation in Coin Selection.” https://iohk.io/en/b
log/posts/2018/07/03/self-organisation-in-coin-selection/ (accessed July
25, 2023).
[9] M. Erhardt, “What Are The Trade-offs Between The Different Algo-
rithms For Deciding Which UTXOs To Spend?.” https://bitcoin.stacke
xchange.com/questions/32145/what-are-the-trade-offs-between-the-dif
ferent-algorithms-for-deciding-which-utxo, 2014.
[10] M. Erhardt, “What is the Waste Metric?.” https://murch.one/posts/wast
e-metric/, 2022.
[11] “Coin Selection for Dummies Part 1 — Overview.” https://blog.summe
rofbitcoin.org/coin-selection-part-1/ (accessed July 25, 2023).
[12] X. Wei, C. Wu, H. Yu, S. Liu, and Y. Yuan, “A Coin Selection Strategy
Based on the Greedy and Genetic Algorithm,” Complex Intelligent
Systems, vol. 9, pp. 421–434, 2023.
[13] S. Abramova and R. Böhme, “Your Money or Your Privacy: A System-
atic Approach to Coin Selection,” Cryptoeconomic Systems, 2020.
[14] V.-H. Nguyen, H.-S. Trang, Q.-T. Nguyen, N. Huynh-Tuong, and T.-
V. Le, “Building Mathematical Models Applied to UTXOs Selection
for Objective Transactions,” in 2018 5th NAFOSTED Conference on
Information and Computer Science (NICS), pp. 160–164, 2018.
[15] M. Erhardt, “An Evaluation of Coin Selection Strategies.” https://murc
h.one/erhardt2016coinselection.pdf, 2016.

You might also like