Browse Source

fix: compilation errors

al-gkr-basic-workflow
Bobbin Threadbare 1 year ago
parent
commit
fe5cac9edc
9 changed files with 84 additions and 88 deletions
  1. +3
    -3
      src/hash/rpo/tests.rs
  2. +1
    -1
      src/merkle/index.rs
  3. +4
    -4
      src/merkle/merkle_tree.rs
  4. +4
    -4
      src/merkle/mmr/tests.rs
  5. +10
    -11
      src/merkle/partial_mt/mod.rs
  6. +51
    -54
      src/merkle/partial_mt/tests.rs
  7. +8
    -8
      src/merkle/path_set.rs
  8. +1
    -1
      src/merkle/simple_smt/tests.rs
  9. +2
    -2
      src/merkle/tiered_smt/tests.rs

+ 3
- 3
src/hash/rpo/tests.rs

@ -206,7 +206,7 @@ fn sponge_bytes_with_remainder_length_wont_panic() {
// size. // size.
// //
// this is a preliminary test to the fuzzy-stress of proptest. // this is a preliminary test to the fuzzy-stress of proptest.
Rpo256::hash(&vec![0; 113]);
Rpo256::hash(&[0; 113]);
} }
#[test] #[test]
@ -230,8 +230,8 @@ fn sponge_zeroes_collision() {
proptest! { proptest! {
#[test] #[test]
fn rpo256_wont_panic_with_arbitrary_input(ref vec in any::<Vec<u8>>()) {
Rpo256::hash(&vec);
fn rpo256_wont_panic_with_arbitrary_input(ref bytes in any::<Vec<u8>>()) {
Rpo256::hash(bytes);
} }
} }

+ 1
- 1
src/merkle/index.rs

@ -190,7 +190,7 @@ mod tests {
if value > (1 << depth) { // round up if value > (1 << depth) { // round up
depth += 1; depth += 1;
} }
NodeIndex::new(depth, value.into()).unwrap()
NodeIndex::new(depth, value).unwrap()
} }
} }

+ 4
- 4
src/merkle/merkle_tree.rs

