BlueWallet / BlueWallet

Bitcoin wallet for iOS & Android. Built with React Native
https://bluewallet.io
MIT License
2.62k stars 797 forks source link

Coin selection doesn't try to find close match, Always spend from the largest UTXO #4957

Open Transisto opened 2 years ago

Transisto commented 2 years ago

To reproduce, example:

A wallet has 21 UTXO, 20 between 0.01 and 0.02 BTC and one of 1.00000000 BTC

Ask the wallet to send 0.009

The wallet will always send from the largest UTXO.

Transisto commented 2 years ago

The coin selection algo should chose the smallest available single output that's larger than the amount to send.

Transisto commented 2 years ago

This is also bad for time domain privacy, basically the wallet will always reused the same large UTXO change for every transaction.

Wondering if anyone can double check that this is what the Coin Selection is doing. In my testing there was no amounts that would select any other UTXO than the largest one.

ncoelho commented 2 years ago

Not how it works. You can read more about the available coin selection algorithms here:

https://github.com/bitcoinjs/coinselect

Overtorment commented 2 years ago

image we use the default one

Overtorment commented 2 years ago

looks like it sorts utxo first, so maybe thats why the largest utxo gets spent first

Overtorment commented 2 years ago

hmm, maybe we should look more into this

Transisto commented 2 years ago

https://github.com/bitcoinjs/coinselect/issues/74

Is that library popular? Looks like such a basic oversight.

Transisto commented 1 year ago

...