Skip to content

Commit

Permalink
Implement TreeHash for 48-byte array (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul authored Mar 12, 2023
1 parent c69165f commit 7c65944
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tree_hash/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ macro_rules! impl_for_lt_32byte_u8_array {
impl_for_lt_32byte_u8_array!(4);
impl_for_lt_32byte_u8_array!(32);

impl TreeHash for [u8; 48] {
fn tree_hash_type() -> TreeHashType {
TreeHashType::Vector
}

fn tree_hash_packed_encoding(&self) -> PackedEncoding {
unreachable!("Vector should never be packed.")
}

fn tree_hash_packing_factor() -> usize {
unreachable!("Vector should never be packed.")
}

fn tree_hash_root(&self) -> Hash256 {
let values_per_chunk = BYTES_PER_CHUNK;
let minimum_chunk_count = (48 + values_per_chunk - 1) / values_per_chunk;
merkle_root(self, minimum_chunk_count)
}
}

impl TreeHash for U128 {
fn tree_hash_type() -> TreeHashType {
TreeHashType::Basic
Expand Down

0 comments on commit 7c65944

Please sign in to comment.