Skip to content

Commit

Permalink
fix: apply some review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptonemo committed Oct 26, 2023
1 parent faecfd5 commit 7563ddf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 76 deletions.
33 changes: 1 addition & 32 deletions filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use typenum::{Unsigned, U11, U2};

use crate::POREP_MINIMUM_CHALLENGES;
use crate::{
api::util::{get_aggregate_target_len, pad_proofs_to_target},
api::util::{get_aggregate_target_len, pad_inputs_to_target, pad_proofs_to_target},
api::{as_safe_commitment, commitment_from_fr, get_base_tree_leafs, get_base_tree_size, util},
caches::{
get_stacked_params, get_stacked_srs_key, get_stacked_srs_verifier_key,
Expand Down Expand Up @@ -669,37 +669,6 @@ pub fn get_seal_inputs<Tree: 'static + MerkleTreeTrait>(
Ok(inputs)
}

/// Given a list of public inputs and a target_len, make sure that the inputs list is padded to the target_len size.
fn pad_inputs_to_target(
commit_inputs: &[Vec<Fr>],
num_inputs_per_proof: usize,
target_len: usize,
) -> Result<Vec<Vec<Fr>>> {
ensure!(
!commit_inputs.is_empty(),
"cannot aggregate with empty public inputs"
);

let mut num_inputs = commit_inputs.len();
let mut new_inputs = commit_inputs.to_owned();

if target_len != num_inputs {
ensure!(
target_len > num_inputs,
"target len must be greater than actual num inputs"
);
let duplicate_inputs = &commit_inputs[(num_inputs - num_inputs_per_proof)..num_inputs];

trace!("padding inputs from {} to {}", num_inputs, target_len);
while target_len != num_inputs {
new_inputs.extend_from_slice(duplicate_inputs);
num_inputs += num_inputs_per_proof;
}
}

Ok(new_inputs)
}

/// Given a porep_config and a list of seal commit outputs, this method aggregates
/// those proofs (naively padding the count if necessary up to a power of 2) and
/// returns the aggregate proof bytes.
Expand Down
47 changes: 3 additions & 44 deletions filecoin-proofs/src/api/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use storage_proofs_update::{
};

use crate::{
api::util::{self, get_aggregate_target_len, pad_proofs_to_target},
api::util::{self, get_aggregate_target_len, pad_inputs_to_target, pad_proofs_to_target},
caches::{
get_empty_sector_update_params, get_empty_sector_update_verifying_key, get_stacked_srs_key,
get_stacked_srs_verifier_key,
Expand Down Expand Up @@ -62,47 +62,6 @@ impl SectorUpdateProofInputs {
}
}

/// Given a list of public inputs and a target_len, make sure that the inputs list is padded to the target_len size.
fn pad_inputs_to_target(
sector_update_inputs: &[Vec<Fr>],
num_inputs_per_proof: usize,
target_len: usize,
) -> Result<Vec<Vec<Fr>>> {
ensure!(
!sector_update_inputs.is_empty(),
"cannot aggregate with empty public inputs"
);

let mut num_inputs = sector_update_inputs.len();
let mut new_inputs = sector_update_inputs.to_owned();

trace!(
"pad_inputs_to_target target_len {}, inputs len {}",
target_len,
num_inputs
);
if target_len != num_inputs {
ensure!(
target_len > num_inputs,
"target len must be greater than actual num inputs"
);
let duplicate_inputs =
&sector_update_inputs[(num_inputs - num_inputs_per_proof)..num_inputs];

trace!("padding inputs from {} to {}", num_inputs, target_len);
while target_len != num_inputs {
new_inputs.extend_from_slice(duplicate_inputs);
num_inputs += num_inputs_per_proof;
ensure!(
num_inputs <= target_len,
"num_inputs extended beyond target"
);
}
}

Ok(new_inputs)
}

// Re-instantiate a t_aux with the new cache path, then use the tree_d
// and tree_r_last configs from it. This is done to preserve the
// original tree configuration info (in particular, the
Expand Down Expand Up @@ -758,7 +717,7 @@ pub fn get_sector_update_inputs<Tree: 'static + MerkleTreeTrait<Hasher = TreeRHa
let partitions = usize::from(config.update_partitions);

let public_inputs: storage_proofs_update::PublicInputs = PublicInputs {
k: partitions,
k: 0,
comm_r_old: comm_r_old_safe,
comm_d_new: comm_d_new_safe,
comm_r_new: comm_r_new_safe,
Expand All @@ -769,7 +728,7 @@ pub fn get_sector_update_inputs<Tree: 'static + MerkleTreeTrait<Hasher = TreeRHa
sector_bytes: u64::from(config.sector_size),
},
partitions: Some(partitions),
priority: true,
priority: false,
};
let pub_params_compound = EmptySectorUpdateCompound::<Tree>::setup(&setup_params_compound)?;

Expand Down
35 changes: 35 additions & 0 deletions filecoin-proofs/src/api/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,38 @@ pub(crate) fn pad_proofs_to_target(

Ok(())
}

/// Given a list of public inputs and a target_len, make sure that the inputs list is padded to the target_len size.
pub(crate) fn pad_inputs_to_target(
fr_inputs: &[Vec<Fr>],
num_inputs_per_proof: usize,
target_len: usize,
) -> Result<Vec<Vec<Fr>>> {
ensure!(
!fr_inputs.is_empty(),
"cannot aggregate with empty public inputs"
);

let mut num_inputs = fr_inputs.len();
let mut new_inputs = fr_inputs.to_owned();

if target_len != num_inputs {
ensure!(
target_len > num_inputs,
"target len must be greater than actual num inputs"
);
let duplicate_inputs = &fr_inputs[(num_inputs - num_inputs_per_proof)..num_inputs];

trace!("padding inputs from {} to {}", num_inputs, target_len);
while target_len != num_inputs {
new_inputs.extend_from_slice(duplicate_inputs);
num_inputs += num_inputs_per_proof;
ensure!(
num_inputs <= target_len,
"num_inputs extended beyond target"
);
}
}

Ok(new_inputs)
}

0 comments on commit 7563ddf

Please sign in to comment.