Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bellman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ mod multiexp;
#[cfg(test)]
mod tests;

cfg_if! {
if #[cfg(feature = "multicore")] {
#[cfg(feature = "wasm")]
compile_error!("Multicore feature is not yet compatible with wasm target arch");

pub mod multicore;
mod worker {
pub use crate::multicore::*;
}
} else {
// cfg_if! {
// if #[cfg(feature = "multicore")] {
// #[cfg(feature = "wasm")]
// compile_error!("Multicore feature is not yet compatible with wasm target arch");

// pub mod multicore;
// mod worker {
// pub use crate::multicore::*;
// }
// } else {
pub mod singlecore;
mod worker {
pub use crate::singlecore::*;
}
}
}
// }
// }

mod cs;
pub use self::cs::*;
Expand Down
3 changes: 2 additions & 1 deletion phase2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ phase1radix2m*
/*.json
/*.bin
/*.params
/verifier.sol
/verifier.sol
data
3 changes: 2 additions & 1 deletion phase2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"circom": "0.0.35",
"snarkjs": "git+https://github.com/kobigurk/snarkjs.git"
"snarkjs": "git+https://github.com/kobigurk/snarkjs.git",
"circomlib": "^2.0.5"
}
}
12 changes: 9 additions & 3 deletions phase2/src/bin/contribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use phase2::parameters::MPCParameters;

fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 4 && args.len() != 6 {

if args.len() != 3 && args.len() != 5 {
println!("Usage: \n<in_params.params> <out_params.params> <in_str_entropy>");
std::process::exit(exitcode::USAGE);
}
Expand All @@ -26,7 +27,9 @@ fn main() {
}
let in_params_filename = &args[1];
let out_params_filename = &args[2];
let entropy = &args[3];

let entropy = if args.len() > 3 { args[3].clone() } else { "".to_string() };

let print_progress = args.len() == 6 && args[4] == "-v";

let disallow_points_at_infinity = false;
Expand All @@ -52,7 +55,10 @@ fn main() {
}

// Hash it all up to make a seed
h.input(&entropy.as_bytes());
if entropy.len() > 0 {
h.input(&entropy.as_bytes());
}

h.result()
};

Expand Down
35 changes: 31 additions & 4 deletions phase2/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ extern crate byteorder;
extern crate num_cpus;
extern crate crossbeam;

#[cfg(feature = "wasm")]
// #[cfg(feature = "wasm")]
use bellman_ce::singlecore::Worker;
#[cfg(not(feature = "wasm"))]
use bellman_ce::multicore::Worker;
// #[cfg(not(feature = "wasm"))]
// use bellman_ce::multicore::Worker;

use byteorder::{
BigEndian,
Expand Down Expand Up @@ -103,6 +103,7 @@ impl MPCParameters {
) -> Result<MPCParameters, SynthesisError>
where C: Circuit<Bn256>
{
println!("MPCParameters::new()");
let mut assembly = KeypairAssembly {
num_inputs: 0,
num_aux: 0,
Expand Down Expand Up @@ -144,6 +145,8 @@ impl MPCParameters {
}
}

println!("MPCParameters::try to load phase1radix2m");

// Try to load "radix_directory/phase1radix2m{}"
let f = match File::open(format!("{}/phase1radix2m{}", radix_directory, exp)) {
Ok(f) => f,
Expand All @@ -153,6 +156,9 @@ impl MPCParameters {
};
let f = &mut BufReader::with_capacity(1024 * 1024, f);


println!("MPCParameters::read_g1");

let read_g1 = |reader: &mut BufReader<File>| -> io::Result<G1Affine> {
let mut repr = G1Uncompressed::empty();
reader.read_exact(repr.as_mut())?;
Expand All @@ -166,6 +172,8 @@ impl MPCParameters {
})
};

println!("MPCParameters::read_g2");

let read_g2 = |reader: &mut BufReader<File>| -> io::Result<G2Affine> {
let mut repr = G2Uncompressed::empty();
reader.read_exact(repr.as_mut())?;
Expand Down Expand Up @@ -211,6 +219,8 @@ impl MPCParameters {
let alpha_coeffs_g1 = Arc::new(alpha_coeffs_g1);
let beta_coeffs_g1 = Arc::new(beta_coeffs_g1);

println!("MPCParameters::h");

let mut h = Vec::with_capacity(m-1);
for _ in 0..m-1 {
h.push(read_g1(f)?);
Expand All @@ -222,6 +232,12 @@ impl MPCParameters {
let mut b_g1 = vec![G1::zero(); assembly.num_inputs + assembly.num_aux];
let mut b_g2 = vec![G2::zero(); assembly.num_inputs + assembly.num_aux];

println!("MPCParameters::eval1");

println!("MPCParameters::worker (start)");
let worker = Worker::new();
println!("MPCParameters::worker (end)");

fn eval(
// Lagrange coefficients for tau
coeffs_g1: Arc<Vec<G1Affine>>,
Expand All @@ -244,6 +260,7 @@ impl MPCParameters {
worker: &Worker
)
{
println!("MPCParameters::sanitycheck");
// Sanity check
assert_eq!(a_g1.len(), at.len());
assert_eq!(a_g1.len(), bt.len());
Expand All @@ -252,8 +269,10 @@ impl MPCParameters {
assert_eq!(a_g1.len(), b_g2.len());
assert_eq!(a_g1.len(), ext.len());

println!("MPCParameters::worker.scope (enter)");
// Evaluate polynomials in multiple threads
worker.scope(a_g1.len(), |scope, chunk| {
println!("MPCParameters::worker.scope (inside)");
for ((((((a_g1, b_g1), b_g2), ext), at), bt), ct) in
a_g1.chunks_mut(chunk)
.zip(b_g1.chunks_mut(chunk))
Expand All @@ -269,6 +288,7 @@ impl MPCParameters {
let beta_coeffs_g1 = beta_coeffs_g1.clone();

scope.spawn(move |_| {
println!("MPCParameters::scope.spawn");
for ((((((a_g1, b_g1), b_g2), ext), at), bt), ct) in
a_g1.iter_mut()
.zip(b_g1.iter_mut())
Expand Down Expand Up @@ -304,8 +324,8 @@ impl MPCParameters {
});
}

let worker = Worker::new();

println!("MPCParameters::eval2");
// Evaluate for inputs.
eval(
coeffs_g1.clone(),
Expand All @@ -322,6 +342,7 @@ impl MPCParameters {
&worker
);

println!("MPCParameters::eval3");
// Evaluate for auxillary variables.
eval(
coeffs_g1.clone(),
Expand All @@ -338,6 +359,8 @@ impl MPCParameters {
&worker
);

println!("MPCParameters::for");

// Don't allow any elements be unconstrained, so that
// the L query is always fully dense.
for e in l.iter() {
Expand Down Expand Up @@ -417,9 +440,11 @@ impl MPCParameters {
progress_update_interval: &u32
) -> [u8; 64]
{
println!("MPCParameters::contribute()");
// Generate a keypair
let (pubkey, privkey) = keypair(rng, self);

println!("MPCParameters::batch_exp1()");
#[cfg(not(feature = "wasm"))]
fn batch_exp<C: CurveAffine>(bases: &mut [C], coeff: C::Scalar, progress_update_interval: &u32, total_exps: &u32) {
let coeff = coeff.into_repr();
Expand Down Expand Up @@ -469,6 +494,7 @@ impl MPCParameters {
}
}

println!("MPCParameters::batch_exp2()");
#[cfg(feature = "wasm")]
fn batch_exp<C: CurveAffine>(bases: &mut [C], coeff: C::Scalar, progress_update_interval: &u32, total_exps: &u32) {
let coeff = coeff.into_repr();
Expand All @@ -495,6 +521,7 @@ impl MPCParameters {
}
}

println!("MPCParameters::delta_inv");
let delta_inv = privkey.delta.inverse().expect("nonzero");
let mut l = (&self.params.l[..]).to_vec();
let mut h = (&self.params.h[..]).to_vec();
Expand Down
72 changes: 65 additions & 7 deletions phase2/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,75 @@ cp ../powersoftau/phase1radix* .
npm install

# compile circuit

circom ./circuits/circuit_transaction_10x2.circom -o ./circuits/circuit_transaction_10x2.json

npx circom circuit.circom -o circuit.json && npx snarkjs info -c circuit.json
# npx snarkjs info -c circuit.json



# initialize ceremony
cargo run --release --bin new circuit.json circom1.params ./
# cargo run --release --bin new circuit.json circom1.params ./
cargo run --release --bin new circuit-by-circom-2.json circom1.params ./
cargo run --release --bin new transaction_2x2.json transaction_2x2_circom1.params ./
cargo run --release --bin new transaction_3x2.json transaction_3x2_circom1.params ./
cargo run --release --bin new transaction_4x2.json transaction_4x2_circom1.params ./
cargo run --release --bin new transaction_5x2.json transaction_5x2_circom1.params ./
cargo run --release --bin new transaction_6x2.json transaction_6x2_circom1.params ./
cargo run --release --bin new transaction_7x2.json transaction_7x2_circom1.params ./
cargo run --release --bin new transaction_8x2.json transaction_8x2_circom1.params ./
# cargo run --release --bin new circuit_constraints.json circom1.params ./

cargo run --release --bin contribute circom1.params circom2.params
cargo run --release --bin contribute transaction_8x2_circom2.params transaction_8x2_circom3.params
cargo run --release --bin contribute transaction_8x2_circom3.params transaction_8x2_circom4.params
cargo run --release --bin contribute transaction_8x2_circom4.params transaction_8x2_circom5.params
cargo run --release --bin contribute transaction_8x2_circom5.params transaction_8x2_circom6.params
cargo run --release --bin contribute transaction_8x2_circom6.params transaction_8x2_circom7.params
cargo run --release --bin contribute transaction_8x2_circom7.params transaction_8x2_circom8.params
cargo run --release --bin contribute transaction_8x2_circom8.params transaction_8x2_circom9.params
cargo run --release --bin contribute transaction_8x2_circom9.params transaction_8x2_circom10.params

cargo run --release --bin contribute circom1.params circom2.params asdajdzixcjlzxjczxlkcjzxlkcj
cargo run --release --bin verify_contribution circuit.json circom1.params circom2.params ./
# cargo run --release --bin verify_contribution circuit.json circom1.params circom2.params ./
cargo run --release --bin verify_contribution transaction_1x2.json transaction_2x2_circom1.params transaction_2x2_circom2.params ./

cargo run --release --bin contribute circom2.params circom3.params dsfjkshdfakjhsdf
cargo run --release --bin verify_contribution circuit.json circom2.params circom3.params ./
cargo run --release --bin contribute circom2.params circom3.params
# cargo run --release --bin verify_contribution circuit.json circom2.params circom3.params ./
cargo run --release --bin verify_contribution transaction_1x2.json circom2.params circom3.params ./

cargo run --release --bin contribute circom3.params circom4.params askldfjklasdf
cargo run --release --bin contribute circom3.params circom4.params
cargo run --release --bin verify_contribution circuit.json circom3.params circom4.params ./


cp ../powersoftau/phase1radix* .
cargo run --release --bin new circuit.json circom1.params ./
cargo run --release --bin contribute circom1.params circom2.params
cargo run --release --bin contribute circom2.params circom3.params
cargo run --release --bin contribute circom3.params circom4.params
cargo run --release --bin contribute circom4.params circom5.params
cargo run --release --bin contribute circom5.params circom6.params
cargo run --release --bin contribute circom6.params circom7.params
cargo run --release --bin contribute circom7.params circom8.params
cargo run --release --bin contribute circom8.params circom9.params
cargo run --release --bin contribute circom9.params circom10.params
cargo run --release --bin contribute circom10.params circom11.params
cargo run --release --bin contribute circom11.params circom12.params
cargo run --release --bin contribute circom12.params circom13.params
cargo run --release --bin contribute circom13.params circom14.params
cargo run --release --bin contribute circom14.params circom15.params
cargo run --release --bin contribute circom15.params circom16.params
cargo run --release --bin contribute circom16.params circom17.params
cargo run --release --bin contribute circom17.params circom18.params
cargo run --release --bin contribute circom18.params circom19.params
cargo run --release --bin contribute circom19.params circom20.params



npx snarkjs groth16 setup circuit.r1cs circom4.params circuit_0000.zkey
cargo run --release --bin copy_json transaction_0001_2x2.zkey pk.json transformed_pk.json


# create dummy keys in circom format
echo "Generating dummy key files..."
npx snarkjs setup --protocol groth
Expand All @@ -41,5 +95,9 @@ cargo run --release --bin generate_verifier circom4.params verifier.sol

# try to generate and verify proof
npx snarkjs calculatewitness
cargo run --release --bin prove circuit.json witness.json circom4.params proof.json public.json
cargo run --release --bin prove circuit-by-circom-2.json witness.json circom4.params proof.json public.json
npx snarkjs verify --vk vk.json --proof proof.json


snarkjs wc circuit.wasm input.json witness.wtns
snarkjs wej witness.wtns witness.json
Loading