Skip to content

Commit

Permalink
feat: add Pasta compatible hashers
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPeterVanNostrand committed Feb 25, 2022
1 parent 4d743cf commit f1af449
Show file tree
Hide file tree
Showing 104 changed files with 4,086 additions and 2,016 deletions.
1 change: 1 addition & 0 deletions fil-proofs-param/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ indicatif = "0.15.0"
group = "0.11.0"
dialoguer = "0.8.0"
clap = "2.33.3"
blstrs = "0.4.0"

[dependencies.reqwest]
version = "0.10"
Expand Down
66 changes: 40 additions & 26 deletions fil-proofs-param/src/bin/paramcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::env;
use std::process::exit;
use std::str::FromStr;

use blstrs::Scalar as Fr;
use dialoguer::{theme::ColorfulTheme, MultiSelect};
use filecoin_hashers::{Domain, Hasher};
use filecoin_proofs::{
constants::{
DefaultPieceHasher, POREP_PARTITIONS, PUBLISHED_SECTOR_SIZES, WINDOW_POST_CHALLENGE_COUNT,
Expand All @@ -22,14 +24,14 @@ use storage_proofs_core::{
};
use storage_proofs_porep::stacked::{StackedCircuit, StackedCompound, StackedDrg};
use storage_proofs_post::fallback::{FallbackPoSt, FallbackPoStCircuit, FallbackPoStCompound};
use storage_proofs_update::constants::TreeRHasher;
use storage_proofs_update::{
circuit::EmptySectorUpdateCircuit, compound::EmptySectorUpdateCompound, EmptySectorUpdate,
PublicParams,
};
use storage_proofs_update::{constants::TreeRHasher, EmptySectorUpdateCompound};
use structopt::StructOpt;

fn cache_porep_params<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) {
fn cache_porep_params<Tree>(porep_config: PoRepConfig)
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("generating PoRep groth params");

let public_params = public_params(
Expand Down Expand Up @@ -66,7 +68,11 @@ fn cache_porep_params<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig
.expect("failed to get verifying key");
}

fn cache_winning_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoStConfig) {
fn cache_winning_post_params<Tree>(post_config: &PoStConfig)
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("generating Winning-PoSt groth params");

let public_params = winning_post_public_params::<Tree>(post_config)
Expand All @@ -92,7 +98,11 @@ fn cache_winning_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoSt
.expect("failed to get verifying key");
}

fn cache_window_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoStConfig) {
fn cache_window_post_params<Tree>(post_config: &PoStConfig)
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("generating Window-PoSt groth params");

let public_params = window_post_public_params::<Tree>(post_config)
Expand All @@ -118,32 +128,36 @@ fn cache_window_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoStC
.expect("failed to get verifying key");
}

