2

I am aware that, in Bitcoin, blocks are immutable because of the Merkle tree structure, which ensures that every block contains the (Merkle root) hash of the previous block.

Thanks to the properties of cryptographic hashes, even a 1 bit change in a previous block leads to a different hash, which can be used to detect tampering if you compare the hash of block (N-1) to the hash included in the next block N.

My question is: when is this check actually carried out?

Some claim that

yes, the blocks get recalculated regularly

but I haven't found any source on this claim.

3 Answers 3

1

It is unnecessary to recalculate block headers regularly. Whenever a new block is announced, the block header’s hash must meet the difficulty requirement to be acceptable. The combination of committing to the preceding block’s hash and the new block’s hash meeting the difficulty requirement, translates to an inductive commitment to all prior blocks in the best chain, as well as a proof of work. After this cheap check, the block is also tested to adhere to all other consensus requirements.

When a new block arrives, it checks whether this block extends its best chain or it constitutes an alternative chaintip with more work. If so, the node extends its best chain, or reorganizes to the new best chain’s tip.

If instead a block is published, that "changes a predecessor of the best chain tip", this would produce a distinct block header from the original, and the new block would constitute an alternative chaintip at a lower height than the best chaintip. (And the attacker would have to spend the same amount of proof of work to make the changed block pass the difficulty requirement.) As the successor of the original block commits to the hash of the best chain, and all further successors each inductively commit to the original block by committing to a successor of the original block, the best chaintip would have more work than the alternative chaintip, unless the attacker builds more blocks on top of their alternative block to outpace the prior best chaintip.

Anyway, we only need to check each block once, and then simply keep the block header chain in memory and extend from there, and it is unnecessary to revalidate blocks later, because we already know that anything that is part of our best chain has been checked before and cannot be changed without changing the header’s hash.

0

As that answer says,

the nodes verify the transactions upon receiving a new block

So each node only needs to check once and it can then make a note of the block-id. A node never needs to refetch a block it has already seen. It would fetch a block at the same height with a different id in which case that block gets validated

There is no real need for a node to periodically revalidate data it already received. Bitcoin core does recheck it's stored Blockchain data at startup though. This guards against local interference not against other nodes trying to transmit tampered blocks.

0

Receiving nodes independently maintain a copy of the UTXO set. This is the set of unspent transaction outputs that the node has checked previously. It is used to check fresh transactions.

When a new block is successfully found, its header and transactions are broadcast.

When a node receives the transactions, it:

  1. Re-constructs the merkle tree from the transactions and checks the header is valid.
  2. For each transaction, it checks that there is a matching output in the UTXO set, and checks that the spend is valid.
  3. It removes spent TXOs and adds new unspent TXOs from the new transactions. Note that for every block, at least one new output is added for the coinbase transaction1.

On full nodes, it is the UTXO set that is "recalculated regularly."


1: It's possible that a coinbase could have no spendable outputs, but it's unlikely!

Note, in implementation, the UTXO set is spread over multiple separate structures, but can be imagined as a single entity for explanatory purposes.

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.