From 13517c7e1eb7c373b5d1fe8318f6acf2e4c86d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E7=BF=B0?= Date: Wed, 26 Oct 2022 06:22:12 +0000 Subject: [PATCH] feat: Introduce PoRepConfig::new_groth16() Instead of constructing the `PoRepConfig` directly, use a constructor function. This simplifies the code and makes things less error-prone. Fixes #1632. --- fil-proofs-param/src/bin/paramcache.rs | 28 +-------- .../src/bin/benchy/prodbench.rs | 16 +++-- .../src/bin/benchy/window_post.rs | 22 ++----- .../src/bin/circuitinfo/main.rs | 7 +-- fil-proofs-tooling/src/shared.rs | 17 +----- filecoin-proofs/benches/aggregation.rs | 44 ++------------ filecoin-proofs/benches/preprocessing.rs | 17 +----- filecoin-proofs/src/api/seal.rs | 18 ++---- filecoin-proofs/src/constants.rs | 59 +++++++++++++------ filecoin-proofs/src/parameters.rs | 9 +-- filecoin-proofs/src/types/porep_config.rs | 17 ++++++ filecoin-proofs/tests/api.rs | 27 +++------ filecoin-proofs/tests/mod.rs | 41 ++----------- 13 files changed, 106 insertions(+), 216 deletions(-) diff --git a/fil-proofs-param/src/bin/paramcache.rs b/fil-proofs-param/src/bin/paramcache.rs index dc09323d8..86168c557 100644 --- a/fil-proofs-param/src/bin/paramcache.rs +++ b/fil-proofs-param/src/bin/paramcache.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use dialoguer::{theme::ColorfulTheme, MultiSelect}; use filecoin_proofs::{ constants::{ - DefaultPieceHasher, POREP_PARTITIONS, PUBLISHED_SECTOR_SIZES, WINDOW_POST_CHALLENGE_COUNT, + DefaultPieceHasher, PUBLISHED_SECTOR_SIZES, WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT, WINNING_POST_CHALLENGE_COUNT, WINNING_POST_SECTOR_COUNT, }, parameters::{public_params, window_post_public_params, winning_post_public_params}, @@ -213,18 +213,7 @@ fn generate_params_porep(sector_size: u64, api_version: ApiVersion) { with_shape!( sector_size, cache_porep_params, - PoRepConfig { - sector_size: SectorSize(sector_size), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(§or_size) - .expect("unknown sector size"), - ), - porep_id: [0; 32], - api_version, - } + PoRepConfig::new_groth16(sector_size, [0; 32], api_version) ); } @@ -232,18 +221,7 @@ fn generate_params_empty_sector_update(sector_size: u64, api_version: ApiVersion with_shape!( sector_size, cache_empty_sector_update_params, - PoRepConfig { - sector_size: SectorSize(sector_size), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(§or_size) - .expect("unknown sector size"), - ), - porep_id: [0; 32], - api_version, - } + PoRepConfig::new_groth16(sector_size, [0; 32], api_version) ); } diff --git a/fil-proofs-tooling/src/bin/benchy/prodbench.rs b/fil-proofs-tooling/src/bin/benchy/prodbench.rs index 1d302de34..37e4fb196 100644 --- a/fil-proofs-tooling/src/bin/benchy/prodbench.rs +++ b/fil-proofs-tooling/src/bin/benchy/prodbench.rs @@ -168,9 +168,8 @@ fn configure_global_config(inputs: &ProdbenchInputs) { .expect("POREP_PARTITIONS poisoned") .insert(inputs.sector_size_bytes(), inputs.porep_partitions); POREP_MINIMUM_CHALLENGES - .write() - .expect("POREP_MINIMUM_CHALLENGES poisoned") - .insert(inputs.sector_size_bytes(), inputs.porep_challenges); + .get_mut() + .insert(inputs.sector_size_bytes(), inputs.porep_challenges as usize); } pub fn run( @@ -314,12 +313,11 @@ fn generate_params(i: &ProdbenchInputs) { ); let dummy_porep_id = [0; 32]; - cache_porep_params(PoRepConfig { - sector_size, - partitions, - porep_id: dummy_porep_id, - api_version: i.api_version(), - }); + cache_porep_params(PoRepConfig::new_groth16( + i.sector_size_bytes(), + dummy_porep_id, + i.api_version(), + )); } fn cache_porep_params(porep_config: PoRepConfig) { diff --git a/fil-proofs-tooling/src/bin/benchy/window_post.rs b/fil-proofs-tooling/src/bin/benchy/window_post.rs index 72e72772c..5d327c6ce 100644 --- a/fil-proofs-tooling/src/bin/benchy/window_post.rs +++ b/fil-proofs-tooling/src/bin/benchy/window_post.rs @@ -9,13 +9,10 @@ use bincode::{deserialize, serialize}; use fil_proofs_tooling::measure::FuncMeasurement; use fil_proofs_tooling::shared::{PROVER_ID, RANDOMNESS, TICKET_BYTES}; use fil_proofs_tooling::{measure, Metadata}; -use filecoin_proofs::constants::{ - POREP_PARTITIONS, WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT, -}; +use filecoin_proofs::constants::{WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT}; use filecoin_proofs::types::{ - PaddedBytesAmount, PieceInfo, PoRepConfig, PoRepProofPartitions, PoStConfig, - SealCommitPhase1Output, SealPreCommitOutput, SealPreCommitPhase1Output, SectorSize, - UnpaddedBytesAmount, + PaddedBytesAmount, PieceInfo, PoRepConfig, PoStConfig, SealCommitPhase1Output, + SealPreCommitOutput, SealPreCommitPhase1Output, SectorSize, UnpaddedBytesAmount, }; use filecoin_proofs::{ add_piece, generate_piece_commitment, generate_window_post, seal_commit_phase1, @@ -82,18 +79,7 @@ fn get_porep_config(sector_size: u64, api_version: ApiVersion) -> PoRepConfig { let arbitrary_porep_id = [99; 32]; // Replicate the staged sector, write the replica file to `sealed_path`. - PoRepConfig { - sector_size: SectorSize(sector_size), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITONS poisoned") - .get(&(sector_size)) - .expect("unknown sector size"), - ), - porep_id: arbitrary_porep_id, - api_version, - } + PoRepConfig::new_groth16(sector_size, arbitrary_porep_id, api_version) } fn run_pre_commit_phases( diff --git a/fil-proofs-tooling/src/bin/circuitinfo/main.rs b/fil-proofs-tooling/src/bin/circuitinfo/main.rs index f8e4791b1..6a88e669b 100644 --- a/fil-proofs-tooling/src/bin/circuitinfo/main.rs +++ b/fil-proofs-tooling/src/bin/circuitinfo/main.rs @@ -143,12 +143,7 @@ fn porep_info(sector_size: u64, api_version: ApiVersion) -> (CircuitInfo, usize) let info = with_shape!( sector_size, get_porep_info, - PoRepConfig { - sector_size: SectorSize(sector_size), - partitions, - porep_id: [0; 32], - api_version, - } + PoRepConfig::new_groth16(sector_size, [0; 32], api_version) ); (info, partitions.into()) } diff --git a/fil-proofs-tooling/src/shared.rs b/fil-proofs-tooling/src/shared.rs index 12f1d3c78..27f258f15 100644 --- a/fil-proofs-tooling/src/shared.rs +++ b/fil-proofs-tooling/src/shared.rs @@ -5,8 +5,8 @@ use std::io::{BufWriter, Seek, SeekFrom, Write}; use filecoin_proofs::{ add_piece, fauxrep_aux, seal_pre_commit_phase1, seal_pre_commit_phase2, validate_cache_for_precommit_phase2, MerkleTreeTrait, PaddedBytesAmount, PieceInfo, - PoRepConfig, PoRepProofPartitions, PrivateReplicaInfo, PublicReplicaInfo, SealPreCommitOutput, - SealPreCommitPhase1Output, SectorSize, UnpaddedBytesAmount, POREP_PARTITIONS, + PoRepConfig, PrivateReplicaInfo, PublicReplicaInfo, SealPreCommitOutput, + SealPreCommitPhase1Output, SectorSize, UnpaddedBytesAmount, }; use generic_array::typenum::Unsigned; use log::info; @@ -118,18 +118,7 @@ pub fn create_replicas( let sector_size_unpadded_bytes_ammount = UnpaddedBytesAmount::from(PaddedBytesAmount::from(sector_size)); - let porep_config = PoRepConfig { - sector_size, - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("poisoned read access") - .get(&u64::from(sector_size)) - .expect("unknown sector size"), - ), - porep_id, - api_version, - }; + let porep_config = PoRepConfig::new_groth16(u64::from(sector_size), porep_id, api_version); let mut out: Vec<(SectorId, PreCommitReplicaOutput)> = Default::default(); let mut sector_ids = Vec::new(); diff --git a/filecoin-proofs/benches/aggregation.rs b/filecoin-proofs/benches/aggregation.rs index 88ca02974..671120b49 100644 --- a/filecoin-proofs/benches/aggregation.rs +++ b/filecoin-proofs/benches/aggregation.rs @@ -4,8 +4,8 @@ use std::time::Duration; use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; use filecoin_proofs::{ caches::{get_stacked_srs_key, get_stacked_srs_verifier_key}, - get_seal_inputs, PoRepConfig, PoRepProofPartitions, SectorShape2KiB, SectorShape32GiB, - SectorSize, POREP_PARTITIONS, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_GIB, + get_seal_inputs, PoRepConfig, SectorShape2KiB, SectorShape32GiB, SECTOR_SIZE_2_KIB, + SECTOR_SIZE_32_GIB, }; use rand::{thread_rng, Rng}; use storage_proofs_core::{api_version::ApiVersion, is_legacy_porep_id}; @@ -28,18 +28,8 @@ fn bench_seal_inputs(c: &mut Criterion) { porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); assert!(!is_legacy_porep_id(porep_id)); - let config = PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_2_KIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_2_KIB) - .expect("unknown sector size"), - ), - porep_id, - api_version: ApiVersion::V1_1_0, - }; + let config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, ApiVersion::V1_1_0); + let comm_r = [5u8; 32]; let comm_d = [6u8; 32]; let prover_id = [7u8; 32]; @@ -79,18 +69,7 @@ fn bench_stacked_srs_key(c: &mut Criterion) { porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); assert!(!is_legacy_porep_id(porep_id)); - let config = PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_32_GIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_32_GIB) - .expect("unknown sector size"), - ), - porep_id, - api_version: ApiVersion::V1_1_0, - }; + let config = PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id, ApiVersion::V1_1_0); let mut group = c.benchmark_group("bench-stacked-srs-key"); for num_proofs_to_aggregate in params { @@ -120,18 +99,7 @@ fn bench_stacked_srs_verifier_key(c: &mut Criterion) { porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); assert!(!is_legacy_porep_id(porep_id)); - let config = PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_32_GIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_32_GIB) - .expect("unknown sector size"), - ), - porep_id, - api_version: ApiVersion::V1_1_0, - }; + let config = PoRepConfig::new_groth16(SECTOR_SIZE_32_GIB, porep_id, ApiVersion::V1_1_0); let mut group = c.benchmark_group("bench-stacked-srs-verifier-key"); for num_proofs_to_aggregate in params { diff --git a/filecoin-proofs/benches/preprocessing.rs b/filecoin-proofs/benches/preprocessing.rs index 9ddc39fea..c41b4673d 100644 --- a/filecoin-proofs/benches/preprocessing.rs +++ b/filecoin-proofs/benches/preprocessing.rs @@ -3,8 +3,8 @@ use std::time::Duration; use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use filecoin_proofs::{ - add_piece, get_seal_inputs, PaddedBytesAmount, PoRepConfig, PoRepProofPartitions, - SectorShape2KiB, SectorSize, UnpaddedBytesAmount, POREP_PARTITIONS, SECTOR_SIZE_2_KIB, + add_piece, get_seal_inputs, PaddedBytesAmount, PoRepConfig, SectorShape2KiB, + UnpaddedBytesAmount, SECTOR_SIZE_2_KIB, }; use fr32::Fr32Reader; use rand::{thread_rng, Rng}; @@ -114,18 +114,7 @@ fn get_seal_inputs_benchmark(c: &mut Criterion) { porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); assert!(!is_legacy_porep_id(porep_id)); - let config = PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_2_KIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_2_KIB) - .expect("unknown sector size"), - ), - porep_id, - api_version: ApiVersion::V1_1_0, - }; + let config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, ApiVersion::V1_1_0); let comm_r: [u8; 32] = [5u8; 32]; let comm_d: [u8; 32] = [6u8; 32]; let prover_id: [u8; 32] = [7u8; 32]; diff --git a/filecoin-proofs/src/api/seal.rs b/filecoin-proofs/src/api/seal.rs index 9f405e47c..cbc715f7f 100644 --- a/filecoin-proofs/src/api/seal.rs +++ b/filecoin-proofs/src/api/seal.rs @@ -30,6 +30,7 @@ use storage_proofs_porep::stacked::{ TemporaryAux, TemporaryAuxCache, }; +use crate::POREP_MINIMUM_CHALLENGES; use crate::{ api::{as_safe_commitment, commitment_from_fr, get_base_tree_leafs, get_base_tree_size}, caches::{ @@ -37,8 +38,7 @@ use crate::{ get_stacked_verifying_key, }, constants::{ - DefaultBinaryTree, DefaultPieceDomain, DefaultPieceHasher, POREP_MINIMUM_CHALLENGES, - SINGLE_PARTITION_PROOF_LEN, + DefaultBinaryTree, DefaultPieceDomain, DefaultPieceHasher, SINGLE_PARTITION_PROOF_LEN, }, parameters::setup_params, pieces::{self, verify_pieces}, @@ -989,11 +989,8 @@ pub fn verify_seal( &public_inputs, &proof, &ChallengeRequirements { - minimum_challenges: *POREP_MINIMUM_CHALLENGES - .read() - .expect("POREP_MINIMUM_CHALLENGES poisoned") - .get(&u64::from(SectorSize::from(porep_config))) - .expect("unknown sector size") as usize, + minimum_challenges: POREP_MINIMUM_CHALLENGES + .from_sector_size(u64::from(SectorSize::from(porep_config))), }, ) }; @@ -1112,11 +1109,8 @@ pub fn verify_batch_seal( &public_inputs, &proofs, &ChallengeRequirements { - minimum_challenges: *POREP_MINIMUM_CHALLENGES - .read() - .expect("POREP_MINIMUM_CHALLENGES poisoned") - .get(&u64::from(SectorSize::from(porep_config))) - .expect("unknown sector size") as usize, + minimum_challenges: POREP_MINIMUM_CHALLENGES + .from_sector_size(u64::from(SectorSize::from(porep_config))), }, ) .map_err(Into::into); diff --git a/filecoin-proofs/src/constants.rs b/filecoin-proofs/src/constants.rs index 1a436cac6..064691bdc 100644 --- a/filecoin-proofs/src/constants.rs +++ b/filecoin-proofs/src/constants.rs @@ -1,5 +1,5 @@ -use std::collections::HashMap; use std::sync::RwLock; +use std::{collections::HashMap, sync::RwLockWriteGuard}; pub use storage_proofs_core::drgraph::BASE_DEGREE as DRG_DEGREE; pub use storage_proofs_porep::stacked::EXP_DEGREE; @@ -47,24 +47,47 @@ pub const PUBLISHED_SECTOR_SIZES: [u64; 10] = [ SECTOR_SIZE_64_GIB, ]; +pub struct PorepMinimumChallenges(RwLock>); +impl PorepMinimumChallenges { + fn new() -> Self { + Self(RwLock::new( + [ + (SECTOR_SIZE_2_KIB, 2), + (SECTOR_SIZE_4_KIB, 2), + (SECTOR_SIZE_16_KIB, 2), + (SECTOR_SIZE_32_KIB, 2), + (SECTOR_SIZE_8_MIB, 2), + (SECTOR_SIZE_16_MIB, 2), + (SECTOR_SIZE_512_MIB, 2), + (SECTOR_SIZE_1_GIB, 2), + (SECTOR_SIZE_32_GIB, 176), + (SECTOR_SIZE_64_GIB, 176), + ] + .iter() + .copied() + .collect(), + )) + } + + pub fn get_mut(&self) -> RwLockWriteGuard<'_, HashMap> { + self.0.write().expect("POREP_MINIMUM_CHALLENGES poisoned") + } + + pub fn from_sector_size(&self, sector_size: u64) -> usize { + match self + .0 + .read() + .expect("POREP_MINIMUM_CHALLENGES poisoned") + .get(§or_size) + { + Some(c) => *c, + None => panic!("invalid sector size"), + } + } +} + lazy_static! { - pub static ref POREP_MINIMUM_CHALLENGES: RwLock> = RwLock::new( - [ - (SECTOR_SIZE_2_KIB, 2), - (SECTOR_SIZE_4_KIB, 2), - (SECTOR_SIZE_16_KIB, 2), - (SECTOR_SIZE_32_KIB, 2), - (SECTOR_SIZE_8_MIB, 2), - (SECTOR_SIZE_16_MIB, 2), - (SECTOR_SIZE_512_MIB, 2), - (SECTOR_SIZE_1_GIB, 2), - (SECTOR_SIZE_32_GIB, 176), - (SECTOR_SIZE_64_GIB, 176), - ] - .iter() - .copied() - .collect() - ); + pub static ref POREP_MINIMUM_CHALLENGES: PorepMinimumChallenges = PorepMinimumChallenges::new(); pub static ref POREP_PARTITIONS: RwLock> = RwLock::new( [ (SECTOR_SIZE_2_KIB, 1), diff --git a/filecoin-proofs/src/parameters.rs b/filecoin-proofs/src/parameters.rs index bc3a31f9c..b5fc4449f 100644 --- a/filecoin-proofs/src/parameters.rs +++ b/filecoin-proofs/src/parameters.rs @@ -4,8 +4,9 @@ use storage_proofs_porep::stacked::{self, LayerChallenges, StackedDrg}; use storage_proofs_post::fallback::{self, FallbackPoSt}; use crate::{ - constants::{DefaultPieceHasher, DRG_DEGREE, EXP_DEGREE, LAYERS, POREP_MINIMUM_CHALLENGES}, + constants::{DefaultPieceHasher, DRG_DEGREE, EXP_DEGREE, LAYERS}, types::{MerkleTreeTrait, PaddedBytesAmount, PoStConfig}, + POREP_MINIMUM_CHALLENGES, }; type WinningPostSetupParams = fallback::SetupParams; @@ -82,11 +83,7 @@ pub fn setup_params( ) -> Result { let layer_challenges = select_challenges( partitions, - *POREP_MINIMUM_CHALLENGES - .read() - .expect("POREP_MINIMUM_CHALLENGES poisoned") - .get(&u64::from(sector_bytes)) - .expect("unknown sector size") as usize, + POREP_MINIMUM_CHALLENGES.from_sector_size(u64::from(sector_bytes)), *LAYERS .read() .expect("LAYERS poisoned") diff --git a/filecoin-proofs/src/types/porep_config.rs b/filecoin-proofs/src/types/porep_config.rs index 4660c946b..b28c62f35 100644 --- a/filecoin-proofs/src/types/porep_config.rs +++ b/filecoin-proofs/src/types/porep_config.rs @@ -15,6 +15,7 @@ use crate::{ constants::DefaultPieceHasher, parameters::public_params, types::{PaddedBytesAmount, PoRepProofPartitions, SectorSize, UnpaddedBytesAmount}, + POREP_PARTITIONS, }; #[derive(Clone, Copy, Debug)] @@ -54,6 +55,22 @@ impl From for SectorSize { } impl PoRepConfig { + /// construct PoRepConfig by groth16 + pub fn new_groth16(sector_size: u64, porep_id: [u8; 32], api_version: ApiVersion) -> Self { + Self { + sector_size: SectorSize(sector_size), + partitions: PoRepProofPartitions( + *POREP_PARTITIONS + .read() + .expect("POREP_PARTITIONS poisoned") + .get(§or_size) + .expect("unknown sector size"), + ), + porep_id, + api_version, + } + } + /// Returns the cache identifier as used by `storage-proofs::parameter_cache`. pub fn get_cache_identifier(&self) -> Result { let params = public_params::( diff --git a/filecoin-proofs/tests/api.rs b/filecoin-proofs/tests/api.rs index 7f06f3c33..451ab8072 100644 --- a/filecoin-proofs/tests/api.rs +++ b/filecoin-proofs/tests/api.rs @@ -23,13 +23,13 @@ use filecoin_proofs::{ validate_cache_for_precommit_phase2, verify_aggregate_seal_commit_proofs, verify_empty_sector_update_proof, verify_partition_proofs, verify_seal, verify_single_partition_proof, verify_window_post, verify_winning_post, Commitment, - DefaultTreeDomain, MerkleTreeTrait, PaddedBytesAmount, PieceInfo, PoRepConfig, - PoRepProofPartitions, PoStConfig, PoStType, PrivateReplicaInfo, ProverId, PublicReplicaInfo, - SealCommitOutput, SealPreCommitOutput, SealPreCommitPhase1Output, SectorShape16KiB, - SectorShape2KiB, SectorShape32KiB, SectorShape4KiB, SectorSize, SectorUpdateConfig, - UnpaddedByteIndex, UnpaddedBytesAmount, POREP_PARTITIONS, SECTOR_SIZE_16_KIB, - SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_KIB, SECTOR_SIZE_4_KIB, WINDOW_POST_CHALLENGE_COUNT, - WINDOW_POST_SECTOR_COUNT, WINNING_POST_CHALLENGE_COUNT, WINNING_POST_SECTOR_COUNT, + DefaultTreeDomain, MerkleTreeTrait, PaddedBytesAmount, PieceInfo, PoRepConfig, PoStConfig, + PoStType, PrivateReplicaInfo, ProverId, PublicReplicaInfo, SealCommitOutput, + SealPreCommitOutput, SealPreCommitPhase1Output, SectorShape16KiB, SectorShape2KiB, + SectorShape32KiB, SectorShape4KiB, SectorUpdateConfig, UnpaddedByteIndex, UnpaddedBytesAmount, + SECTOR_SIZE_16_KIB, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_KIB, SECTOR_SIZE_4_KIB, + WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT, WINNING_POST_CHALLENGE_COUNT, + WINNING_POST_SECTOR_COUNT, }; use fr32::bytes_into_fr; use log::info; @@ -1377,18 +1377,7 @@ fn generate_piece_file(sector_size: u64) -> Result<(NamedTempFile, Vec)> { } fn porep_config(sector_size: u64, porep_id: [u8; 32], api_version: ApiVersion) -> PoRepConfig { - PoRepConfig { - sector_size: SectorSize(sector_size), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(§or_size) - .expect("unknown sector size"), - ), - porep_id, - api_version, - } + PoRepConfig::new_groth16(sector_size, porep_id, api_version) } fn run_seal_pre_commit_phase1( diff --git a/filecoin-proofs/tests/mod.rs b/filecoin-proofs/tests/mod.rs index 5625a1d39..5a8e4186c 100644 --- a/filecoin-proofs/tests/mod.rs +++ b/filecoin-proofs/tests/mod.rs @@ -4,7 +4,7 @@ use blstrs::Scalar as Fr; use ff::Field; use filecoin_proofs::{ as_safe_commitment, verify_seal, DefaultOctLCTree, DefaultTreeDomain, PoRepConfig, - PoRepProofPartitions, SectorSize, POREP_PARTITIONS, SECTOR_SIZE_2_KIB, TEST_SEED, + SECTOR_SIZE_2_KIB, TEST_SEED, }; use fr32::bytes_into_fr; use rand::SeedableRng; @@ -26,18 +26,7 @@ fn test_verify_seal_fr32_validation() { // Test failure for invalid comm_r conversion. { let result = verify_seal::( - PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_2_KIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_2_KIB) - .expect("unknown sector size"), - ), - porep_id: arbitrary_porep_id, - api_version: ApiVersion::V1_1_0, - }, + PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, arbitrary_porep_id, ApiVersion::V1_1_0), not_convertible_to_fr_bytes, convertible_to_fr_bytes, [0; 32], @@ -65,18 +54,7 @@ fn test_verify_seal_fr32_validation() { // Test failure for invalid comm_d conversion. { let result = verify_seal::( - PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_2_KIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_2_KIB) - .expect("unknown sector size"), - ), - porep_id: arbitrary_porep_id, - api_version: ApiVersion::V1_1_0, - }, + PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, arbitrary_porep_id, ApiVersion::V1_1_0), convertible_to_fr_bytes, not_convertible_to_fr_bytes, [0; 32], @@ -108,18 +86,7 @@ fn test_verify_seal_fr32_validation() { assert!(out.is_ok(), "tripwire"); let result = verify_seal::( - PoRepConfig { - sector_size: SectorSize(SECTOR_SIZE_2_KIB), - partitions: PoRepProofPartitions( - *POREP_PARTITIONS - .read() - .expect("POREP_PARTITIONS poisoned") - .get(&SECTOR_SIZE_2_KIB) - .expect("unknown sector size"), - ), - porep_id: arbitrary_porep_id, - api_version: ApiVersion::V1_1_0, - }, + PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, arbitrary_porep_id, ApiVersion::V1_1_0), non_zero_commitment_fr_bytes, non_zero_commitment_fr_bytes, [0; 32],