Skip to content

Commit

Permalink
feat: enforce FIP-0090 bounds on NI-PoRep aggregation counts
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptonemo committed May 16, 2024
1 parent 3e04757 commit be14643
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 12 additions & 1 deletion filecoin-proofs/src/api/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use crate::{
get_stacked_verifying_key,
},
constants::{
DefaultBinaryTree, DefaultPieceDomain, DefaultPieceHasher, SINGLE_PARTITION_PROOF_LEN,
DefaultBinaryTree, DefaultPieceDomain, DefaultPieceHasher,
FIP90_MAX_NI_POREP_AGGREGATION_PROOFS, FIP90_MIN_NI_POREP_AGGREGATION_PROOFS,
SINGLE_PARTITION_PROOF_LEN,
},
parameters::setup_params,
pieces::{self, verify_pieces},
Expand Down Expand Up @@ -772,11 +774,20 @@ pub fn aggregate_seal_commit_proofs<Tree: 'static + MerkleTreeTrait>(
proofs.len(),
);

if porep_config.feature_enabled(ApiFeature::NonInteractivePoRep) {
ensure!(
proofs.len() >= FIP90_MIN_NI_POREP_AGGREGATION_PROOFS
&& proofs.len() <= FIP90_MAX_NI_POREP_AGGREGATION_PROOFS,
"{} proofs is outside of FIP-0090 specified NI-PoRep aggregation bounds",
proofs.len()
);
}
let target_proofs_len = get_aggregate_target_len(proofs.len());
ensure!(
target_proofs_len > 1,
"cannot aggregate less than two proofs"
);

trace!(
"aggregate_seal_commit_proofs will pad proofs to target_len {}",
target_proofs_len
Expand Down
4 changes: 4 additions & 0 deletions filecoin-proofs/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub const WINDOW_POST_CHALLENGE_COUNT: usize = 10;

pub const MAX_LEGACY_REGISTERED_SEAL_PROOF_ID: u64 = MAX_LEGACY_POREP_REGISTERED_PROOF_ID;

// Constant NI-PoRep aggregation bounds specified in FIP-0090
pub const FIP90_MIN_NI_POREP_AGGREGATION_PROOFS: usize = 2;
pub const FIP90_MAX_NI_POREP_AGGREGATION_PROOFS: usize = 65;

/// Sector sizes for which parameters are supported.
pub const SUPPORTED_SECTOR_SIZES: [u64; 10] = [
SECTOR_SIZE_2_KIB,
Expand Down
6 changes: 3 additions & 3 deletions filecoin-proofs/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ fn test_seal_proof_aggregation_2kib() -> Result<()> {
(1, 5, ApiVersion::V1_1_0, vec![]),
(5, 5, ApiVersion::V1_2_0, vec![ApiFeature::SyntheticPoRep]),
(
257,
65,
5,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
Expand Down Expand Up @@ -653,7 +653,7 @@ fn test_seal_proof_aggregation_4kib() -> Result<()> {
(7, 5, ApiVersion::V1_1_0, vec![]),
(24, 5, ApiVersion::V1_2_0, vec![ApiFeature::SyntheticPoRep]),
(
123,
17,
5,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
Expand Down Expand Up @@ -682,7 +682,7 @@ fn test_seal_proof_aggregation_32kib() -> Result<()> {
(220, 5, ApiVersion::V1_1_0, vec![]),
(500, 5, ApiVersion::V1_2_0, vec![ApiFeature::SyntheticPoRep]),
(
818,
5,
5,
ApiVersion::V1_2_0,
vec![ApiFeature::NonInteractivePoRep],
Expand Down

0 comments on commit be14643

Please sign in to comment.