Skip to content

Commit

Permalink
integrate phase21 library
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 3, 2020
1 parent 300d518 commit 0486025
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
11 changes: 7 additions & 4 deletions phase2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition = "2018"
bellperson = { version = "0.12.0", default-features = false }
filecoin-proofs = { version = "5.4.0", path = "../filecoin-proofs", default-features = false }
storage-proofs = { version = "5.4.0", path = "../storage-proofs", default-features = false }
phase2 = { version = "0.11", package = "phase21", default-features = false }
groupy = "0.3.1"
log = "0.4.11"
clap = "2.33.3"
Expand All @@ -21,9 +20,13 @@ simplelog = "0.8.0"
dialoguer = "0.7.1"
hex = "0.4.2"
blake2b_simd = "0.5.11"
fff = "0.2.3"
rayon = "1.5.0"
num_cpus = "1.13.0"
crossbeam = "0.8.0"

[features]
default = ["pairing", "gpu"]
gpu = ["bellperson/gpu", "filecoin-proofs/gpu", "storage-proofs/gpu", "phase2/gpu"]
pairing = ["bellperson/pairing", "filecoin-proofs/pairing", "storage-proofs/pairing", "phase2/pairing"]
blst = ["bellperson/blst", "filecoin-proofs/blst", "storage-proofs/blst", "phase2/blst"]
gpu = ["bellperson/gpu", "filecoin-proofs/gpu", "storage-proofs/gpu"]
pairing = ["bellperson/pairing", "filecoin-proofs/pairing", "storage-proofs/pairing"]
blst = ["bellperson/blst", "filecoin-proofs/blst", "storage-proofs/blst"]
18 changes: 9 additions & 9 deletions phase2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! a field element.
//!
//! ```rust
//! use ff::Field;
//! use fff::Field;
//! use bellperson::{
//! Circuit,
//! ConstraintSystem,
Expand Down Expand Up @@ -187,7 +187,7 @@
//! Great, now if you're happy, grab the Groth16 `Parameters` with
//! `params.params()`, so that you can interact with the bellman APIs
//! just as before.
#![deny(clippy::all, clippy::perf, clippy::correctness)]
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]

pub mod small;

Expand All @@ -198,20 +198,20 @@ use std::{
sync::Arc,
};

