pub fn compute_additions_root(additions: &[Coin]) -> Bytes32Expand description
additions_root (header field, SPEC §3.4) — Merkle-set root over created coins grouped by puzzle_hash.
Normative: HSH-004 and Chia
block_body_validation
(additions handling ~158–175).
Algorithm: Walk additions in slice order; bucket coin IDs by Coin::puzzle_hash. Emit two 32-byte
leaves per group, in first-seen puzzle_hash order: [puzzle_hash, hash_coin_ids(ids…)], then
chia_consensus::merkle_set::compute_merkle_set_root with DIG empty-set semantics (EMPTY_ROOT when there are
no additions).
Why IndexMap instead of HashMap: HSH-004’s pseudocode uses a map for grouping; Chia’s Python uses dict
insertion order when flattening groups. Rust’s HashMap iteration order is nondeterministic, which would make roots
non-reproducible. IndexMap matches insertion-order semantics and the existing crate::L2Block::compute_additions_root
behavior exercised by BLK-004 tests.
hash_coin_ids: sorts multiple IDs descending by bytes, concatenates, SHA-256 — see the crate-internal
hash_coin_ids helper and Chia
coin.py.
Callers: crate::L2Block::compute_additions_root delegates here after
collecting SpendBundle::additions-derived Coins so validation and tooling share one definition.