3

for business reason i need to use the bitcoin-core (v0.20.1) automatic coin selection feature and few days ago i saw a transaction come out that left me puzzled, it was like that:

input

  0.00017[...]  bc1qaddr1
  0.01292[...]  bc1qaddr2
  0.00030[...]  bc1qaddr3
  0.00020[...]  bc1qaddr4
  0.00015[...]  bc1qaddr5
  0.00035[...]  bc1qaddr6
  0.02371[...]  bc1qaddr7

output

  0.02783[...]  bc1qaddr8  > amount sent
  0.00965[...]  bc1qaddr9  > change

in this transaction 5 out of 7 utxos are unnecessary, is there some benefit in chaining toghether utxos in this way?
from my point of view this is a terrible way of loosing privacy and pay way more fee than needed, what i miss?
i read that bitcoin-core tries to find an exact match from available utxos and the amount to send, but if it fails then try to find a subset of utxos to reach a change of 0.01btc, is that right?
so, in my case, the unneeded utxos are added to get the change of my trasaction closer to 0.01?

9
  • Did you have another UTXO or UTXOs(less than 7) to pay for 0.027 or more BTC?
    – Prayank
    Mar 24 at 22:59
  • If yes: github.com/bitcoin/bitcoin/issues/20598
    – Prayank
    Mar 24 at 22:59
  • bc1qaddr2 and bc1qaddr7 summed are already more than 0.03663 Mar 24 at 23:02
  • Known Issue from long time.Few other issues with wallet related to privacy. Workarounds: 1. Dont use Bitcoin Core wallet until those issues are fixed 2. Try to fix those issues. Another example: github.com/bitcoin/bitcoin/pull/21284#issuecomment-787538566
    – Prayank
    Mar 24 at 23:06
  • the issue here is not that there are better (smaller) subset to choose, but that most utxos in this subset are completely useless to reach the amount needed Mar 24 at 23:09
3

This occurs because Bitcoin Core's coin selection algorithm tries to have a minimum change of 0.01 BTC. Fees are subtracted from the change output so the result is that the change output has a lower value, but before fees, it will try to for the change output to be at least 0.01 BTC.

As we can see in your transaction, the change before fees is approximately 0.01 BTC. Presumably it is actually over that because you have obfuscated the last several digits. Then the transaction fee was subtracted from the change output to get the final change output value that you have.


The reason that there is a minimum change is so to avoid creating very small change outputs. Small change outputs can be detrimental to the user's wallet and to the network as a whole. Those small change outputs result in the wallet having more UTXOs, which means that for future transactions, require more UTXOs to spend. Furthermore, small values can quickly become uneconomical outputs when the feerate rises. If lots of small change outputs were being created, a wallet could end up having a significant portion of its UTXOs be unspendable when fees are high.

Additionally, by having a minimum change target, the coin selection algorithm will tend to consolidate and sweep up smaller UTXOs. This behavior is, in general, good for the wallet and good for the network. It reduces the number of UTXOs globally, reduces the number of UTXOs that the wallet needs to handle and keep track of, and makes it less likely that UTXOs in the wallet will become uneconomical in high fee events.


In general, coin selection is a hard problem which needs to balance several factors. It is not just what the fees are for the transaction right now, nor is it necessarily just about the user of the wallet in that moment. Coin selection needs to consider the cost of spending outputs in the future and how its behavior will effect the selection of UTXOs in a future transaction. Coin selection needs to balance the health of the network and the performance of the user's wallet.

12
  • tries to have a minimum change of 0.01 BTC this is not how it should work IMO. Not sure how these random values are defined.
    – Prayank
    Mar 24 at 23:40
  • 1
    @Prayank You're right, it's probably an outdated, hardcoded value that shouldn't be needed. But we also can't just get rid of it - Bitcoin Core's coin selection algorithm is the result of many tweaks over the years, and we know it works okayish in most cases. It is obviously suboptimal in some, but small and innocently looking changes can have very dramatic effects (in fact, seemingly good ideas have been reverted in the past because they resulted in very bad wallet states). We need improvements to coin selection, but they're not as simple as getting rid of things you don't understand. Mar 24 at 23:49
  • 1
    @Andrew Chow Perhaps explain why a rule like this - albeit outdated - is useful: without it, the wallet in some usage patterns quickly grinds down its UTXO set to dust. Mar 24 at 23:51
  • ok, i understand that the matter is not easy and there are many needs to be taken into account, but what scary me a bit is that this transaction alone, after a few days, allows to group dozens of other transactions and in a few months there will probably be hundreds ... does this loss of privacy really make sense to avoid further fragmenting the utxos? in my view, if there is a subset of utxos within the bitcoin-core chosen utxos group, which is sufficient to reach the amount to be sent, the utxos that are not in this subset are just an unsolicited consolidation. Mar 25 at 0:04
  • I've updated my answer to specify why there is a minimum change target.
    – Andrew Chow
    Mar 25 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.