Glossary / Transactions & fees
Coinbase block height
- Definition
- The coinbase block height is the block's own height, written as the first bytes of the coinbase field, which BIP34 has required of every block since March 2013.
Specified in BIP-34.
It is bitcoin's cheapest fix for a real bug. Before the rule, two blocks with identical coinbase transactions produced identical transaction ids, which happened at blocks 91,842 and 91,880 in 2010. Writing the height in makes every coinbase unique, and lets anyone read a block's position out of the block itself.
How it works
The height is stored as a script push, so a parser reads one length byte and then that many bytes of number.
The number is written little endian and minimally encoded, the way bitcoin script encodes any integer. At present heights it takes three bytes, so the push reads 03 and then the height. Block 840,000, the halving block, therefore opens its coinbase with 03 40 d1 0c: a three byte push, then 840,000 with its least significant byte first. Three bytes cover every height up to 8,388,607, which at ten minute blocks is more than a century away, and the encoding widens to four bytes by itself when that day arrives.
BIP34 deployed as a miner-activated soft fork keyed to the block version number. Blocks declaring version 2 were counted in a rolling window of 1,000: at 750 of the last 1,000, a version 2 block missing its height became invalid, and at 950 the older version 1 format was rejected outright. The last version 1 block ever accepted was 227,835, timestamped March 24, 2013, and Bitcoin Core still hard-codes the activation height as 227,931.
The rule also replaced an expensive check with a free one. BIP30 had already forbidden a new transaction from reusing the id of an existing unspent one, but enforcing it meant a database lookup for every transaction in every block. Once every coinbase is different by construction, duplicate ids cannot occur, so nodes skip that lookup for everything mined after the switchover. A consensus rule that makes validation faster rather than slower is rare enough to be worth noticing.
Where you see it
Any block explorer prints the decoded coinbase, and the height is the first thing in it.
Where it bites is mining. A pool assembles its own coinbase transaction from the template its node supplies, and a pool that inserts the wrong height, usually while racing a block that has just arrived, produces a block every node throws away with a bad-cb-height error. The electricity is spent, the proof of work is valid, and the reward is nothing.
It also matters to anyone proving something about a block without holding the whole chain. A block header does not state its own height; you learn that by counting back to the genesis block. A full block does state it, in a place covered by the merkle root and therefore by the proof of work, so a height claim backed by a coinbase and a merkle branch stands up on its own. Sidechains, timestamping services, and light client protocols all lean on that property.
Coinbase block height vs block height
Block height is a position in the chain, a number anyone can reach by counting back to the block Satoshi mined on January 3, 2009. The coinbase block height is that same number written inside the block's own data because consensus demands it. One is an observation about where a block sits, the other is a field a miner can get wrong and lose a block over.