According to the specification https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki, height is serialized as: “first byte is number of bytes in the number, … following bytes are little-endian representation of the number”
However, CScript() << nHeight
invokes push_int64
function which has
different serialization strategy for numbers smaller than 17.
The current implementation doesn’t cause any issues as BIP34 is enabled from height 227931.
But, if in regtest set consensus.BIP34Height=1
(which can be convenient to test BIP34),
most of the tests will fail as they follow the specification.