Skip to content

Enrich GetImmutableBlockPointError with an error variant for invalid hash size, so ouroboros-consensus can properly validate RawBlockHash size #5396

Description

@tbagrel1

The getImmutableBlockPoint callback in Cardano.Network.LedgerPeerConsensusInterface.LedgerPeersConsensusInterface receives a Point RawBlockHash, where RawBlockHash wraps a ShortByteString of arbitrary length apparently.

On the consensus side, in ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs, when we use getImmutableBlockPoint, we have to convert that raw hash into a block-specific HeaderHash blk. Previously ConvertRawHash was very lax about hash length, and hashSize value was not enforced by conversion methods from/to HeaderHash.

With [Peras 25.5] PR we are improving the ConvertRawHash class to be more explicit about expected hash length, and ensure the hash length invariant is respected during conversions (FTR, the old functions are still available but have been prefixed by unsafe to indicate that they do not enforce the invariant).

So, ideally, in getImmutableBlockPoint, when the RawBlockHash size doesn't match the expected one for HeaderHash blk, we would like to be able to return a proper error value instead of a fatal error.

Suggestion

Add a constructor ImmutableBlockInvalidHashSize Int Int to GetImmutableBlockPointError type in Cardano.Network.LedgerPeerConsensusInterface

Metadata

Metadata

Assignees

No one assigned

    Labels

    cardano-diffusionIssues/PRs related to cardano-diffusion.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions