Skip to content

Commit

Permalink
refactor: phase2: created dedicated functions for public params
Browse files Browse the repository at this point in the history
Those functions will be used by subsequent commits for splitting the
trusted setup results into the correct parameter files.
  • Loading branch information
vmx committed Aug 5, 2020
1 parent abe7355 commit 4db8e3c
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions filecoin-proofs/src/bin/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ use simplelog::{self, CombinedLogger, LevelFilter, TermLogger, TerminalMode, Wri
use storage_proofs::compound_proof::{self, CompoundProof};
use storage_proofs::hasher::Sha256Hasher;
use storage_proofs::merkle::MerkleTreeTrait;
use storage_proofs::porep::stacked::{StackedCircuit, StackedCompound, StackedDrg};
use storage_proofs::post::fallback::{FallbackPoSt, FallbackPoStCircuit, FallbackPoStCompound};
use storage_proofs::porep::stacked::{
PublicParams as PoRepPublicParams, StackedCompound, StackedDrg,
};
use storage_proofs::post::fallback::{
FallbackPoSt, FallbackPoStCircuit, FallbackPoStCompound, PublicParams as PoStPublicParams,
};

const CHUNK_SIZE: usize = 10_000;

Expand Down Expand Up @@ -281,9 +285,7 @@ fn parse_params_filename(path: &str) -> (Proof, Hasher, Sector, String, usize, P
)
}

fn blank_sdr_poseidon_circuit<Tree: MerkleTreeTrait>(
sector_size: u64,
) -> StackedCircuit<'static, Tree, Sha256Hasher> {
fn blank_sdr_poseidon_params<Tree: MerkleTreeTrait>(sector_size: u64) -> PoRepPublicParams<Tree> {
let n_partitions = *POREP_PARTITIONS.read().unwrap().get(&sector_size).unwrap();

let porep_config = PoRepConfig {
Expand All @@ -308,11 +310,7 @@ fn blank_sdr_poseidon_circuit<Tree: MerkleTreeTrait>(
_,
>>::setup(&setup_params)
.unwrap();

<StackedCompound<Tree, Sha256Hasher> as CompoundProof<
StackedDrg<Tree, Sha256Hasher>,
_,
>>::blank_circuit(&public_params.vanilla_params)
public_params.vanilla_params
}

/*
Expand Down Expand Up @@ -350,9 +348,9 @@ fn blank_porep_sha_pedersen_circuit(
}
*/

fn blank_winning_post_poseidon_circuit<Tree: 'static + MerkleTreeTrait>(
fn blank_winning_post_poseidon_params<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
) -> FallbackPoStCircuit<Tree> {
) -> PoStPublicParams {
let post_config = PoStConfig {
sector_size: SectorSize(sector_size),
challenge_count: WINNING_POST_CHALLENGE_COUNT,
Expand All @@ -361,17 +359,12 @@ fn blank_winning_post_poseidon_circuit<Tree: 'static + MerkleTreeTrait>(
priority: false,
};

let public_params = winning_post_public_params::<Tree>(&post_config).unwrap();

<FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params)
winning_post_public_params::<Tree>(&post_config).unwrap()
}

fn blank_window_post_poseidon_circuit<Tree: 'static + MerkleTreeTrait>(
fn blank_window_post_poseidon_params<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
) -> FallbackPoStCircuit<Tree> {
) -> PoStPublicParams {
let post_config = PoStConfig {
sector_size: SectorSize(sector_size),
challenge_count: WINDOW_POST_CHALLENGE_COUNT,
Expand All @@ -384,12 +377,7 @@ fn blank_window_post_poseidon_circuit<Tree: 'static + MerkleTreeTrait>(
priority: false,
};

let public_params = window_post_public_params::<Tree>(&post_config).unwrap();

<FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params)
window_post_public_params::<Tree>(&post_config).unwrap()
}

/// Creates the first phase2 parameters for a circuit and writes them to a file.
Expand All @@ -415,7 +403,11 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
let params = match (proof, hasher) {
(Proof::Sdr, Hasher::Poseidon) => {
let start = Instant::now();
let circuit = blank_sdr_poseidon_circuit::<Tree>(sector_size.as_u64());
let public_params = blank_sdr_poseidon_params(sector_size.as_u64());
let circuit = <StackedCompound<Tree, Sha256Hasher> as CompoundProof<
StackedDrg<Tree, Sha256Hasher>,
_,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
let start = Instant::now();
let params = MPCParameters::new(circuit).unwrap();
Expand All @@ -424,7 +416,11 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
}
(Proof::Winning, Hasher::Poseidon) => {
let start = Instant::now();
let circuit = blank_winning_post_poseidon_circuit::<Tree>(sector_size.as_u64());
let public_params = blank_winning_post_poseidon_params::<Tree>(sector_size.as_u64());
let circuit = <FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
let start = Instant::now();
let params = MPCParameters::new(circuit).unwrap();
Expand All @@ -433,7 +429,11 @@ fn create_initial_params<Tree: 'static + MerkleTreeTrait>(
}
(Proof::Window, Hasher::Poseidon) => {
let start = Instant::now();
let circuit = blank_window_post_poseidon_circuit::<Tree>(sector_size.as_u64());
let public_params = blank_window_post_poseidon_params::<Tree>(sector_size.as_u64());
let circuit = <FallbackPoStCompound<Tree> as CompoundProof<
FallbackPoSt<Tree>,
FallbackPoStCircuit<Tree>,
>>::blank_circuit(&public_params);
dt_create_circuit = start.elapsed().as_secs();
let start = Instant::now();
let params = MPCParameters::new(circuit).unwrap();
Expand Down

0 comments on commit 4db8e3c

Please sign in to comment.