Skip to content

Commit

Permalink
feat: Halo2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPeterVanNostrand committed Feb 10, 2022
1 parent 38b4eaa commit ad5955e
Show file tree
Hide file tree
Showing 56 changed files with 1,056 additions and 504 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
21 changes: 17 additions & 4 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 @@ -29,7 +31,10 @@ use storage_proofs_update::{
};
use structopt::StructOpt;

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

let public_params = public_params(
Expand Down Expand Up @@ -66,7 +71,10 @@ 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: 'static + MerkleTreeTrait>(post_config: &PoStConfig)
where
<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 +100,10 @@ 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: 'static + MerkleTreeTrait>(post_config: &PoStConfig)
where
<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 Down Expand Up @@ -120,7 +131,9 @@ fn cache_window_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoStC

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

let public_params: storage_proofs_update::PublicParams =
Expand Down
12 changes: 10 additions & 2 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 @@ -104,7 +106,10 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
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::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 @@ -345,7 +350,10 @@ 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::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
let (
(seal_pre_commit_phase1_cpu_time_ms, seal_pre_commit_phase1_wall_time_ms),
(
Expand Down
7 changes: 6 additions & 1 deletion 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 @@ -49,7 +51,10 @@ impl Report {
pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
) -> anyhow::Result<()> {
) -> anyhow::Result<()>
where
<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
16 changes: 13 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,10 @@ 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: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) -> CircuitInfo
where
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("PoRep info");

let public_params = public_params(
Expand All @@ -55,7 +59,10 @@ 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: 'static + MerkleTreeTrait>(post_config: &PoStConfig) -> CircuitInfo
where
<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 +76,10 @@ 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: 'static + MerkleTreeTrait>(post_config: &PoStConfig) -> CircuitInfo
where
<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
8 changes: 6 additions & 2 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 @@ -29,7 +30,10 @@ fn gen_graph_cache<Tree: 'static + MerkleTreeTrait>(
porep_id: [u8; 32],
api_version: ApiVersion,
parent_cache_summary_map: &mut ParentCacheSummaryMap,
) -> Result<()> {
) -> Result<()>
where
<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 Down
17 changes: 14 additions & 3 deletions fil-proofs-tooling/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::cmp::min;
use std::io::{BufWriter, Seek, SeekFrom, Write};

use blstrs::Scalar as Fr;
use filecoin_hashers::{Domain, Hasher};
use filecoin_proofs::{
add_piece, seal_pre_commit_phase1, seal_pre_commit_phase2, validate_cache_for_precommit_phase2,
MerkleTreeTrait, PaddedBytesAmount, PieceInfo, PoRepConfig, PoRepProofPartitions,
Expand All @@ -21,7 +23,10 @@ pub const PROVER_ID: [u8; 32] = [9; 32];
pub const RANDOMNESS: [u8; 32] = [44; 32];
pub const TICKET_BYTES: [u8; 32] = [1; 32];

pub struct PreCommitReplicaOutput<Tree: 'static + MerkleTreeTrait> {
pub struct PreCommitReplicaOutput<Tree: 'static + MerkleTreeTrait>
where
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
pub piece_info: Vec<PieceInfo>,
pub private_replica_info: PrivateReplicaInfo<Tree>,
pub public_replica_info: PublicReplicaInfo,
Expand Down Expand Up @@ -69,7 +74,10 @@ pub fn create_replica<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
porep_id: [u8; 32],
api_version: ApiVersion,
) -> (SectorId, PreCommitReplicaOutput<Tree>) {
) -> (SectorId, PreCommitReplicaOutput<Tree>)
where
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
let (_porep_config, result) =
create_replicas::<Tree>(SectorSize(sector_size), 1, false, porep_id, api_version);
// Extract the sector ID and replica output out of the result
Expand All @@ -93,7 +101,10 @@ pub fn create_replicas<Tree: 'static + MerkleTreeTrait>(
Vec<(SectorId, PreCommitReplicaOutput<Tree>)>,
FuncMeasurement<Vec<SealPreCommitOutput>>,
)>,
) {
)
where
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
{
info!("creating replicas: {:?} - {}", sector_size, qty_sectors);
let sector_size_unpadded_bytes_ammount =
UnpaddedBytesAmount::from(PaddedBytesAmount::from(sector_size));
Expand Down
Loading

0 comments on commit ad5955e

Please sign in to comment.