diff --git a/src/tendermint_hash.rs b/src/tendermint_hash.rs index fec4f53..5dc70a4 100644 --- a/src/tendermint_hash.rs +++ b/src/tendermint_hash.rs @@ -2,22 +2,25 @@ use sha2::{Sha256, Digest}; use crate::simple_merkle::tree::MerkleHash; -fn hash(bytes: &[u8]) -> [u8; 32] { - let mut hasher = Sha256::new(); - hasher.update(bytes); - let result: [u8; 32] = hasher.finalize().into(); - result -} - const LEAF_PREFIX: &[u8] = &[0]; const INNER_PREFIX: &[u8] = &[1]; fn leaf_hash(bytes: &[u8]) -> [u8; 32] { - hash([LEAF_PREFIX, bytes].concat().as_slice()) + //hash([LEAF_PREFIX, bytes].concat().as_slice()) + let mut hasher = Sha256::new(); + hasher.update(LEAF_PREFIX); + hasher.update(bytes); + let result: [u8; 32] = hasher.finalize().into(); + result } fn inner_hash(left: &[u8], right: &[u8]) -> [u8; 32] { - hash([INNER_PREFIX, left, right].concat().as_slice()) + let mut hasher = Sha256::new(); + hasher.update(INNER_PREFIX); + hasher.update(left); + hasher.update(right); + let result: [u8; 32] = hasher.finalize().into(); + result } /// A sha256 hasher, compatible with [Tendermint merkle hash](https://github.com/informalsystems/tendermint-rs/blob/979456c9f33463944f97f7ea3900640e59f7ea6d/tendermint/src/merkle.rs)