Skip to content

Commit

Permalink
added doc for get_leaf_sibling_hash and made it pub. Renamed compute_…
Browse files Browse the repository at this point in the history
…path to compute_auth_path
  • Loading branch information
intx4 committed Jan 19, 2024
1 parent fe685f8 commit aad2785
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ impl<P: Config> MerkleTree<P> {
self.height
}

fn get_leaf_sibling_hash(&self, index: usize) -> P::LeafDigest{
/// Given the `index` of a leaf, returns the digest of its leaf sibling
pub fn get_leaf_sibling_hash(&self, index: usize) -> P::LeafDigest{
if index & 1 == 0 {
// leaf is left child
self.leaf_nodes[index + 1].clone()
Expand All @@ -518,7 +519,7 @@ impl<P: Config> MerkleTree<P> {
}

/// Returns the authentication path from leaf at `index` to root, as a Vec of digests
fn compute_path(&self, index: usize) -> Vec<P::InnerDigest> {
fn compute_auth_path(&self, index: usize) -> Vec<P::InnerDigest> {
// gather basic tree information
let tree_height = tree_height(self.leaf_nodes.len());

Expand All @@ -544,7 +545,7 @@ impl<P: Config> MerkleTree<P> {

/// Returns the authentication path from leaf at `index` to root.
pub fn generate_proof(&self, index: usize) -> Result<Path<P>, crate::Error> {
let path = self.compute_path(index);
let path = self.compute_auth_path(index);
Ok(Path {
leaf_index: index,
auth_path: path,
Expand Down Expand Up @@ -580,7 +581,7 @@ impl<P: Config> MerkleTree<P> {

leaf_siblings_hashes.push(self.get_leaf_sibling_hash(*index));

let path = self.compute_path(*index);
let path = self.compute_auth_path(*index);

// incremental encoding
let (prefix_len, suffix) = prefix_encode_path(&prev_path, &path);
Expand Down

0 comments on commit aad2785

Please sign in to comment.