Is there a convention for how to order UTXOs in a transaction with multiple inputs?

1

I am not sure it matters to produce a correctly formatted transaction, but I am playing around with a wallet that does not keep its own private keys, but produces the raw txs to sign and want to give the user the ability to verify the details of the raw txs with a third party or some control libraries. Assume, Bitcoin Core sets the standard, but I am unfortunately C illiterate. Thanks, Kyle

K Stewart

Posted 2019-11-26T01:25:48.900

Reputation: 13

Answers

0

The two preceding answers describe correctly that there is no network-wide requirement to order inputs or outputs, but I don't agree that the "order doesn't matter".

Early on, many wallets did order their inputs and outputs, e.g. the inputs were in the order the addresses were created, in the order that they got picked by the wallet's coin selection, or simply sorted by age. Similarly, outputs would often list the recipient outputs first and the change output last. Such patterns are a privacy leak as they fingerprint the used wallet software, and may allow observers to learn additional data about the user's finances.

If everyone shuffled the inputs and outputs of a transaction properly these issues would be mitigated. However, it can be difficult to recognize whether an order is random or follows a more complex pattern. From what I understand, this is why BIP69 instead suggests a global adoption of sorting inputs and outputs lexicographically. Again, everyone would be indistinguishable if they all sorted the same way, and it would be much easier to audit, test, and notice wallets that don't adhere to such a standard.

Murch

Posted 2019-11-26T01:25:48.900

Reputation: 41 609

Great answer, thank you for pointing me in the direction of BIP69K Stewart 2019-11-30T21:24:14.343

1

The convention is to have the outputs in random order. This is specifically done in an effort to conceal which output is the change output. The change is by default sent to a new address that is owned by the sender, and as such has no history associated with it.

The majority of bitcoin's code is actually c++. Here is a link to the relevant transaction creation code, maybe there are a few comments that could point you in the right direction.

presstab

Posted 2019-11-26T01:25:48.900

Reputation: 166

Thank you, presstab. My question may not have been very clear. I am looking for the order of the inputs. But, the order of the outputs are just as important for my use case. I will check out the link.K Stewart 2019-11-26T01:54:48.090

The order of the inputs does not matter. What does matter is that the inputs have not been spent, have valid signature, and are worth more than the outputs of the transaction being created.presstab 2019-11-26T03:24:14.360

0

No, the order in which you add inputs while building a raw transaction does not matter. The RPC documentation on raw transactions describes what you need to create a transaction and/or sign.

m1xolyd1an

Posted 2019-11-26T01:25:48.900

Reputation: 3 356

Why on earth would you order them? That makes absolutely no sense.Anonymous 2019-11-26T03:03:45.093

No, there is no need for this. All private keys will be available for all transaction input, regardless of their order. You may be confusing with the OP_CHECKMULTISIG opcode, which requires signatures in the same order as its public keys? Even there, the RPC interface to Bitcoin Core does not care about the order private keys are passed in in.Pieter Wuille 2019-11-26T15:04:25.617

Edited to remove incorrect detail on the array input.m1xolyd1an 2019-11-27T04:48:02.223