use bellperson::bls::{
Bls12, Engine, Fr, G1Affine, G1Projective, G1Uncompressed, G2Affine, G2Projective,
G2Uncompressed, PairingCurveAffine,
};
use bellperson::{
groth16::{Parameters, VerifyingKey},
multicore::Worker,
Circuit, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable,
};
use blake2b_simd::State as Blake2b;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use ff::{Field, PrimeField};
use fff::{Field, PrimeField};
use groupy::{CurveAffine, CurveProjective, EncodedPoint, Wnaf};
use log::{error, info};
use bellperson::bls::{
Bls12, Fr, G1Affine, G1Uncompressed, G2Affine, G2Uncompressed, G1Projective, G2Projective,
Engine, PairingCurveAffine,
};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaChaRng;
use rayon::prelude::*;
Expand Down Expand Up @@ -382,7 +382,7 @@ pub struct MPCParameters {

// Required by `assert_eq!()`.
impl Debug for MPCParameters {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("MPCParameters")
.field("params", &"<bellman::groth16::Parameters>")
.field("cs_hash", &self.cs_hash.to_vec())
Expand Down Expand Up @@ -1177,7 +1177,7 @@ struct PublicKey {

// Required by `assert_eq!()`.
impl Debug for PublicKey {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("PublicKey")
.field("delta_after", &self.delta_after)
.field("s", &self.s)
Expand Down
20 changes: 11 additions & 9 deletions phase2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]

use std::fmt::{self, Debug, Formatter};
use std::fs::{self, File, OpenOptions};
use std::io::{self, BufReader, BufWriter, Read, Seek, SeekFrom, Write};
Expand All @@ -13,6 +15,8 @@ use bellperson::bls::{Bls12, G1Affine, G1Uncompressed, G2Affine, G2Uncompressed}
use bellperson::groth16;
use byteorder::{BigEndian, ReadBytesExt};
use clap::{App, AppSettings, Arg, ArgGroup, SubCommand};
use filecoin_phase2::small::{read_small_params_from_large_file, MPCSmall, Streamer};
use filecoin_phase2::MPCParameters;
use filecoin_proofs::constants::*;
use filecoin_proofs::parameters::{
setup_params, window_post_public_params, winning_post_public_params,
Expand All @@ -23,8 +27,6 @@ use filecoin_proofs::types::{
use filecoin_proofs::with_shape;
use groupy::{CurveAffine, EncodedPoint};
use log::{error, info, warn};
use phase2::small::{read_small_params_from_large_file, MPCSmall, Streamer};
use phase2::MPCParameters;
use rand::rngs::OsRng;
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaChaRng;
Expand Down Expand Up @@ -313,7 +315,7 @@ fn blank_sdr_poseidon_params<Tree: MerkleTreeTrait>(sector_size: u64) -> PoRepPu
};

let public_params = <StackedCompound<Tree, Sha256Hasher> as CompoundProof<
StackedDrg<Tree, Sha256Hasher>,
StackedDrg<'_, Tree, Sha256Hasher>,
_,
>>::setup(&setup_params)
.expect("public param setup failed");
Expand Down Expand Up @@ -377,7 +379,7 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
let start = Instant::now();
let public_params = blank_sdr_poseidon_params(sector_size.as_u64());
let circuit = <StackedCompound<Tree, Sha256Hasher> as CompoundProof<
StackedDrg<Tree, Sha256Hasher>,
StackedDrg<'_, Tree, Sha256Hasher>,
_,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
Expand All @@ -390,7 +392,7 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
let start = Instant::now();
let public_params = blank_winning_post_poseidon_params::<Tree>(sector_size.as_u64());
let circuit = <FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoSt<'_, Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
Expand All @@ -403,7 +405,7 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
let start = Instant::now();
let public_params = blank_window_post_poseidon_params::<Tree>(sector_size.as_u64());
let circuit = <FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoSt<'_, Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
Expand Down Expand Up @@ -814,7 +816,7 @@ fn verify_contribution(
info!("verifying contribution");
let start_verification = Instant::now();

let calculated_contrib = phase2::small::verify_contribution_small(
let calculated_contrib = filecoin_phase2::small::verify_contribution_small(
&before_params.expect("before params failure"),
&after_params.expect("after params failure"),
)
Expand Down Expand Up @@ -901,7 +903,7 @@ struct FileInfo {
}

impl Debug for FileInfo {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("FileInfo")
.field("delta_g1_offset", &self.delta_g1_offset)
.field("delta_g1", &self.delta_g1)
Expand Down Expand Up @@ -1065,7 +1067,7 @@ fn parameter_identifier<Tree: 'static + MerkleTreeTrait>(sector_size: u64, proof
let public_params = blank_sdr_poseidon_params::<Tree>(sector_size);

<StackedCompound<Tree, Sha256Hasher> as CacheableParameters<
StackedCircuit<Tree, Sha256Hasher>,
StackedCircuit<'_, Tree, Sha256Hasher>,
_,
>>::cache_identifier(&public_params)
}
Expand Down
12 changes: 5 additions & 7 deletions phase2/src/small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use std::fs::File;
use std::io::{self, BufReader, BufWriter, Read, Seek, SeekFrom, Write};
use std::mem::size_of;

use bellperson::bls::{Fr, G1Affine, G1Projective, G1Uncompressed, G2Affine, G2Uncompressed};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use ff::{Field, PrimeField};
use fff::{Field, PrimeField};
use groupy::{CurveAffine, CurveProjective, EncodedPoint, Wnaf};
use log::{error, info};
use bellperson::bls::{
Fr, G1Affine, G1Uncompressed, G2Affine, G2Uncompressed, G1Projective,
};
use rand::Rng;

use crate::{hash_to_g2, merge_pairs, same_ratio, HashWriter, PrivateKey, PublicKey};
Expand Down Expand Up @@ -43,7 +41,7 @@ pub struct Streamer<'a> {

impl<'a> Streamer<'a> {
// Create a new `Streamer` from small params file.
pub fn new(path: &'a str, read_raw: bool, write_raw: bool) -> io::Result<Streamer> {
pub fn new(path: &'a str, read_raw: bool, write_raw: bool) -> io::Result<Streamer<'_>> {
let mut file = File::open(path)?;

let delta_g1: G1Affine = read_g1(&mut file)?;
Expand Down Expand Up @@ -90,7 +88,7 @@ impl<'a> Streamer<'a> {
path: &'a str,
read_raw: bool,
write_raw: bool,
) -> io::Result<Streamer> {
) -> io::Result<Streamer<'_>> {
let mut file = File::open(path)?;

/*
Expand Down Expand Up @@ -390,7 +388,7 @@ impl<'a> Streamer<'a> {

// Required by `assert_eq!()`.
impl Debug for MPCSmall {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("MPCSmall")
.field("delta_g1", &self.delta_g1)
.field("delta_g2", &self.delta_g2)
Expand Down
7 changes: 3 additions & 4 deletions phase2/tests/large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ mod mimc;

use std::path::Path;

use bellperson::groth16::{create_random_proof, prepare_verifying_key, verify_proof};
use ff::Field;
use bellperson::bls::{Bls12, Fr};
use phase21::{contains_contribution, MPCParameters, verify_contribution};
use bellperson::groth16::{create_random_proof, prepare_verifying_key, verify_proof};
use fff::Field;
use filecoin_phase2::{contains_contribution, verify_contribution, MPCParameters};
use rand::thread_rng;

use mimc::{mimc as mimc_hash, MiMCDemo, MIMC_ROUNDS};
Expand Down Expand Up @@ -55,7 +55,6 @@ fn test_large_params() {
assert!(contains_contribution(&all_contributions, &first_contrib));
assert!(contains_contribution(&all_contributions, &second_contrib));


// Create a Groth16 proof using the generated parameters and verfy that the proof is valid.
let groth_params = params.get_params();

Expand Down
4 changes: 2 additions & 2 deletions phase2/tests/mimc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bellperson::{Circuit, ConstraintSystem, SynthesisError};
use ff::Field;
use bellperson::bls::Engine;
use bellperson::{Circuit, ConstraintSystem, SynthesisError};
use fff::Field;

pub const MIMC_ROUNDS: usize = 322;

Expand Down
10 changes: 6 additions & 4 deletions phase2/tests/small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use std::fs::{remove_file, File};
use std::io::{BufReader, BufWriter};
use std::path::Path;

use bellperson::groth16::{create_random_proof, prepare_verifying_key, verify_proof};
use ff::Field;
use bellperson::bls::{Bls12, Fr};
use phase21::small::{read_small_params_from_large_file, verify_contribution_small, MPCSmall};
use phase21::{verify_contribution, MPCParameters};
use bellperson::groth16::{create_random_proof, prepare_verifying_key, verify_proof};
use fff::Field;
use filecoin_phase2::small::{
read_small_params_from_large_file, verify_contribution_small, MPCSmall,
};
use filecoin_phase2::{verify_contribution, MPCParameters};
use rand::{thread_rng, SeedableRng};
use rand_chacha::ChaChaRng;

Expand Down

0 comments on commit 0486025

Please sign in to comment.