Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
create uniform prover with or without precomputations
Browse files Browse the repository at this point in the history
  • Loading branch information
shamatar committed Apr 2, 2020
1 parent 31c92e5 commit 16d1747
Show file tree
Hide file tree
Showing 6 changed files with 2,820 additions and 1 deletion.
107 changes: 107 additions & 0 deletions src/plonk/better_cs/adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,113 @@ fn transpile_xor_using_new_adaptor() {
);
verification_key.write(&mut key_writer).unwrap();

let mut proof_writer = std::io::BufWriter::with_capacity(
1<<24,
std::fs::File::create("./xor_proof.proof").unwrap()
);
proof.write(&mut proof_writer).unwrap();
}

#[test]
fn transpile_xor_and_prove_with_no_precomputations() {
use crate::tests::XORDemo;
use crate::cs::Circuit;
use crate::pairing::bn256::{Bn256, Fr};
use super::test_assembly::*;
use super::cs::PlonkCsWidth4WithNextStepParams;
use super::generator::*;
use super::prover::*;
use crate::multicore::Worker;
use super::verifier::*;
use crate::kate_commitment::*;
use crate::plonk::commitments::transcript::*;
use crate::plonk::commitments::transcript::keccak_transcript::*;
use crate::plonk::fft::cooley_tukey_ntt::*;
use super::keys::*;
use crate::plonk::domains::Domain;
use super::utils::make_non_residues;

let c = XORDemo::<Bn256> {
a: None,
b: None,
_marker: PhantomData
};

let mut transpiler = Transpiler::<Bn256, PlonkCsWidth4WithNextStepParams>::new();

c.synthesize(&mut transpiler).expect("sythesize into traspilation must succeed");

let hints = transpiler.hints;

for (constraint_id, hint) in hints.iter() {
println!("Constraint {} into {:?}", constraint_id, hint);
}

// let c = XORDemo::<Bn256> {
// a: None,
// b: None,
// _marker: PhantomData
// };

let c = XORDemo::<Bn256> {
a: Some(true),
b: Some(false),
_marker: PhantomData
};

let adapted_curcuit = AdaptorCircuit::<Bn256, PlonkCsWidth4WithNextStepParams, _>::new(c.clone(), &hints);

let mut assembly = TestAssembly::<Bn256, PlonkCsWidth4WithNextStepParams>::new();
adapted_curcuit.synthesize(&mut assembly).expect("sythesize of transpiled into CS must succeed");
let num_gates = assembly.num_gates();
println!("Transpiled into {} gates", num_gates);

let adapted_curcuit = AdaptorCircuit::<Bn256, PlonkCsWidth4WithNextStepParams, _>::new(c.clone(), &hints);
let mut assembly = GeneratorAssembly4WithNextStep::<Bn256>::new();
adapted_curcuit.synthesize(&mut assembly).expect("sythesize of transpiled into CS must succeed");
assembly.finalize();

let worker = Worker::new();

let setup = assembly.setup(&worker).unwrap();

let crs_mons = Crs::<Bn256, CrsForMonomialForm>::crs_42(setup.permutation_polynomials[0].size(), &worker);

let verification_key = VerificationKey::from_setup(
&setup,
&worker,
&crs_mons
).unwrap();

let size = setup.permutation_polynomials[0].size();

let domain = Domain::<Fr>::new_for_size(size as u64).unwrap();
let non_residues = make_non_residues::<Fr>(3, &domain);
println!("Non residues = {:?}", non_residues);

type Transcr = RollingKeccakTranscript<Fr>;

let proof = super::super::prove_by_steps::<_, _, Transcr>(
c,
&hints,
&setup,
None,
&crs_mons
).unwrap();

let is_valid = verify::<Bn256, PlonkCsWidth4WithNextStepParams, Transcr>(&proof, &verification_key).unwrap();

assert!(is_valid);

// println!("Verification key = {:?}", verification_key);
// println!("Proof = {:?}", proof);

let mut key_writer = std::io::BufWriter::with_capacity(
1<<24,
std::fs::File::create("./xor_vk.key").unwrap()
);
verification_key.write(&mut key_writer).unwrap();

let mut proof_writer = std::io::BufWriter::with_capacity(
1<<24,
std::fs::File::create("./xor_proof.proof").unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/plonk/better_cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ pub mod verifier;
pub mod one_shot_test_assembly;
pub mod fma_adaptor;

mod utils;
pub(crate) mod utils;

const LDE_FACTOR: usize = 4;
Loading

0 comments on commit 16d1747

Please sign in to comment.