Skip to main content

Module hash

Module hash 

Source
Expand description

Tagged Merkle hashing for binary Merkle trees (HSH-007).

Normative: HSH-007 / hashing NORMATIVE
Crate spec: SPEC §3.3
Prefixes: crate::HASH_LEAF_PREFIX and crate::HASH_TREE_PREFIX (BLK-005).

§What this module is for

  • hash_leaf and hash_node are the explicit SHA-256 formulas Chia uses for leaf and internal nodes in chia_sdk_types::MerkleTree (see merkle_tree.rs in that crate: HASH_LEAF_PREFIX = &[1], HASH_TREE_PREFIX = &[2]upstream source).
  • DIG block code builds those trees via the crate-internal merkle_util::merkle_tree_root helper and direct chia_sdk_types::MerkleTree::new calls; do not hand-roll a parallel Merkle implementation with different tags.

§What this is not

  • chia_consensus::merkle_set::compute_merkle_set_root (additions/removals roots) uses Chia’s radix / sorted-set tree and a different internal hash(ltype, rtype, left, right) — not 0x01||data / 0x02||a||b. That path is correct for HSH-004/HSH-005 but is out of scope for the formulas in this file (see the crate-internal merkle_util module for Merkle-set callers).

§Rationale

Exposing hash_leaf / hash_node makes the domain separation testable and gives downstream crates a single place to name the tagging scheme, while the actual tree shape remains delegated to chia-sdk-types.

Functions§

hash_leaf
Leaf digest: SHA-256( HASH_LEAF_PREFIXdata ) (SPEC §3.3).
hash_node
Internal node digest: SHA-256( HASH_TREE_PREFIXleftright ) (SPEC §3.3).