2

I have been working on understanding the inputs/outputs and transaction details as according to the UTXO model which is discussed in this question and also thinking about how it relates to transaction fee based on size in kb of the transaction which is discussed in this question. I want to clarify a few things, feel free to pick apart anything I say that is wrong in addition to answering my questions - since the questions are derived from my understandings.

It seems that the transaction size is mostly a function of number of inputs and outputs (in the sense that those are the things I as a sender have control over, where the other components contributing to size are more or less static).

Clarification 1: (ignoring the fee and change) Suppose Alice sends me (Bob!) 2 btc. She got these 2 btc as a result of Larry and Greg each sending her 1 btc. This means she has these two UTXO outputs each for 1 btc associated to her wallet, and when she sends them to me the transaction will have 2 inputs and 1 output, kind of like this transaction I found on a block explorer.

enter image description here

Once this transaction is processed, does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

Clarification 2: (with fee and change) Alice wants to send me 2 btc. She has previously been sent 1 btc by each of Larry, Greg, and Allan. So she has 3 UTXO's associated with her wallet, each worth 1 btc. She goes to send me 2 btc, but needs to cover the fee. For convenience lets say a .5 btc fee. Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee) (she needs all three coins to pay me and cover the fee, and then I will be one output and her "change address" will be the other.

Lastly, I think I understand that most wallet services "handle" all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

Addendum: I do plan on being active on this site, so please do critique if my questions can be improved to better fit this community.

3 Answers 3

4

does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

(1) Your have a single 2 BTC UTXO, created by Alice's transaction. That transaction spent two UTXOs, but melded them into a single one. Your wallet doesn't care about its history - it has one UTXO, and when spending it, it needs a transaction with one input.

It is possible for wallet or other software to figure out the history of the coins, and figure out that it came from a transaction that spent two. But it has no impact on future transactions with it.

Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee)

That's right. You'd create a transaction with 3 inputs (each 1 BTC) and 2 outputs (one of 2 BTC, one of 0.5 BTC). The difference is 0.5 BTC going to fees.

Do they typically do this in a most efficient way?

Often, no, actually. Because "most efficient" isn't the only criterion to optimize for. For example, you want to minimize the cost of transactions now, but you also don't want to bring your wallet in a state that increases the cost of transactions later. For example, some strategies for coin selection (as this problem is called) would result in continuously grinding down your coins into ever-smaller change in typical workloads, making it more and more expensive to send out future coins.

Some wallets will take current fee conditions into account to make these decisions.

Overall there is a significant amount of work analyzing various coin selection schemes. Some are featured in Mark Erhardt's master thesis.

3
  • 1
    Thank you the for the link! My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions.
    – Prince M
    Commented Mar 8, 2021 at 2:14
  • a related question to this post. Is the reason that transaction fee is related to size because smaller size tx implies the miner could have fitten more tx's in a block?
    – Prince M
    Commented Mar 18, 2021 at 22:53
  • 1
    Yes, exactly that. Optimizing for maximum fee income automatically leads miners to prioritize by fee per byte (or per weight, since segwit, as constraint is limited block weight, not block size now). Commented Mar 18, 2021 at 22:56
2

Once this transaction is processed, does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

Your wallet may or may not keep track of the history of the funds you received. But all that really matters from that point on is that you have one UTXO that is yours to do with as you wish.

Lastly, I think I understand that most wallet services "handle" all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

For simple cases, they typically do. For very complex cases, it's computationally quite expensive to ensure you that always produce the absolutely optimal result given that the number of possibilities that need to be considered can get absurdly large. Most implementations do not guarantee they will always produce the very best result but instead use heuristics that do in fact find the optimal result the vast majority of the time for typical cases and still provide very good results in absurdly complex situations with potentially thousands of UTXOs to choose from.

0
2

does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

It shows as 1 UTXO that you can spend. Your wallet does not care about the UTXOs that were spent to create the UTXOs that you can spend. There's nothing there it needs to know, so it doesn't care about it.

Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee) (she needs all three coins to pay me and cover the fee, and then I will be one output and her "change address" will be the other.

Yes.

Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

Not necessarily.

Now you are getting into an area that is considered hard. In general, this question is about coin selection algorithms, of which there are many and they optimize for different things. Coin selection is also a multidimensional problem, and what is considered good, bad, efficient, or inefficient is not well defined.

1
  • Thank you the for the elaboration on coin selection. My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions. Can you point me to anywhere that I can find out more about hot research areas surrounding btc / crypto / blockchain?
    – Prince M
    Commented Mar 8, 2021 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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