Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 15, 2021
1 parent 880a0e9 commit 6b9ceff
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
17 changes: 6 additions & 11 deletions filecoin-proofs/src/api/post_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ pub fn partition_vanilla_proofs<Tree: MerkleTreeTrait>(
randomness: pub_inputs.randomness,
prover_id: pub_inputs.prover_id,
sectors: sectors_chunk.to_vec(),
k: pub_inputs.k,
k: Some(j),
},
vanilla_proofs,
j,
)?;
partition_proofs.push(proof);
}
Expand All @@ -228,9 +227,8 @@ pub fn partition_vanilla_proofs<Tree: MerkleTreeTrait>(
let proof = single_partition_vanilla_proofs(
post_config,
pub_params,
pub_inputs,
&fallback::FallbackPoSt::<Tree>::with_partition(pub_inputs.clone(), Some(j)),
sectors_chunk,
j,
)?;
partition_proofs.push(proof);
}
Expand Down Expand Up @@ -265,9 +263,11 @@ pub fn single_partition_vanilla_proofs<Tree: MerkleTreeTrait>(
pub_params: &fallback::PublicParams,
pub_inputs: &fallback::PublicInputs<<Tree::Hasher as Hasher>::Domain>,
vanilla_proofs: &[FallbackPoStSectorProof<Tree>],
partition_index: usize,
) -> Result<VanillaProof<Tree>> {
info!("single_partition_vanilla_proofs:start");
ensure!(pub_inputs.k.is_some(), "must have a partition index");
let partition_index = pub_inputs.k.unwrap();

debug!("processing partition: {}", partition_index);
ensure!(
post_config.typ == PoStType::Window || post_config.typ == PoStType::Winning,
Expand Down Expand Up @@ -363,12 +363,7 @@ pub fn single_partition_vanilla_proofs<Tree: MerkleTreeTrait>(
info!("single_partition_vanilla_proofs:finish");

ensure!(
FallbackPoSt::<Tree>::verify_single_partitions(
pub_params,
pub_inputs,
&partition_proof,
partition_index,
)?,
FallbackPoSt::<Tree>::verify(pub_params, pub_inputs, &partition_proof,)?,
"partitioned vanilla proofs failed to verify"
);

Expand Down
3 changes: 1 addition & 2 deletions filecoin-proofs/src/api/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,14 @@ pub fn generate_single_window_post_with_vanilla<Tree: 'static + MerkleTreeTrait>
randomness: randomness_safe,
prover_id: prover_id_safe,
sectors: pub_sectors,
k: None,
k: Some(partition_index),
};

let partitioned_proofs = single_partition_vanilla_proofs(
&post_config,
&pub_params.vanilla_params,
&pub_inputs,
&vanilla_proofs,
partition_index,
)?;

let proof = FallbackPoStCompound::prove_with_vanilla(
Expand Down
13 changes: 0 additions & 13 deletions storage-proofs-core/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ pub trait ProofScheme<'a> {
Ok(true)
}

fn verify_single_partitions(
pub_params: &Self::PublicParams,
pub_in: &Self::PublicInputs,
proof: &Self::Proof,
partition_index: usize,
) -> Result<bool> {
let partition_pub_in = Self::with_partition((*pub_in).clone(), Some(partition_index));
if !Self::verify(pub_params, &partition_pub_in, proof)? {
return Ok(false);
}
Ok(true)
}

// This method must be specialized by concrete ProofScheme implementations which use partitions.
fn with_partition(pub_in: Self::PublicInputs, _k: Option<usize>) -> Self::PublicInputs {
pub_in
Expand Down
20 changes: 13 additions & 7 deletions storage-proofs-post/src/fallback/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,15 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
.zip(pub_inputs.sectors.chunks(num_sectors_per_chunk))
.enumerate()
{
let is_valid = Self::verify_single_partitions(
let is_valid = Self::verify(
pub_params,
&PublicInputs {
randomness: pub_inputs.randomness,
prover_id: pub_inputs.prover_id,
sectors: pub_sectors_chunk.to_vec(),
k: pub_inputs.k,
k: Some(j),
},
proof,
j,
)?;

if !is_valid {
Expand All @@ -531,6 +530,11 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
Ok(true)
}

fn with_partition(mut pub_in: Self::PublicInputs, k: Option<usize>) -> Self::PublicInputs {
pub_in.k = k;
pub_in
}

fn satisfies_requirements(
public_params: &Self::PublicParams,
requirements: &Self::Requirements,
Expand All @@ -550,14 +554,16 @@ impl<'a, Tree: 'a + MerkleTreeTrait> ProofScheme<'a> for FallbackPoSt<'a, Tree>
checked * public_params.challenge_count >= requirements.minimum_challenge_count
}

// Verify vanilla proofs for a single partition.
// Calculate the offset for the challenge position of the sector
fn verify_single_partitions(
fn verify(
pub_params: &Self::PublicParams,
pub_inputs: &Self::PublicInputs,
partition_proof: &Self::Proof,
partition_index: usize,
) -> Result<bool> {
ensure!(
pub_inputs.k.is_some(),
"must be called with a partition index"
);
let partition_index = pub_inputs.k.unwrap();
let challenge_count = pub_params.challenge_count;
let num_sectors_per_chunk = pub_params.sector_count;

Expand Down

0 comments on commit 6b9ceff

Please sign in to comment.