Skip to content

Commit 220308f

Browse files
feat: add Pasta compatible hashers
1 parent 1758ec6 commit 220308f

File tree

105 files changed

+4559
-2266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+4559
-2266
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ jobs:
9898
cargo +$(cat rust-toolchain) test -p storage-proofs-update --features isolated-testing --release test_empty_sector_update_circuit_8kib
9999
cargo +$(cat rust-toolchain) test -p storage-proofs-update --features isolated-testing --release test_empty_sector_update_circuit_16kib
100100
cargo +$(cat rust-toolchain) test -p storage-proofs-update --features isolated-testing --release test_empty_sector_update_circuit_32kib
101+
cargo +$(cat rust-toolchain) test -p storage-proofs-update --features isolated-testing --release test_empty_sector_update_poseidon_circuit_1kib
102+
cargo +$(cat rust-toolchain) test -p storage-proofs-update --features isolated-testing --release test_empty_sector_update_poseidon_circuit_8kib
101103
no_output_timeout: 30m
102104

103105
test_ignored_release:

fil-proofs-param/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ indicatif = "0.15.0"
4949
group = "0.11.0"
5050
dialoguer = "0.8.0"
5151
clap = "2.33.3"
52+
blstrs = "0.4.0"
5253

5354
[dependencies.reqwest]
5455
version = "0.10"

fil-proofs-param/src/bin/paramcache.rs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use std::env;
22
use std::process::exit;
33
use std::str::FromStr;
44

