Skip to content

Commit

Permalink
refactor: improve naming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPeterVanNostrand authored and cryptonemo committed Dec 9, 2021
1 parent a826d59 commit 1266749
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions storage-proofs-update/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ where
partition_count,
partition_bit_len,
apex_leaf_count,
apex_select_bit_len,
apex_leaf_bit_len,
},
pub_inputs:
PublicInputs {
Expand Down Expand Up @@ -691,9 +691,9 @@ where
root_r_new.clone(),
)?;

let apex_select_bits: Vec<Boolean> = {
let start = challenge_bit_len - partition_bit_len - apex_select_bit_len;
let stop = start + apex_select_bit_len;
let apex_leaf_bits: Vec<Boolean> = {
let start = challenge_bit_len - partition_bit_len - apex_leaf_bit_len;
let stop = start + apex_leaf_bit_len;
c_bits[start..stop]
.iter()
.cloned()
Expand All @@ -704,10 +704,10 @@ where
let apex_leaf = select(
cs.namespace(|| format!("select_apex_leaf (c_index={})", c_index)),
&apex_leafs,
&apex_select_bits,
&apex_leaf_bits,
)?;

let path_len_to_apex_leaf = challenge_bit_len - partition_bit_len - apex_select_bit_len;
let path_len_to_apex_leaf = challenge_bit_len - partition_bit_len - apex_leaf_bit_len;

let c_bits_to_apex_leaf: Vec<AllocatedBit> =
c_bits.into_iter().take(path_len_to_apex_leaf).collect();
Expand Down
1 change: 0 additions & 1 deletion storage-proofs-update/src/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ where
comm_r_new,
);

// `comm_c` is a public-input for the vanilla proof and a private-input for the circuit.
let priv_inputs = circuit::PrivateInputs::new(
vanilla_proof.comm_c,
&vanilla_proof.apex_leafs,
Expand Down
39 changes: 20 additions & 19 deletions storage-proofs-update/src/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct PublicParams {
pub apex_leaf_count: usize,
// The bit length of an integer in `0..apex_leaf_count` which is also the height of each
// partition's apex-tree.
pub apex_select_bit_len: usize,
pub apex_leaf_bit_len: usize,
}

impl ParameterSetMetadata for PublicParams {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl PublicParams {

let apex_leaf_count = apex_leaf_count(sector_nodes);
// `apex_leaf_count` is guaranteed to be a power of two.
let apex_select_bit_len = apex_leaf_count.trailing_zeros() as usize;
let apex_leaf_bit_len = apex_leaf_count.trailing_zeros() as usize;

PublicParams {
sector_nodes,
Expand All @@ -113,7 +113,7 @@ impl PublicParams {
partition_count,
partition_bit_len,
apex_leaf_count,
apex_select_bit_len,
apex_leaf_bit_len,
}
}
}
Expand Down Expand Up @@ -185,11 +185,12 @@ where
{
pub fn verify_merkle_proofs(
&self,
c: usize,
c: u32,
root_r_old: &TreeRDomain,
comm_d_new: &TreeDDomain,
root_r_new: &TreeRDomain,
) -> bool {
let c = c as usize;
self.proof_r_old.path_index() == c
&& self.proof_d_new.path_index() == c
&& self.proof_r_new.path_index() == c
Expand Down Expand Up @@ -341,7 +342,7 @@ where
partition_count,
partition_bit_len,
apex_leaf_count,
apex_select_bit_len,
apex_leaf_bit_len,
} = *pub_params;

let PublicInputs {
Expand Down Expand Up @@ -377,7 +378,7 @@ where

// Compute apex-tree.
let mut apex_tree: Vec<Vec<TreeDDomain>> = vec![apex_leafs.clone()];
for _ in 0..apex_select_bit_len {
for _ in 0..apex_leaf_bit_len {
let tree_row: Vec<TreeDDomain> = apex_tree
.last()
.unwrap()
Expand All @@ -391,8 +392,8 @@ where

// All TreeDNew Merkle proofs should have an apex-leaf at height `apex_leafs_height` in the
// proof path, i.e. TreeDNew has height `challenge_bit_len`, partition-tree has height
// `partition_bit_len`, and apex-tree has height `apex_select_bit_len`.
let apex_leafs_height = challenge_bit_len - partition_bit_len - apex_select_bit_len;
// `partition_bit_len`, and apex-tree has height `apex_leaf_bit_len`.
let apex_leafs_height = challenge_bit_len - partition_bit_len - apex_leaf_bit_len;

let root_r_old = challenge_proofs[0].proof_r_old.root();
let root_r_new = challenge_proofs[0].proof_r_new.root();
Expand All @@ -414,13 +415,8 @@ where
.into_par_iter()
.zip(challenge_proofs.into_par_iter())
.all(|(c, challenge_proof)| {
// Verify TreeROld Merkle proof.
if !challenge_proof.verify_merkle_proofs(
c as usize,
&root_r_old,
&comm_d_new,
&root_r_new,
) {
// Verify TreeROld, TreeDNew, and TreeRNew Merkle proofs.
if !challenge_proof.verify_merkle_proofs(c, &root_r_old, &comm_d_new, &root_r_new) {
return false;
}

Expand All @@ -435,12 +431,17 @@ where
return false;
}

// Verify that the TreeDNew Merkle proof's apex-path is consistent with apex-tree.
challenge_proof.proof_d_new.path()
[apex_leafs_height..apex_leafs_height + apex_select_bit_len]
// Check that apex-path is consistent with apex-tree.
let apex_path = &challenge_proof.proof_d_new.path()
[apex_leafs_height..apex_leafs_height + apex_leaf_bit_len];

apex_path
.iter()
.zip(apex_tree.iter())
.all(|(path_elem, apex_tree_row)| apex_tree_row.contains(&path_elem.0[0]))
.all(|(path_elem, apex_tree_row)| {
let sibling = &path_elem.0[0];
apex_tree_row.contains(sibling)
})
});

Ok(challenge_proofs_are_valid)
Expand Down

0 comments on commit 1266749

Please sign in to comment.