Author

Topic: Order of inputs/outputs in transaction and order of transactions in block (Read 867 times)

legendary
Activity: 1526
Merit: 1134
If you want the input signature to be independent of other inputs (so you can re-order or add or delete other inputs) you can sign with SIGHASH_ANYONECANPAY.
kjj
legendary
Activity: 1302
Merit: 1026
Depends on the signature flag in the transaction.  If no flag is specified, the signature is calculated based on the entire transaction. *

That means that for a standard transaction, a change in the order of either the inputs or the outputs will break the signatures.

See the hashtype values here for more information.

And yes, changing the order of the transactions in the block will change the merkle root, which will change the block header and invalidate the hash.

* Technical detail:  the signature fields in the inputs are deleted for the purposes of calculating the signatures.
legendary
Activity: 1792
Merit: 1111
Assuming we have an unsigned standard transaction with 2 inputs (A, followed by B) and 2 outputs (C, followed by D). After the input A is signed, is it possible to alter the order of inputs or outputs without voiding the A signature? (Obviously we cannot alter the order of inputs / outputs AFTER the transaction is recorded in the blockchain since that will change the transaction hash and will be regarded as double-spend. My question is about altering the order before the transaction is broadcast, or when it is partially signed)

Similarly, when a correct nonce is found for a block, will changing the order of transactions within the block voiding it? (I guess it will since it should change the block hash. Just want to confirm)

Thanks!
Jump to: