0

This previous answer shows that BIP34 adds block height as one of the fields in a coinbase transaction of a block. This question is about whether block height is calculated fully independently by each node, or the miner gets to influence it somehow (even by providing a garbled value that'll be considered only temporarily, i.e, before the validation of his supplied height fails).

Concrete questions:

  • Does this miner-chosen coinbase block height play any role in the determination of the actual block height when other nodes add this block in the chain?
  • Is the coinbase block height value "validated" by other nodes and if yes, where in the source code?
  • Is there any other imaginable situation/way a miner could pass a garbled height value and try to confuse other nodes?
1

If you look at the changes made to the bitcoin reference implementation with the implementation of BIP 43 (see this commit), you will see that a check has been added to the function 'AcceptBlock'. With this change, the function is now validating the height against the value taken from the coinbase script of the incoming block.

CScript expect = CScript() << nHeight;
if (!std::equal(expect.begin(), expect.end(),vtx[0].vin[0].scriptSig.begin()))
            return DoS(100, error("AcceptBlock() : block height mismatch in coinbase"));

So a block that contains a wrong block height in the coinbase transaction would actually be rejected by the other nodes in the bitcoin network (in the current version of the source code, this check is now in ContextualCheckBlock in validation.cpp). The value of the height to which the coinbase script entry is compared is taken to be the height of the current last block plus one, so it is calculated.

Thus the answers to your questions are:

1) no, the block height that a node actually uses is determined based on the current last block

2) yes, see the check in ContextualCheckBlock

3) probably yes, but then the DoS protection mechanism in the network would kick in and ban the respective node - and apart from that, the mining power that the miner has invested into the block with the incorrect height would be lost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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