fix mask_bits bug
This commit is contained in:
parent
0696e6477b
commit
a6bfc1ae92
|
@ -86,7 +86,9 @@ pub fn verify_witness<
|
||||||
params.max_depth,
|
params.max_depth,
|
||||||
mask_bits.clone(),
|
mask_bits.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let cell_index = bits_le_padded_to_usize(&cell_index_bits);
|
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);
|
let s_res = verify_cell_proof(&witness, ¶ms, cell_index, i);
|
||||||
if s_res.unwrap() == false {
|
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 mut block_path = witness.merkle_paths[ctr].path.clone();
|
||||||
let slot_path = block_path.split_off(split_point);
|
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::<F,D>::reconstruct_root2(
|
let block_res = MerkleProof::<F,D>::reconstruct_root2(
|
||||||
leaf_hash,
|
leaf_hash,
|
||||||
block_path_bits.clone(),
|
block_path_bits.clone(),
|
||||||
block_last_bits.clone(),
|
block_last_bits.clone(),
|
||||||
block_path,
|
block_path,
|
||||||
mask_bits.clone(),
|
block_mask_bits,
|
||||||
params.bot_depth(),
|
params.bot_depth(),
|
||||||
);
|
);
|
||||||
let reconstructed_root = MerkleProof::<F,D>::reconstruct_root2(
|
let reconstructed_root = MerkleProof::<F,D>::reconstruct_root2(
|
||||||
|
@ -133,7 +139,7 @@ pub fn verify_cell_proof<
|
||||||
slot_path_bits,
|
slot_path_bits,
|
||||||
slot_last_bits,
|
slot_last_bits,
|
||||||
slot_path,
|
slot_path,
|
||||||
mask_bits.clone(),
|
slot_mask_bits,
|
||||||
params.max_depth - params.bot_depth(),
|
params.max_depth - params.bot_depth(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -359,6 +365,7 @@ impl<
|
||||||
mask_bits.clone()
|
mask_bits.clone()
|
||||||
);
|
);
|
||||||
let cell_index = bits_le_padded_to_usize(&cell_index_bits);
|
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);
|
let mut s_proof = slot.get_proof(cell_index);
|
||||||
Self::pad_proof(&mut s_proof, self.params.max_depth);
|
Self::pad_proof(&mut s_proof, self.params.max_depth);
|
||||||
slot_proofs.push(s_proof);
|
slot_proofs.push(s_proof);
|
||||||
|
|
|
@ -50,13 +50,6 @@ pub(crate) fn calculate_cell_index_bits<
|
||||||
masked_cell_index_bits
|
masked_cell_index_bits
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn take_n_bits_from_bytes(bytes: &[u8], n: usize) -> Vec<bool> {
|
|
||||||
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).
|
/// Converts a vector of bits (LSB first) into an index (usize).
|
||||||
pub(crate) fn bits_le_padded_to_usize(bits: &[bool]) -> usize {
|
pub(crate) fn bits_le_padded_to_usize(bits: &[bool]) -> usize {
|
||||||
bits.iter().enumerate().fold(0usize, |acc, (i, &bit)| {
|
bits.iter().enumerate().fold(0usize, |acc, (i, &bit)| {
|
||||||
|
|
Loading…
Reference in New Issue