diff --git a/filecoin-proofs/src/api/post_util.rs b/filecoin-proofs/src/api/post_util.rs index e1d6d117d5..2015919059 100644 --- a/filecoin-proofs/src/api/post_util.rs +++ b/filecoin-proofs/src/api/post_util.rs @@ -215,10 +215,9 @@ pub fn partition_vanilla_proofs( 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); } @@ -228,9 +227,8 @@ pub fn partition_vanilla_proofs( let proof = single_partition_vanilla_proofs( post_config, pub_params, - pub_inputs, + &fallback::FallbackPoSt::::with_partition(pub_inputs.clone(), Some(j)), sectors_chunk, - j, )?; partition_proofs.push(proof); } @@ -265,9 +263,11 @@ pub fn single_partition_vanilla_proofs( pub_params: &fallback::PublicParams, pub_inputs: &fallback::PublicInputs<::Domain>, vanilla_proofs: &[FallbackPoStSectorProof], - partition_index: usize, ) -> Result> { 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, @@ -363,12 +363,7 @@ pub fn single_partition_vanilla_proofs( info!("single_partition_vanilla_proofs:finish"); ensure!( - FallbackPoSt::::verify_single_partitions( - pub_params, - pub_inputs, - &partition_proof, - partition_index, - )?, + FallbackPoSt::::verify(pub_params, pub_inputs, &partition_proof,)?, "partitioned vanilla proofs failed to verify" ); diff --git a/filecoin-proofs/src/api/window_post.rs b/filecoin-proofs/src/api/window_post.rs index 5b73b22304..20454a7f59 100644 --- a/filecoin-proofs/src/api/window_post.rs +++ b/filecoin-proofs/src/api/window_post.rs @@ -290,7 +290,7 @@ pub fn generate_single_window_post_with_vanilla randomness: randomness_safe, prover_id: prover_id_safe, sectors: pub_sectors, - k: None, + k: Some(partition_index), }; let partitioned_proofs = single_partition_vanilla_proofs( @@ -298,7 +298,6 @@ pub fn generate_single_window_post_with_vanilla &pub_params.vanilla_params, &pub_inputs, &vanilla_proofs, - partition_index, )?; let proof = FallbackPoStCompound::prove_with_vanilla( diff --git a/storage-proofs-core/src/proof.rs b/storage-proofs-core/src/proof.rs index 21a1683296..2b39a9fc69 100644 --- a/storage-proofs-core/src/proof.rs +++ b/storage-proofs-core/src/proof.rs @@ -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 { - 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) -> Self::PublicInputs { pub_in diff --git a/storage-proofs-post/src/fallback/vanilla.rs b/storage-proofs-post/src/fallback/vanilla.rs index 9899f74174..85de70c497 100644 --- a/storage-proofs-post/src/fallback/vanilla.rs +++ b/storage-proofs-post/src/fallback/vanilla.rs @@ -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 { @@ -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) -> Self::PublicInputs { + pub_in.k = k; + pub_in + } + fn satisfies_requirements( public_params: &Self::PublicParams, requirements: &Self::Requirements, @@ -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 { + 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;