adds small test parameters, generalizes repr_to_big

This commit is contained in:
Kobi Gurkan 2020-01-23 16:42:21 +02:00
parent a3f53aec44
commit 1ef0e48957
9 changed files with 53 additions and 33 deletions

@ -1,18 +1,17 @@
extern crate bellman_ce;
extern crate rand;
extern crate phase2;
extern crate num_bigint;
extern crate num_traits;
extern crate exitcode;
extern crate serde;
extern crate serde_json;
extern crate num_bigint;
extern crate num_traits;
use std::fs;
use std::fs::OpenOptions;
use num_bigint::BigUint;
use num_traits::Num;
use serde::{Deserialize, Serialize};
use phase2::parameters::MPCParameters;
use phase2::utils::repr_to_big;
use bellman_ce::pairing::{
Engine,
CurveAffine,
@ -85,9 +84,6 @@ fn main() {
vk_delta_2: vec![],
h: vec![],
};
let repr_to_big = |r| {
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
};
let p1_to_vec = |p : &<Bn256 as Engine>::G1Affine| {
vec![

@ -1,17 +1,16 @@
extern crate phase2;
extern crate bellman_ce;
extern crate num_bigint;
extern crate num_traits;
extern crate exitcode;
extern crate serde;
extern crate num_bigint;
extern crate num_traits;
use std::fs;
use std::fs::OpenOptions;
use num_bigint::BigUint;
use num_traits::Num;
use serde::{Deserialize, Serialize};
use phase2::parameters::MPCParameters;
use phase2::circom_circuit::CircomCircuit;
use phase2::utils::repr_to_big;
use bellman_ce::groth16::{prepare_verifying_key, create_random_proof, verify_proof};
use bellman_ce::pairing::{
Engine,
@ -32,6 +31,7 @@ struct ProofJson {
pub pi_c: Vec<String>,
}
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 6 {
@ -73,12 +73,6 @@ fn main() {
).unwrap();
assert!(result, "Proof is correct");
let repr_to_big = |r| {
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
};
let repr_to_big2 = |r| {
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
};
let p1_to_vec = |p : &<Bn256 as Engine>::G1Affine| {
vec![
repr_to_big(p.get_x().into_repr()),
@ -116,10 +110,10 @@ fn main() {
let mut public_inputs = vec![];
for x in input[1..].iter() {
public_inputs.push(repr_to_big2(x.into_repr()));
public_inputs.push(repr_to_big(x.into_repr()));
}
let public_json = serde_json::to_string(&public_inputs).unwrap();
fs::write(public_filename, public_json.as_bytes()).unwrap();
println!("Done!")
}
}

@ -8,6 +8,8 @@ extern crate byteorder;
extern crate blake2_rfc;
extern crate num_cpus;
extern crate crossbeam;
extern crate num_bigint;
extern crate num_traits;
extern crate cfg_if;
use cfg_if::cfg_if;

@ -6,9 +6,9 @@ use byteorder::{
BigEndian,
ReadBytesExt,
};
use num_bigint::BigUint;
use num_traits::Num;
use std::sync::Arc;
use bellman_ce::pairing::{
ff::{
PrimeField,
@ -20,7 +20,6 @@ use bellman_ce::pairing::{
G2,
}
};
use rand::{
Rng,
Rand,
@ -114,4 +113,8 @@ pub fn hash_to_g2(mut digest: &[u8]) -> G2
}
ChaChaRng::from_seed(&seed).gen()
}
}
pub fn repr_to_big<T: std::fmt::Display>(r: T) -> String {
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
}

@ -28,4 +28,5 @@ itertools = "0.8.0"
bellman_ce = { path = "../bellman" }
[features]
smalltest = []

@ -7,6 +7,7 @@ extern crate byteorder;
extern crate crypto;
use powersoftau::bn256::{Bn256CeremonyParameters};
use powersoftau::batched_accumulator::{BatchedAccumulator};
use powersoftau::keypair::{keypair};
use powersoftau::parameters::{UseCompression, CheckForCorrectness};

@ -3,6 +3,7 @@ extern crate bellman_ce;
extern crate memmap;
use powersoftau::bn256::{Bn256CeremonyParameters};
use powersoftau::batched_accumulator::{BatchedAccumulator};
use powersoftau::parameters::{UseCompression};
use powersoftau::utils::{blank_hash};

@ -24,11 +24,13 @@ use crate::parameters::*;
use crate::keypair::*;
use crate::utils::*;
#[cfg(not(feature = "smalltest"))]
#[derive(Clone)]
pub struct Bn256CeremonyParameters {
}
#[cfg(not(feature = "smalltest"))]
impl PowersOfTauParameters for Bn256CeremonyParameters {
const REQUIRED_POWER: usize = 28; // generate to have roughly 64 million constraints
@ -39,6 +41,26 @@ impl PowersOfTauParameters for Bn256CeremonyParameters {
const G2_COMPRESSED_BYTE_SIZE: usize = 64;
}
#[cfg(feature = "smalltest")]
#[derive(Clone)]
pub struct Bn256CeremonyParameters {
}
#[cfg(feature = "smalltest")]
impl PowersOfTauParameters for Bn256CeremonyParameters {
const REQUIRED_POWER: usize = 12;
const EMPIRICAL_BATCH_SIZE: usize = 1 << 10;
// This ceremony is based on the BN256 elliptic curve construction.
const G1_UNCOMPRESSED_BYTE_SIZE: usize = 64;
const G2_UNCOMPRESSED_BYTE_SIZE: usize = 128;
const G1_COMPRESSED_BYTE_SIZE: usize = 32;
const G2_COMPRESSED_BYTE_SIZE: usize = 64;
}
#[test]
fn test_pubkey_serialization() {
use self::rand::thread_rng;

@ -8,18 +8,18 @@ rm tmp_*
set -e
cargo run --release --bin new_constrained challenge1
cargo run --release --bin compute_constrained challenge1 response1
cargo run --release --bin verify_transform_constrained challenge1 response1 challenge2
cargo run --release --bin new_constrained --features smalltest -- challenge1
yes | cargo run --release --bin compute_constrained --features smalltest -- challenge1 response1
cargo run --release --bin verify_transform_constrained --features smalltest -- challenge1 response1 challenge2
cargo run --release --bin beacon_constrained challenge2 response2
cargo run --release --bin verify_transform_constrained challenge2 response2 challenge3
yes | cargo run --release --bin compute_constrained --features smalltest -- challenge2 response2
cargo run --release --bin verify_transform_constrained --features smalltest -- challenge2 response2 challenge3
cargo run --release --bin beacon_constrained challenge3 response3
cargo run --release --bin verify_transform_constrained challenge3 response3 challenge4
yes | cargo run --release --bin compute_constrained --features smalltest -- challenge3 response3
cargo run --release --bin verify_transform_constrained --features smalltest -- challenge3 response3 challenge4
cargo run --release --bin beacon_constrained challenge4 response4
cargo run --release --bin verify_transform_constrained challenge4 response4 challenge5
cargo run --release --bin beacon_constrained --features smalltest -- challenge4 response4
cargo run --release --bin verify_transform_constrained --features smalltest -- challenge4 response4 challenge5
cat response1 response2 response3 response4 > transcript
cargo run --release --bin verify transcript
cargo run --release --bin verify --features smalltest -- transcript