diff --git a/crypto/src/merkle_tree/merkle.rs b/crypto/src/merkle_tree/merkle.rs index 9f4b126d1..bbfe89bf7 100644 --- a/crypto/src/merkle_tree/merkle.rs +++ b/crypto/src/merkle_tree/merkle.rs @@ -123,7 +123,7 @@ mod tests { let values: Vec = vec![FE::new(1)]; // Single element let merkle_tree = MerkleTree::>::build(&values).unwrap(); - assert_eq!(merkle_tree.root, FE::new(4)); // Adjusted expected value + assert_eq!(merkle_tree.root, FE::new(2)); // Adjusted expected value } #[test] diff --git a/crypto/src/merkle_tree/proof.rs b/crypto/src/merkle_tree/proof.rs index 6f875fa6a..65e37555a 100644 --- a/crypto/src/merkle_tree/proof.rs +++ b/crypto/src/merkle_tree/proof.rs @@ -163,8 +163,8 @@ mod tests { let merkle_tree = MerkleTree::>::build(&values).unwrap(); // Update the expected root value based on the actual logic of TestBackend - // For example, if combining two `1`s results in `4`, update this accordingly - let expected_root = FE::new(4); // Assuming combining two `1`s results in `4` + // For example, in this case hashing a single `1` results in `2` + let expected_root = FE::new(2); // Assuming hashing a `1`s results in `2` assert_eq!( merkle_tree.root, expected_root, "The root of the Merkle tree does not match the expected value." diff --git a/crypto/src/merkle_tree/utils.rs b/crypto/src/merkle_tree/utils.rs index 33740780e..1a32d205a 100644 --- a/crypto/src/merkle_tree/utils.rs +++ b/crypto/src/merkle_tree/utils.rs @@ -29,13 +29,12 @@ pub fn complete_until_power_of_two(mut values: Vec) -> Vec { } // ! NOTE ! -// We in this function we say 2^0 = 1 is not a power of two when it is infact true. We -// need this to maintain that the smallest tree at two leaves counts and we could not find -// a name that wasn't overly verbose. In the case of a single value being present in a leaf node -// this indicates we pad to next power of two (i.e. 2). The function is private and is only used -// to ensure the tree has a power of 2 number of leaves. +// In this function we say 2^0 = 1 is a power of two. +// In turn, this makes the smallest tree of one leaf, possible. +// The function is private and is only used to ensure the tree +// has a power of 2 number of leaves. fn is_power_of_two(x: usize) -> bool { - (x > 1) && ((x & (x - 1)) == 0) + (x & (x - 1)) == 0 } // ! CAUTION ! @@ -124,9 +123,8 @@ mod tests { let mut expected_leaves = vec![FE::new(2)]; expected_leaves.extend([FE::new(2)]); - assert_eq!(hashed_leaves.len(), 2); + assert_eq!(hashed_leaves.len(), 1); assert_eq!(hashed_leaves[0], expected_leaves[0]); - assert_eq!(hashed_leaves[1], expected_leaves[1]); } const ROOT: usize = 0;