<p>If you look at the changes made to the bitcoin reference implementation with the implementation of BIP 43 (see <a href="https://github.com/bitcoin/bitcoin/commit/af3b5ea56926f56e5e16e901678f494390fe6bbb" rel="nofollow noreferrer">this commit</a>), 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. </p>

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

<p>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.</p>

<p>Thus the answers to your questions are:</p>

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

<p>2) yes, see the check in ContextualCheckBlock</p>

<p>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</p>

CC BY-SA 3.0
2018-04-10T10:32:56.270Z
2018-04-10T10:32:56.270Z
christianb93
<p>This previous <a href="https://bitcoin.stackexchange.com/questions/48188/is-it-possible-to-decode-block-height-from-a-blockhash">answer</a> shows that <a href="https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki" rel="nofollow noreferrer">BIP34</a> 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). </p>

<p>Concrete questions:</p>

<ul>
<li>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? </li>
<li>Is the coinbase block height value "validated" by other nodes and if yes, where in the source code?</li>
<li>Is there any other imaginable situation/way a miner could pass a garbled height value and try to confuse other nodes?</li>
</ul>

<bip-34>
Can miner send garbled block height?
bgd223
# Can miner send garbled block height?

(Asked by: username_0 on 2018-03-26)

This previous [answer](https://bitcoin.stackexchange.com/questions/48188/is-it-possible-to-decode-block-height-from-a-blockhash) shows that [BIP34](https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki) 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?

**Tags:** bip-34


---

## 1 answers

### Answer by username_1 on 2018-04-10. Score: 2

If you look at the changes made to the bitcoin reference implementation with the implementation of BIP 43 (see [this commit](https://github.com/bitcoin/bitcoin/commit/af3b5ea56926f56e5e16e901678f494390fe6bbb)), 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


---

