Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage-proofs): zizag, drgporep and por abstract over the hasher in circuits #543

Merged
merged 7 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions filecoin-proofs/examples/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use sapling_crypto::jubjub::{JubjubBls12, JubjubEngine};

use storage_proofs::circuit;
use storage_proofs::circuit::variables::Root;

use storage_proofs::example_helper::Example;
use storage_proofs::hasher::PedersenHasher;
use storage_proofs::test_helper::fake_drgpoprep_proof;

struct DrgPoRepExample<'a, E: JubjubEngine> {
Expand All @@ -35,7 +35,7 @@ struct DrgPoRepExample<'a, E: JubjubEngine> {

impl<'a> Circuit<Bls12> for DrgPoRepExample<'a, Bls12> {
fn synthesize<CS: ConstraintSystem<Bls12>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
circuit::drgporep::DrgPoRepCircuit::synthesize(
circuit::drgporep::DrgPoRepCircuit::<_, PedersenHasher>::synthesize(
cs.namespace(|| "drgporep"),
self.params,
self.sloth_iter,
Expand Down
32 changes: 16 additions & 16 deletions parameters.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"v10-zigzag-proof-of-replication-b8f3290335d11af86f8193cc2c3bbf451b4b2cc33e59e8ecad060999f3bebe77": {
"cid": "QmeAwbo2CM4t58kV7byr1X2beA7pzbGvStCVSDSG4ydu2E",
"digest": "a30003a7b2b2512cd5e66cfefdd9fe7b"
},
"v10-zigzag-proof-of-replication-b8f3290335d11af86f8193cc2c3bbf451b4b2cc33e59e8ecad060999f3bebe77.vk": {
"cid": "QmeubWLDsLvL5ULFote1Gce1RfNKcHicCkcwsNyBkhtWuv",
"digest": "61eb4d1b2862feb1149284108c29386b"
},
"v10-vdf-post-c8ddc8e74f9c2ed6a4bc83df171a9e9e84e242cf6e48e20f71585106fa8a3ce6.vk": {
"cid": "QmTKL1MiWSWFUMEECZPaBX6ddoZy9HCAA4mdaW65BKDoEp",
"digest": "2684b87a68d3a02118584e524a3f073a"
},
"v10-vdf-post-c8ddc8e74f9c2ed6a4bc83df171a9e9e84e242cf6e48e20f71585106fa8a3ce6": {
"cid": "QmPuZ1fZGVDBTjsARTWuMesKjaXqUeNENsQrWBLh7PAjEU",
"digest": "71f6673c73376cca102390150174bbe4"
},
"v10-zigzag-proof-of-replication-733b035c440d8b0e4a03ab5e4c58553b6c674cc64bd6a130e8764f7abeb38f69.vk": {
"cid": "QmRkiXN7RTWjTgTz3DTjCjDaVNS5vNd8z174UrZLyMowmS",
"digest": "d9f8f2c3a74c45cce4dfa26b65ccc3c9"
"v10-zigzag-proof-of-replication-6648cd509799c8b76f944bbc971692c69d1480fa60c569bfc1284f0bd8ead988": {
"cid": "QmeAwbo2CM4t58kV7byr1X2beA7pzbGvStCVSDSG4ydu2E",
"digest": "a30003a7b2b2512cd5e66cfefdd9fe7b"
},
"v10-vdf-post-912e5a392c09cbfa0bf369ac77f939a45e0f2aec968cf3846cbe356a19b76685": {
"cid": "QmP1PkagfiC9cUEh3r7NEWaJfnBGEnqfABxXxh3PSoiMtX",
"digest": "ff7fa52e9bf2a3b5261f6d5740156f79"
},
"v10-zigzag-proof-of-replication-733b035c440d8b0e4a03ab5e4c58553b6c674cc64bd6a130e8764f7abeb38f69": {
"v10-vdf-post-c8ddc8e74f9c2ed6a4bc83df171a9e9e84e242cf6e48e20f71585106fa8a3ce6": {
"cid": "QmPuZ1fZGVDBTjsARTWuMesKjaXqUeNENsQrWBLh7PAjEU",
"digest": "71f6673c73376cca102390150174bbe4"
},
"v10-zigzag-proof-of-replication-56360c4554216174de15d2c76acbd0f360e0fabf07dd470ca50f7d39676e7874": {
"cid": "QmbPHbry667qc7JEhYDWpvs6mj6rD9UQRi9ZpQb6q6pcoq",
"digest": "9268d86f4e3c23eb8483d65834e27c0d"
},
"v10-zigzag-proof-of-replication-6648cd509799c8b76f944bbc971692c69d1480fa60c569bfc1284f0bd8ead988.vk": {
"cid": "QmeubWLDsLvL5ULFote1Gce1RfNKcHicCkcwsNyBkhtWuv",
"digest": "61eb4d1b2862feb1149284108c29386b"
},
"v10-zigzag-proof-of-replication-56360c4554216174de15d2c76acbd0f360e0fabf07dd470ca50f7d39676e7874.vk": {
"cid": "QmRkiXN7RTWjTgTz3DTjCjDaVNS5vNd8z174UrZLyMowmS",
"digest": "d9f8f2c3a74c45cce4dfa26b65ccc3c9"
},
"v10-vdf-post-912e5a392c09cbfa0bf369ac77f939a45e0f2aec968cf3846cbe356a19b76685.vk": {
"cid": "QmaNXg87KFw4pKxa9mXThprpDns7aJZCN5k9WCtneMBkoY",
"digest": "3e97aff1d9d2d712163befee897c8b5d"
Expand Down
79 changes: 43 additions & 36 deletions storage-proofs/src/circuit/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use std::marker::PhantomData;
use crate::circuit::por::{PoRCircuit, PoRCompound};
use crate::hasher::{Domain, Hasher};

pub struct DrgPoRepCircuit<'a, E: JubjubEngine> {
pub struct DrgPoRepCircuit<'a, E: JubjubEngine, H: Hasher> {
params: &'a E::Params,
sloth_iter: usize,
replica_nodes: Vec<Option<E::Fr>>,
Expand All @@ -68,9 +68,10 @@ pub struct DrgPoRepCircuit<'a, E: JubjubEngine> {
replica_id: Option<E::Fr>,
degree: usize,
private: bool,
_h: PhantomData<H>,
}

impl<'a, E: JubjubEngine> DrgPoRepCircuit<'a, E> {
impl<'a, E: JubjubEngine, H: Hasher> DrgPoRepCircuit<'a, E, H> {
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub fn synthesize<CS>(
mut cs: CS,
Expand All @@ -92,7 +93,7 @@ impl<'a, E: JubjubEngine> DrgPoRepCircuit<'a, E> {
E: JubjubEngine,
CS: ConstraintSystem<E>,
{
DrgPoRepCircuit {
DrgPoRepCircuit::<_, H> {
params,
sloth_iter,
replica_nodes,
Expand All @@ -106,6 +107,7 @@ impl<'a, E: JubjubEngine> DrgPoRepCircuit<'a, E> {
replica_id,
degree,
private,
_h: Default::default(),
}
.synthesize(&mut cs)
}
Expand All @@ -126,7 +128,7 @@ impl<E: JubjubEngine> Default for ComponentPrivateInputs<E> {
}
}

impl<'a, E: JubjubEngine> CircuitComponent for DrgPoRepCircuit<'a, E> {
impl<'a, E: JubjubEngine, H: Hasher> CircuitComponent for DrgPoRepCircuit<'a, E, H> {
type ComponentPrivateInputs = ComponentPrivateInputs<E>;
}

Expand All @@ -144,11 +146,11 @@ impl<E: JubjubEngine, C: Circuit<E>, H: Hasher, G: Graph<H>, P: ParameterSetIden
CacheableParameters<E, C, P> for DrgPoRepCompound<H, G>
{
fn cache_prefix() -> String {
String::from("drg-proof-of-replication")
format!("drg-proof-of-replication-{}", H::name())
}
}

impl<'a, H, G> CompoundProof<'a, Bls12, DrgPoRep<'a, H, G>, DrgPoRepCircuit<'a, Bls12>>
impl<'a, H, G> CompoundProof<'a, Bls12, DrgPoRep<'a, H, G>, DrgPoRepCircuit<'a, Bls12, H>>
for DrgPoRepCompound<H, G>
where
H: 'a + Hasher,
Expand Down Expand Up @@ -219,11 +221,11 @@ where

fn circuit<'b>(
public_inputs: &'b <DrgPoRep<'a, H, G> as ProofScheme<'a>>::PublicInputs,
component_private_inputs: <DrgPoRepCircuit<'a, Bls12> as CircuitComponent>::ComponentPrivateInputs,
component_private_inputs: <DrgPoRepCircuit<'a, Bls12, H> as CircuitComponent>::ComponentPrivateInputs,
proof: &'b <DrgPoRep<'a, H, G> as ProofScheme<'a>>::Proof,
public_params: &'b <DrgPoRep<'a, H, G> as ProofScheme<'a>>::PublicParams,
engine_params: &'a <Bls12 as JubjubEngine>::Params,
) -> DrgPoRepCircuit<'a, Bls12> {
) -> DrgPoRepCircuit<'a, Bls12, H> {
let challenges = public_params.challenges_count;
let len = proof.nodes.len();

Expand Down Expand Up @@ -314,13 +316,14 @@ where
replica_id: replica_id.map(Into::into),
degree: public_params.graph.degree(),
private: public_params.private,
_h: Default::default(),
}
}

fn blank_circuit(
public_params: &<DrgPoRep<'a, H, G> as ProofScheme<'a>>::PublicParams,
params: &'a <Bls12 as JubjubEngine>::Params,
) -> DrgPoRepCircuit<'a, Bls12> {
) -> DrgPoRepCircuit<'a, Bls12, H> {
let depth = public_params.graph.merkle_tree_depth() as usize;
let degree = public_params.graph.degree();
let challenges_count = public_params.challenges_count;
Expand Down Expand Up @@ -349,6 +352,7 @@ where
replica_id: None,
degree: public_params.graph.degree(),
private: public_params.private,
_h: Default::default(),
}
}
}
Expand Down Expand Up @@ -376,7 +380,7 @@ where
///
/// Total = 2 + replica_parents.len()
///
impl<'a, E: JubjubEngine> Circuit<E> for DrgPoRepCircuit<'a, E> {
impl<'a, E: JubjubEngine, H: Hasher> Circuit<E> for DrgPoRepCircuit<'a, E, H> {
fn synthesize<CS: ConstraintSystem<E>>(self, cs: &mut CS) -> Result<(), SynthesisError>
where
E: JubjubEngine,
Expand Down Expand Up @@ -437,7 +441,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for DrgPoRepCircuit<'a, E> {
// Inclusion checks
{
let mut cs = cs.namespace(|| "inclusion_checks");
PoRCircuit::synthesize(
PoRCircuit::<_, H>::synthesize(
cs.namespace(|| "replica_inclusion"),
&params,
*replica_node,
Expand All @@ -448,7 +452,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for DrgPoRepCircuit<'a, E> {

// validate each replica_parents merkle proof
for j in 0..replica_parents.len() {
PoRCircuit::synthesize(
PoRCircuit::<_, H>::synthesize(
cs.namespace(|| format!("parents_inclusion_{}", j)),
&params,
replica_parents[j],
Expand All @@ -459,7 +463,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for DrgPoRepCircuit<'a, E> {
}

// validate data node commitment
PoRCircuit::synthesize(
PoRCircuit::<_, H>::synthesize(
cs.namespace(|| "data_inclusion"),
&params,
*data_node,
Expand Down Expand Up @@ -530,10 +534,11 @@ mod tests {
use crate::drgporep;
use crate::drgraph::{graph_height, new_seed, BucketGraph};
use crate::fr32::{bytes_into_fr, fr_into_bytes};
use crate::hasher::pedersen::*;
use crate::hasher::{Blake2sHasher, Hasher, PedersenHasher};
use crate::porep::PoRep;
use crate::proof::ProofScheme;
use crate::util::data_at_node;

use pairing::Field;
use rand::Rand;
use rand::{Rng, SeedableRng, XorShiftRng};
Expand Down Expand Up @@ -645,7 +650,7 @@ mod tests {
);

let mut cs = TestConstraintSystem::<Bls12>::new();
DrgPoRepCircuit::synthesize(
DrgPoRepCircuit::<_, PedersenHasher>::synthesize(
cs.namespace(|| "drgporep"),
params,
sloth_iter,
Expand Down Expand Up @@ -694,7 +699,7 @@ mod tests {
let sloth_iter = 1;

let mut cs = TestConstraintSystem::<Bls12>::new();
DrgPoRepCircuit::synthesize(
DrgPoRepCircuit::<_, PedersenHasher>::synthesize(
cs.namespace(|| "drgporep"),
params,
sloth_iter,
Expand All @@ -718,7 +723,17 @@ mod tests {

#[test]
#[ignore] // Slow test – run only when compiled for release.
fn drgporep_test_compound() {
fn test_drgporep_compound_pedersen() {
drgporep_test_compound::<PedersenHasher>();
}

#[test]
#[ignore] // Slow test – run only when compiled for release.
fn test_drgporep_compound_blake2s() {
drgporep_test_compound::<Blake2sHasher>();
}

fn drgporep_test_compound<H: Hasher>() {
let params = &JubjubBls12::new();
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

Expand Down Expand Up @@ -752,18 +767,17 @@ mod tests {
};

let public_params =
DrgPoRepCompound::<PedersenHasher, BucketGraph<_>>::setup(&setup_params)
.expect("setup failed");
DrgPoRepCompound::<H, BucketGraph<_>>::setup(&setup_params).expect("setup failed");

let (tau, aux) = drgporep::DrgPoRep::<PedersenHasher, _>::replicate(
let (tau, aux) = drgporep::DrgPoRep::<H, _>::replicate(
&public_params.vanilla_params,
&replica_id.into(),
data.as_mut_slice(),
None,
)
.expect("failed to replicate");

let public_inputs = drgporep::PublicInputs::<PedersenDomain> {
let public_inputs = drgporep::PublicInputs::<H::Domain> {
replica_id: Some(replica_id.into()),
challenges,
tau: Some(tau),
Expand Down Expand Up @@ -791,11 +805,10 @@ mod tests {
};

let public_params =
DrgPoRepCompound::<PedersenHasher, BucketGraph<_>>::setup(&setup_params)
.expect("setup failed");
DrgPoRepCompound::<H, BucketGraph<_>>::setup(&setup_params).expect("setup failed");

{
let (circuit, inputs) = DrgPoRepCompound::<PedersenHasher, _>::circuit_for_test(
let (circuit, inputs) = DrgPoRepCompound::<H, _>::circuit_for_test(
&public_params,
&public_inputs,
&private_inputs,
Expand All @@ -809,26 +822,20 @@ mod tests {
}

{
let gparams = DrgPoRepCompound::<PedersenHasher, _>::groth_params(
&public_params.vanilla_params,
&params,
)
.expect("failed to get groth params");
let gparams =
DrgPoRepCompound::<H, _>::groth_params(&public_params.vanilla_params, &params)
.expect("failed to get groth params");

let proof = DrgPoRepCompound::<PedersenHasher, _>::prove(
let proof = DrgPoRepCompound::<H, _>::prove(
&public_params,
&public_inputs,
&private_inputs,
&gparams,
)
.expect("failed while proving");

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

assert!(verified);
}
Expand Down
Loading