From a8517eda5b0874ca09e74ea8cf06402a453aea53 Mon Sep 17 00:00:00 2001 From: DrPeterVanNostrand Date: Wed, 8 May 2024 14:10:58 -0400 Subject: [PATCH 1/2] fix: remove challenge seed from NI-PoRep SnarkPack transcript --- filecoin-proofs/src/api/seal.rs | 37 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/filecoin-proofs/src/api/seal.rs b/filecoin-proofs/src/api/seal.rs index d77204680..4b29462d9 100644 --- a/filecoin-proofs/src/api/seal.rs +++ b/filecoin-proofs/src/api/seal.rs @@ -740,13 +740,22 @@ pub fn aggregate_seal_commit_proofs( // If we're not at the pow2 target, duplicate the last proof until we are. pad_proofs_to_target(&mut proofs, target_proofs_len)?; - // Hash all of the seeds and comm_r's pair-wise into a digest for the aggregate proof method. + // For standard PoRep, the SnarkPack transcript should include a hash of each aggregated PoRep's + // challenge seed and comm_r (pair-wise); however since NI-PoRep does not use a seed to generate + // it's challenges, any challenge seeds provided as arguments to this function should be ignored + // (and thus not be included in an NI-PoRep's SnarkPack transcript). let hashed_seeds_and_comm_rs: [u8; 32] = { let mut hasher = Sha256::new(); - for cur in seeds.iter().zip(comm_rs.iter()) { - let (seed, comm_r) = cur; - hasher.update(seed); - hasher.update(comm_r); + if porep_config.feature_enabled(ApiFeature::NonInteractivePoRep) { + for comm_r in comm_rs.iter() { + hasher.update(comm_r); + } + } else { + for cur in seeds.iter().zip(comm_rs.iter()) { + let (seed, comm_r) = cur; + hasher.update(seed); + hasher.update(comm_r); + } } hasher.finalize().into() }; @@ -834,13 +843,21 @@ pub fn verify_aggregate_seal_commit_proofs( let srs_verifier_key = get_stacked_srs_verifier_key::(porep_config, aggregated_proofs_len)?; - // Hash all of the seeds and comm_r's pair-wise into a digest for the aggregate proof method. + // For standard PoRep, the SnarkPack transcript should include a hash of each aggregated PoRep's + // challenge seed and comm_r (pair-wise); however NI-PoRep's transcript should only include + // comm_r (as NI-PoRep does not use a seed to generate its challenges). let hashed_seeds_and_comm_rs: [u8; 32] = { let mut hasher = Sha256::new(); - for cur in seeds.iter().zip(comm_rs.iter()) { - let (seed, comm_r) = cur; - hasher.update(seed); - hasher.update(comm_r); + if porep_config.feature_enabled(ApiFeature::NonInteractivePoRep) { + for comm_r in comm_rs.iter() { + hasher.update(comm_r); + } + } else { + for cur in seeds.iter().zip(comm_rs.iter()) { + let (seed, comm_r) = cur; + hasher.update(seed); + hasher.update(comm_r); + } } hasher.finalize().into() }; From a9af8b70da2d4743ccf1ff6a6a783777057b1118 Mon Sep 17 00:00:00 2001 From: DrPeterVanNostrand Date: Tue, 14 May 2024 11:55:21 -0400 Subject: [PATCH 2/2] Add comment in seal_commit_phase1 re. NI-PoRep seed value --- filecoin-proofs/src/api/seal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/filecoin-proofs/src/api/seal.rs b/filecoin-proofs/src/api/seal.rs index 4b29462d9..f6567d820 100644 --- a/filecoin-proofs/src/api/seal.rs +++ b/filecoin-proofs/src/api/seal.rs @@ -352,6 +352,8 @@ pub fn seal_commit_phase1, Tree: 'static + MerkleTreeTrait>( prover_id: ProverId, sector_id: SectorId, ticket: Ticket, + // Note: when using NI-PoRep the PoRep challenge generation seed is ignored, thus any value can + // be passed in here for `seed`. seed: Ticket, pre_commit: SealPreCommitOutput, piece_infos: &[PieceInfo],