Skip to content

Commit

Permalink
fix: for Ni-PoRep, make sure proofs are in smaller batches
Browse files Browse the repository at this point in the history
Synthesizing takes a lot of memory, hence reduce the number of proofs
we process in parallel.
  • Loading branch information
vmx committed Nov 3, 2023
1 parent 39b427b commit ea715cf
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions storage-proofs-core/src/compound_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ use crate::{
proof::ProofScheme,
};

/// The maximum number of Groth16 proofs that will be processed in parallel. This limit is set as
/// synthesis takes a lot of memory. The current value is based on the number of proofs that are
/// run in parallel in the interactive PoRep (the number of partitions). This way there's just a
/// single batch for the interactive PoRep, but the non-interactive PoRep is split into batches.
const MAX_GROTH16_BATCH_SIZE: usize = 10;

#[derive(Clone)]
pub struct SetupParams<'a, S: ProofScheme<'a>> {
pub vanilla_params: <S as ProofScheme<'a>>::SetupParams,
Expand Down Expand Up @@ -242,7 +248,7 @@ where
"cannot create a circuit proof over missing vanilla proofs"
);

let circuits = vanilla_proofs
let mut circuits = vanilla_proofs
.into_par_iter()
.enumerate()
.map(|(k, vanilla_proof)| {
Expand All @@ -256,14 +262,25 @@ where
})
.collect::<Result<Vec<_>>>()?;

let groth_proofs = if priority {
create_random_proof_batch_in_priority(circuits, groth_params, &mut rng)?
// The same function is used within the while loop below, decide on the function once and
// not on every iteration.
let create_random_proof_batch_fun = if priority {
create_random_proof_batch_in_priority
} else {
create_random_proof_batch(circuits, groth_params, &mut rng)?
create_random_proof_batch
};

let mut groth_proofs = Vec::with_capacity(circuits.len());
// Bellperson expects a vector of proofs, hence drain it from the list of proofs, so that
// we don't need to keep an extra copy around.
while !circuits.is_empty() {
let batch = circuits.drain(0..MAX_GROTH16_BATCH_SIZE).collect();
let proofs = create_random_proof_batch_fun(batch, groth_params, &mut rng)?;
groth_proofs.extend_from_slice(&proofs);
}

groth_proofs
.into_iter()
.iter()
.map(|groth_proof| {
let mut proof_vec = Vec::new();
groth_proof.write(&mut proof_vec)?;
Expand Down

0 comments on commit ea715cf

Please sign in to comment.