Bitcoin Forum
May 22, 2024, 12:51:00 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Order of inputs/outputs in transaction and order of transactions in block  (Read 848 times)
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1097


View Profile
October 10, 2012, 02:58:35 AM
 #1

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!

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
October 10, 2012, 12:56:31 PM
 #2

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.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
Mike Hearn
Legendary
*
expert
Offline Offline

Activity: 1526
Merit: 1129


View Profile
October 10, 2012, 06:02:07 PM
 #3

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!