IntersectMBO / IntersectMBO/cardano-ledger

[Documentation] How to calculate block hash and block body hash.

Open
#3,777 3 comments 0 reactions 0 assignees View on GitHub
:fountain_pen: documentation
Dominant language
Haskell
Stars
295
Forks
179
Avg merge
4d 7h
Merged PRs (30d)
29

Description

It is my understanding that the block hash is the hash of the header of a block;

the hash of the header would be the one to be later included in the next block header as [`prev_hash` field](https://github.com/input-output-hk/cardano-ledger/blob/065f467ab1827549af051a43cb0677cbe7b81d51/eras/babbage/test-suite/cddl-files/babbage.cddl#L30)(null in case the block in question is genesis ?)

the header of a block includes as a field the hash of the body in the [cddl commented with `; merkle triple root`](https://github.com/input-output-hk/cardano-ledger/blob/065f467ab1827549af051a43cb0677cbe7b81d51/eras/babbage/test-suite/cddl-files/babbage.cddl#L35)

in the source the best I could find is [`hashAlonzoTxSeq`](https://github.com/input-output-hk/cardano-ledger/blob/065f467ab1827549af051a43cb0677cbe7b81d51/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxSeq.hs#L176)

where it seems the hash of the block body is calculated as something like this

```
hash(
hash( toCbor( bodies ) ) +
hash( toCbor( witnesses ) ) +
hash( toCbor( meatadata ) ) +
hash( toCbor( isValidSet ) )
)
```
( where "`+`" is the concatenation of bytestrings )

### Questions

1) is my understanding of the `block_hash` being different than `block_body_hash` correct?

2) the `Hash` type kinda hides the hash algorithm, is it safe to assume we are talking of `blake2b` with digest of 32 bytes?

3) what is the `; merkle triple root` comment for? I see 4 parts being hashed in `hashAlonzoTxSeq`. are the transactions bodies hashed as a merkle tree? or just as a cbor array of tx bodies?

4) CBOR can represent the same data in many ways, is there a standard encoding for the block elements?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.