Skip to content

Commit

Permalink
feat(bls-snark-setup): contribute in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Mar 27, 2020
1 parent 5587f8f commit 0213d56
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions bls-snark-setup/src/cli/contribute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gumdrop::Options;
use memmap::MmapOptions;
use phase2::chunked_groth16::contribute as chunked_contribute;
use rand::Rng;
use snark_utils::Result;
Expand All @@ -23,13 +24,19 @@ pub struct ContributeOpts {
}

pub fn contribute<R: Rng>(opts: &ContributeOpts, rng: &mut R) -> Result<()> {
let mut file = OpenOptions::new()
let file = OpenOptions::new()
.read(true)
.write(true)
.open(&opts.data)
.expect("could not open file for writing the new MPC parameters ");
let mut file = unsafe {
MmapOptions::new()
.map_mut(&file)
.expect("unable to create a memory map for input")
};

chunked_contribute::<SW6, _, _>(&mut file, rng, opts.batch)?;

chunked_contribute::<SW6, _>(&mut file, rng, opts.batch)?;

Ok(())
}
4 changes: 2 additions & 2 deletions bls-snark-setup/src/cli/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use phase2::parameters::{circuit_to_qap, MPCParameters};
use snark_utils::{log_2, Groth16Params, Result, UseCompression};

use std::fs::OpenOptions;
use memmap::MmapOptions;


#[derive(Debug, Options, Clone)]
pub struct NewOpts {
Expand Down Expand Up @@ -65,8 +67,6 @@ pub fn empty_circuit(opt: &NewOpts) -> (ValidatorSetUpdate<Bls12_377>, usize) {
(valset, num_constraints)
}

use memmap::MmapOptions;

pub fn new(opt: &NewOpts) -> Result<()> {
let phase1_transcript = OpenOptions::new()
.read(true)
Expand Down
3 changes: 2 additions & 1 deletion powersoftau/src/bin/prepare_phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ fn prepare_phase2<E: PairingEngine + Sync>(opts: &PreparePhase2Opts) -> Result<(
current_accumulator.alpha_tau_powers_g1,
current_accumulator.beta_tau_powers_g1,
current_accumulator.beta_g2,
).expect("could not create Groth16 Lagrange coefficients");
)
.expect("could not create Groth16 Lagrange coefficients");

// Write the parameters
groth16_params.write(&mut writer, UseCompression::No)?;
Expand Down
3 changes: 2 additions & 1 deletion snark-utils/src/groth16_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ mod tests {
accumulator.alpha_tau_powers_g1,
accumulator.beta_tau_powers_g1,
accumulator.beta_g2,
).unwrap();
)
.unwrap();

let mut writer = vec![];
groth_params.write(&mut writer, compat(compressed)).unwrap();
Expand Down

0 comments on commit 0213d56

Please sign in to comment.