Your assumption in the following equation
transaction = transaction input(UTXO+sig) + transaction output is wrong.
Correct would be
transaction = UTXO + sig[tx data + hash(UTXO)] + output
UTXO + sig[tx data + hash(UTXO) is added for each input
output is added for each output
This is JSON format of transaction that I have recently created and
not yet broadcasted. You may notice that it has 1 input and 1 output.
"scriptSig": "304402203a0a2a31e906997d8beed8ca5a81bd303f9fff2475cb0400983eef0fb718a573022069103db03857fb8c7b204e3ed3706ea6fa729708bc85492a7783ca11760a672101 02856209e1b0dfd542898c8a8c58da4a91f9f6a82cddb4157117fe18157fc28c94",
"scriptPubKey": "OP_DUP OP_HASH160 c74eb0fc16d79cbf4399c80e7ec07162a41f30c6 OP_EQUALVERIFY OP_CHECKSIG"
As you may know, to prove that you are allowed to spend input of tx you need to provide
Digital signature - that is the
scriptSig element inside
scriptSig are digitally signed following data:
- ID (hash) of particular input (prev_out)
- double SHA of new transaction data
Signing transaction data prevents anyone from executing so called
Man-in-the-middle attack and intercept and direct
out to their wallet, since they cannot provide correct digital signature for the malformed transaction.
Why not try yourself? Here is the hex of above tx:
You can replace output address
c74eb0fc16d79cbf4399c80e7ec07162a41f30c6 with double hash (RIPEDM160(SHA256(K)) of your public key.
Then try to broadcast the malformed tx with http://btc.blockr.io/tx/push to see it is impossible. Or if you are skilled you may use
sendrawtransaction <tx hex here> command in