5+
use blstrs::Scalar as Fr;
56
use dialoguer::{theme::ColorfulTheme, MultiSelect};
7+
use filecoin_hashers::{Domain, Hasher};
68
use filecoin_proofs::{
79
constants::{
810
DefaultPieceHasher, POREP_PARTITIONS, PUBLISHED_SECTOR_SIZES, WINDOW_POST_CHALLENGE_COUNT,
@@ -22,14 +24,14 @@ use storage_proofs_core::{
2224
};
2325
use storage_proofs_porep::stacked::{StackedCircuit, StackedCompound, StackedDrg};
2426
use storage_proofs_post::fallback::{FallbackPoSt, FallbackPoStCircuit, FallbackPoStCompound};
25-
use storage_proofs_update::constants::TreeRHasher;
26-
use storage_proofs_update::{
27-
circuit::EmptySectorUpdateCircuit, compound::EmptySectorUpdateCompound, EmptySectorUpdate,
28-
PublicParams,
29-
};
27+
use storage_proofs_update::{constants::TreeRHasher, EmptySectorUpdateCompound};
3028
use structopt::StructOpt;
3129

32-
fn cache_porep_params<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) {
30+
fn cache_porep_params<Tree>(porep_config: PoRepConfig)
31+
where
32+
Tree: 'static + MerkleTreeTrait,
33+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
34+
{
3335
info!("generating PoRep groth params");
3436

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

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

7278
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
9298
.expect("failed to get verifying key");
9399
}
94100

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

98108
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
118128
.expect("failed to get verifying key");
119129
}
120130

121-
fn cache_empty_sector_update_params<Tree: 'static + MerkleTreeTrait<Hasher = TreeRHasher>>(
122-
porep_config: PoRepConfig,
123-
) {
131+
fn cache_empty_sector_update_params<Tree>(porep_config: PoRepConfig)
132+
where
133+
Tree: 'static + MerkleTreeTrait<Hasher = TreeRHasher<Fr>>,
134+
{
124135
info!("generating EmptySectorUpdate groth params");
125136

126-
let public_params: storage_proofs_update::PublicParams =
127-
PublicParams::from_sector_size(u64::from(porep_config.sector_size));
137+
let public_params =
138+
storage_proofs_update::PublicParams::from_sector_size(u64::from(porep_config.sector_size));
128139

129-
let circuit = <EmptySectorUpdateCompound<Tree> as CompoundProof<
130-
EmptySectorUpdate<Tree>,
131-
EmptySectorUpdateCircuit<Tree>,
132-
>>::blank_circuit(&public_params);
140+
let circuit = EmptySectorUpdateCompound::<
141+
Tree::Arity,
142+
Tree::SubTreeArity,
143+
Tree::TopTreeArity,
144+
>::blank_circuit(&public_params);
133145

134-
let _ = <EmptySectorUpdateCompound<Tree> as CompoundProof<
135-
EmptySectorUpdate<Tree>,
136-
EmptySectorUpdateCircuit<Tree>,
137-
>>::groth_params::<OsRng>(Some(&mut OsRng), &public_params)
146+
let _ = EmptySectorUpdateCompound::<
147+
Tree::Arity,
148+
Tree::SubTreeArity,
149+
Tree::TopTreeArity,
150+
>::groth_params(Some(&mut OsRng), &public_params)
138151
.expect("failed to get groth params");
139152

140-
let _ = <EmptySectorUpdateCompound<Tree>>::get_param_metadata(circuit, &public_params)
153+
let _ = EmptySectorUpdateCompound::get_param_metadata(circuit, &public_params)
141154
.expect("failed to get metadata");
142155

143-
let _ = <EmptySectorUpdateCompound<Tree> as CompoundProof<
144-
EmptySectorUpdate<Tree>,
145-
EmptySectorUpdateCircuit<Tree>,
146-
>>::verifying_key::<OsRng>(Some(&mut OsRng), &public_params)
156+
let _ = EmptySectorUpdateCompound::<
157+
Tree::Arity,
158+
Tree::SubTreeArity,
159+
Tree::TopTreeArity,
160+
>::verifying_key(Some(&mut OsRng), &public_params)
147161
.expect("failed to get verifying key");
148162
}
149163

fil-proofs-tooling/src/bin/benchy/prodbench.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,11 @@ fn measure_porep_circuit(i: &ProdbenchInputs) -> usize {
286286
api_version: i.api_version(),
287287
};
288288

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

291292
let mut cs = BenchCS::<Fr>::new();
292-
<StackedCompound<_, _> as CompoundProof<StackedDrg<ProdbenchTree, Sha256Hasher>, _>>::blank_circuit(
293+
<StackedCompound<_, _> as CompoundProof<StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>, _>>::blank_circuit(
293294
&pp,
294295
)
295296
.synthesize(&mut cs)
@@ -332,18 +333,21 @@ fn cache_porep_params(porep_config: PoRepConfig) {
332333

333334
{
334335
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
335-
StackedDrg<ProdbenchTree, Sha256Hasher>,
336+
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
336337
_,
337338
>>::blank_circuit(&public_params);
338-
StackedCompound::<ProdbenchTree, Sha256Hasher>::get_param_metadata(circuit, &public_params)
339-
.expect("cannot get param metadata");
339+
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_param_metadata(
340+
circuit,
341+
&public_params,
342+
)
343+
.expect("cannot get param metadata");
340344
}
341345
{
342346
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
343-
StackedDrg<ProdbenchTree, Sha256Hasher>,
347+
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
344348
_,
345349
>>::blank_circuit(&public_params);
346-
StackedCompound::<ProdbenchTree, Sha256Hasher>::get_groth_params(
350+
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_groth_params(
347351
Some(&mut XorShiftRng::from_seed(SEED)),
348352
circuit,
349353
&public_params,
@@ -352,11 +356,11 @@ fn cache_porep_params(porep_config: PoRepConfig) {
352356
}
353357
{
354358
let circuit = <StackedCompound<ProdbenchTree, _> as CompoundProof<
355-
StackedDrg<ProdbenchTree, Sha256Hasher>,
359+
StackedDrg<ProdbenchTree, Sha256Hasher<Fr>>,
356360
_,
357361
>>::blank_circuit(&public_params);
358362

359-
StackedCompound::<ProdbenchTree, Sha256Hasher>::get_verifying_key(
363+
StackedCompound::<ProdbenchTree, Sha256Hasher<Fr>>::get_verifying_key(
360364
Some(&mut XorShiftRng::from_seed(SEED)),
361365
circuit,
362366
&public_params,

fil-proofs-tooling/src/bin/benchy/window_post.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use std::time::{SystemTime, UNIX_EPOCH};
66

77
use anyhow::{ensure, Context};
88
use bincode::{deserialize, serialize};
9+
use blstrs::Scalar as Fr;
910
use fil_proofs_tooling::measure::FuncMeasurement;
1011
use fil_proofs_tooling::shared::{PROVER_ID, RANDOMNESS, TICKET_BYTES};
1112
use fil_proofs_tooling::{measure, Metadata};
13+
use filecoin_hashers::{Domain, Hasher};
1214
use filecoin_proofs::constants::{
1315
POREP_PARTITIONS, WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT,
1416
};
@@ -96,15 +98,19 @@ fn get_porep_config(sector_size: u64, api_version: ApiVersion) -> PoRepConfig {
9698
}
9799
}
98100

99-
fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
101+
fn run_pre_commit_phases<Tree>(
100102
sector_size: u64,
101103
api_version: ApiVersion,
102104
cache_dir: PathBuf,
103105
skip_precommit_phase1: bool,
104106
skip_precommit_phase2: bool,
105107
test_resume: bool,
106108
skip_staging: bool,
107-
) -> anyhow::Result<((u64, u64), (u64, u64), (u64, u64))> {
109+
) -> anyhow::Result<((u64, u64), (u64, u64), (u64, u64))>
110+
where
111+
Tree: 'static + MerkleTreeTrait,
112+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
113+
{
108114
let (seal_pre_commit_phase1_measurement_cpu_time, seal_pre_commit_phase1_measurement_wall_time): (u64, u64) = if skip_precommit_phase1 {
109115
// generate no-op measurements
110116
(0, 0)
@@ -335,7 +341,7 @@ fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
335341
}
336342

337343
#[allow(clippy::too_many_arguments)]
338-
pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
344+
pub fn run_window_post_bench<Tree>(
339345
sector_size: u64,
340346
api_version: ApiVersion,
341347
cache_dir: PathBuf,
@@ -345,7 +351,11 @@ pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
345351
skip_commit_phase1: bool,
346352
skip_commit_phase2: bool,
347353
test_resume: bool,
348-
) -> anyhow::Result<()> {
354+
) -> anyhow::Result<()>
355+
where
356+
Tree: 'static + MerkleTreeTrait,
357+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
358+
{
349359
let (
350360
(seal_pre_commit_phase1_cpu_time_ms, seal_pre_commit_phase1_wall_time_ms),
351361
(

fil-proofs-tooling/src/bin/benchy/winning_post.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::io::stdout;
22

33
use anyhow::anyhow;
4+
use blstrs::Scalar as Fr;
45
use fil_proofs_tooling::shared::{create_replica, PROVER_ID, RANDOMNESS};
56
use fil_proofs_tooling::{measure, Metadata};
7+
use filecoin_hashers::{Domain, Hasher};
68
use filecoin_proofs::constants::{WINNING_POST_CHALLENGE_COUNT, WINNING_POST_SECTOR_COUNT};
79
use filecoin_proofs::types::PoStConfig;
810
use filecoin_proofs::{
@@ -46,10 +48,14 @@ impl Report {
4648
}
4749
}
4850

49-
pub fn run_fallback_post_bench<Tree: 'static + MerkleTreeTrait>(
51+
pub fn run_fallback_post_bench<Tree>(
5052
sector_size: u64,
5153
api_version: ApiVersion,
52-
) -> anyhow::Result<()> {
54+
) -> anyhow::Result<()>
55+
where
56+
Tree: 'static + MerkleTreeTrait,
57+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
58+
{
5359
if WINNING_POST_SECTOR_COUNT != 1 {
5460
return Err(anyhow!(
5561
"This benchmark only works with WINNING_POST_SECTOR_COUNT == 1"

fil-proofs-tooling/src/bin/circuitinfo/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::str::FromStr;
33
use bellperson::{util_cs::bench_cs::BenchCS, Circuit};
44
use blstrs::Scalar as Fr;
55
use dialoguer::{theme::ColorfulTheme, MultiSelect};
6+
use filecoin_hashers::{Domain, Hasher};
67
use filecoin_proofs::{
78
parameters::{public_params, window_post_public_params, winning_post_public_params},
89
with_shape, DefaultPieceHasher, PaddedBytesAmount, PoRepConfig, PoRepProofPartitions,
@@ -36,7 +37,11 @@ fn circuit_info<C: Circuit<Fr>>(circuit: C) -> CircuitInfo {
3637
}
3738
}
3839

39-
fn get_porep_info<Tree: 'static + MerkleTreeTrait>(porep_config: PoRepConfig) -> CircuitInfo {
40+
fn get_porep_info<Tree>(porep_config: PoRepConfig) -> CircuitInfo
41+
where
42+
Tree: 'static + MerkleTreeTrait,
43+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
44+
{
4045
info!("PoRep info");
4146

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

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

6170
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
6978
circuit_info(circuit)
7079
}
7180

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

7588
let post_public_params = window_post_public_params::<Tree>(post_config)

fil-proofs-tooling/src/bin/gen_graph_cache/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::io::BufWriter;
44
use std::path::Path;
55

66
use anyhow::Result;
7+
use blstrs::Scalar as Fr;
78
use clap::{value_t, App, Arg};
8-
use filecoin_hashers::sha256::Sha256Hasher;
9+
use filecoin_hashers::{sha256::Sha256Hasher, Domain, Hasher};
910
use filecoin_proofs::{
1011
with_shape, DRG_DEGREE, EXP_DEGREE, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_GIB, SECTOR_SIZE_512_MIB,
1112
SECTOR_SIZE_64_GIB, SECTOR_SIZE_8_MIB,
@@ -24,12 +25,16 @@ pub struct ParentCacheSummary {
2425
pub digest: String,
2526
}
2627

27-
fn gen_graph_cache<Tree: 'static + MerkleTreeTrait>(
28+
fn gen_graph_cache<Tree>(
2829
sector_size: usize,
2930
porep_id: [u8; 32],
3031
api_version: ApiVersion,
3132
parent_cache_summary_map: &mut ParentCacheSummaryMap,
32-
) -> Result<()> {
33+
) -> Result<()>
34+
where
35+
Tree: 'static + MerkleTreeTrait,
36+
<Tree::Hasher as Hasher>::Domain: Domain<Field = Fr>,
37+
{
3338
let nodes = (sector_size / 32) as usize;
3439

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

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

5358
let data = ParentCacheSummary {

0 commit comments

Comments
 (0)