I am learning the Bitcoin protocol by reading the bitcoin developer reference documentation.
As far as I know, a raw transaction consists of:
- Version (which is always 1)
- Inputs. Each input contains:
- Hash of the transaction that contains the output that we are going to spend here
- Index of the output in that transaction
- Script that satisfies the conditions placed in the script of the referenced ouput.
- Outputs. Each output contains:
- 8 bytes for the value in satoshis
- Script with the conditions that must be satisfied in order for this output to be spent.
- Locktime (which is usually 0)
I am not very sure what the script of the inputs contain, but I guess it should contain the public key, and a signed message.
My question is, why can't the miner modify the scripts in the outputs (replacing the address by their own), if those scripts are not part of the message that the real user had to sign?
Or maybe this question would be better asked like this: What is signed in the input scripts?