From 706541e251d16bf4bfb3f8bad2f91996e1877c3d Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 29 Mar 2024 19:07:09 -0600 Subject: [PATCH] clean ups --- ssz-rs/src/merkleization/merkleize.rs | 2 +- ssz-rs/src/merkleization/mod.rs | 3 +-- ssz-rs/src/merkleization/proofs.rs | 31 +++++++-------------------- ssz-rs/src/vector.rs | 6 +++--- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/ssz-rs/src/merkleization/merkleize.rs b/ssz-rs/src/merkleization/merkleize.rs index f9945add..19469b3c 100644 --- a/ssz-rs/src/merkleization/merkleize.rs +++ b/ssz-rs/src/merkleization/merkleize.rs @@ -292,7 +292,7 @@ pub fn compute_merkle_tree( mod tests { use super::*; use crate as ssz_rs; - use crate::{merkleization::default_generalized_index, prelude::*}; + use crate::{merkleization::generalized_index::default_generalized_index, prelude::*}; macro_rules! hex { ($input:expr) => { diff --git a/ssz-rs/src/merkleization/mod.rs b/ssz-rs/src/merkleization/mod.rs index 26239552..d41f54be 100644 --- a/ssz-rs/src/merkleization/mod.rs +++ b/ssz-rs/src/merkleization/mod.rs @@ -6,8 +6,7 @@ pub mod proofs; use crate::{lib::*, ser::SerializeError}; pub use generalized_index::{ - default_generalized_index, get_power_of_two_ceil, GeneralizedIndex, GeneralizedIndexable, Path, - PathElement, + get_power_of_two_ceil, GeneralizedIndex, GeneralizedIndexable, Path, PathElement, }; pub use merkleize::*; pub use node::*; diff --git a/ssz-rs/src/merkleization/proofs.rs b/ssz-rs/src/merkleization/proofs.rs index 683e1f3e..7cf78e49 100644 --- a/ssz-rs/src/merkleization/proofs.rs +++ b/ssz-rs/src/merkleization/proofs.rs @@ -2,8 +2,8 @@ use crate::{ lib::*, merkleization::{ - compute_merkle_tree, default_generalized_index, generalized_index::log_2, GeneralizedIndex, - GeneralizedIndexable, HashTreeRoot, MerkleizationError as Error, Node, Path, + compute_merkle_tree, generalized_index::log_2, GeneralizedIndex, GeneralizedIndexable, + MerkleizationError as Error, Node, Path, }, }; use sha2::{Digest, Sha256}; @@ -40,23 +40,23 @@ pub fn compute_local_merkle_coordinates( #[derive(Debug)] pub struct Prover { - pub(crate) hasher: Sha256, - pub proof: Proof, - pub witness: Node, + hasher: Sha256, + proof: Proof, + witness: Node, } impl Prover { - pub fn set_leaf(&mut self, leaf: Node) { + fn set_leaf(&mut self, leaf: Node) { self.proof.leaf = leaf; } // Adds a node to the Merkle proof's branch. // Assumes nodes are provided going from the bottom of the tree to the top. - pub fn extend_branch(&mut self, node: Node) { + fn extend_branch(&mut self, node: Node) { self.proof.branch.push(node) } - pub fn set_witness(&mut self, witness: Node) { + fn set_witness(&mut self, witness: Node) { self.witness = witness; } @@ -172,21 +172,6 @@ impl Proof { } } -pub fn prove_primitive( - data: &mut T, - prover: &mut Prover, -) -> Result<(), Error> { - let index = prover.proof.index; - if index != default_generalized_index() { - return Err(Error::InvalidGeneralizedIndex) - } - - let root = data.hash_tree_root()?; - prover.set_leaf(root); - prover.set_witness(root); - Ok(()) -} - pub fn is_valid_merkle_branch_for_generalized_index>( leaf: Node, branch: &[T], diff --git a/ssz-rs/src/vector.rs b/ssz-rs/src/vector.rs index a5f6f864..aae05364 100644 --- a/ssz-rs/src/vector.rs +++ b/ssz-rs/src/vector.rs @@ -225,7 +225,7 @@ impl Vector where T: SimpleSerialize, { - fn to_chunks(&mut self) -> Result, MerkleizationError> { + fn assemble_chunks(&mut self) -> Result, MerkleizationError> { if T::is_composite_type() { let count = self.len(); elements_to_chunks(self.data.iter_mut().enumerate(), count) @@ -235,7 +235,7 @@ where } fn compute_hash_tree_root(&mut self) -> Result { - let chunks = self.to_chunks()?; + let chunks = self.assemble_chunks()?; merkleize(&chunks, None) } } @@ -287,7 +287,7 @@ where type Child = T; fn chunks(&mut self) -> Result, MerkleizationError> { - self.to_chunks() + self.assemble_chunks() } fn child(&mut self, index: usize) -> Result<&mut Self::Child, MerkleizationError> {