From 83072ea4b5807180d3493889afc912afade771ed Mon Sep 17 00:00:00 2001 From: Varun Thakore Date: Mon, 2 Sep 2024 03:03:52 +0530 Subject: [PATCH] refactor: update hash output to [u8; 32] && other minor changes --- commitment_scheme/Cargo.toml | 1 + commitment_scheme/src/lib.rs | 5 +- commitment_scheme/src/merkle/hash.rs | 129 ++--- .../src/merkle/merkle_commitment_scheme.rs | 26 +- commitment_scheme/src/merkle/mod.rs | 455 +++++++++--------- .../src/packaging_commitment_scheme.rs | 18 +- commitment_scheme/src/packer_hasher.rs | 12 +- commitment_scheme/src/table_verifier.rs | 4 +- 8 files changed, 319 insertions(+), 331 deletions(-) diff --git a/commitment_scheme/Cargo.toml b/commitment_scheme/Cargo.toml index f9bd6bd..2cb68b9 100644 --- a/commitment_scheme/Cargo.toml +++ b/commitment_scheme/Cargo.toml @@ -13,6 +13,7 @@ felt = { path = "../felt" } channel = { path = "../channel" } randomness ={ path = "../randomness" } anyhow.workspace = true +num-bigint.workspace = true [dev-dependencies] hex.workspace = true diff --git a/commitment_scheme/src/lib.rs b/commitment_scheme/src/lib.rs index 254ef64..26f4eeb 100644 --- a/commitment_scheme/src/lib.rs +++ b/commitment_scheme/src/lib.rs @@ -60,7 +60,10 @@ pub trait CommitmentSchemeVerifier { fn read_commitment(&mut self) -> Result<(), anyhow::Error>; // Verify the integrity of the data - fn verify_integrity(&mut self, elements_to_verify: BTreeMap>) -> Option; + fn verify_integrity( + &mut self, + elements_to_verify: BTreeMap>, + ) -> Result; // Return the total number of elements in the current layer fn num_of_elements(&self) -> usize; diff --git a/commitment_scheme/src/merkle/hash.rs b/commitment_scheme/src/merkle/hash.rs index ed2ce97..8226ce1 100644 --- a/commitment_scheme/src/merkle/hash.rs +++ b/commitment_scheme/src/merkle/hash.rs @@ -1,6 +1,7 @@ use ark_ff::{BigInteger, PrimeField}; use blake2::{Blake2s256, Digest}; use felt::Felt252; +use num_bigint::BigUint; use poseidon::{FieldHasher, Poseidon3}; use sha3::Keccak256; use std::{fmt::Debug, marker::PhantomData}; @@ -14,10 +15,24 @@ pub trait Hasher { type Output: Clone + Eq + Default + Debug + AsRef<[u8]>; // compress a list of internal nodes into a single internal node - fn node(input: &[Self::Output]) -> Self::Output; + fn node(input: &[Self::Output]) -> Self::Output { + assert_eq!(input.len(), 2); + assert_eq!(input[0].as_ref().len(), 32); + assert_eq!(input[1].as_ref().len(), 32); + let mut combined = Vec::with_capacity(64); + combined.extend_from_slice(input[0].as_ref()); + combined.extend_from_slice(input[1].as_ref()); + Self::hash_bytes(&combined) + } // compress a list of leaves into a single leaf - fn leaf(input: &[F]) -> Self::Output; + fn leaf(input: &[F]) -> Self::Output { + let input_bytes: Vec = input + .iter() + .flat_map(|f| f.into_bigint().to_bytes_be()) + .collect(); + Self::hash_bytes(&input_bytes) + } // compress a list of bytes into a single internal node fn hash_bytes(data: &[u8]) -> Self::Output; @@ -31,37 +46,12 @@ pub struct Blake2s256Hasher { impl Hasher for Blake2s256Hasher { const DIGEST_NUM_BYTES: usize = 32; - type Output = Vec; - - fn leaf(input: &[F]) -> Self::Output { - let mut hasher = Blake2s256::new(); - input - .iter() - .for_each(|f| hasher.update(f.into_bigint().to_bytes_be())); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash - } - - fn node(input: &[Self::Output]) -> Self::Output { - assert_eq!(input.len(), 2); - - let mut hasher = Blake2s256::new(); - input.iter().for_each(|f| { - assert_eq!(f.len(), Self::DIGEST_NUM_BYTES); - hasher.update(f) - }); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash - } + type Output = [u8; 32]; fn hash_bytes(data: &[u8]) -> Self::Output { let mut hasher = Blake2s256::new(); hasher.update(data); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash + hasher.finalize().into() } } @@ -73,37 +63,12 @@ pub struct Keccak256Hasher { impl Hasher for Keccak256Hasher { const DIGEST_NUM_BYTES: usize = 32; - type Output = Vec; - - fn leaf(input: &[F]) -> Self::Output { - let mut hasher = Keccak256::new(); - input - .iter() - .for_each(|f| hasher.update(f.into_bigint().to_bytes_be())); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash - } - - fn node(input: &[Self::Output]) -> Self::Output { - assert_eq!(input.len(), 2); - - let mut hasher = Keccak256::new(); - input.iter().for_each(|f| { - assert_eq!(f.len(), Self::DIGEST_NUM_BYTES); - hasher.update(f) - }); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash - } + type Output = [u8; 32]; fn hash_bytes(data: &[u8]) -> Self::Output { let mut hasher = Keccak256::new(); hasher.update(data); - let hash = hasher.finalize().to_vec(); - assert_eq!(hash.len(), Self::DIGEST_NUM_BYTES); - hash + hasher.finalize().into() } } @@ -115,7 +80,7 @@ pub struct Poseidon3Hasher { impl Hasher for Poseidon3Hasher { const DIGEST_NUM_BYTES: usize = 32; - type Output = Vec; + type Output = [u8; 32]; fn leaf(input: &[F]) -> Self::Output { let input_felts: Vec = input @@ -129,18 +94,23 @@ impl Hasher for Poseidon3Hasher { let mut array = [0u8; 32]; array[..hash.len()].copy_from_slice(&hash); - array.to_vec() + array } fn node(input: &[Self::Output]) -> Self::Output { assert_eq!(input.len(), 2); - let input0 = Felt252::from_be_bytes_mod_order(&input[0]); - let input1 = Felt252::from_be_bytes_mod_order(&input[1]); + let input0_int = BigUint::from_bytes_be(&input[0]); + let input1_int = BigUint::from_bytes_be(&input[1]); + assert!(input0_int < F::MODULUS.into()); + assert!(input1_int < F::MODULUS.into()); + + let input0 = input0_int.into(); + let input1 = input1_int.into(); let hash = Poseidon3::pair(input0, input1).into_bigint().to_bytes_be(); let mut array = [0u8; 32]; array[..hash.len()].copy_from_slice(&hash); - array.to_vec() + array } fn hash_bytes(data: &[u8]) -> Self::Output { @@ -150,7 +120,7 @@ impl Hasher for Poseidon3Hasher { let mut array = [0u8; 32]; array[..hash.len()].copy_from_slice(&hash); - array.to_vec() + array } } @@ -168,30 +138,14 @@ pub struct MaskedHash< // Implement Hasher trait for MaskedHash impl< F: PrimeField, - H: Hasher>, + H: Hasher, const NUM_EFFECTIVE_BYTES: usize, const IS_MSB: bool, > Hasher for MaskedHash { const DIGEST_NUM_BYTES: usize = H::DIGEST_NUM_BYTES; - type Output = Vec; - - fn leaf(input: &[F]) -> Self::Output { - let hash = H::leaf(input); - Self::mask_hash(&hash) - } - - fn node(input: &[Self::Output]) -> Self::Output { - assert_eq!(input.len(), 2); - let mut extended_input = Vec::new(); - for vec in input { - extended_input.extend(vec); - } - - let hash = H::hash_bytes(&extended_input); - Self::mask_hash(&hash) - } + type Output = [u8; 32]; fn hash_bytes(data: &[u8]) -> Self::Output { let hash = H::hash_bytes(data); @@ -202,14 +156,13 @@ impl< impl, const NUM_EFFECTIVE_BYTES: usize, const IS_MSB: bool> MaskedHash { - fn mask_hash(digest: &[u8]) -> Vec { - let digest_bytes = H::DIGEST_NUM_BYTES; - let mut buffer = vec![0u8; digest_bytes]; + fn mask_hash(digest: &[u8]) -> [u8; 32] { + let mut buffer = [0u8; 32]; if IS_MSB { buffer[..NUM_EFFECTIVE_BYTES].copy_from_slice(&digest[..NUM_EFFECTIVE_BYTES]); } else { - buffer[digest_bytes - NUM_EFFECTIVE_BYTES..] + buffer[32 - NUM_EFFECTIVE_BYTES..] .copy_from_slice(&digest[digest.len() - NUM_EFFECTIVE_BYTES..]); } @@ -223,7 +176,7 @@ mod tests { use felt::Felt252; use super::{Hasher, Keccak256Hasher, MaskedHash}; - use crate::merkle::tests::hex_to_vec; + use crate::merkle::tests::hex_to_b32; fn as_masked(data: Vec, is_msb: bool, mask_bytes: usize) -> Vec { assert!(data.len() >= mask_bytes); @@ -249,8 +202,8 @@ mod tests { #[test] fn test_masked_hash() { let hash = MaskedKeccak20True::hash_bytes(&[]); - let exp = hex_to_vec("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"); - assert_eq!(hash, as_masked(exp, true, 20)); + let exp = hex_to_b32("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"); + assert_eq!(hash.to_vec(), as_masked(exp.to_vec(), true, 20)); let testing_string = b"testing"; let expected_hash: [u8; 32] = [ @@ -259,7 +212,7 @@ mod tests { 0xdf, 0x9d, 0x1b, 0x02, ]; let hash = MaskedKeccak20True::hash_bytes(testing_string); - assert_eq!(hash, as_masked(expected_hash.to_vec(), true, 20)); + assert_eq!(hash.to_vec(), as_masked(expected_hash.to_vec(), true, 20)); let testing_string = b"testing"; let h1 = MaskedKeccak20True::hash_bytes(testing_string); diff --git a/commitment_scheme/src/merkle/merkle_commitment_scheme.rs b/commitment_scheme/src/merkle/merkle_commitment_scheme.rs index fb334d7..3473a1a 100644 --- a/commitment_scheme/src/merkle/merkle_commitment_scheme.rs +++ b/commitment_scheme/src/merkle/merkle_commitment_scheme.rs @@ -41,7 +41,7 @@ impl, P: Prng, W: Digest> MerkleCommitmentSchemeProv } } -impl>, P: Prng, W: Digest> CommitmentSchemeProver +impl, P: Prng, W: Digest> CommitmentSchemeProver for MerkleCommitmentSchemeProver { fn num_segments(&self) -> usize { @@ -105,19 +105,35 @@ impl, P: Prng, W: Digest> MerkleCommitmentSchemeVeri } } -impl>, P: Prng, W: Digest> CommitmentSchemeVerifier +impl, P: Prng, W: Digest> CommitmentSchemeVerifier for MerkleCommitmentSchemeVerifier { fn read_commitment(&mut self) -> Result<(), anyhow::Error> { let mut channel = self.channel.borrow_mut(); - self.comm = channel.recv_commit_hash(H::DIGEST_NUM_BYTES)?; + let comm_vec = channel.recv_commit_hash(H::DIGEST_NUM_BYTES)?; + assert_eq!(comm_vec.len(), 32); + let mut comm_bytes = [0u8; 32]; + comm_bytes.copy_from_slice(&comm_vec); + self.comm = comm_bytes; Ok(()) } - fn verify_integrity(&mut self, elements_to_verify: BTreeMap>) -> Option { + fn verify_integrity( + &mut self, + elements_to_verify: BTreeMap>, + ) -> Result { let mut channel = self.channel.borrow_mut(); + let elements_to_verify = elements_to_verify + .iter() + .map(|(i, v)| { + assert_eq!(v.len(), 32); + let mut bytes = [0u8; 32]; + bytes.copy_from_slice(v); + (*i, bytes) + }) + .collect(); MerkleTree::::verify_decommitment( - self.comm.clone(), + self.comm, self.n_elements, &elements_to_verify, &mut channel, diff --git a/commitment_scheme/src/merkle/mod.rs b/commitment_scheme/src/merkle/mod.rs index bae1002..6e1e808 100644 --- a/commitment_scheme/src/merkle/mod.rs +++ b/commitment_scheme/src/merkle/mod.rs @@ -1,6 +1,7 @@ pub mod hash; pub mod merkle_commitment_scheme; use crate::merkle::hash::Hasher; +use anyhow::Error; use thiserror::Error; use std::collections::{BTreeMap, BTreeSet}; @@ -15,7 +16,7 @@ use randomness::Prng; use sha3::Digest; pub struct MerkleTree> { - data_length: usize, + num_leafs: usize, nodes: Vec, _ph: PhantomData, } @@ -25,30 +26,30 @@ impl> MerkleTree { /// /// # Arguments /// - /// - `data_length`: length of data which the tree will commit to. + /// - `num_leafs`: length of data which the tree will commit to. /// /// # Returns /// /// - `Self`: MerkleTree with empty nodes - pub fn new(data_length: usize) -> Self { - // assert data_length is a power of 2 + pub fn new(num_leafs: usize) -> Self { + // assert num_leafs is a power of 2 assert!( - data_length != 0 && (data_length & (data_length - 1)) == 0, + num_leafs.is_power_of_two(), "Data length is not a power of two." ); // for better indexing, use an array that has one extra cell at the beginning - let nodes: Vec = vec![H::Output::default(); 2 * data_length]; + let nodes: Vec = vec![H::Output::default(); 2 * num_leafs]; Self { - data_length, + num_leafs, nodes, _ph: PhantomData, } } } -impl>> MerkleTree { +impl> MerkleTree { /// Feeds the tree with data to commit on. /// /// # Arguments @@ -56,22 +57,21 @@ impl>> MerkleTree { /// - `data`: input data to commit on. /// - `start_index`: index of the tree leaves where the data will be added. pub fn add_data(&mut self, data: &[H::Output], start_index: usize) { - assert!(start_index + data.len() <= self.data_length); + assert!(start_index + data.len() <= self.num_leafs); // copy given data to the leaves of the tree self.nodes.splice( - (self.data_length + start_index)..(self.data_length + start_index + data.len()), + (self.num_leafs + start_index)..(self.num_leafs + start_index + data.len()), data.to_vec(), ); // Hash to compute all parent nodes - let mut cur = (self.data_length + start_index) / 2; + let mut cur = (self.num_leafs + start_index) / 2; let mut sub_layer_length = data.len() / 2; while sub_layer_length > 0 { for j in cur..(cur + sub_layer_length) { - self.nodes[j] = - H::node(&[self.nodes[2 * j].clone(), self.nodes[2 * j + 1].clone()]); + self.nodes[j] = H::node(&[self.nodes[2 * j], self.nodes[2 * j + 1]]); } cur /= 2; sub_layer_length /= 2; @@ -85,13 +85,13 @@ impl>> MerkleTree { /// /// Returns the root of the tree. pub fn get_root(&mut self) -> H::Output { - let height_correct = self.data_length; + let height_correct = self.num_leafs; for j in (1..height_correct).rev() { - self.nodes[j] = H::node(&[self.nodes[2 * j].clone(), self.nodes[2 * j + 1].clone()]); + self.nodes[j] = H::node(&[self.nodes[2 * j], self.nodes[2 * j + 1]]); } - self.nodes[1].clone() + self.nodes[1] } /// Verifies a batched Merkle-tree decommitment. @@ -111,43 +111,58 @@ impl>> MerkleTree { total_data_length: usize, data_to_verify: &BTreeMap, channel: &mut FSVerifierChannel, - ) -> Option { + ) -> Result { assert!(total_data_length > 0); // add the nodes to verify to the set of known nodes let mut queue: VecDeque<(usize, H::Output)> = VecDeque::new(); for (&key, value) in data_to_verify { - queue.push_back((key + total_data_length, value.clone())); + queue.push_back((key + total_data_length, *value)); } - let (mut node_idx, mut node_hash) = queue.front()?.clone(); + let (mut node_idx, mut node_hash) = *queue + .front() + .ok_or_else(|| anyhow::anyhow!("front() called on empty queue !"))?; let mut sib = [H::Output::default(), H::Output::default()]; let mut sib_node_idx; let mut sib_node_hash = H::Output::default(); while node_idx != 1 { - queue.pop_front()?; + queue + .pop_front() + .ok_or_else(|| anyhow::anyhow!("pop_front() called on empty queue !"))?; sib_node_idx = node_idx ^ 1; - sib[node_idx & 1] = node_hash.to_vec(); + sib[node_idx & 1] = node_hash; - if !queue.is_empty() && queue.front()?.0 == sib_node_idx { - sib_node_hash.clone_from(&queue.front()?.1); + if !queue.is_empty() && queue.front().unwrap().0 == sib_node_idx { + sib_node_hash.clone_from(&queue.front().unwrap().1); queue.pop_front(); } else { let decommitment_node = channel.recv_decommit_node(H::DIGEST_NUM_BYTES); match decommitment_node { - Ok(value) => sib_node_hash = value, - Err(_e) => (), + Ok(value) => { + assert_eq!(value.len(), 32); + let mut bytes = [0u8; 32]; + bytes.copy_from_slice(&value); + sib_node_hash = bytes; + } + + Err(e) => { + return Err(anyhow::anyhow!("failed to receive decommit node: {} !", e)) + } } } sib[sib_node_idx & 1].clone_from(&sib_node_hash); queue.push_back((node_idx / 2, H::node(&sib))); - node_idx = queue.front()?.0; - node_hash.clone_from(&queue.front()?.1); + node_idx = queue + .front() + .ok_or_else(|| anyhow::anyhow!("front() called on empty queue !"))? + .0; + node_hash.clone_from(&queue.front().unwrap().1); } - Some(queue.front()?.1 == merkle_root) + Ok(queue.front().unwrap().1 == merkle_root) } /// Generates decommitment nodes used to verify data. @@ -169,8 +184,8 @@ impl>> MerkleTree { .iter() .cloned() .map(|idx| { - assert!(idx < self.data_length, "query out of range"); - idx + self.data_length + assert!(idx < self.num_leafs, "query out of range"); + idx + self.num_leafs }) .collect(); @@ -184,7 +199,7 @@ impl>> MerkleTree { queue.pop_front(); } else { // next node is not the sibling, send node to channel - let _ = channel.send_decommit_node(self.nodes[sib_node_idx].clone()); + let _ = channel.send_decommit_node(self.nodes[sib_node_idx]); } node_idx = queue.pop_front()?; @@ -204,19 +219,19 @@ impl>> MerkleTree { /// # Returns /// /// Returns vector of hash output. -pub fn bytes_as_hash>>( +pub fn bytes_as_hash>( bytes_data: &[u8], size_of_element: usize, ) -> Vec { - let n_elements = bytes_data.len() / size_of_element; - let mut bytes_as_hash = Vec::with_capacity(n_elements); - - for hash_idx in 0..n_elements { - let offset = hash_idx * size_of_element; - let chunk = &bytes_data[offset..offset + size_of_element]; - let hash = chunk.to_vec(); - bytes_as_hash.push(hash); - } + let chunks = bytes_data.chunks_exact(size_of_element); + assert!(chunks.remainder().is_empty()); + + let bytes_as_hash: Vec = chunks + .map(|chunk| { + let chunk: [u8; 32] = chunk.try_into().expect("chunk size is incorrect"); + chunk + }) + .collect(); bytes_as_hash } @@ -256,7 +271,7 @@ mod tests { use super::hash::Poseidon3Hasher; - pub fn hex_to_vec(hex_str: &str) -> Vec { + pub fn hex_to_b32(hex_str: &str) -> [u8; 32] { let mut hex_str = String::from(hex_str); let padding_length = 64_i32.saturating_sub(hex_str.len() as i32); if padding_length > 0 { @@ -264,16 +279,16 @@ mod tests { hex_str.insert_str(0, &padding); } let bytes = decode(hex_str).unwrap(); - assert_eq!(bytes.len(), 32); - - bytes + let mut out_bytes = [0u8; 32]; + out_bytes.copy_from_slice(&bytes); + out_bytes } fn test_diff_tree_diff_root(data0: &[H::Output], data1: &[H::Output]) where F: PrimeField, - H: Hasher>, + H: Hasher, { assert_eq!(data0.len(), data1.len()); let mut tree = MerkleTree::::new(data0.len()); @@ -290,7 +305,7 @@ mod tests { fn test_root_compute(data0: &[H::Output], data1: &[H::Output], exp_root: H::Output) where F: PrimeField, - H: Hasher>, + H: Hasher, { assert_eq!(data0.len(), data1.len()); let mut tree = MerkleTree::::new(data0.len() * 2); @@ -308,71 +323,71 @@ mod tests { fn test_tree_root() { // test with Blake2s256 let data0 = [ - hex_to_vec("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), - hex_to_vec("d05c29c29f7db3906f02dc7fbcbb16da58c9d67de7d8c3405cf81592e7a7087b"), - hex_to_vec("e9cdcd85e00bf03e3b7741830cfc3e94d5dd16419b1fcec02eadbf1387cbbf74"), - hex_to_vec("8951af3f7576fea7f4f29422cecf9a072487af9b5fbc0eb06d23889e81d98979"), - hex_to_vec("09114eaab98d5d3fbfd5ab29c707b5c361ec79d514a6c3bd31c5ec3ec54d55bf"), - hex_to_vec("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), - hex_to_vec("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), - hex_to_vec("0a47848bf63587decc1675ec0ad26bd3b6734a00ebcfcf84e9191ebcacb9c94e"), + hex_to_b32("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), + hex_to_b32("d05c29c29f7db3906f02dc7fbcbb16da58c9d67de7d8c3405cf81592e7a7087b"), + hex_to_b32("e9cdcd85e00bf03e3b7741830cfc3e94d5dd16419b1fcec02eadbf1387cbbf74"), + hex_to_b32("8951af3f7576fea7f4f29422cecf9a072487af9b5fbc0eb06d23889e81d98979"), + hex_to_b32("09114eaab98d5d3fbfd5ab29c707b5c361ec79d514a6c3bd31c5ec3ec54d55bf"), + hex_to_b32("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), + hex_to_b32("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), + hex_to_b32("0a47848bf63587decc1675ec0ad26bd3b6734a00ebcfcf84e9191ebcacb9c94e"), ]; let data1 = [ - hex_to_vec("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), - hex_to_vec("98e8177af0b18366127b14940c2eafcc1f5da635d73891d6bce7e5a5e2d3c721"), - hex_to_vec("b9179e6abddace935de2846267c0b8ef90b575c0f1bfe2a2bc804a05e452e8f9"), - hex_to_vec("a741d2a18d6a1d3d76b06b66febfa128ffbf9ce7ff880d811244ec75887b25e0"), - hex_to_vec("a5bad18826679e52eb722f6fbd3d45cd08add9cec39a15a1046b7f2b17507565"), - hex_to_vec("33ae65efe662938f03694fab95a0ad87653de68e811b9b41292433dc1433c559"), - hex_to_vec("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), - hex_to_vec("6dc75f281250f2d2194b86e272be6662aa28f4ee2e5202556a0796d50a7469dc"), + hex_to_b32("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), + hex_to_b32("98e8177af0b18366127b14940c2eafcc1f5da635d73891d6bce7e5a5e2d3c721"), + hex_to_b32("b9179e6abddace935de2846267c0b8ef90b575c0f1bfe2a2bc804a05e452e8f9"), + hex_to_b32("a741d2a18d6a1d3d76b06b66febfa128ffbf9ce7ff880d811244ec75887b25e0"), + hex_to_b32("a5bad18826679e52eb722f6fbd3d45cd08add9cec39a15a1046b7f2b17507565"), + hex_to_b32("33ae65efe662938f03694fab95a0ad87653de68e811b9b41292433dc1433c559"), + hex_to_b32("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), + hex_to_b32("6dc75f281250f2d2194b86e272be6662aa28f4ee2e5202556a0796d50a7469dc"), ]; let root_exp = - hex_to_vec("b7a3cd28384b4baea480d070801106bf07f56f848acf271f6b6415ddc355f8e9"); + hex_to_b32("b7a3cd28384b4baea480d070801106bf07f56f848acf271f6b6415ddc355f8e9"); test_diff_tree_diff_root::>(&data0, &data1); test_root_compute::>(&data0, &data1, root_exp); // test with Keccak256 let data0 = [ - hex_to_vec("1edc3c8392034de0f516534ed7f5441f971d6fa78e1458107939398aaf35162c"), - hex_to_vec("e6d004f42a562534a47d304aaf52425773b70d11c0be3bd59112a0ccf1f0ab2b"), - hex_to_vec("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), - hex_to_vec("564b9ffa2508e2d59c2d5f43c4ca96b7646f3b2363814dac042a89b48af183a3"), - hex_to_vec("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), - hex_to_vec("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), - hex_to_vec("3136305dd4779e01c586fb66b0400d44606dfd3a38c51eda04dc3c059b3c3215"), - hex_to_vec("0085f15f8357aecc4ed40fa7de7a8c44e4800ef5f556d73d6d9e8e77e99eefce"), + hex_to_b32("1edc3c8392034de0f516534ed7f5441f971d6fa78e1458107939398aaf35162c"), + hex_to_b32("e6d004f42a562534a47d304aaf52425773b70d11c0be3bd59112a0ccf1f0ab2b"), + hex_to_b32("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), + hex_to_b32("564b9ffa2508e2d59c2d5f43c4ca96b7646f3b2363814dac042a89b48af183a3"), + hex_to_b32("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), + hex_to_b32("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), + hex_to_b32("3136305dd4779e01c586fb66b0400d44606dfd3a38c51eda04dc3c059b3c3215"), + hex_to_b32("0085f15f8357aecc4ed40fa7de7a8c44e4800ef5f556d73d6d9e8e77e99eefce"), ]; let data1 = [ - hex_to_vec("c11b6869d1674f3342a366f2fc728bed396ab858a36d0d125dea64fb2495e7ac"), - hex_to_vec("ba350a7e4e86f425f9624be90cb4a82c59263304aa02acd8fcb6e246cdc9b12c"), - hex_to_vec("19350ec1a9d255a21556d63d9e35bfb0839ceab89d4d221e92d6cf68ba02bbd5"), - hex_to_vec("9c3982feabacd25de79b03852235fb8c757c2f41912aeda46a5f84b534e2ad40"), - hex_to_vec("87204b53f02a216e574b13e78a7ab11c15181ccbab05694039cfae3333e308a0"), - hex_to_vec("81ac8a8b30bf7170f11d23847729f335bfeaa4107a7acd68a87eb43a097bfc36"), - hex_to_vec("0678011aba74ebbdc6d79093b39aa4b6d4c88eb96043a95537633f361e1dc4ed"), - hex_to_vec("8a45012a030697b1c0db1504c68ee0fca1ab0ac8e3ad80c032b26f7b38ea97b4"), + hex_to_b32("c11b6869d1674f3342a366f2fc728bed396ab858a36d0d125dea64fb2495e7ac"), + hex_to_b32("ba350a7e4e86f425f9624be90cb4a82c59263304aa02acd8fcb6e246cdc9b12c"), + hex_to_b32("19350ec1a9d255a21556d63d9e35bfb0839ceab89d4d221e92d6cf68ba02bbd5"), + hex_to_b32("9c3982feabacd25de79b03852235fb8c757c2f41912aeda46a5f84b534e2ad40"), + hex_to_b32("87204b53f02a216e574b13e78a7ab11c15181ccbab05694039cfae3333e308a0"), + hex_to_b32("81ac8a8b30bf7170f11d23847729f335bfeaa4107a7acd68a87eb43a097bfc36"), + hex_to_b32("0678011aba74ebbdc6d79093b39aa4b6d4c88eb96043a95537633f361e1dc4ed"), + hex_to_b32("8a45012a030697b1c0db1504c68ee0fca1ab0ac8e3ad80c032b26f7b38ea97b4"), ]; let root_exp = - hex_to_vec("fba6d37293ad9845ff546e9615853594c47237ee666cf5267788e14e0032f3de"); + hex_to_b32("fba6d37293ad9845ff546e9615853594c47237ee666cf5267788e14e0032f3de"); test_diff_tree_diff_root::>(&data0, &data1); test_root_compute::>(&data0, &data1, root_exp); // test with Poseidon3 let data0 = [ - hex_to_vec("36313083bda3d5d1f1ade3dfb59311bd38f583c92f570719cb41be7e46e6ee5"), - hex_to_vec("353699d84e4b67ce55874046b58e501a73582c2b16ceed4ff651e6439089483"), - hex_to_vec("452135053077d0c52f8057d5a418a67bdecec4afb240d59613e885e0e71a0bf"), - hex_to_vec("4705a84ca4ee4bc971f9bdf51fd2f74e1273ca72261c0a5845e89dc5c3a1a00"), + hex_to_b32("36313083bda3d5d1f1ade3dfb59311bd38f583c92f570719cb41be7e46e6ee5"), + hex_to_b32("353699d84e4b67ce55874046b58e501a73582c2b16ceed4ff651e6439089483"), + hex_to_b32("452135053077d0c52f8057d5a418a67bdecec4afb240d59613e885e0e71a0bf"), + hex_to_b32("4705a84ca4ee4bc971f9bdf51fd2f74e1273ca72261c0a5845e89dc5c3a1a00"), ]; let data1 = [ - hex_to_vec("27c1e003f81b13f5282b863dceddb162dd6180150eabc16d2267b5aa25c1786"), - hex_to_vec("27b3118926ffe13b70a3a3ed551869cc31d344551e5a7013a9146d0fa84f06a"), - hex_to_vec("5f7701e493613cfb4e3b0600eccf74d4916cc66aa2631ab374e73d3a43bcee4"), - hex_to_vec("5e598f5a773a9ab554121b8d4937bf1b383393f10ae49f98532a2beea1f7852"), + hex_to_b32("27c1e003f81b13f5282b863dceddb162dd6180150eabc16d2267b5aa25c1786"), + hex_to_b32("27b3118926ffe13b70a3a3ed551869cc31d344551e5a7013a9146d0fa84f06a"), + hex_to_b32("5f7701e493613cfb4e3b0600eccf74d4916cc66aa2631ab374e73d3a43bcee4"), + hex_to_b32("5e598f5a773a9ab554121b8d4937bf1b383393f10ae49f98532a2beea1f7852"), ]; let root_exp = - hex_to_vec("3a80041b3647dd472cb7979dc422e9b7d86d4bcd08b957a6ae05caf6c6e189b"); + hex_to_b32("3a80041b3647dd472cb7979dc422e9b7d86d4bcd08b957a6ae05caf6c6e189b"); test_diff_tree_diff_root::>(&data0, &data1); test_root_compute::>(&data0, &data1, root_exp); } @@ -380,7 +395,7 @@ mod tests { fn test_verify_true(data: &[H::Output], root_exp: H::Output) where F: PrimeField, - H: Hasher>, + H: Hasher, { let mut rng = rand::thread_rng(); @@ -421,7 +436,7 @@ mod tests { query_data: &BTreeMap, ) where F: PrimeField, - H: Hasher>, + H: Hasher, { let queries: BTreeSet = query_data.keys().cloned().collect(); @@ -450,341 +465,341 @@ mod tests { #[test] fn test_verify() { // tests using Blake2s256 - let input = [hex_to_vec( + let input = [hex_to_b32( "216acdc6a1fe9e6b89605b2eb3452c613b4ebc09af6c8477bf79d69fa9ec1125", )]; let root_exp = - hex_to_vec("216acdc6a1fe9e6b89605b2eb3452c613b4ebc09af6c8477bf79d69fa9ec1125"); + hex_to_b32("216acdc6a1fe9e6b89605b2eb3452c613b4ebc09af6c8477bf79d69fa9ec1125"); let to_verify = BTreeMap::from([( 0, - hex_to_vec("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), + hex_to_b32("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), - hex_to_vec("6dc48ad654bc4a3e3c8f3270a987b2782af1707e78e1512018f16fdee124bdbd"), + hex_to_b32("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), + hex_to_b32("6dc48ad654bc4a3e3c8f3270a987b2782af1707e78e1512018f16fdee124bdbd"), ]; let root_exp = - hex_to_vec("b823ac891cee85512521528e1d61cdcad829080392b63f393e46adc213862af9"); + hex_to_b32("b823ac891cee85512521528e1d61cdcad829080392b63f393e46adc213862af9"); let to_verify = BTreeMap::from([ ( 0, - hex_to_vec("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), + hex_to_b32("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), ), ( 1, - hex_to_vec("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), + hex_to_b32("d7005ac2e5ece2a48746ae40264076edf63fc833532572d359a0c47cbc42c482"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), - hex_to_vec("12ee05a2b647db0371c79c13842574c13ccc3610faa888aa4ec4764407fe84ed"), - hex_to_vec("aa7ea89c5a679c4aa2c7f85d58988bc42eb97828f5bf18a8fca88f52fe3cf933"), - hex_to_vec("1c16cd6af66980b3f38f66a213a82b0c5d3480296d6315d12ea3862e72e29a8c"), + hex_to_b32("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), + hex_to_b32("12ee05a2b647db0371c79c13842574c13ccc3610faa888aa4ec4764407fe84ed"), + hex_to_b32("aa7ea89c5a679c4aa2c7f85d58988bc42eb97828f5bf18a8fca88f52fe3cf933"), + hex_to_b32("1c16cd6af66980b3f38f66a213a82b0c5d3480296d6315d12ea3862e72e29a8c"), ]; let root_exp = - hex_to_vec("57989eb39d929071d2f3a4400067d00e4d77671d9ed682a8cdd2d4e11d3f5aea"); + hex_to_b32("57989eb39d929071d2f3a4400067d00e4d77671d9ed682a8cdd2d4e11d3f5aea"); let to_verify = BTreeMap::from([ ( 0, - hex_to_vec("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), + hex_to_b32("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), ), ( 3, - hex_to_vec("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), + hex_to_b32("1363b8220c90c05d93c279ab287fadfe2e223543ca46dee65b32ecd7d7bc891c"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("a9a9cce2406aac65d8b8c2e64fa88c20af029373d784bb4357db4521cb05df2f"), - hex_to_vec("82ce423aac9f3cf8b8c28553a5ae607f2586c2f0ca695d4ec97136a8b7fc9f91"), - hex_to_vec("7cf9a07e6169885c6c2a3e8e32ea3aec234d79095a775aeaf04250276c77ed89"), - hex_to_vec("9e74347b0b870523de79a2117c2f6954ccdbef01baa6850e22680dd9a7bbf0f2"), - hex_to_vec("c34262d4a92511ae195259274a83191dd6dd41659621b152cd88b59181f0d8f1"), - hex_to_vec("1998e773220e155214ae129d65c0bfe98b0b729d69b5fa487ca2343783cc8a3d"), - hex_to_vec("0a614f0d06d701ddc9674406097452de7cf9df5fff1382d167a5f6801620cbfa"), - hex_to_vec("0c5ba953f251b55655ac4cda2622f13e4d68016a3297ff29e0b8d21984ccc33a"), + hex_to_b32("a9a9cce2406aac65d8b8c2e64fa88c20af029373d784bb4357db4521cb05df2f"), + hex_to_b32("82ce423aac9f3cf8b8c28553a5ae607f2586c2f0ca695d4ec97136a8b7fc9f91"), + hex_to_b32("7cf9a07e6169885c6c2a3e8e32ea3aec234d79095a775aeaf04250276c77ed89"), + hex_to_b32("9e74347b0b870523de79a2117c2f6954ccdbef01baa6850e22680dd9a7bbf0f2"), + hex_to_b32("c34262d4a92511ae195259274a83191dd6dd41659621b152cd88b59181f0d8f1"), + hex_to_b32("1998e773220e155214ae129d65c0bfe98b0b729d69b5fa487ca2343783cc8a3d"), + hex_to_b32("0a614f0d06d701ddc9674406097452de7cf9df5fff1382d167a5f6801620cbfa"), + hex_to_b32("0c5ba953f251b55655ac4cda2622f13e4d68016a3297ff29e0b8d21984ccc33a"), ]; let root_exp = - hex_to_vec("594e2c4c084f406df0130a252fe030a64a1539225e2b4156f04cf4cefcd75b01"); + hex_to_b32("594e2c4c084f406df0130a252fe030a64a1539225e2b4156f04cf4cefcd75b01"); let to_verify = BTreeMap::from([ ( 2, - hex_to_vec("7cf9a07e6169885c6c2a3e8e32ea3aec234d79095a775aeaf04250276c77ed89"), + hex_to_b32("7cf9a07e6169885c6c2a3e8e32ea3aec234d79095a775aeaf04250276c77ed89"), ), ( 3, - hex_to_vec("a9a9cce2406aac65d8b8c2e64fa88c20af029373d784bb4357db4521cb05df2f"), + hex_to_b32("a9a9cce2406aac65d8b8c2e64fa88c20af029373d784bb4357db4521cb05df2f"), ), ( 4, - hex_to_vec("c34262d4a92511ae195259274a83191dd6dd41659621b152cd88b59181f0d8f1"), + hex_to_b32("c34262d4a92511ae195259274a83191dd6dd41659621b152cd88b59181f0d8f1"), ), ( 5, - hex_to_vec("1998e773220e155214ae129d65c0bfe98b0b729d69b5fa487ca2343783cc8a3d"), + hex_to_b32("1998e773220e155214ae129d65c0bfe98b0b729d69b5fa487ca2343783cc8a3d"), ), ( 7, - hex_to_vec("0c5ba953f251b55655ac4cda2622f13e4d68016a3297ff29e0b8d21984ccc33a"), + hex_to_b32("0c5ba953f251b55655ac4cda2622f13e4d68016a3297ff29e0b8d21984ccc33a"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), - hex_to_vec("d05c29c29f7db3906f02dc7fbcbb16da58c9d67de7d8c3405cf81592e7a7087b"), - hex_to_vec("e9cdcd85e00bf03e3b7741830cfc3e94d5dd16419b1fcec02eadbf1387cbbf74"), - hex_to_vec("8951af3f7576fea7f4f29422cecf9a072487af9b5fbc0eb06d23889e81d98979"), - hex_to_vec("09114eaab98d5d3fbfd5ab29c707b5c361ec79d514a6c3bd31c5ec3ec54d55bf"), - hex_to_vec("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), - hex_to_vec("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), - hex_to_vec("0a47848bf63587decc1675ec0ad26bd3b6734a00ebcfcf84e9191ebcacb9c94e"), - hex_to_vec("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), - hex_to_vec("98e8177af0b18366127b14940c2eafcc1f5da635d73891d6bce7e5a5e2d3c721"), - hex_to_vec("b9179e6abddace935de2846267c0b8ef90b575c0f1bfe2a2bc804a05e452e8f9"), - hex_to_vec("a741d2a18d6a1d3d76b06b66febfa128ffbf9ce7ff880d811244ec75887b25e0"), - hex_to_vec("a5bad18826679e52eb722f6fbd3d45cd08add9cec39a15a1046b7f2b17507565"), - hex_to_vec("33ae65efe662938f03694fab95a0ad87653de68e811b9b41292433dc1433c559"), - hex_to_vec("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), - hex_to_vec("6dc75f281250f2d2194b86e272be6662aa28f4ee2e5202556a0796d50a7469dc"), + hex_to_b32("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), + hex_to_b32("d05c29c29f7db3906f02dc7fbcbb16da58c9d67de7d8c3405cf81592e7a7087b"), + hex_to_b32("e9cdcd85e00bf03e3b7741830cfc3e94d5dd16419b1fcec02eadbf1387cbbf74"), + hex_to_b32("8951af3f7576fea7f4f29422cecf9a072487af9b5fbc0eb06d23889e81d98979"), + hex_to_b32("09114eaab98d5d3fbfd5ab29c707b5c361ec79d514a6c3bd31c5ec3ec54d55bf"), + hex_to_b32("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), + hex_to_b32("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), + hex_to_b32("0a47848bf63587decc1675ec0ad26bd3b6734a00ebcfcf84e9191ebcacb9c94e"), + hex_to_b32("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), + hex_to_b32("98e8177af0b18366127b14940c2eafcc1f5da635d73891d6bce7e5a5e2d3c721"), + hex_to_b32("b9179e6abddace935de2846267c0b8ef90b575c0f1bfe2a2bc804a05e452e8f9"), + hex_to_b32("a741d2a18d6a1d3d76b06b66febfa128ffbf9ce7ff880d811244ec75887b25e0"), + hex_to_b32("a5bad18826679e52eb722f6fbd3d45cd08add9cec39a15a1046b7f2b17507565"), + hex_to_b32("33ae65efe662938f03694fab95a0ad87653de68e811b9b41292433dc1433c559"), + hex_to_b32("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), + hex_to_b32("6dc75f281250f2d2194b86e272be6662aa28f4ee2e5202556a0796d50a7469dc"), ]; let root_exp = - hex_to_vec("b7a3cd28384b4baea480d070801106bf07f56f848acf271f6b6415ddc355f8e9"); + hex_to_b32("b7a3cd28384b4baea480d070801106bf07f56f848acf271f6b6415ddc355f8e9"); let to_verify = BTreeMap::from([ ( 0, - hex_to_vec("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), + hex_to_b32("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), ), ( 3, - hex_to_vec("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), + hex_to_b32("837cd6db8f93d5ddfeaaba5509551c69c760c099e97969cfa04047ae65c33c8c"), ), ( 5, - hex_to_vec("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), + hex_to_b32("64a6d52004718db41784b1c1738ab18fb48b9ef323065151ea603dbf50a8c36d"), ), ( 6, - hex_to_vec("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), + hex_to_b32("b36e83f5fdf23aa5799c0f0358af60979e919c88cb08a2d29c122f644e2f167e"), ), ( 8, - hex_to_vec("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), + hex_to_b32("9be40d50e1559d36162d268b4af350c65fc8a7b3dc1cbe82a1b5b4e33726d297"), ), ( 14, - hex_to_vec("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), + hex_to_b32("53ebf1e5f6477b7f0d7a9b631d5ed97f0a14ca54c61173bb50ae98b8d7d81440"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); // tests using Keccak256 - let input = [hex_to_vec( + let input = [hex_to_b32( "ed5f0c2a7fdf07022be01ec165a50601807910d9dcc0ce3def6d291e9675e127", )]; let root_exp = - hex_to_vec("ed5f0c2a7fdf07022be01ec165a50601807910d9dcc0ce3def6d291e9675e127"); + hex_to_b32("ed5f0c2a7fdf07022be01ec165a50601807910d9dcc0ce3def6d291e9675e127"); let to_verify = BTreeMap::from([( 0, - hex_to_vec("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), + hex_to_b32("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), - hex_to_vec("a1482873bccd9dd66ec6ef8c8a092c7f70839af97b22936ffa5606f1cd28dcea"), + hex_to_b32("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), + hex_to_b32("a1482873bccd9dd66ec6ef8c8a092c7f70839af97b22936ffa5606f1cd28dcea"), ]; let root_exp = - hex_to_vec("f272f3ba749e68b9ccd51f322c6ae6cac8734967ecc31c1058b8f9a8c99fb083"); + hex_to_b32("f272f3ba749e68b9ccd51f322c6ae6cac8734967ecc31c1058b8f9a8c99fb083"); let to_verify = BTreeMap::from([( 1, - hex_to_vec("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), + hex_to_b32("8b471e237284b2a8d0845469431ecc163264d4924c984987a4dac5c40e2c34f2"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("b77b78e96b3f1de1a11ad49cae9804d8fd754123c916f25c638dd84d7ef8687d"), - hex_to_vec("15014fef710a715ea5a879a328912d8e1feefbc23137e8bf223139285fd9203e"), - hex_to_vec("2483654ae6756dc99e99173802f5737cf44d23ffa8b8fae732160c14db636793"), - hex_to_vec("c0e9d48d53c45ebfa3cd5ba2492638322463df296bab03b6492f4f11536e7e0e"), + hex_to_b32("b77b78e96b3f1de1a11ad49cae9804d8fd754123c916f25c638dd84d7ef8687d"), + hex_to_b32("15014fef710a715ea5a879a328912d8e1feefbc23137e8bf223139285fd9203e"), + hex_to_b32("2483654ae6756dc99e99173802f5737cf44d23ffa8b8fae732160c14db636793"), + hex_to_b32("c0e9d48d53c45ebfa3cd5ba2492638322463df296bab03b6492f4f11536e7e0e"), ]; let root_exp = - hex_to_vec("24562159dd8260d379ae390b80cb8266da3f4469bc6643db3b5c3f760c126b83"); + hex_to_b32("24562159dd8260d379ae390b80cb8266da3f4469bc6643db3b5c3f760c126b83"); let to_verify = BTreeMap::from([ ( 1, - hex_to_vec("15014fef710a715ea5a879a328912d8e1feefbc23137e8bf223139285fd9203e"), + hex_to_b32("15014fef710a715ea5a879a328912d8e1feefbc23137e8bf223139285fd9203e"), ), ( 3, - hex_to_vec("2483654ae6756dc99e99173802f5737cf44d23ffa8b8fae732160c14db636793"), + hex_to_b32("2483654ae6756dc99e99173802f5737cf44d23ffa8b8fae732160c14db636793"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("66661b6925e2abacbb63f975277eb908fa7d3f2c4de8d2cfe9788fd0e2af3234"), - hex_to_vec("fdc012059327bae5b7796e255b251a5eefcc4310f8438bb738c12964f0630da1"), - hex_to_vec("abe2a0f9213f7033dccb60a9742f9edcbbb7e952ca4eaf2736735155d66a9be9"), - hex_to_vec("6c63d57004dd9fb1f6a65d111e2230cca32f9aff392d0b84e6ba8c47fe093ae0"), - hex_to_vec("1e0841b00ea5648b2996203d58818b39e7c951c7f12de730aecaa69670e324f6"), - hex_to_vec("3213a156ac8029f8355208b9e6afd496775a494bee3bf4a2bbdaade80da9cc93"), - hex_to_vec("8e62dab2bb313c8e2ed86d601e47e3307e919fac5042be9faa53ba83902dd0a8"), - hex_to_vec("2fe79a0be4d26e69164bdd96404780e8e504c5e96eb975975236579c8b569a95"), + hex_to_b32("66661b6925e2abacbb63f975277eb908fa7d3f2c4de8d2cfe9788fd0e2af3234"), + hex_to_b32("fdc012059327bae5b7796e255b251a5eefcc4310f8438bb738c12964f0630da1"), + hex_to_b32("abe2a0f9213f7033dccb60a9742f9edcbbb7e952ca4eaf2736735155d66a9be9"), + hex_to_b32("6c63d57004dd9fb1f6a65d111e2230cca32f9aff392d0b84e6ba8c47fe093ae0"), + hex_to_b32("1e0841b00ea5648b2996203d58818b39e7c951c7f12de730aecaa69670e324f6"), + hex_to_b32("3213a156ac8029f8355208b9e6afd496775a494bee3bf4a2bbdaade80da9cc93"), + hex_to_b32("8e62dab2bb313c8e2ed86d601e47e3307e919fac5042be9faa53ba83902dd0a8"), + hex_to_b32("2fe79a0be4d26e69164bdd96404780e8e504c5e96eb975975236579c8b569a95"), ]; let root_exp = - hex_to_vec("50a1b9b02edd048756030d39f12e795ab7885565964dde0de6e5de1655f0d793"); + hex_to_b32("50a1b9b02edd048756030d39f12e795ab7885565964dde0de6e5de1655f0d793"); let to_verify = BTreeMap::from([ ( 0, - hex_to_vec("fdc012059327bae5b7796e255b251a5eefcc4310f8438bb738c12964f0630da1"), + hex_to_b32("fdc012059327bae5b7796e255b251a5eefcc4310f8438bb738c12964f0630da1"), ), ( 3, - hex_to_vec("abe2a0f9213f7033dccb60a9742f9edcbbb7e952ca4eaf2736735155d66a9be9"), + hex_to_b32("abe2a0f9213f7033dccb60a9742f9edcbbb7e952ca4eaf2736735155d66a9be9"), ), ( 4, - hex_to_vec("1e0841b00ea5648b2996203d58818b39e7c951c7f12de730aecaa69670e324f6"), + hex_to_b32("1e0841b00ea5648b2996203d58818b39e7c951c7f12de730aecaa69670e324f6"), ), ( 7, - hex_to_vec("2fe79a0be4d26e69164bdd96404780e8e504c5e96eb975975236579c8b569a95"), + hex_to_b32("2fe79a0be4d26e69164bdd96404780e8e504c5e96eb975975236579c8b569a95"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("1edc3c8392034de0f516534ed7f5441f971d6fa78e1458107939398aaf35162c"), - hex_to_vec("e6d004f42a562534a47d304aaf52425773b70d11c0be3bd59112a0ccf1f0ab2b"), - hex_to_vec("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), - hex_to_vec("564b9ffa2508e2d59c2d5f43c4ca96b7646f3b2363814dac042a89b48af183a3"), - hex_to_vec("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), - hex_to_vec("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), - hex_to_vec("3136305dd4779e01c586fb66b0400d44606dfd3a38c51eda04dc3c059b3c3215"), - hex_to_vec("0085f15f8357aecc4ed40fa7de7a8c44e4800ef5f556d73d6d9e8e77e99eefce"), - hex_to_vec("c11b6869d1674f3342a366f2fc728bed396ab858a36d0d125dea64fb2495e7ac"), - hex_to_vec("ba350a7e4e86f425f9624be90cb4a82c59263304aa02acd8fcb6e246cdc9b12c"), - hex_to_vec("19350ec1a9d255a21556d63d9e35bfb0839ceab89d4d221e92d6cf68ba02bbd5"), - hex_to_vec("9c3982feabacd25de79b03852235fb8c757c2f41912aeda46a5f84b534e2ad40"), - hex_to_vec("87204b53f02a216e574b13e78a7ab11c15181ccbab05694039cfae3333e308a0"), - hex_to_vec("81ac8a8b30bf7170f11d23847729f335bfeaa4107a7acd68a87eb43a097bfc36"), - hex_to_vec("0678011aba74ebbdc6d79093b39aa4b6d4c88eb96043a95537633f361e1dc4ed"), - hex_to_vec("8a45012a030697b1c0db1504c68ee0fca1ab0ac8e3ad80c032b26f7b38ea97b4"), + hex_to_b32("1edc3c8392034de0f516534ed7f5441f971d6fa78e1458107939398aaf35162c"), + hex_to_b32("e6d004f42a562534a47d304aaf52425773b70d11c0be3bd59112a0ccf1f0ab2b"), + hex_to_b32("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), + hex_to_b32("564b9ffa2508e2d59c2d5f43c4ca96b7646f3b2363814dac042a89b48af183a3"), + hex_to_b32("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), + hex_to_b32("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), + hex_to_b32("3136305dd4779e01c586fb66b0400d44606dfd3a38c51eda04dc3c059b3c3215"), + hex_to_b32("0085f15f8357aecc4ed40fa7de7a8c44e4800ef5f556d73d6d9e8e77e99eefce"), + hex_to_b32("c11b6869d1674f3342a366f2fc728bed396ab858a36d0d125dea64fb2495e7ac"), + hex_to_b32("ba350a7e4e86f425f9624be90cb4a82c59263304aa02acd8fcb6e246cdc9b12c"), + hex_to_b32("19350ec1a9d255a21556d63d9e35bfb0839ceab89d4d221e92d6cf68ba02bbd5"), + hex_to_b32("9c3982feabacd25de79b03852235fb8c757c2f41912aeda46a5f84b534e2ad40"), + hex_to_b32("87204b53f02a216e574b13e78a7ab11c15181ccbab05694039cfae3333e308a0"), + hex_to_b32("81ac8a8b30bf7170f11d23847729f335bfeaa4107a7acd68a87eb43a097bfc36"), + hex_to_b32("0678011aba74ebbdc6d79093b39aa4b6d4c88eb96043a95537633f361e1dc4ed"), + hex_to_b32("8a45012a030697b1c0db1504c68ee0fca1ab0ac8e3ad80c032b26f7b38ea97b4"), ]; let root_exp = - hex_to_vec("fba6d37293ad9845ff546e9615853594c47237ee666cf5267788e14e0032f3de"); + hex_to_b32("fba6d37293ad9845ff546e9615853594c47237ee666cf5267788e14e0032f3de"); let to_verify = BTreeMap::from([ ( 4, - hex_to_vec("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), + hex_to_b32("e4ef3f3ea1ae8c961aa6ef36cfdd91831aaa2c92d832aee4687a46144ebbef83"), ), ( 5, - hex_to_vec("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), + hex_to_b32("5462d01e69b3006ea33734a6eea7dbf05d983a46fed38522ac2fae8373b0c715"), ), ( 13, - hex_to_vec("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), + hex_to_b32("614a71ae7c9c127e71884f6bc64454842977b58be4dfcd3a2db8763bba5e8ae5"), ), ]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); // tests using Poseidon3 - let input = [hex_to_vec( + let input = [hex_to_b32( "c89ae25f3fa9f809dc7e255509bbe13d8ee41e7050a1757d10b14380479762", )]; - let root_exp = hex_to_vec("c89ae25f3fa9f809dc7e255509bbe13d8ee41e7050a1757d10b14380479762"); + let root_exp = hex_to_b32("c89ae25f3fa9f809dc7e255509bbe13d8ee41e7050a1757d10b14380479762"); let to_verify = BTreeMap::from([( 0, - hex_to_vec("061e4f02a5fb16a37cef579d5a3bc31ab6bc3dfb112d0bbe440afcf4ef6b2dbd"), + hex_to_b32("061e4f02a5fb16a37cef579d5a3bc31ab6bc3dfb112d0bbe440afcf4ef6b2dbd"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("02f926674daed935c5ec20daf9e116f45e74ebad57909889e6c4e60ac9a7239a"), - hex_to_vec("059089a262fd310d47e824b3add73c7bbedd67b2f111b3d67a48177765891a1f"), + hex_to_b32("02f926674daed935c5ec20daf9e116f45e74ebad57909889e6c4e60ac9a7239a"), + hex_to_b32("059089a262fd310d47e824b3add73c7bbedd67b2f111b3d67a48177765891a1f"), ]; let root_exp = - hex_to_vec("07572153d1bc66733cf79b40c1427cdf8c5754e71254491da93c3a789c5f1af3"); + hex_to_b32("07572153d1bc66733cf79b40c1427cdf8c5754e71254491da93c3a789c5f1af3"); let to_verify = BTreeMap::from([( 1, - hex_to_vec("0070336f8988bd453e936b157afcfcf07fa2924e5d670f36fcc9cf01ff09fc6f"), + hex_to_b32("0070336f8988bd453e936b157afcfcf07fa2924e5d670f36fcc9cf01ff09fc6f"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("167c6d08b3aec83b4b27bce5df9c9ba4dce709ea7d40497f7bf2cc2b787cc41"), - hex_to_vec("5934aa1631d1759018513505f5407abb4e232bdab2aa74e48cbbe1cec301387"), - hex_to_vec("56daeb7ceeeda161e5ee669bf88202e034216fa8424c89e1408ad77ea6b8829"), - hex_to_vec("1808bca5f11183aaf603971b0ac93f5b4558c47f0777e5db2cc14e3b512c66"), + hex_to_b32("167c6d08b3aec83b4b27bce5df9c9ba4dce709ea7d40497f7bf2cc2b787cc41"), + hex_to_b32("5934aa1631d1759018513505f5407abb4e232bdab2aa74e48cbbe1cec301387"), + hex_to_b32("56daeb7ceeeda161e5ee669bf88202e034216fa8424c89e1408ad77ea6b8829"), + hex_to_b32("1808bca5f11183aaf603971b0ac93f5b4558c47f0777e5db2cc14e3b512c66"), ]; let root_exp = - hex_to_vec("32cbc8162b4c5f91efd2a5f2c2701fbabafdd08ea8ce7f06d6f0ee2a28cdef5"); + hex_to_b32("32cbc8162b4c5f91efd2a5f2c2701fbabafdd08ea8ce7f06d6f0ee2a28cdef5"); let to_verify = BTreeMap::from([( 2, - hex_to_vec("1f8c6141be9707ec0a767257d522ef2bf321a2e9efc6b93136e3dc9d9665d26"), + hex_to_b32("1f8c6141be9707ec0a767257d522ef2bf321a2e9efc6b93136e3dc9d9665d26"), )]); test_verify_true::>(&input, root_exp.clone()); test_verify_false::>(&input, root_exp, &to_verify); let input = [ - hex_to_vec("726cb96d8303497a472d118b54046e2966076ad68b3c39a24cd96a8c5ae466b"), - hex_to_vec("6380a19495b51c52bd73a7111d5a4b0c022efedfb90d46660301ce365b0069c"), - hex_to_vec("4c3abd3626c95cd55e330856ebc8cc85c8871349c28079149e1ee19f4ba7809"), - hex_to_vec("438059b58dd33650037db7274014d00ce07a1a62ddbf68b43b10a91de504606"), - hex_to_vec("573f3d932cbfc0070b76aa652a82bd93bc0e92517068092b252788bd54bbe84"), - hex_to_vec("26a109ece8e786838ad839a0513db66ff403cb97e6c35396b8e82ef014729ff"), - hex_to_vec("355834fe0fb7afcbd719967841a691822148ff959c16e5ba67114a9774c57e5"), - hex_to_vec("203b523ca101a81bbb94013b9408968c324e35340081375f77f628114441622"), + hex_to_b32("726cb96d8303497a472d118b54046e2966076ad68b3c39a24cd96a8c5ae466b"), + hex_to_b32("6380a19495b51c52bd73a7111d5a4b0c022efedfb90d46660301ce365b0069c"), + hex_to_b32("4c3abd3626c95cd55e330856ebc8cc85c8871349c28079149e1ee19f4ba7809"), + hex_to_b32("438059b58dd33650037db7274014d00ce07a1a62ddbf68b43b10a91de504606"), + hex_to_b32("573f3d932cbfc0070b76aa652a82bd93bc0e92517068092b252788bd54bbe84"), + hex_to_b32("26a109ece8e786838ad839a0513db66ff403cb97e6c35396b8e82ef014729ff"), + hex_to_b32("355834fe0fb7afcbd719967841a691822148ff959c16e5ba67114a9774c57e5"), + hex_to_b32("203b523ca101a81bbb94013b9408968c324e35340081375f77f628114441622"), ]; let root_exp = - hex_to_vec("577c0d4d52b1b4b583e4f6be73ed16b33067318b0d9eda930c47f60679fe5c0"); + hex_to_b32("577c0d4d52b1b4b583e4f6be73ed16b33067318b0d9eda930c47f60679fe5c0"); let to_verify = BTreeMap::from([ ( 0, - hex_to_vec("726cb96d8303497a472d118b54046e2966076ad68b3c39a24cd96a8c5ae466b"), + hex_to_b32("726cb96d8303497a472d118b54046e2966076ad68b3c39a24cd96a8c5ae466b"), ), ( 1, - hex_to_vec("6380a19495b51c52bd73a7111d5a4b0c022efedfb90d46660301ce365b0069c"), + hex_to_b32("6380a19495b51c52bd73a7111d5a4b0c022efedfb90d46660301ce365b0069c"), ), ( 2, - hex_to_vec("4c3abd3626c95cd55e330856ebc8cc85c8871349c28079149e1ee19f4ba7809"), + hex_to_b32("4c3abd3626c95cd55e330856ebc8cc85c8871349c28079149e1ee19f4ba7809"), ), ( 3, - hex_to_vec("28dc328d44f2a150c15de51b322b020adbf685b520cac210a314fa98efedab3"), + hex_to_b32("28dc328d44f2a150c15de51b322b020adbf685b520cac210a314fa98efedab3"), ), ( 4, - hex_to_vec("573f3d932cbfc0070b76aa652a82bd93bc0e92517068092b252788bd54bbe84"), + hex_to_b32("573f3d932cbfc0070b76aa652a82bd93bc0e92517068092b252788bd54bbe84"), ), ( 5, - hex_to_vec("26a109ece8e786838ad839a0513db66ff403cb97e6c35396b8e82ef014729ff"), + hex_to_b32("26a109ece8e786838ad839a0513db66ff403cb97e6c35396b8e82ef014729ff"), ), ( 6, - hex_to_vec("355834fe0fb7afcbd719967841a691822148ff959c16e5ba67114a9774c57e5"), + hex_to_b32("355834fe0fb7afcbd719967841a691822148ff959c16e5ba67114a9774c57e5"), ), ]); test_verify_true::>(&input, root_exp.clone()); diff --git a/commitment_scheme/src/packaging_commitment_scheme.rs b/commitment_scheme/src/packaging_commitment_scheme.rs index 177f41e..eaedd8c 100644 --- a/commitment_scheme/src/packaging_commitment_scheme.rs +++ b/commitment_scheme/src/packaging_commitment_scheme.rs @@ -1,6 +1,7 @@ use crate::merkle::hash::Hasher; use crate::packer_hasher::PackerHasher; use crate::{CommitmentSchemeProver, CommitmentSchemeVerifier}; +use anyhow::Error; use ark_ff::PrimeField; use channel::fs_prover_channel::FSProverChannel; use channel::fs_verifier_channel::FSVerifierChannel; @@ -34,7 +35,7 @@ pub struct PackagingCommitmentSchemeProver, P: Prng, } #[allow(dead_code)] -impl>, P: Prng, W: Digest> +impl, P: Prng, W: Digest> PackagingCommitmentSchemeProver { pub fn new( @@ -101,7 +102,7 @@ impl>, P: Prng, W: Digest> } } -impl>, P: Prng, W: Digest> CommitmentSchemeProver +impl, P: Prng, W: Digest> CommitmentSchemeProver for PackagingCommitmentSchemeProver { fn element_length_in_bytes(&self) -> usize { @@ -214,7 +215,7 @@ pub struct PackagingCommitmentSchemeVerifier, P: Prn } #[allow(dead_code)] -impl>, P: Prng, W: Digest> +impl, P: Prng, W: Digest> PackagingCommitmentSchemeVerifier { /// Constructs a new PackagingCommitmentSchemeVerifier using the commitment scheme factory input. @@ -321,7 +322,7 @@ impl>, P: Prng, W: Digest> } /// Implement CommitmentSchemeVerifier trait for PackagingCommitmentSchemeVerifier -impl>, P: Prng, W: Digest> CommitmentSchemeVerifier +impl, P: Prng, W: Digest> CommitmentSchemeVerifier for PackagingCommitmentSchemeVerifier { fn num_of_elements(&self) -> usize { @@ -332,7 +333,10 @@ impl>, P: Prng, W: Digest> Commitme self.inner_commitment_scheme.read_commitment() } - fn verify_integrity(&mut self, elements_to_verify: BTreeMap>) -> Option { + fn verify_integrity( + &mut self, + elements_to_verify: BTreeMap>, + ) -> Result { // Get missing elements required to compute hashes let keys: BTreeSet = elements_to_verify.keys().copied().collect(); let missing_elements_idxs = self.packer.elements_required_to_compute_hashes(&keys); @@ -342,11 +346,11 @@ impl>, P: Prng, W: Digest> Commitme for &missing_element_idx in &missing_elements_idxs { if self.is_merkle_layer { let mut channel = self.channel.borrow_mut(); - let result_array = channel.recv_decommit_node(H::DIGEST_NUM_BYTES).ok()?; + let result_array = channel.recv_decommit_node(H::DIGEST_NUM_BYTES)?; full_data_to_verify.insert(missing_element_idx, result_array.to_vec()); } else { let mut channel = self.channel.borrow_mut(); - let data = channel.recv_data(self.size_of_element).ok()?; + let data = channel.recv_data(self.size_of_element)?; full_data_to_verify.insert(missing_element_idx, data); } } diff --git a/commitment_scheme/src/packer_hasher.rs b/commitment_scheme/src/packer_hasher.rs index 5022661..6af39db 100644 --- a/commitment_scheme/src/packer_hasher.rs +++ b/commitment_scheme/src/packer_hasher.rs @@ -14,7 +14,7 @@ pub struct PackerHasher> { _ph: PhantomData<(F, H)>, } -impl>> PackerHasher { +impl> PackerHasher { /// Constructs a new PackerHasher. /// /// # Arguments @@ -234,7 +234,7 @@ fn compute_num_elements_in_package( /// # Returns /// /// Returns the resulting sequence of hashes as vector of bytes. -pub fn hash_elements>>( +pub fn hash_elements>( data: &[u8], n_elements: usize, ) -> Vec { @@ -267,7 +267,7 @@ pub fn hash_elements>>( /// # Returns /// /// Returns the resulting sequence of hashes as vector of bytes. -pub fn hash_elements_two_to_one>>( +pub fn hash_elements_two_to_one>( data: &[u8], ) -> Vec { // If data is empty, return an empty vector. @@ -285,11 +285,7 @@ pub fn hash_elements_two_to_one>>( // Compute the next hash layer. let mut res = Vec::with_capacity(n_elements_next_layer * H::DIGEST_NUM_BYTES); for i in 0..n_elements_next_layer { - let mut next_hash = H::node(&[ - bytes_as_hash[i * 2].clone(), - bytes_as_hash[i * 2 + 1].clone(), - ]) - .to_vec(); + let mut next_hash = H::node(&[bytes_as_hash[i * 2], bytes_as_hash[i * 2 + 1]]).to_vec(); res.append(&mut next_hash); } diff --git a/commitment_scheme/src/table_verifier.rs b/commitment_scheme/src/table_verifier.rs index 3d3eb9c..a459abe 100644 --- a/commitment_scheme/src/table_verifier.rs +++ b/commitment_scheme/src/table_verifier.rs @@ -1,6 +1,6 @@ use crate::table_utils::{all_query_rows, elements_to_be_transmitted, RowCol}; use crate::CommitmentSchemeVerifier; -use anyhow::Ok; +use anyhow::{Error, Ok}; use ark_ff::{BigInteger, PrimeField}; use channel::fs_verifier_channel::FSVerifierChannel; use channel::VerifierChannel; @@ -68,7 +68,7 @@ impl TableVerifier { /// Given indexed field elements, verify that these field elements are indeed the ones committed to /// by the prover, against the commitment obtained by read_commitment(). #[allow(dead_code)] - fn verify_decommitment(&mut self, all_rows_data: &BTreeMap) -> Option { + fn verify_decommitment(&mut self, all_rows_data: &BTreeMap) -> Result { let mut integrity_map: BTreeMap> = BTreeMap::new(); let element_size = F::MODULUS_BIT_SIZE.div_ceil(8) as usize;