Skip to main content

coinbase_height_is_committed

Function coinbase_height_is_committed 

Source
pub fn coinbase_height_is_committed(
    block: &Block,
    height: Height,
) -> Result<(), BlockError>
Expand description

Returns Ok(()) if block’s header commits to height, the height in its coinbase input.

The block hash commits to the header, and the header commits to the transaction IDs through its Merkle root, so callers must also check merkle_root_validity() before trusting height.

Before V5, the coinbase input script that holds the height is part of the transaction ID. From V5 onward it is authorizing data, which the transaction ID doesn’t commit to (ZIP 244), so a peer can rewrite the height without changing the block hash. But a V5 or later transaction ID commits to the expiry height, which must equal the block height in every valid coinbase that can have that version:

[NU5 onward] The nExpiryHeight field of a coinbase transaction MUST be equal to its block height.

https://zips.z.cash/protocol/protocol.pdf#txnconsensus

§Security

This checks every V5 or later coinbase, whatever height is. The consensus check in crate::transaction::check::coinbase_expiry_height() decides whether the rule applies from the block height, so it can’t check that height. A rewritten NU5 coinbase that claims a pre-NU5 height would skip it, and only be rejected later for its consensus branch ID, an error that doesn’t show the body was forged.