From a6bfc1ae92f910e564c9705184877a260c996ecd Mon Sep 17 00:00:00 2001 From: M Alghazwi Date: Sat, 9 Nov 2024 11:37:08 +0100 Subject: [PATCH] fix mask_bits bug --- proof-input/src/gen_input.rs | 13 ++++++++++--- proof-input/src/utils.rs | 7 ------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/proof-input/src/gen_input.rs b/proof-input/src/gen_input.rs index c4505fb..9915f2d 100644 --- a/proof-input/src/gen_input.rs +++ b/proof-input/src/gen_input.rs @@ -86,7 +86,9 @@ pub fn verify_witness< params.max_depth, mask_bits.clone(), ); + let cell_index = bits_le_padded_to_usize(&cell_index_bits); + println!("cell index ={}", cell_index); let s_res = verify_cell_proof(&witness, ¶ms, cell_index, i); if s_res.unwrap() == false { @@ -118,14 +120,18 @@ pub fn verify_cell_proof< let mut block_path = witness.merkle_paths[ctr].path.clone(); let slot_path = block_path.split_off(split_point); - let mask_bits = usize_to_bits_le_padded(last_index, params.max_depth+1); + let mut block_mask_bits = usize_to_bits_le_padded(last_index, params.max_depth+1); + let mut slot_mask_bits = block_mask_bits.split_off(split_point); + + block_mask_bits.push(false); + slot_mask_bits.push(false); let block_res = MerkleProof::::reconstruct_root2( leaf_hash, block_path_bits.clone(), block_last_bits.clone(), block_path, - mask_bits.clone(), + block_mask_bits, params.bot_depth(), ); let reconstructed_root = MerkleProof::::reconstruct_root2( @@ -133,7 +139,7 @@ pub fn verify_cell_proof< slot_path_bits, slot_last_bits, slot_path, - mask_bits.clone(), + slot_mask_bits, params.max_depth - params.bot_depth(), ); @@ -359,6 +365,7 @@ impl< mask_bits.clone() ); let cell_index = bits_le_padded_to_usize(&cell_index_bits); + println!("sample cell index = {}", cell_index); let mut s_proof = slot.get_proof(cell_index); Self::pad_proof(&mut s_proof, self.params.max_depth); slot_proofs.push(s_proof); diff --git a/proof-input/src/utils.rs b/proof-input/src/utils.rs index d9c0c11..af11e53 100644 --- a/proof-input/src/utils.rs +++ b/proof-input/src/utils.rs @@ -50,13 +50,6 @@ pub(crate) fn calculate_cell_index_bits< masked_cell_index_bits } -pub(crate) fn take_n_bits_from_bytes(bytes: &[u8], n: usize) -> Vec { - bytes.iter() - .flat_map(|byte| (0..8u8).map(move |i| (byte >> i) & 1 == 1)) - .take(n) - .collect() -} - /// Converts a vector of bits (LSB first) into an index (usize). pub(crate) fn bits_le_padded_to_usize(bits: &[bool]) -> usize { bits.iter().enumerate().fold(0usize, |acc, (i, &bit)| {