0

I know that the transactions stay in the block and hashed alongside few other things and that hash is stored in the next block. And I understand that if you try to tamper with one of the transactions, the hash will change and it will affect all the blocks that come after it.

However, how does a block know that its transactions have tampered with in the first place?

Assume that block #1000 has 10 transactions. Now, the hash has been calculated and stored in block #1001

so, if I go back to block #1000 and add one more transaction, this will change the hash and it wont be the same one stored in #1001. However, how the hash of block #1000 changes in the first place if it was already calculated? does this mean that the hash of each block is recalculated regularly?

2
  • 1
    what makes you think you can "add" a transaction to a block? the miner chooses what goes in the block. a miner can mine with your transaction included or excluded, but if he includes it, he can get the fees. somebody might find another block at the same height, that doesn't include your transaction but has high enough difficulty. but the security assumption is that it's hash will be different. Commented Sep 23, 2019 at 23:11
  • Related: bitcoin.stackexchange.com/q/95564/5406
    – Murch
    Commented Aug 22 at 15:34

4 Answers 4

1

Hashes don't actually 'change'. When you add a transaction to a block you are creating another block.

It's like an author published a book and then next year printed a new edition with an extra comma in the page 36 and the fans said he released a 'new' book. It doesn't make sense for books but for blockchain every bit counts.

1

If I go back to block #1000 and add one more transaction, this will change the hash and it wont be the same one stored in #1001. However, how the hash of block #1000 changes in the first place if it was already calculated?

Once a block has been mined and accepted as part of the longest valid chain (ie, several confirmations deep), it will not ever change (which means the block's contents, and thus hash, will not change).

In order to change it, you would have to also change every block that comes after it, all the way up until the current chain tip. This would take a huge amount of computational power to pull off, you would basically need to 51% attack the network, to re-write the blockchain history. This sort of attack is extremely expensive, and ignores the incentives for mining honestly, you can read more about it here.

Otherwise, if you just changed block #1000, and then attempted to broadcast the changed block to your peers, they will all reject that block, since it is not part of the longest valid chain (assuming they have already heard about the original block #1000, and all of the blocks that came after it).

does this mean that the hash of each block is recalculated regularly?

A block's hash will be calculated in order to determine its validity, but we would never expect the hash to change for a block that has a sufficient number of confirmations on the network.

0

I think you are referring to consensus..if you try to go back and add something to a prior block and transmit it to the network the other nodes will reject it..

2
  • This doesn't answer the question Commented Jan 6, 2020 at 4:36
  • Sure it does, if its rejected you know Commented Jan 6, 2020 at 4:55
-1

how does a block know that its transactions have tampered with in the first place?

It is not the block that knows this; it is the nodes which verify that. To quote the bitcoin whitepaper:

When a node finds a proof-of-work, it broadcasts the block to all nodes. Nodes accept the block only if all transactions in it are valid and not already spent.

and

[...] network nodes can verify transactions for themselves

So, the nodes verify the transactions upon receiving a new block. This adds to the blocks confirmation counter (you can see it in here, for example), hence making it more trustworthy.

To answer your question directly, yes, the blocks get recalculated regularly.

This is not much of a problem for a node however, since it needs only one hash (the nonce is already known) to verify a block, which is vastly easier than calculating a proof-of-work. Same goes for verifying transactions. Exactly how many transactions are verified is something which I don't know myself, might be a topic for another question.

When a node "notices" that a block is invalid, it discards it and can even

[prompt] user's software to download the full block and alerted transactions to confirm the inconsistency.

You might also find this thread quite informative: Bitcoin transactions validation process

1
  • I know I'm late to this thread, but do you have any source on "yes, the blocks get recalculated regularly"? I haven't seen it mentioned on the thread you linked
    – A. Darwin
    Commented Apr 27 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.