fn cache_empty_sector_update_params<Tree: 'static + MerkleTreeTrait<Hasher = TreeRHasher>>(
porep_config: PoRepConfig,
) {
fn cache_empty_sector_update_params<Tree>(porep_config: PoRepConfig)
where
Tree: 'static + MerkleTreeTrait<Hasher = TreeRHasher<Fr>>,
{
info!("generating EmptySectorUpdate groth params");

let public_params: storage_proofs_update::PublicParams =
PublicParams::from_sector_size(u64::from(porep_config.sector_size));
let public_params =
storage_proofs_update::PublicParams::from_sector_size(u64::from(porep_config.sector_size));

let circuit = <EmptySectorUpdateCompound<Tree> as CompoundProof<
EmptySectorUpdate<Tree>,
EmptySectorUpdateCircuit<Tree>,
>>::blank_circuit(&public_params);
let circuit = EmptySectorUpdateCompound::<
Tree::Arity,
Tree::SubTreeArity,
Tree::TopTreeArity,
>::blank_circuit(&public_params);

let _ = <EmptySectorUpdateCompound<Tree> as CompoundProof<
EmptySectorUpdate<Tree>,
EmptySectorUpdateCircuit<Tree>,
>>::groth_params::<OsRng>(Some(&mut OsRng), &public_params)
let _ = EmptySectorUpdateCompound::<
Tree::Arity,
Tree::SubTreeArity,
Tree::TopTreeArity,
>::groth_params(Some(&mut OsRng), &public_params)
.expect("failed to get groth params");

let _ = <EmptySectorUpdateCompound<Tree>>::get_param_metadata(circuit, &public_params)
let _ = EmptySectorUpdateCompound::get_param_metadata(circuit, &public_params)
.expect("failed to get metadata");

let _ = <EmptySectorUpdateCompound<Tree> as CompoundProof<
EmptySectorUpdate<Tree>,
EmptySectorUpdateCircuit<Tree>,
>>::verifying_key::<OsRng>(Some(&mut OsRng), &public_params)
let _ = EmptySectorUpdateCompound::<
Tree::Arity,
Tree::SubTreeArity,
Tree::TopTreeArity,
>::verifying_key(Some(&mut OsRng), &public_params)
.expect("failed to get verifying key");
}

Expand Down
22 changes: 13 additions & 9 deletions fil-proofs-tooling/src/bin/benchy/prodbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ fn measure_porep_circuit(i: &ProdbenchInputs) -> usize {
api_version: i.api_version(),
};

let pp = StackedDrg::<ProdbenchTree, Sha256Hasher>::setup(&sp).expect("failed to setup DRG");
let pp =
StackedDrg::<ProdbenchTree, Sha256Hasher<Fr>>::setup(&sp).expect("failed to setup DRG");

let mut cs = BenchCS::<Fr>::new();
<StackedCompound<_, _> as CompoundProof<StackedDrg<ProdbenchTree, Sha256Hasher>, _>>::blank_circuit(
<StackedCompound<_, _> as CompoundProof<StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>, _>>::blank_circuit(
&pp,
)
.synthesize(&mut cs)
Expand Down Expand Up @@ -332,18 +333,21 @@ fn cache_porep_params(porep_config: PoRepConfig) {

{
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
StackedDrg<ProdbenchTree, Sha256Hasher>,
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
_,
>>::blank_circuit(&public_params);
StackedCompound::<ProdbenchTree, Sha256Hasher>::get_param_metadata(circuit, &public_params)
.expect("cannot get param metadata");
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_param_metadata(
circuit,
&public_params,
)
.expect("cannot get param metadata");
}
{
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
StackedDrg<ProdbenchTree, Sha256Hasher>,
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
_,
>>::blank_circuit(&public_params);
StackedCompound::<ProdbenchTree, Sha256Hasher>::get_groth_params(
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_groth_params(
Some(&mut XorShiftRng::from_seed(SEED)),
circuit,
&public_params,
Expand All @@ -352,11 +356,11 @@ fn cache_porep_params(porep_config: PoRepConfig) {
}
{
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
StackedDrg<ProdbenchTree, Sha256Hasher>,
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
_,
>>::blank_circuit(&public_params);

StackedCompound::<ProdbenchTree, Sha256Hasher>::get_verifying_key(
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_verifying_key(
Some(&mut XorShiftRng::from_seed(SEED)),
circuit,
&public_params,
Expand Down
18 changes: 14 additions & 4 deletions fil-proofs-tooling/src/bin/benchy/window_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use std::time::{SystemTime, UNIX_EPOCH};

use anyhow::{ensure, Context};
use bincode::{deserialize, serialize};
use blstrs::Scalar as Fr;
use fil_proofs_tooling::measure::FuncMeasurement;
use fil_proofs_tooling::shared::{PROVER_ID, RANDOMNESS, TICKET_BYTES};
use fil_proofs_tooling::{measure, Metadata};
use filecoin_hashers::{Domain, Hasher};
use filecoin_proofs::constants::{
POREP_PARTITIONS, WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT,
};
Expand Down Expand Up @@ -96,15 +98,19 @@ fn get_porep_config(sector_size: u64, api_version: ApiVersion) -> PoRepConfig {
}
}

fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
fn run_pre_commit_phases<Tree>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
skip_precommit_phase1: bool,
skip_precommit_phase2: bool,
test_resume: bool,
skip_staging: bool,
) -> anyhow::Result<((u64, u64), (u64, u64), (u64, u64))> {
) -> anyhow::Result<((u64, u64), (u64, u64), (u64, u64))>
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
let (seal_pre_commit_phase1_measurement_cpu_time, seal_pre_commit_phase1_measurement_wall_time): (u64, u64) = if skip_precommit_phase1 {
// generate no-op measurements
(0, 0)
Expand Down Expand Up @@ -335,7 +341,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
}

#[allow(clippy::too_many_arguments)]
pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
pub fn run_window_post_bench<Tree>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
Expand All @@ -345,7 +351,11 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
skip_commit_phase1: bool,
skip_commit_phase2: bool,
test_resume: bool,
) -> anyhow::Result<()> {
) -> anyhow::Result<()>
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
let (
(seal_pre_commit_phase1_cpu_time_ms, seal_pre_commit_phase1_wall_time_ms),
(
Expand Down
10 changes: 8 additions & 2 deletions fil-proofs-tooling/src/bin/benchy/winning_post.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::io::stdout;

use anyhow::anyhow;
use blstrs::Scalar as Fr;
use fil_proofs_tooling::shared::{create_replica, PROVER_ID, RANDOMNESS};
use fil_proofs_tooling::{measure, Metadata};
use filecoin_hashers::{Domain, Hasher};
use filecoin_proofs::constants::{WINNING_POST_CHALLENGE_COUNT, WINNING_POST_SECTOR_COUNT};
use filecoin_proofs::types::PoStConfig;
use filecoin_proofs::{
Expand Down Expand Up @@ -46,10 +48,14 @@ impl Report {
}
}

pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
pub fn run_fallback_post_bench<Tree>(
sector_size: u64,
api_version: ApiVersion,
) -> anyhow::Result<()> {
) -> anyhow::Result<()>
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
if WINNING_POST_SECTOR_COUNT != 1 {
return Err(anyhow!(
"This benchmark only works with WINNING_POST_SECTOR_COUNT == 1"
Expand Down
19 changes: 16 additions & 3 deletions fil-proofs-tooling/src/bin/circuitinfo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::str::FromStr;
use bellperson::{util_cs::bench_cs::BenchCS, Circuit};
use blstrs::Scalar as Fr;
use dialoguer::{theme::ColorfulTheme, MultiSelect};
use filecoin_hashers::{Domain, Hasher};
use filecoin_proofs::{
parameters::{public_params, window_post_public_params, winning_post_public_params},
with_shape, DefaultPieceHasher, PaddedBytesAmount, PoRepConfig, PoRepProofPartitions,
Expand Down Expand Up @@ -36,7 +37,11 @@ fn circuit_info<C: Circuit<Fr>>(circuit: C) -> CircuitInfo {
}
}

fn get_porep_info<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) -> CircuitInfo {
fn get_porep_info<Tree>(porep_config: PoRepConfig) -> CircuitInfo
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("PoRep info");

let public_params = public_params(
Expand All @@ -55,7 +60,11 @@ fn get_porep_info<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) ->
circuit_info(circuit)
}

fn get_winning_post_info<Tree: 'static + MerkleTreeTrait>(post_config: &PoStConfig) -> CircuitInfo {
fn get_winning_post_info<Tree>(post_config: &PoStConfig) -> CircuitInfo
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("Winning PoSt info");

let post_public_params = winning_post_public_params::<Tree>(post_config)
Expand All @@ -69,7 +78,11 @@ fn get_winning_post_info<Tree: 'static + MerkleTreeTrait>(post_config: &PoStConf
circuit_info(circuit)
}

fn get_window_post_info<Tree: 'static + MerkleTreeTrait>(post_config: &PoStConfig) -> CircuitInfo {
fn get_window_post_info<Tree>(post_config: &PoStConfig) -> CircuitInfo
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("Window PoSt info");

let post_public_params = window_post_public_params::<Tree>(post_config)
Expand Down
13 changes: 9 additions & 4 deletions fil-proofs-tooling/src/bin/gen_graph_cache/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::io::BufWriter;
use std::path::Path;

use anyhow::Result;
use blstrs::Scalar as Fr;
use clap::{value_t, App, Arg};
use filecoin_hashers::sha256::Sha256Hasher;
use filecoin_hashers::{sha256::Sha256Hasher, Domain, Hasher};
use filecoin_proofs::{
with_shape, DRG_DEGREE, EXP_DEGREE, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_GIB, SECTOR_SIZE_512_MIB,
SECTOR_SIZE_64_GIB, SECTOR_SIZE_8_MIB,
Expand All @@ -24,12 +25,16 @@ pub struct ParentCacheSummary {
pub digest: String,
}

fn gen_graph_cache<Tree: 'static + MerkleTreeTrait>(
fn gen_graph_cache<Tree>(
sector_size: usize,
porep_id: [u8; 32],
api_version: ApiVersion,
parent_cache_summary_map: &mut ParentCacheSummaryMap,
) -> Result<()> {
) -> Result<()>
where
Tree: 'static + MerkleTreeTrait,
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
let nodes = (sector_size / 32) as usize;

// Note that layers and challenge_count don't affect the graph, so
Expand All @@ -47,7 +52,7 @@ fn gen_graph_cache<Tree: 'static + MerkleTreeTrait>(
api_version,
};

let pp = StackedDrg::<Tree, Sha256Hasher>::setup(&sp).expect("failed to setup DRG");
let pp = StackedDrg::<Tree, Sha256Hasher<Fr>>::setup(&sp).expect("failed to setup DRG");
let parent_cache = pp.graph.parent_cache()?;

let data = ParentCacheSummary {
Expand Down
Loading

0 comments on commit f1af449

Please sign in to comment.