diff --git a/phase2/Cargo.toml b/phase2/Cargo.toml index 5642e8641..04405d5d3 100644 --- a/phase2/Cargo.toml +++ b/phase2/Cargo.toml @@ -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" @@ -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"] diff --git a/phase2/src/lib.rs b/phase2/src/lib.rs index 799b5c862..229003c0b 100644 --- a/phase2/src/lib.rs +++ b/phase2/src/lib.rs @@ -10,7 +10,7 @@ //! a field element. //! //! ```rust -//! use ff::Field; +//! use fff::Field; //! use bellperson::{ //! Circuit, //! ConstraintSystem, @@ -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; @@ -198,6 +198,10 @@ use std::{ sync::Arc, }; +use bellperson::bls::{ + Bls12, Engine, Fr, G1Affine, G1Projective, G1Uncompressed, G2Affine, G2Projective, + G2Uncompressed, PairingCurveAffine, +}; use bellperson::{ groth16::{Parameters, VerifyingKey}, multicore::Worker, @@ -205,13 +209,9 @@ use bellperson::{ }; 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::*; @@ -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", &"") .field("cs_hash", &self.cs_hash.to_vec()) @@ -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) diff --git a/phase2/src/main.rs b/phase2/src/main.rs index 5055c6cf3..20762593d 100644 --- a/phase2/src/main.rs +++ b/phase2/src/main.rs @@ -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}; @@ -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, @@ -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; @@ -313,7 +315,7 @@ fn blank_sdr_poseidon_params(sector_size: u64) -> PoRepPu }; let public_params = as CompoundProof< - StackedDrg, + StackedDrg<'_, Tree, Sha256Hasher>, _, >>::setup(&setup_params) .expect("public param setup failed"); @@ -377,7 +379,7 @@ fn create_initial_params( let start = Instant::now(); let public_params = blank_sdr_poseidon_params(sector_size.as_u64()); let circuit = as CompoundProof< - StackedDrg, + StackedDrg<'_, Tree, Sha256Hasher>, _, >>::blank_circuit(&public_params); dt_create_circuit = start.elapsed().as_secs(); @@ -390,7 +392,7 @@ fn create_initial_params( let start = Instant::now(); let public_params = blank_winning_post_poseidon_params::(sector_size.as_u64()); let circuit = as CompoundProof< - FallbackPoSt, + FallbackPoSt<'_, Tree>, FallbackPoStCircuit, >>::blank_circuit(&public_params); dt_create_circuit = start.elapsed().as_secs(); @@ -403,7 +405,7 @@ fn create_initial_params( let start = Instant::now(); let public_params = blank_window_post_poseidon_params::(sector_size.as_u64()); let circuit = as CompoundProof< - FallbackPoSt, + FallbackPoSt<'_, Tree>, FallbackPoStCircuit, >>::blank_circuit(&public_params); dt_create_circuit = start.elapsed().as_secs(); @@ -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"), ) @@ -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) @@ -1065,7 +1067,7 @@ fn parameter_identifier(sector_size: u64, proof let public_params = blank_sdr_poseidon_params::(sector_size); as CacheableParameters< - StackedCircuit, + StackedCircuit<'_, Tree, Sha256Hasher>, _, >>::cache_identifier(&public_params) } diff --git a/phase2/src/small.rs b/phase2/src/small.rs index ac991ede9..882d8ba9d 100644 --- a/phase2/src/small.rs +++ b/phase2/src/small.rs @@ -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}; @@ -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 { + pub fn new(path: &'a str, read_raw: bool, write_raw: bool) -> io::Result> { let mut file = File::open(path)?; let delta_g1: G1Affine = read_g1(&mut file)?; @@ -90,7 +88,7 @@ impl<'a> Streamer<'a> { path: &'a str, read_raw: bool, write_raw: bool, - ) -> io::Result { + ) -> io::Result> { let mut file = File::open(path)?; /* @@ -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) diff --git a/phase2/tests/large.rs b/phase2/tests/large.rs index 43c924819..d04760c25 100644 --- a/phase2/tests/large.rs +++ b/phase2/tests/large.rs @@ -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}; @@ -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(); diff --git a/phase2/tests/mimc/mod.rs b/phase2/tests/mimc/mod.rs index 0e97c316d..913ff2866 100644 --- a/phase2/tests/mimc/mod.rs +++ b/phase2/tests/mimc/mod.rs @@ -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; diff --git a/phase2/tests/small.rs b/phase2/tests/small.rs index 77e6f8175..0907da3f4 100644 --- a/phase2/tests/small.rs +++ b/phase2/tests/small.rs @@ -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;