Skip to content

Commit

Permalink
clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Mar 30, 2024
1 parent a778e10 commit 706541e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ssz-rs/src/merkleization/merkleize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions ssz-rs/src/merkleization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
31 changes: 8 additions & 23 deletions ssz-rs/src/merkleization/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -172,21 +172,6 @@ impl Proof {
}
}

pub fn prove_primitive<T: HashTreeRoot + ?Sized>(
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<T: AsRef<[u8]>>(
leaf: Node,
branch: &[T],
Expand Down
6 changes: 3 additions & 3 deletions ssz-rs/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<T, const N: usize> Vector<T, N>
where
T: SimpleSerialize,
{
fn to_chunks(&mut self) -> Result<Vec<u8>, MerkleizationError> {
fn assemble_chunks(&mut self) -> Result<Vec<u8>, MerkleizationError> {
if T::is_composite_type() {
let count = self.len();
elements_to_chunks(self.data.iter_mut().enumerate(), count)
Expand All @@ -235,7 +235,7 @@ where
}

fn compute_hash_tree_root(&mut self) -> Result<Node, MerkleizationError> {
let chunks = self.to_chunks()?;
let chunks = self.assemble_chunks()?;
merkleize(&chunks, None)
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ where
type Child = T;

fn chunks(&mut self) -> Result<Vec<u8>, MerkleizationError> {
self.to_chunks()
self.assemble_chunks()
}

fn child(&mut self, index: usize) -> Result<&mut Self::Child, MerkleizationError> {
Expand Down

0 comments on commit 706541e

Please sign in to comment.