@ -287,7 +287,7 @@ mod tests {
// leaves were copied correctly // leaves were copied correctly
for (a, b) in tree.nodes.iter().skip(4).zip(LEAVES4.iter()) { for (a, b) in tree.nodes.iter().skip(4).zip(LEAVES4.iter()) {
assert_eq!(*a, RpoDigest::from(*b));
assert_eq!(a, b);
} }
let (root, node2, node3) = compute_internal_nodes(); let (root, node2, node3) = compute_internal_nodes();
@ -341,7 +341,7 @@ mod tests {
let value = 3; let value = 3;
let new_node = int_to_leaf(9); let new_node = int_to_leaf(9);
let mut expected_leaves = digests_to_words(&LEAVES8); let mut expected_leaves = digests_to_words(&LEAVES8);
expected_leaves[value as usize] = new_node.into();
expected_leaves[value as usize] = new_node;
let expected_tree = super::MerkleTree::new(expected_leaves.clone()).unwrap(); let expected_tree = super::MerkleTree::new(expected_leaves.clone()).unwrap();
tree.update_leaf(value, new_node).unwrap(); tree.update_leaf(value, new_node).unwrap();
@ -408,8 +408,8 @@ mod tests {
let digest = RpoDigest::from(word); let digest = RpoDigest::from(word);
// assert the addresses are different // assert the addresses are different
let word_ptr = (&word).as_ptr() as *const u8;
let digest_ptr = (&digest).as_ptr() as *const u8;
let word_ptr = word.as_ptr() as *const u8;
let digest_ptr = digest.as_ptr() as *const u8;
assert_ne!(word_ptr, digest_ptr); assert_ne!(word_ptr, digest_ptr);
// compare the bytes representation // compare the bytes representation

+ 4
- 4
src/merkle/mmr/tests.rs

@ -439,15 +439,15 @@ fn test_mmr_peaks_hash_less_than_16() {
#[test] #[test]
fn test_mmr_peaks_hash_odd() { fn test_mmr_peaks_hash_odd() {
let peaks: Vec<_> = (0..=17).map(|i| int_to_node(i)).collect();
let peaks: Vec<_> = (0..=17).map(int_to_node).collect();
let accumulator = MmrPeaks { let accumulator = MmrPeaks {
num_leaves: (1 << peaks.len()) - 1, num_leaves: (1 << peaks.len()) - 1,
peaks: peaks.clone(), peaks: peaks.clone(),
}; };
// odd length bigger than 16 is padded to the next even nubmer
let mut expected_peaks = peaks.clone();
// odd length bigger than 16 is padded to the next even number
let mut expected_peaks = peaks;
expected_peaks.resize(18, RpoDigest::default()); expected_peaks.resize(18, RpoDigest::default());
assert_eq!( assert_eq!(
accumulator.hash_peaks(), accumulator.hash_peaks(),
@ -488,5 +488,5 @@ mod property_tests {
// ================================================================================================ // ================================================================================================
fn digests_to_elements(digests: &[RpoDigest]) -> Vec<Felt> { fn digests_to_elements(digests: &[RpoDigest]) -> Vec<Felt> {
digests.iter().flat_map(|v| Word::from(v)).collect()
digests.iter().flat_map(Word::from).collect()
} }

+ 10
- 11
src/merkle/partial_mt/mod.rs

@ -1,6 +1,5 @@
use super::{ use super::{
BTreeMap, BTreeSet, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Vec,
Word, EMPTY_WORD,
BTreeMap, BTreeSet, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Vec, ZERO,
}; };
use crate::utils::{format, string::String, word_to_hex}; use crate::utils::{format, string::String, word_to_hex};
use core::fmt; use core::fmt;
@ -15,7 +14,7 @@ mod tests;
const ROOT_INDEX: NodeIndex = NodeIndex::root(); const ROOT_INDEX: NodeIndex = NodeIndex::root();
/// An RpoDigest consisting of 4 ZERO elements. /// An RpoDigest consisting of 4 ZERO elements.
const EMPTY_DIGEST: RpoDigest = RpoDigest::new(EMPTY_WORD);
const EMPTY_DIGEST: RpoDigest = RpoDigest::new([ZERO; 4]);
// PARTIAL MERKLE TREE // PARTIAL MERKLE TREE
// ================================================================================================ // ================================================================================================
@ -50,7 +49,7 @@ impl PartialMerkleTree {
// CONSTRUCTORS // CONSTRUCTORS
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
/// Returns a new emply [PartialMerkleTree].
/// Returns a new empty [PartialMerkleTree].
pub fn new() -> Self { pub fn new() -> Self {
PartialMerkleTree { PartialMerkleTree {
max_depth: 0, max_depth: 0,
@ -108,7 +107,7 @@ impl PartialMerkleTree {
paths.push(( paths.push((
leaf, leaf,
ValuePath { ValuePath {
value: *self.get_node(leaf).expect("Failed to get leaf node"),
value: self.get_node(leaf).expect("Failed to get leaf node"),
path: self.get_path(leaf).expect("Failed to get path"), path: self.get_path(leaf).expect("Failed to get path"),
}, },
)); ));
@ -142,7 +141,7 @@ impl PartialMerkleTree {
index.move_up(); index.move_up();
let sibling = let sibling =
self.nodes.get(&sibling_index).cloned().expect("Sibling node not in the map"); self.nodes.get(&sibling_index).cloned().expect("Sibling node not in the map");
path.push(Word::from(sibling));
path.push(sibling);
} }
Ok(MerklePath::new(path)) Ok(MerklePath::new(path))
} }
@ -189,11 +188,11 @@ impl PartialMerkleTree {
// add provided node and its sibling to the nodes map // add provided node and its sibling to the nodes map
self.nodes.insert(index_value, value); self.nodes.insert(index_value, value);
self.nodes.insert(sibling_node_index, path[0].into());
self.nodes.insert(sibling_node_index, path[0]);
// traverse to the root, updating the nodes // traverse to the root, updating the nodes
let mut index_value = index_value; let mut index_value = index_value;
let node = Rpo256::merge(&index_value.build_node(value, path[0].into()));
let node = Rpo256::merge(&index_value.build_node(value, path[0]));
let root = path.iter().skip(1).copied().fold(node, |node, hash| { let root = path.iter().skip(1).copied().fold(node, |node, hash| {
index_value.move_up(); index_value.move_up();
// insert calculated node to the nodes map // insert calculated node to the nodes map
@ -215,11 +214,11 @@ impl PartialMerkleTree {
// - New node can be a calculated node or a "sibling" node from a Merkle Path: // - New node can be a calculated node or a "sibling" node from a Merkle Path:
// --- Calculated node, obviously, never can be a leaf. // --- Calculated node, obviously, never can be a leaf.
// --- Sibling node can be only a leaf, because otherwise it is not a new node. // --- Sibling node can be only a leaf, because otherwise it is not a new node.
if self.nodes.insert(sibling_node, hash.into()).is_none() {
if self.nodes.insert(sibling_node, hash).is_none() {
self.leaves.insert(sibling_node); self.leaves.insert(sibling_node);
} }
Rpo256::merge(&index_value.build_node(node, hash.into()))
Rpo256::merge(&index_value.build_node(node, hash))
}); });
// if the path set is empty (the root is all ZEROs), set the root to the root of the added // if the path set is empty (the root is all ZEROs), set the root to the root of the added
@ -227,7 +226,7 @@ impl PartialMerkleTree {
if self.root() == EMPTY_DIGEST { if self.root() == EMPTY_DIGEST {
self.nodes.insert(ROOT_INDEX, root); self.nodes.insert(ROOT_INDEX, root);
} else if self.root() != root { } else if self.root() != root {
return Err(MerkleError::ConflictingRoots([*self.root(), *root].to_vec()));
return Err(MerkleError::ConflictingRoots([self.root(), root].to_vec()));
} }
Ok(()) Ok(())

+ 51
- 54
src/merkle/partial_mt/tests.rs

@ -1,6 +1,6 @@
use super::{ use super::{
super::{int_to_node, MerkleStore, MerkleTree, NodeIndex, PartialMerkleTree},
ValuePath, Vec, Word,
super::{digests_to_words, int_to_node, MerkleStore, MerkleTree, NodeIndex, PartialMerkleTree},
RpoDigest, ValuePath, Vec,
}; };
// TEST DATA // TEST DATA
@ -18,7 +18,7 @@ const NODE31: NodeIndex = NodeIndex::new_unchecked(3, 1);
const NODE32: NodeIndex = NodeIndex::new_unchecked(3, 2); const NODE32: NodeIndex = NodeIndex::new_unchecked(3, 2);
const NODE33: NodeIndex = NodeIndex::new_unchecked(3, 3); const NODE33: NodeIndex = NodeIndex::new_unchecked(3, 3);
const VALUES8: [Word; 8] = [
const VALUES8: [RpoDigest; 8] = [
int_to_node(30), int_to_node(30),
int_to_node(31), int_to_node(31),
int_to_node(32), int_to_node(32),
@ -44,22 +44,21 @@ const VALUES8: [Word; 8] = [
// (30) (31) (32) (33) (34) (35) (36) (37) // (30) (31) (32) (33) (34) (35) (36) (37)
// //
// Where node number is a concatenation of its depth and index. For example, node with // Where node number is a concatenation of its depth and index. For example, node with
// NodeIndex(3, 5) will be labled as `35`. Leaves of the tree are shown as nodes with parenthesis
// NodeIndex(3, 5) will be labeled as `35`. Leaves of the tree are shown as nodes with parenthesis
// (33). // (33).
/// Checks that root returned by `root()` function is equal to the expected one. /// Checks that root returned by `root()` function is equal to the expected one.
#[test] #[test]
fn get_root() { fn get_root() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
assert_eq!(pmt.root(), expected_root.into());
assert_eq!(pmt.root(), expected_root);
} }
/// This test checks correctness of the `add_path()` and `get_path()` functions. First it creates a /// This test checks correctness of the `add_path()` and `get_path()` functions. First it creates a
@ -67,7 +66,7 @@ fn get_root() {
/// it checks that paths returned by `get_path()` function are equal to the expected ones. /// it checks that paths returned by `get_path()` function are equal to the expected ones.
#[test] #[test]
fn add_and_get_paths() { fn add_and_get_paths() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
@ -76,10 +75,8 @@ fn add_and_get_paths() {
let expected_path22 = ms.get_path(expected_root, NODE22).unwrap(); let expected_path22 = ms.get_path(expected_root, NODE22).unwrap();
let mut pmt = PartialMerkleTree::new(); let mut pmt = PartialMerkleTree::new();
pmt.add_path(3, expected_path33.value.into(), expected_path33.path.clone())
.unwrap();
pmt.add_path(2, expected_path22.value.into(), expected_path22.path.clone())
.unwrap();
pmt.add_path(3, expected_path33.value, expected_path33.path.clone()).unwrap();
pmt.add_path(2, expected_path22.value, expected_path22.path.clone()).unwrap();
let path33 = pmt.get_path(NODE33).unwrap(); let path33 = pmt.get_path(NODE33).unwrap();
let path22 = pmt.get_path(NODE22).unwrap(); let path22 = pmt.get_path(NODE22).unwrap();
@ -87,58 +84,58 @@ fn add_and_get_paths() {
assert_eq!(expected_path33.path, path33); assert_eq!(expected_path33.path, path33);
assert_eq!(expected_path22.path, path22); assert_eq!(expected_path22.path, path22);
assert_eq!(expected_root, *actual_root);
assert_eq!(expected_root, actual_root);
} }
/// Checks that function `get_node` used on nodes 10 and 32 returns expected values. /// Checks that function `get_node` used on nodes 10 and 32 returns expected values.
#[test] #[test]
fn get_node() { fn get_node() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
assert_eq!(ms.get_node(expected_root, NODE32).unwrap(), *pmt.get_node(NODE32).unwrap());
assert_eq!(ms.get_node(expected_root, NODE10).unwrap(), *pmt.get_node(NODE10).unwrap());
assert_eq!(ms.get_node(expected_root, NODE32).unwrap(), pmt.get_node(NODE32).unwrap());
assert_eq!(ms.get_node(expected_root, NODE10).unwrap(), pmt.get_node(NODE10).unwrap());
} }
/// Updates leaves of the PMT using `update_leaf()` function and checks that new root of the tree /// Updates leaves of the PMT using `update_leaf()` function and checks that new root of the tree
/// is equal to the expected one. /// is equal to the expected one.
#[test] #[test]
fn update_leaf() { fn update_leaf() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let root = mt.root(); let root = mt.root();
let mut ms = MerkleStore::from(&mt); let mut ms = MerkleStore::from(&mt);
let path33 = ms.get_path(root, NODE33).unwrap(); let path33 = ms.get_path(root, NODE33).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
let new_value32 = int_to_node(132); let new_value32 = int_to_node(132);
let expected_root = ms.set_node(root, NODE32, new_value32).unwrap().root; let expected_root = ms.set_node(root, NODE32, new_value32).unwrap().root;
pmt.update_leaf(NODE32, new_value32.into()).unwrap();
pmt.update_leaf(NODE32, new_value32).unwrap();
let actual_root = pmt.root(); let actual_root = pmt.root();
assert_eq!(expected_root, *actual_root);
assert_eq!(expected_root, actual_root);
let new_value20 = int_to_node(120); let new_value20 = int_to_node(120);
let expected_root = ms.set_node(expected_root, NODE20, new_value20).unwrap().root; let expected_root = ms.set_node(expected_root, NODE20, new_value20).unwrap().root;
pmt.update_leaf(NODE20, new_value20.into()).unwrap();
pmt.update_leaf(NODE20, new_value20).unwrap();
let actual_root = pmt.root(); let actual_root = pmt.root();
assert_eq!(expected_root, *actual_root);
assert_eq!(expected_root, actual_root);
} }
/// Checks that paths of the PMT returned by `paths()` function are equal to the expected ones. /// Checks that paths of the PMT returned by `paths()` function are equal to the expected ones.
#[test] #[test]
fn get_paths() { fn get_paths() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
@ -147,8 +144,8 @@ fn get_paths() {
let path22 = ms.get_path(expected_root, NODE22).unwrap(); let path22 = ms.get_path(expected_root, NODE22).unwrap();
let mut pmt = PartialMerkleTree::new(); let mut pmt = PartialMerkleTree::new();
pmt.add_path(3, path33.value.into(), path33.path.clone()).unwrap();
pmt.add_path(2, path22.value.into(), path22.path.clone()).unwrap();
pmt.add_path(3, path33.value, path33.path).unwrap();
pmt.add_path(2, path22.value, path22.path).unwrap();
// After PMT creation with path33 (33; 32, 20, 11) and path22 (22; 23, 10) we will have this // After PMT creation with path33 (33; 32, 20, 11) and path22 (22; 23, 10) we will have this
// tree: // tree:
// //
@ -170,7 +167,7 @@ fn get_paths() {
( (
leaf, leaf,
ValuePath { ValuePath {
value: mt.get_node(leaf).unwrap().into(),
value: mt.get_node(leaf).unwrap(),
path: mt.get_path(leaf).unwrap(), path: mt.get_path(leaf).unwrap(),
}, },
) )
@ -185,7 +182,7 @@ fn get_paths() {
// Checks correctness of leaves determination when using the `leaves()` function. // Checks correctness of leaves determination when using the `leaves()` function.
#[test] #[test]
fn leaves() { fn leaves() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
@ -193,7 +190,7 @@ fn leaves() {
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let path22 = ms.get_path(expected_root, NODE22).unwrap(); let path22 = ms.get_path(expected_root, NODE22).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
// After PMT creation with path33 (33; 32, 20, 11) we will have this tree: // After PMT creation with path33 (33; 32, 20, 11) we will have this tree:
// //
// ______root______ // ______root______
@ -206,17 +203,17 @@ fn leaves() {
// //
// Which have leaf nodes 11, 20, 32 and 33. // Which have leaf nodes 11, 20, 32 and 33.
let value11 = mt.get_node(NODE11).unwrap().into();
let value20 = mt.get_node(NODE20).unwrap().into();
let value32 = mt.get_node(NODE32).unwrap().into();
let value33 = mt.get_node(NODE33).unwrap().into();
let value11 = mt.get_node(NODE11).unwrap();
let value20 = mt.get_node(NODE20).unwrap();
let value32 = mt.get_node(NODE32).unwrap();
let value33 = mt.get_node(NODE33).unwrap();
let leaves = vec![(NODE11, value11), (NODE20, value20), (NODE32, value32), (NODE33, value33)]; let leaves = vec![(NODE11, value11), (NODE20, value20), (NODE32, value32), (NODE33, value33)];
let expected_leaves = leaves.iter().map(|&tuple| tuple);
let expected_leaves = leaves.iter().copied();
assert!(expected_leaves.eq(pmt.leaves())); assert!(expected_leaves.eq(pmt.leaves()));
pmt.add_path(2, path22.value.into(), path22.path).unwrap();
pmt.add_path(2, path22.value, path22.path).unwrap();
// After adding the path22 (22; 23, 10) to the existing PMT we will have this tree: // After adding the path22 (22; 23, 10) to the existing PMT we will have this tree:
// //
// ______root______ // ______root______
@ -229,11 +226,11 @@ fn leaves() {
// //
// Which have leaf nodes 20, 22, 23, 32 and 33. // Which have leaf nodes 20, 22, 23, 32 and 33.
let value20 = mt.get_node(NODE20).unwrap().into();
let value22 = mt.get_node(NODE22).unwrap().into();
let value23 = mt.get_node(NODE23).unwrap().into();
let value32 = mt.get_node(NODE32).unwrap().into();
let value33 = mt.get_node(NODE33).unwrap().into();
let value20 = mt.get_node(NODE20).unwrap();
let value22 = mt.get_node(NODE22).unwrap();
let value23 = mt.get_node(NODE23).unwrap();
let value32 = mt.get_node(NODE32).unwrap();
let value33 = mt.get_node(NODE33).unwrap();
let leaves = vec![ let leaves = vec![
(NODE20, value20), (NODE20, value20),
@ -243,7 +240,7 @@ fn leaves() {
(NODE33, value33), (NODE33, value33),
]; ];
let expected_leaves = leaves.iter().map(|&tuple| tuple);
let expected_leaves = leaves.iter().copied();
assert!(expected_leaves.eq(pmt.leaves())); assert!(expected_leaves.eq(pmt.leaves()));
} }
@ -254,22 +251,22 @@ fn err_add_path() {
let path22 = vec![int_to_node(4), int_to_node(5)].into(); let path22 = vec![int_to_node(4), int_to_node(5)].into();
let mut pmt = PartialMerkleTree::new(); let mut pmt = PartialMerkleTree::new();
pmt.add_path(3, int_to_node(6).into(), path33).unwrap();
pmt.add_path(3, int_to_node(6), path33).unwrap();
assert!(pmt.add_path(2, int_to_node(7).into(), path22).is_err());
assert!(pmt.add_path(2, int_to_node(7), path22).is_err());
} }
/// Checks that the request of the node which is not in the PMT will cause an error. /// Checks that the request of the node which is not in the PMT will cause an error.
#[test] #[test]
fn err_get_node() { fn err_get_node() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
assert!(pmt.get_node(NODE22).is_err()); assert!(pmt.get_node(NODE22).is_err());
assert!(pmt.get_node(NODE23).is_err()); assert!(pmt.get_node(NODE23).is_err());
@ -280,14 +277,14 @@ fn err_get_node() {
/// Checks that the request of the path from the leaf which is not in the PMT will cause an error. /// Checks that the request of the path from the leaf which is not in the PMT will cause an error.
#[test] #[test]
fn err_get_path() { fn err_get_path() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
assert!(pmt.get_path(NODE22).is_err()); assert!(pmt.get_path(NODE22).is_err());
assert!(pmt.get_path(NODE23).is_err()); assert!(pmt.get_path(NODE23).is_err());
@ -297,17 +294,17 @@ fn err_get_path() {
#[test] #[test]
fn err_update_leaf() { fn err_update_leaf() {
let mt = MerkleTree::new(VALUES8.to_vec()).unwrap();
let mt = MerkleTree::new(digests_to_words(&VALUES8)).unwrap();
let expected_root = mt.root(); let expected_root = mt.root();
let ms = MerkleStore::from(&mt); let ms = MerkleStore::from(&mt);
let path33 = ms.get_path(expected_root, NODE33).unwrap(); let path33 = ms.get_path(expected_root, NODE33).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value.into(), path33.path)]).unwrap();
let mut pmt = PartialMerkleTree::with_paths([(3, path33.value, path33.path)]).unwrap();
assert!(pmt.update_leaf(NODE22, int_to_node(22).into()).is_err());
assert!(pmt.update_leaf(NODE23, int_to_node(23).into()).is_err());
assert!(pmt.update_leaf(NODE30, int_to_node(30).into()).is_err());
assert!(pmt.update_leaf(NODE31, int_to_node(31).into()).is_err());
assert!(pmt.update_leaf(NODE22, int_to_node(22)).is_err());
assert!(pmt.update_leaf(NODE23, int_to_node(23)).is_err());
assert!(pmt.update_leaf(NODE30, int_to_node(30)).is_err());
assert!(pmt.update_leaf(NODE31, int_to_node(31)).is_err());
} }

+ 8
- 8
src/merkle/path_set.rs

@ -354,35 +354,35 @@ mod tests {
let m = Rpo256::merge(&[i, j]); let m = Rpo256::merge(&[i, j]);
let n = Rpo256::merge(&[k, l]); let n = Rpo256::merge(&[k, l]);
let root = Rpo256::merge(&[m.into(), n.into()]);
let root = Rpo256::merge(&[m, n]);
let mut set = MerklePathSet::new(3); let mut set = MerklePathSet::new(3);
let value = b; let value = b;
let index = 1; let index = 1;
let path = MerklePath::new([a, j, n].to_vec()); let path = MerklePath::new([a, j, n].to_vec());
set.add_path(index, value.into(), path.clone()).unwrap();
set.add_path(index, value.into(), path).unwrap();
assert_eq!(*value, set.get_leaf(index).unwrap()); assert_eq!(*value, set.get_leaf(index).unwrap());
assert_eq!(root, set.root()); assert_eq!(root, set.root());
let value = e; let value = e;
let index = 4; let index = 4;
let path = MerklePath::new([f.into(), l.into(), m.into()].to_vec());
set.add_path(index, value.into(), path.clone()).unwrap();
let path = MerklePath::new([f, l, m].to_vec());
set.add_path(index, value.into(), path).unwrap();
assert_eq!(*value, set.get_leaf(index).unwrap()); assert_eq!(*value, set.get_leaf(index).unwrap());
assert_eq!(root, set.root()); assert_eq!(root, set.root());
let value = a; let value = a;
let index = 0; let index = 0;
let path = MerklePath::new([b.into(), j.into(), n.into()].to_vec());
set.add_path(index, value.into(), path.clone()).unwrap();
let path = MerklePath::new([b, j, n].to_vec());
set.add_path(index, value.into(), path).unwrap();
assert_eq!(*value, set.get_leaf(index).unwrap()); assert_eq!(*value, set.get_leaf(index).unwrap());
assert_eq!(root, set.root()); assert_eq!(root, set.root());
let value = h; let value = h;
let index = 7; let index = 7;
let path = MerklePath::new([g.into(), k.into(), m.into()].to_vec());
set.add_path(index, value.into(), path.clone()).unwrap();
let path = MerklePath::new([g, k, m].to_vec());
set.add_path(index, value.into(), path).unwrap();
assert_eq!(*value, set.get_leaf(index).unwrap()); assert_eq!(*value, set.get_leaf(index).unwrap());
assert_eq!(root, set.root()); assert_eq!(root, set.root());
} }

+ 1
- 1
src/merkle/simple_smt/tests.rs

@ -203,7 +203,7 @@ fn small_tree_opening_is_consistent() {
let entries = vec![(0, a), (1, b), (4, c), (7, d)]; let entries = vec![(0, a), (1, b), (4, c), (7, d)];
let tree = SimpleSmt::with_leaves(depth, entries).unwrap(); let tree = SimpleSmt::with_leaves(depth, entries).unwrap();
assert_eq!(tree.root(), RpoDigest::from(k));
assert_eq!(tree.root(), k);
let cases: Vec<(u8, u64, Vec<RpoDigest>)> = vec![ let cases: Vec<(u8, u64, Vec<RpoDigest>)> = vec![
(3, 0, vec![b.into(), f, j]), (3, 0, vec![b.into(), f, j]),

+ 2
- 2
src/merkle/tiered_smt/tests.rs

@ -432,10 +432,10 @@ fn build_bottom_leaf_node(keys: &[RpoDigest], values: &[Word]) -> RpoDigest {
fn get_non_empty_nodes(store: &MerkleStore) -> Vec<InnerNodeInfo> { fn get_non_empty_nodes(store: &MerkleStore) -> Vec<InnerNodeInfo> {
store store
.inner_nodes() .inner_nodes()
.filter(|node| !is_empty_subtree(&RpoDigest::from(node.value)))
.filter(|node| !is_empty_subtree(&node.value))
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }
fn is_empty_subtree(node: &RpoDigest) -> bool { fn is_empty_subtree(node: &RpoDigest) -> bool {
EmptySubtreeRoots::empty_hashes(255).contains(&node)
EmptySubtreeRoots::empty_hashes(255).contains(node)
} }

Loading…
Cancel
Save