Skip to content

Commit

Permalink
Remove old merkle
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 24, 2024
1 parent a1b0d69 commit f7586f2
Show file tree
Hide file tree
Showing 15 changed files with 12 additions and 2,999 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ name = "field"
harness = false
name = "matrix"

[[bench]]
name = "merkle_bench"
harness = false

[[bench]]
name = "merkle"
harness = false
Expand Down
99 changes: 0 additions & 99 deletions benches/merkle_bench.rs

This file was deleted.

22 changes: 0 additions & 22 deletions src/commitment_scheme/blake2_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,6 @@ mod tests {
);
}

#[test]
fn hash_many_vs_single() {
let hash_a = blake2_hash::Blake2sHasher::hash(b"a");
let mut out = [0_u8; 32];
let out_ptrs = [out.as_mut_ptr()];
unsafe { Blake2sHasher::hash_many_in_place(&[b"a".as_ptr()], 1, &out_ptrs) };
assert_eq!(hash_a.to_string(), hex::encode(out));
}

#[test]
fn hash_many_xof_test() {
let input1 = "a";
let input2 = "b";
let input_arr = [input1.as_ptr(), input2.as_ptr()];

let mut out = [0_u8; 96];
let out_ptrs = [out.as_mut_ptr(), unsafe { out.as_mut_ptr().add(32) }];
unsafe { Blake2sHasher::hash_many_in_place(&input_arr, 1, &out_ptrs) };

assert_eq!("f2ab64ae6530f3a5d19369752cd30eadf455153c29dbf2cb70f00f73d5b41c504383e3109201cbbb59233961bb55f5fe0c49f444751dc782080fe1d9780bfded0000000000000000000000000000000000000000000000000000000000000000", hex::encode(out));
}

#[test]
fn hash_state_test() {
let mut state = Blake2sHasher::new();
Expand Down
33 changes: 0 additions & 33 deletions src/commitment_scheme/blake3_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ impl super::hasher::Hasher for Blake3Hasher {
self.state.reset();
res
}

unsafe fn hash_many_in_place(
data: &[*const u8],
single_input_length_bytes: usize,
dst: &[*mut u8],
) {
let mut hasher = blake3::Hasher::new();
data.iter()
.map(|p| std::slice::from_raw_parts(*p, single_input_length_bytes))
.zip(
dst.iter()
.map(|p| std::slice::from_raw_parts_mut(*p, Self::OUTPUT_SIZE)),
)
.for_each(|(input, out)| {
hasher.update(input);
let mut output_reader = hasher.finalize_xof();
output_reader.fill(&mut out[..Self::OUTPUT_SIZE]);
hasher.reset();
})
}
}

#[cfg(test)]
Expand All @@ -127,19 +107,6 @@ mod tests {
);
}

#[test]
fn hash_many_xof_test() {
let input1 = "a";
let input2 = "b";
let input_arr = [input1.as_ptr(), input2.as_ptr()];

let mut out = [0_u8; 96];
let out_ptrs = [out.as_mut_ptr(), unsafe { out.as_mut_ptr().add(42) }];
unsafe { Blake3Hasher::hash_many_in_place(&input_arr, 1, &out_ptrs) };

assert_eq!("17762fddd969a453925d65717ac3eea21320b66b54342fde15128d6caf21215f0000000000000000000010e5cf3d3c8a4f9f3468c8cc58eea84892a22fdadbc1acb22410190044c1d55300000000000000000000000000000000000000000000", hex::encode(out));
}

#[test]
fn hash_state_test() {
let mut state = Blake3Hasher::new();
Expand Down
26 changes: 0 additions & 26 deletions src/commitment_scheme/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,6 @@ pub trait Hasher: Sized + Default {
hasher.update(data);
hasher.finalize()
}

/// Hash many inputs of the same length.
/// Writes output directly to corresponding pointers in dst.
///
/// # Safety
///
/// Inputs must be of the same size. output locations must all point to valid, allocated and
/// distinct locations in memory.
// TODO(Ohad): make redundent and delete.
unsafe fn hash_many_in_place(
data: &[*const Self::NativeType],
single_input_length_bytes: usize,
dst: &[*mut Self::NativeType],
) {
data.iter()
.map(|p| std::slice::from_raw_parts(*p, single_input_length_bytes))
.zip(
dst.iter()
.map(|p| std::slice::from_raw_parts_mut(*p, Self::OUTPUT_SIZE)),
)
.for_each(|(input, out)| {
let mut hasher = Self::new();
hasher.update(input);
out.clone_from_slice(&hasher.finalize().into());
})
}
}

pub trait Hash<NativeType: Sized + Eq>:
Expand Down
Loading

0 comments on commit f7586f2

Please sign in to comment.