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

1

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.

1
  • Great answer, thank you for pointing me in the direction of BIP69 – K Stewart Nov 30 '19 at 21:24
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.

2
  • 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 Nov 26 '19 at 1:54
  • 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 Nov 26 '19 at 3:24
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.

3
  • Why on earth would you order them? That makes absolutely no sense. – Anonymous Nov 26 '19 at 3:03
  • 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 Nov 26 '19 at 15:04
  • Edited to remove incorrect detail on the array input. – m1xolyd1an Nov 27 '19 at 4:48

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.