Add merkle_crh_sprout() and tidy note* things
//!
//! A root of a note commitment tree is associated with each treestate.
#![allow(clippy::unit_arg)]
+#![allow(dead_code)]
use std::fmt;
+use byteorder::{ByteOrder, LittleEndian};
#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;
+use sha2::digest::generic_array::{typenum::U64, GenericArray};
+
+/// MerkleCRH^Sprout Hash Function
+///
+/// MerkleCRH^Sprout(layer, left, right) := SHA256Compress(left || right)
+///
+/// `layer` is unused for Sprout but used for the Sapling equivalent.
+///
+/// https://zips.z.cash/protocol/protocol.pdf#merklecrh
+fn merkle_crh_sprout(left: [u8; 32], right: [u8; 32]) -> [u8; 32] {
+ let mut state = [0u32; 8];
+ let mut block = GenericArray::<u8, U64>::default();
+
+ block.as_mut_slice()[0..32].copy_from_slice(&left[..]);
+ block.as_mut_slice()[32..63].copy_from_slice(&right[..]);
+
+ sha2::compress256(&mut state, &[block]);
+
+ let mut derived_bytes = [0u8; 32];
+ LittleEndian::write_u32_into(&state, &mut derived_bytes);
+
+ derived_bytes
+}
/// Sprout note commitment tree root node hash.
///
