Preventing changes to past transactions, how?


#1

Hi, sorry if this has been asked / discussed before.

I’m struggling to understand one of the inner workings of the bitcoin blockchain, namely, how does the chain actually prevent changes to past transactions? Sorry this is a bit of a lengthy question:

Here’s my current understanding / premise:

  • I know that in order to submit a transaction / input, one must sign it with their digital signature (which can only be created if you have access to your private key for the address you’re sending it from), so far so good.
  • The miner picks this transaction up from the mempool (at some point), validates it (any idea what type of validation?) and then adds it to a block.
  • Once sufficient transactions have been added to the block, the block gets mined, I.e. the miner guesses the output of that block (containing all the transactions, the hash of the previous block and the time stamp of the block) until he/she reaches an output that starts with 18 zeroes (might be more zeroes by now).
  • Once the miner has the correct output he/she distributes this to the rest of the network and the network validates that the hash for the block is indeed correct; I.e. proof of work; which is easy to verify once the output is known.
  • The block is now considered mined and the miner gets paid in shiny new bitcoins (woohoo). Let’s call this block 2,345

So my transaction sits in block 2,345 and the blockchain continues on its merry way, let’s say that miners in the mean time reach block 10,575.

If I now go and change the transaction in block 2,345, by adding a 0 somewhere in the transaction data, how does the network know that this blocks transaction has changed?

I know that any change, changes the hash value of the transaction and as such the hash value of the block and therefore has a perceived ripple effect on the rest of the blockchain since all transactions based on this block are now referring to a block hash that is no longer accurate. My questions however are:

  • What if I add the zero and do not recalculate the hash of the transaction? I.e. the hash of the transaction and the hash of the block do not change.
  • When is this change recalculated?
  • Is this recalculating part of the bitcoin/blockchain protocol?
  • What triggers recalculating?
  • How is this automated?
  • What is it that the miner validates when validating the transaction?

Thanks for taking the time to read and thanks in advance for answering or pointing me in the right direction.

Cheers,


#2

Great question! From my understanding, the block is not consistently checked to see if it’s valid, but if you try to change a transaction you will have 2 problems:

  1. The first problem is that you would have to change every copy of the transaction, in all the copies of the blockchain in order for it to be considered true by the network, since:
  2. Nodes are always talking to each other and trying to figure out which version of the blockchain is the ‘real’ one, this is part of the consensus algorithm. If you try to make a new transaction that uses this fake one as an output, it will not be validated by anyone, not even you (since you didn’t recalculate the hashes) and as such will not be included in any block never.

Basically you can mess your copy, but when you try to communicate with the rest of the network people will know it’s altered.

As for the miners, the validation is simply checking the transaction is valid(if the inputs are valid, if the signatures are real, if everything is wrote in the correct way, etc). What happens in mining is that since the miner invested a lot of time and work in discovering a valid block, you can assume to reasonable degree that he has an incentive to follow the rules of the network, since this way the network will work better and his reward will be more valuable. This is what called Proof-of-Work , you believe what the miner says (not entirely as you also check if everything is valid) because he has a incentive to help the network succeed.

Hope this was helpful :grin:


#3

Awesome, thanks.

I think that answers my question, I’m still seeing a loophole with this but I’m digging back into Satoshi’s white paper (don’t know how many times I’ve read this and still discover new things) to find the answer.

Great answer!