Skip to content

Commit

Permalink
chore: rm penultimate_level_data() from Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobottazzi committed Nov 10, 2023
1 parent e308b7e commit 2d9d65c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 46 deletions.
10 changes: 0 additions & 10 deletions zk_prover/src/merkle_sum_tree/mst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ impl<const N_ASSETS: usize, const N_BYTES: usize> Tree<N_ASSETS, N_BYTES>
fn get_entry(&self, index: usize) -> &Entry<N_ASSETS> {
&self.entries[index]
}

/// Returns the nodes stored at the penultimate level of the tree, namely the one before the root
fn penultimate_level_data(&self) -> Result<(&Node<N_ASSETS>, &Node<N_ASSETS>), &'static str> {
let penultimate_level = self
.nodes
.get(self.depth - 1)
.ok_or("The tree does not have a penultimate level")?;

Ok((&penultimate_level[0], &penultimate_level[1]))
}
}

impl<const N_ASSETS: usize, const N_BYTES: usize> MerkleSumTree<N_ASSETS, N_BYTES> {
Expand Down
33 changes: 0 additions & 33 deletions zk_prover/src/merkle_sum_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,4 @@ mod test {
let fp_3 = fp_2 - fp;
assert_eq!(fp_3, 18446744073709551613.into());
}

#[test]
fn test_penultimate_level_data() {
let merkle_tree =
MerkleSumTree::<N_ASSETS, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();

let root = merkle_tree.root();

let (node_left, node_right) = merkle_tree
.penultimate_level_data()
.expect("Failed to retrieve penultimate level data");

// perform hashing using poseidon node
let expected_root = poseidon_node(
node_left.hash,
node_left.balances,
node_right.hash,
node_right.balances,
);

assert_eq!(root.hash, expected_root);

assert_eq!(
root.balances[0],
node_left.balances[0] + node_right.balances[0]
);

assert_eq!(
root.balances[1],
node_left.balances[1] + node_right.balances[1]
);
}
}
3 changes: 0 additions & 3 deletions zk_prover/src/merkle_sum_tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub trait Tree<const N_ASSETS: usize, const N_BYTES: usize> {

fn get_entry(&self, index: usize) -> &Entry<N_ASSETS>;

/// Returns the nodes stored at the penultimate level of the tree, namely the one before the root
fn penultimate_level_data(&self) -> Result<(&Node<N_ASSETS>, &Node<N_ASSETS>), &'static str>;

/// Generates a MerkleProof for the user with the given index.
fn generate_proof(&self, index: usize) -> Result<MerkleProof<N_ASSETS, N_BYTES>, &'static str> {
let nodes = self.nodes();
Expand Down

0 comments on commit 2d9d65c

Please sign in to comment.