-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] feat: Halo2 compatible vanilla Hashers #1560
base: master
Are you sure you want to change the base?
Changes from 3 commits
6c28dd0
7edf855
ee726db
020b406
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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( | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESU can only use TreeRs whose hasher is |
||
{ | ||
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"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}; | ||
|
@@ -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>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: for now, only bench using the field |
||
{ | ||
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) | ||
|
@@ -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, | ||
|
@@ -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), | ||
( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Groth16 circuits can only be created using the field |
||
{ | ||
info!("PoRep info"); | ||
|
||
let public_params = public_params( | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: for now, only generate parent cache for the production field |
||
{ | ||
let nodes = (sector_size / 32) as usize; | ||
|
||
// Note that layers and challenge_count don't affect the graph, so | ||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Groth16 params can only be generated for the field
Fr
.