fn hash_inner(
        mut level_hashes: [Option<ValueHash>; Self::CHILD_COUNT as usize],
        hasher: &mut HasherWithStats<'_>,
        level: usize,
        mut cache: Option<&mut InternalNodeCache>,
    ) -> ValueHash {
        let mut next_level_len = level_hashes.len() / 2;
        for level_in_tree in (1..=4).rev() {
            let overall_level = level + level_in_tree;
            // Depth of a potential empty subtree rooted at the current level.
            let subtree_depth = TREE_DEPTH - overall_level;

            for i in 0..next_level_len {
                level_hashes[i] = hasher.hash_optional_branch(
                    subtree_depth,
                    level_hashes[2 * i],
                    level_hashes[2 * i + 1],
                );
            }
            next_level_len /= 2;

            if let Some(cache) = cache.as_deref_mut() {
                cache.set_level(level_in_tree - 1, &level_hashes);
            }
        }
        level_hashes[0].unwrap_or_else(|| hasher.empty_subtree_hash(TREE_DEPTH - level))
    }
Hashes this tree given the 0-based level of its tip.
core/lib/merkle_tree/src/hasher/nodes.rs