Skip to content

Commit

Permalink
ZigZag Groundwork (zcash#95)
Browse files Browse the repository at this point in the history
* Minimal zigzag circuit scaffolding.

* Rename make_circuit to circuit, to emphasize that this is an inexpensive assembly.

* --wip-- [skip ci]

* DrgPoRep compiles (without tests).

* DrgPoRep tests pass.

* Don't pass Options to synthesize function.

* Cleanup.

* Extend Option de-conversion to examples.

* DrgPoRepCompound inputize creates the right number of inputs.

* DrgPoRep Circuit test_compound compiles.

* Fix constraint-count test.

* Repeat bad parents test if random data doesn't exercise it.

* Include graph random seed in DrgParams (included in drgporep::SetupParams).

* Split verify into verify_inputs and verify_proof.

* Some drgporep circuit cleanup.

* Use (vanilla) proof when verifying inputs.

* Implement verify_inputs for merklepor.

* Rename verify_inputs to verify_proof_meta.

* Implement verify_prove_meta for drgporep.

* CHECKPOINT WIP -- drgporep circuit test_compound passing.

* WIP All code running, some constraints not satisfied.

* Extract data from replicat for data node. Drgporep compound test passing.

* Back out small changes to ease diff review.

* Remove superfluous [feature].

* Directly verify that supplied challenge is the one proved.

* Cleanup.

* Remove defunct comment.

* Reinstate Options everywhere.

* Rustfmt and clippy.

* Rebase fixes.

* Bump cargo version to clear cache.

* Different rustfmt.

* Try rustfmt synced to newly-built docker image.

* Bump prefix to clear cargo cache on CI.

* Use Fr::rand().

* Add FIXME for BatchPoST verify_proof_meta.

* Remove stray comment.

* Typo.

* Add documentation comment.

* Comment.

* Doc comment.

* Remove verify_proof_meta.

* Bump cargo cache key.

* Rename inputize to generate_public_inputs and document traits.

* Bump cargo cache key. (We need to fix this.)
  • Loading branch information
porcuquine authored Aug 6, 2018
1 parent bba5f67 commit b4a0019
Show file tree
Hide file tree
Showing 29 changed files with 946 additions and 486 deletions.
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ version: 2
jobs:
cargo_fetch:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run: cargo update
- run: cargo fetch
- persist_to_workspace:
root: "."
paths:
- Cargo.lock
- save_cache:
key: cargo-v3-{{ checksum "Cargo.toml" }}
key: cargo-v7-{{ checksum "Cargo.toml" }}
paths:
- /root/.cargo
- /root/.rustup
test:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run:
name: Build and test
command: cargo +stable test --verbose --frozen
Expand All @@ -47,58 +47,58 @@ jobs:
- target/debug/*
test_release:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run:
name: Build and test in release profile
command: cargo +stable test --verbose --release --frozen
test_nightly:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run:
name: Build and test with nightly Rust
command: cargo +nightly test --verbose --frozen
rustfmt:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run:
name: Run cargo fmt
command: cargo fmt -- --check

clippy:
docker:
- image: dignifiedquire/rust:latest
- image: clwk/rust:latest
working_directory: /mnt/crate
steps:
- checkout
- attach_workspace:
at: "."
- restore_cache:
keys:
- cargo-v3-{{ checksum "Cargo.toml" }}
- cargo-v7-{{ checksum "Cargo.toml" }}
- run:
name: Run cargo clippy
command: cargo clippy
Expand Down
31 changes: 14 additions & 17 deletions benches/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for PedersenExample<'a, E> {
cs.namespace(|| format!("bit {}", i)),
*b,
)?))
})
.collect::<Result<Vec<_>, SynthesisError>>()?;
}).collect::<Result<Vec<_>, SynthesisError>>()?;

let cs = cs.namespace(|| "pedersen");
let res = circuit::pedersen::pedersen_compression_num(cs, self.params, &data)?;
Expand Down Expand Up @@ -92,24 +91,22 @@ fn pedersen_benchmark(c: &mut Criterion) {

black_box(proof)
});
})
.with_function("circuit - just synthesize circuit", move |b, bytes| {
b.iter(|| {
let mut cs = BenchCS::<Bls12>::new();
}).with_function("circuit - just synthesize circuit", move |b, bytes| {
b.iter(|| {
let mut cs = BenchCS::<Bls12>::new();

let mut rng = rng2.clone();
let data: Vec<Option<bool>> = (0..bytes * 8).map(|_| Some(rng.gen())).collect();
let mut rng = rng2.clone();
let data: Vec<Option<bool>> = (0..bytes * 8).map(|_| Some(rng.gen())).collect();

PedersenExample {
params: &jubjub_params2,
data: data.as_slice(),
}.synthesize(&mut cs)
.unwrap();
PedersenExample {
params: &jubjub_params2,
data: data.as_slice(),
}.synthesize(&mut cs)
.unwrap();

black_box(cs)
});
})
.sample_size(20),
black_box(cs)
});
}).sample_size(20),
);
}

Expand Down
14 changes: 8 additions & 6 deletions examples/drgporep-vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ fn do_the_work(data_size: usize, m: usize) {

let sp = SetupParams {
lambda,
drg: DrgParams { nodes, degree: m },
drg: DrgParams {
nodes,
degree: m,
seed: new_seed(),
},
};

info!("running setup");
Expand All @@ -53,7 +57,7 @@ fn do_the_work(data_size: usize, m: usize) {
let (tau, aux) = DrgPoRep::replicate(&pp, prover_id.as_slice(), data.as_mut_slice()).unwrap();

let pub_inputs = PublicInputs {
prover_id: &bytes_into_fr::<Bls12>(prover_id.as_slice()).unwrap(),
prover_id: bytes_into_fr::<Bls12>(prover_id.as_slice()).unwrap(),
challenge,
tau: &tau,
};
Expand Down Expand Up @@ -115,14 +119,12 @@ fn main() {
.long("size")
.help("The data size in KB")
.takes_value(true),
)
.arg(
).arg(
Arg::with_name("m")
.help("The size of m")
.default_value("6")
.takes_value(true),
)
.get_matches();
).get_matches();

let data_size = value_t!(matches, "size", usize).unwrap() * 1024;
let m = value_t!(matches, "m", usize).unwrap();
Expand Down
45 changes: 22 additions & 23 deletions examples/drgporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ use proofs::test_helper::fake_drgpoprep_proof;
struct DrgPoRepExample<'a, E: JubjubEngine> {
params: &'a E::Params,
lambda: usize,
replica_node: Option<&'a E::Fr>,
replica_node_path: &'a [Option<(E::Fr, bool)>],
replica_node: Option<E::Fr>,
replica_node_path: Vec<Option<(E::Fr, bool)>>,
replica_root: Option<E::Fr>,
replica_parents: Vec<Option<&'a E::Fr>>,
replica_parents_paths: &'a [Vec<Option<(E::Fr, bool)>>],
data_node: Option<&'a E::Fr>,
replica_parents: Vec<Option<E::Fr>>,
replica_parents_paths: Vec<Vec<Option<(E::Fr, bool)>>>,
data_node: Option<E::Fr>,
data_node_path: Vec<Option<(E::Fr, bool)>>,
data_root: Option<E::Fr>,
prover_id: Option<&'a [u8]>,
prover_id: Option<E::Fr>,
m: usize,
}

impl<'a, E: JubjubEngine> Circuit<E> for DrgPoRepExample<'a, E> {
fn synthesize<CS: ConstraintSystem<E>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
circuit::drgporep::drgporep(
circuit::drgporep::synthesize_drgporep(
cs.namespace(|| "drgporep"),
self.params,
self.lambda,
Expand Down Expand Up @@ -69,25 +69,25 @@ impl DrgPoRepApp {
m: usize,
) -> BenchCS<Bls12> {
let f = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&f.prover_id);

// create an instance of our circut (with the witness)
let c = DrgPoRepExample {
params: engine_params,
lambda: lambda * 8,
replica_node: Some(&f.replica_node),
replica_node_path: &f.replica_node_path,
replica_node: Some(f.replica_node),
replica_node_path: f.replica_node_path,
replica_root: Some(f.replica_root),
replica_parents: f
.replica_parents
.iter()
.map(|parent| Some(parent))
.map(|parent| Some(*parent))
.collect(),
replica_parents_paths: &f.replica_parents_paths,
data_node: Some(&f.data_node),
replica_parents_paths: f.replica_parents_paths,
data_node: Some(f.data_node),
data_node_path: f.data_node_path.clone(),
data_root: Some(f.data_root),
prover_id: Some(prover_bytes.as_slice()),
prover_id: Some(f.prover_id),
m,
};

Expand Down Expand Up @@ -120,10 +120,10 @@ impl Example<Bls12> for DrgPoRepApp {
params: jubjub_params,
lambda: lambda * 8,
replica_node: None,
replica_node_path: &vec![None; tree_depth],
replica_node_path: vec![None; tree_depth],
replica_root: None,
replica_parents: vec![None; m],
replica_parents_paths: &vec![vec![None; tree_depth]; m],
replica_parents_paths: vec![vec![None; tree_depth]; m],
data_node: None,
data_node_path: vec![None; tree_depth],
data_root: None,
Expand All @@ -150,26 +150,25 @@ impl Example<Bls12> for DrgPoRepApp {
m: usize,
) -> Proof<Bls12> {
let f = fake_drgpoprep_proof(rng, tree_depth, m, SLOTH_ROUNDS);

let prover_bytes = fr_into_bytes::<Bls12>(&f.prover_id);

// create an instance of our circut (with the witness)
let c = DrgPoRepExample {
params: engine_params,
lambda: lambda * 8,
replica_node: Some(&f.replica_node),
replica_node_path: &f.replica_node_path,
replica_node: Some(f.replica_node),
replica_node_path: f.replica_node_path,
replica_root: Some(f.replica_root),
replica_parents: f
.replica_parents
.iter()
.map(|parent| Some(parent))
.map(|parent| Some(*parent))
.collect(),
replica_parents_paths: &f.replica_parents_paths,
data_node: Some(&f.data_node),
replica_parents_paths: f.replica_parents_paths,
data_node: Some(f.data_node),
data_node_path: f.data_node_path.clone(),
data_root: Some(f.data_root),
prover_id: Some(prover_bytes.as_slice()),
prover_id: Some(f.prover_id),
m,
};

Expand Down
13 changes: 6 additions & 7 deletions examples/merklepor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl MerklePorApp {
self.root = root;
self.leaf = leaf;
self.auth_paths = (0..challenge_count).map(|_| auth_path.clone()).collect();
let values = (0..challenge_count).map(|_| Some(&self.leaf)).collect();
let values = (0..challenge_count).map(|_| Some(self.leaf)).collect();

// create an instance of our circut (with the witness)
let c = circuit::ppor::ParallelProofOfRetrievability {
params: engine_params,
values,
auth_paths: &self.auth_paths,
auth_paths: self.auth_paths.clone(),
root: Some(self.root),
};

Expand Down Expand Up @@ -87,7 +87,7 @@ impl Example<Bls12> for MerklePorApp {
circuit::ppor::ParallelProofOfRetrievability {
params: jubjub_params,
values: vec![None; challenge_count],
auth_paths: &vec![vec![None; tree_depth]; challenge_count],
auth_paths: vec![vec![None; tree_depth]; challenge_count],
root: None,
},
rng,
Expand All @@ -113,14 +113,14 @@ impl Example<Bls12> for MerklePorApp {
self.root = root;
self.leaf = leaf;
self.auth_paths = (0..challenge_count).map(|_| auth_path.clone()).collect();
let values = (0..challenge_count).map(|_| Some(&self.leaf)).collect();
let values = (0..challenge_count).map(|_| Some(self.leaf)).collect();

// create an instance of our circut (with the witness)
let proof = {
let c = circuit::ppor::ParallelProofOfRetrievability {
params: engine_params,
values,
auth_paths: &self.auth_paths,
auth_paths: self.auth_paths.clone(),
root: Some(self.root),
};

Expand Down Expand Up @@ -154,8 +154,7 @@ impl Example<Bls12> for MerklePorApp {
let mut input = vec![*values[j].unwrap()];
input.extend(packed_auth_path);
input
})
.collect();
}).collect();

// add the root as the last one
expected_inputs.push(self.root);
Expand Down
4 changes: 2 additions & 2 deletions src/batchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn derive_challenge(
#[cfg(test)]
mod tests {
use super::*;
use drgraph::{BucketGraph, Graph};
use drgraph::{new_seed, BucketGraph, Graph};
use fr32::fr_into_bytes;
use merklepor;
use pairing::bls12_381::Bls12;
Expand All @@ -220,7 +220,7 @@ mod tests {
let data: Vec<u8> = (0..32)
.flat_map(|_| fr_into_bytes::<Bls12>(&rng.gen()))
.collect();
let graph = BucketGraph::new(32, 16);
let graph = BucketGraph::new(32, 16, new_seed());
let tree = graph.merkle_tree(data.as_slice(), 32).unwrap();

let pub_inputs = PublicInputs {
Expand Down
Loading

0 comments on commit b4a0019

Please sign in to comment.