Skip to content

Commit

Permalink
Add CompoundProof Requirements and add ChallengeRequirements for laye…
Browse files Browse the repository at this point in the history
…red DrgPoRep.
  • Loading branch information
porcuquine committed Apr 16, 2019
1 parent b77ef12 commit 14166be
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 32 deletions.
13 changes: 10 additions & 3 deletions filecoin-proofs/examples/zigzag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use storage_proofs::drgraph::*;
use storage_proofs::example_helper::prettyb;
use storage_proofs::fr32::fr_into_bytes;
use storage_proofs::hasher::{Blake2sHasher, Hasher, PedersenHasher, Sha256Hasher};
use storage_proofs::layered_drgporep::{self, LayerChallenges};
use storage_proofs::layered_drgporep::{self, ChallengeRequirements, LayerChallenges};
use storage_proofs::porep::PoRep;
use storage_proofs::proof::ProofScheme;
use storage_proofs::zigzag_drgporep::*;
Expand Down Expand Up @@ -371,8 +371,15 @@ fn do_the_work<H: 'static>(
for _ in 0..samples {
let start = Instant::now();
let cur_result = result;
ZigZagCompound::verify(&compound_public_params, &pub_inputs, &multi_proof)
.unwrap();
ZigZagCompound::verify(
&compound_public_params,
&pub_inputs,
&multi_proof,
&ChallengeRequirements {
minimum_challenges: 1,
},
)
.unwrap();
// If one verification fails, result becomes permanently false.
result = result && cur_result;
total_groth_verifying += start.elapsed();
Expand Down
26 changes: 20 additions & 6 deletions filecoin-proofs/src/api/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ use storage_proofs::drgraph::{DefaultTreeHasher, Graph};
use storage_proofs::fr32::{bytes_into_fr, fr_into_bytes, Fr32Ary};
use storage_proofs::hasher::pedersen::{PedersenDomain, PedersenHasher};
use storage_proofs::hasher::{Domain, Hasher};
use storage_proofs::layered_drgporep::{self, LayerChallenges};
use storage_proofs::layered_drgporep::{self, ChallengeRequirements, LayerChallenges};
use storage_proofs::merkle::MerkleTree;
use storage_proofs::porep::{replica_id, PoRep, Tau};
use storage_proofs::proof::ProofScheme;
use storage_proofs::proof::{NoRequirements, ProofScheme};
use storage_proofs::vdf_post::{self, VDFPoSt};
use storage_proofs::vdf_sloth::{self, Sloth};
use storage_proofs::zigzag_drgporep::ZigZagDrgPoRep;
Expand All @@ -55,6 +55,8 @@ const SNARK_BYTES: usize = 192;
const POREP_PARTITIONS: usize = 2;
const POREP_PROOF_BYTES: usize = SNARK_BYTES * POREP_PARTITIONS;

const POREP_MINIMUM_CHALLENGES: usize = 1; // FIXME: 8,000

const POST_PARTITIONS: usize = 1;
const POST_PROOF_BYTES: usize = SNARK_BYTES * POST_PARTITIONS;

Expand Down Expand Up @@ -438,9 +440,13 @@ fn verify_post_fixed_sectors_count(
// For some reason, the circuit test does not verify when called in tests here.
// However, everything up to that point does/should work — so we want to continue to exercise
// for integration purposes.
let _fixme_ignore: error::Result<bool> =
VDFPostCompound::verify(&compound_public_params, &public_inputs, &proof)
.map_err(Into::into);
let _fixme_ignore: error::Result<bool> = VDFPostCompound::verify(
&compound_public_params,
&public_inputs,
&proof,
&NoRequirements(),
)
.map_err(Into::into);

// Since callers may rely on previous mocked success, just pretend verification succeeded, for now.
Ok(VerifyPoStFixedSectorsCountOutput { is_valid: true })
Expand Down Expand Up @@ -679,7 +685,15 @@ pub fn verify_seal(
&verifying_key,
)?;

ZigZagCompound::verify(&compound_public_params, &public_inputs, &proof).map_err(Into::into)
ZigZagCompound::verify(
&compound_public_params,
&public_inputs,
&proof,
&ChallengeRequirements {
minimum_challenges: POREP_MINIMUM_CHALLENGES,
},
)
.map_err(Into::into)
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/src/batchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::Result;
use crate::hasher::{Domain, Hasher};
use crate::merkle::MerkleTree;
use crate::merklepor;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};
use crate::util::data_at_node;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -71,6 +71,7 @@ impl<'a, H: 'a + Hasher> ProofScheme<'a> for BatchPoST<H> {
type PublicInputs = PublicInputs<'a, H::Domain>;
type PrivateInputs = PrivateInputs<'a, H>;
type Proof = Proof<H>;
type Requirements = NoRequirements;

fn setup(_sp: &Self::SetupParams) -> Result<Self::PublicParams> {
// merklepor does not have a setup currently
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/src/beacon_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::error::{Error, Result};
use crate::hasher::{Domain, Hasher};
use crate::merkle::MerkleTree;
use crate::parameter_cache::ParameterSetIdentifier;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};
use crate::vdf::Vdf;
use crate::vdf_post;

Expand Down Expand Up @@ -118,6 +118,7 @@ where
type PublicInputs = PublicInputs<H::Domain>;
type PrivateInputs = PrivateInputs<'a, H>;
type Proof = Proof<'a, H, V>;
type Requirements = NoRequirements;

fn setup(sp: &SetupParams<H::Domain, V>) -> Result<PublicParams<H::Domain, V>> {
Ok(PublicParams {
Expand Down
11 changes: 8 additions & 3 deletions storage-proofs/src/circuit/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ mod tests {
use crate::fr32::{bytes_into_fr, fr_into_bytes};
use crate::hasher::{Blake2sHasher, Hasher, PedersenHasher};
use crate::porep::PoRep;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};
use crate::util::data_at_node;

use ff::Field;
Expand Down Expand Up @@ -833,8 +833,13 @@ mod tests {
)
.expect("failed while proving");

let verified = DrgPoRepCompound::<H, _>::verify(&public_params, &public_inputs, &proof)
.expect("failed while verifying");
let verified = DrgPoRepCompound::<H, _>::verify(
&public_params,
&public_inputs,
&proof,
&NoRequirements(),
)
.expect("failed while verifying");

assert!(verified);
}
Expand Down
17 changes: 11 additions & 6 deletions storage-proofs/src/circuit/por.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::drgraph::graph_height;
use crate::hasher::{HashFunction, Hasher};
use crate::merklepor::MerklePoR;
use crate::parameter_cache::{CacheableParameters, ParameterSetIdentifier};
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};

/// Proof of retrievability.
///
Expand Down Expand Up @@ -309,9 +309,13 @@ mod tests {
)
.expect("failed while proving");

let verified =
PoRCompound::<PedersenHasher>::verify(&public_params, &public_inputs, &proof)
.expect("failed while verifying");
let verified = PoRCompound::<PedersenHasher>::verify(
&public_params,
&public_inputs,
&proof,
&NoRequirements(),
)
.expect("failed while verifying");
assert!(verified);

let (circuit, inputs) = PoRCompound::<PedersenHasher>::circuit_for_test(
Expand Down Expand Up @@ -507,8 +511,9 @@ mod tests {
assert!(cs.verify(&inputs));
}

let verified = PoRCompound::<H>::verify(&public_params, &public_inputs, &proof)
.expect("failed while verifying");
let verified =
PoRCompound::<H>::verify(&public_params, &public_inputs, &proof, &NoRequirements())
.expect("failed while verifying");
assert!(verified);
}
}
Expand Down
11 changes: 8 additions & 3 deletions storage-proofs/src/circuit/porc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ mod tests {
use crate::fr32::fr_into_bytes;
use crate::hasher::pedersen::*;
use crate::porc::{self, PoRC};
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};

#[test]
fn test_porc_circuit_with_bls12_381() {
Expand Down Expand Up @@ -445,8 +445,13 @@ mod tests {
assert!(cs.is_satisfied());
assert!(cs.verify(&inputs));

let verified = PoRCCompound::<PedersenHasher>::verify(&pub_params, &pub_inputs, &proof)
.expect("failed while verifying");
let verified = PoRCCompound::<PedersenHasher>::verify(
&pub_params,
&pub_inputs,
&proof,
&NoRequirements(),
)
.expect("failed while verifying");

assert!(verified);
}
Expand Down
4 changes: 2 additions & 2 deletions storage-proofs/src/circuit/vdf_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ mod tests {
use crate::drgraph::{new_seed, BucketGraph, Graph};
use crate::fr32::fr_into_bytes;
use crate::hasher::pedersen::*;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};
use crate::vdf_post;
use crate::vdf_sloth;

Expand Down Expand Up @@ -632,7 +632,7 @@ mod tests {
// }
// }

let verified = VDFPostCompound::verify(&pub_params, &pub_inputs, &proof)
let verified = VDFPostCompound::verify(&pub_params, &pub_inputs, &proof, &NoRequirements())
.expect("failed while verifying");

assert!(verified);
Expand Down
13 changes: 10 additions & 3 deletions storage-proofs/src/circuit/zigzag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
use crate::drgraph::new_seed;
use crate::fr32::fr_into_bytes;
use crate::hasher::{Blake2sHasher, Hasher, PedersenHasher};
use crate::layered_drgporep::{self, LayerChallenges};
use crate::layered_drgporep::{self, ChallengeRequirements, LayerChallenges};
use crate::porep::PoRep;
use crate::proof::ProofScheme;

Expand Down Expand Up @@ -698,8 +698,15 @@ mod tests {
)
.expect("failed while proving");

let verified = ZigZagCompound::verify(&public_params, &public_inputs, &proof)
.expect("failed while verifying");
let verified = ZigZagCompound::verify(
&public_params,
&public_inputs,
&proof,
&ChallengeRequirements {
minimum_challenges: 1,
},
)
.expect("failed while verifying");

assert!(verified);
}
Expand Down
9 changes: 9 additions & 0 deletions storage-proofs/src/compound_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@ where
public_params: &PublicParams<'a, E, S>,
public_inputs: &S::PublicInputs,
multi_proof: &MultiProof<E>,
requirements: &S::Requirements,
) -> Result<bool> {
let vanilla_public_params = &public_params.vanilla_params;
let pvk = groth16::prepare_verifying_key(&multi_proof.verifying_key);
if multi_proof.circuit_proofs.len() != Self::partition_count(public_params) {
return Ok(false);
}

if !<S as ProofScheme>::satisfies_requirements(
&public_params.vanilla_params,
requirements,
multi_proof.circuit_proofs.len(),
) {
return Ok(false);
}

for (k, circuit_proof) in multi_proof.circuit_proofs.iter().enumerate() {
let inputs =
Self::generate_public_inputs(public_inputs, vanilla_public_params, Some(k));
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/src/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::hasher::{Domain, Hasher};
use crate::merkle::{MerkleProof, MerkleTree};
use crate::parameter_cache::ParameterSetIdentifier;
use crate::porep::{self, PoRep};
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};
use crate::vde::{self, decode_block, decode_domain_block};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -248,6 +248,7 @@ where
type PublicInputs = PublicInputs<H::Domain>;
type PrivateInputs = PrivateInputs<'a, H>;
type Proof = Proof<H>;
type Requirements = NoRequirements;

fn setup(sp: &Self::SetupParams) -> Result<Self::PublicParams> {
let graph = G::new(
Expand Down
16 changes: 16 additions & 0 deletions storage-proofs/src/layered_drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ pub struct Tau<T: Domain> {
pub comm_r_star: T,
}

#[derive(Default)]
pub struct ChallengeRequirements {
pub minimum_challenges: usize,
}

impl<T: Domain> Tau<T> {
/// Return a single porep::Tau with the initial data and final replica commitments of layer_taus.
pub fn simplify(&self) -> porep::Tau<T> {
Expand Down Expand Up @@ -486,6 +491,7 @@ impl<'a, L: Layers> ProofScheme<'a> for L {
type PublicInputs = PublicInputs<<L::Hasher as Hasher>::Domain>;
type PrivateInputs = PrivateInputs<L::Hasher>;
type Proof = Proof<L::Hasher>;
type Requirements = ChallengeRequirements;

fn setup(sp: &Self::SetupParams) -> Result<Self::PublicParams> {
let graph = L::Graph::new(
Expand Down Expand Up @@ -627,6 +633,16 @@ impl<'a, L: Layers> ProofScheme<'a> for L {
k,
}
}

fn satisfies_requirements(
public_params: &PublicParams<L::Hasher, L::Graph>,
requirements: &ChallengeRequirements,
partitions: usize,
) -> bool {
let partition_challenges = public_params.layer_challenges.total_challenges();

partition_challenges * partitions >= requirements.minimum_challenges
}
}

// We need to calculate CommR* -- which is: H(replica_id|comm_r[0]|comm_r[1]|…comm_r[n])
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/src/merklepor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::error::*;
use crate::hasher::{Domain, Hasher};
use crate::merkle::{MerkleProof, MerkleTree};
use crate::parameter_cache::ParameterSetIdentifier;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};

/// The parameters shared between the prover and verifier.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -75,6 +75,7 @@ impl<'a, H: 'a + Hasher> ProofScheme<'a> for MerklePoR<H> {
type PublicInputs = PublicInputs<H::Domain>;
type PrivateInputs = PrivateInputs<'a, H>;
type Proof = Proof<H>;
type Requirements = NoRequirements;

fn setup(sp: &SetupParams) -> Result<PublicParams> {
Ok(PublicParams {
Expand Down
3 changes: 2 additions & 1 deletion storage-proofs/src/porc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::error::{Error, Result};
use crate::hasher::{Domain, Hasher};
use crate::merkle::{MerkleProof, MerkleTree};
use crate::parameter_cache::ParameterSetIdentifier;
use crate::proof::ProofScheme;
use crate::proof::{NoRequirements, ProofScheme};

#[derive(Debug, Clone)]
pub struct SetupParams {
Expand Down Expand Up @@ -93,6 +93,7 @@ impl<'a, H: 'a + Hasher> ProofScheme<'a> for PoRC<'a, H> {
type PublicInputs = PublicInputs<'a, H::Domain>;
type PrivateInputs = PrivateInputs<'a, H>;
type Proof = Proof<H>;
type Requirements = NoRequirements;

fn setup(sp: &Self::SetupParams) -> Result<Self::PublicParams> {
Ok(PublicParams {
Expand Down
12 changes: 12 additions & 0 deletions storage-proofs/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub trait ProofScheme<'a> {
type PublicInputs: Clone;
type PrivateInputs;
type Proof: Clone + Serialize + DeserializeOwned;
type Requirements: Default;

/// setup is used to generate public parameters from setup parameters in order to specialize
/// a ProofScheme to the specific parameters required by a consumer.
Expand Down Expand Up @@ -88,4 +89,15 @@ pub trait ProofScheme<'a> {
fn with_partition(pub_in: Self::PublicInputs, _k: Option<usize>) -> Self::PublicInputs {
pub_in
}

fn satisfies_requirements(
_pub_params: &Self::PublicParams,
_requirements: &Self::Requirements,
_partitions: usize,
) -> bool {
true
}
}

#[derive(Default)]
pub struct NoRequirements();
Loading

0 comments on commit 14166be

Please sign in to comment.