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 25, 2024
1 parent 86c68f3 commit 92eed0a
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 2,998 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,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.

34 changes: 1 addition & 33 deletions src/commitment_scheme/blake2_hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;

use blake2::digest::{Update, VariableOutput};
use blake2::{Blake2s256, Blake2sVar, Digest};
use blake2::{Blake2s256, Digest};

// Wrapper for the blake2s hash type.
#[derive(Clone, Copy, PartialEq, Default, Eq)]
Expand Down Expand Up @@ -96,24 +95,6 @@ impl super::hasher::Hasher for Blake2sHasher {
fn finalize_reset(&mut self) -> Blake2sHash {
Blake2sHash(self.state.finalize_reset().into())
}

unsafe fn hash_many_in_place(
data: &[*const u8],
single_input_length_bytes: usize,
dst: &[*mut u8],
) {
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 = Blake2sVar::new(Self::OUTPUT_SIZE).unwrap();
hasher.update(input);
hasher.finalize_variable(out).unwrap();
})
}
}

#[cfg(test)]
Expand All @@ -131,19 +112,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 { Blake2sHasher::hash_many_in_place(&input_arr, 1, &out_ptrs) };

assert_eq!("4a0d129873403037c2cd9b9048203687f6233fb6738956e0349bd4320fec3e900000000000000000000004449e92c9a7657ef2d677b8ef9da46c088f13575ea887e4818fc455a2bca50000000000000000000000000000000000000000000000", 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
14 changes: 0 additions & 14 deletions src/commitment_scheme/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +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],
);
}

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

0 comments on commit 92eed0a

Please sign in to comment.