update cli
This commit is contained in:
parent
f3f1b84818
commit
01995f2e16
9 changed files with 203 additions and 37 deletions
|
@ -93,16 +93,28 @@ impl TryFrom<(&str, &str, &str)> for Parameters {
|
||||||
#[cfg(feature = "bellman")]
|
#[cfg(feature = "bellman")]
|
||||||
(BackendParameter::Bellman, CurveParameter::Bls12_381, SchemeParameter::G16) => Ok(()),
|
(BackendParameter::Bellman, CurveParameter::Bls12_381, SchemeParameter::G16) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::G16) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::GM17) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::G16) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::G16) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::G16) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::GM17) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::GM17) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => Ok(()),
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::MARLIN) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => Ok(()),
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => Ok(()),
|
(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => Ok(()),
|
||||||
#[cfg(feature = "libsnark")]
|
#[cfg(feature = "libsnark")]
|
||||||
(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => Ok(()),
|
(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => Ok(()),
|
||||||
|
|
|
@ -112,20 +112,29 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, _, SchemeParameter::G16) => match prog {
|
||||||
|
ProgEnum::Bn128Program(p) => cli_generate_proof::<_, _, G16, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_381Program(p) => cli_generate_proof::<_, _, G16, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_377Program(p) => cli_generate_proof::<_, _, G16, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bw6_761Program(p) => cli_generate_proof::<_, _, G16, Ark>(p, sub_matches),
|
||||||
|
},
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
|
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
|
||||||
|
ProgEnum::Bn128Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_381Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
||||||
ProgEnum::Bls12_377Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
ProgEnum::Bls12_377Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
||||||
ProgEnum::Bw6_761Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
ProgEnum::Bw6_761Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
||||||
ProgEnum::Bn128Program(p) => cli_generate_proof::<_, _, GM17, Ark>(p, sub_matches),
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
},
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => match prog {
|
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => match prog {
|
||||||
|
ProgEnum::Bn128Program(p) => cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_381Program(p) => {
|
||||||
|
cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches)
|
||||||
|
}
|
||||||
ProgEnum::Bls12_377Program(p) => {
|
ProgEnum::Bls12_377Program(p) => {
|
||||||
cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches)
|
cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches)
|
||||||
}
|
}
|
||||||
ProgEnum::Bw6_761Program(p) => cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches),
|
ProgEnum::Bw6_761Program(p) => cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches),
|
||||||
ProgEnum::Bn128Program(p) => cli_generate_proof::<_, _, Marlin, Ark>(p, sub_matches),
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
},
|
||||||
#[cfg(feature = "libsnark")]
|
#[cfg(feature = "libsnark")]
|
||||||
Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
||||||
|
|
|
@ -114,15 +114,30 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, _, SchemeParameter::G16) => match prog {
|
||||||
|
ProgEnum::Bn128Program(p) => cli_setup_non_universal::<_, _, G16, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_381Program(p) => {
|
||||||
|
cli_setup_non_universal::<_, _, G16, Ark>(p, sub_matches)
|
||||||
|
}
|
||||||
|
ProgEnum::Bls12_377Program(p) => {
|
||||||
|
cli_setup_non_universal::<_, _, G16, Ark>(p, sub_matches)
|
||||||
|
}
|
||||||
|
ProgEnum::Bw6_761Program(p) => {
|
||||||
|
cli_setup_non_universal::<_, _, G16, Ark>(p, sub_matches)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
|
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
|
||||||
|
ProgEnum::Bn128Program(p) => cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches),
|
||||||
|
ProgEnum::Bls12_381Program(p) => {
|
||||||
|
cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches)
|
||||||
|
}
|
||||||
ProgEnum::Bls12_377Program(p) => {
|
ProgEnum::Bls12_377Program(p) => {
|
||||||
cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches)
|
cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches)
|
||||||
}
|
}
|
||||||
ProgEnum::Bw6_761Program(p) => {
|
ProgEnum::Bw6_761Program(p) => {
|
||||||
cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches)
|
cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches)
|
||||||
}
|
}
|
||||||
ProgEnum::Bn128Program(p) => cli_setup_non_universal::<_, _, GM17, Ark>(p, sub_matches),
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
},
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => {
|
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => {
|
||||||
|
@ -140,16 +155,18 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
.map_err(|_| "Cannot read universal setup".to_string())?;
|
.map_err(|_| "Cannot read universal setup".to_string())?;
|
||||||
|
|
||||||
match prog {
|
match prog {
|
||||||
ProgEnum::Bls12_377Program(p) => {
|
ProgEnum::Bn128Program(p) => {
|
||||||
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
||||||
}
|
}
|
||||||
ProgEnum::Bn128Program(p) => {
|
ProgEnum::Bls12_381Program(p) => {
|
||||||
|
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
||||||
|
}
|
||||||
|
ProgEnum::Bls12_377Program(p) => {
|
||||||
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
||||||
}
|
}
|
||||||
ProgEnum::Bw6_761Program(p) => {
|
ProgEnum::Bw6_761Program(p) => {
|
||||||
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
cli_setup_universal::<_, _, Marlin, Ark>(p, setup, sub_matches)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "libsnark")]
|
#[cfg(feature = "libsnark")]
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::path::Path;
|
||||||
use zokrates_core::proof_system::ark::Ark;
|
use zokrates_core::proof_system::ark::Ark;
|
||||||
#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))]
|
#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))]
|
||||||
use zokrates_core::proof_system::*;
|
use zokrates_core::proof_system::*;
|
||||||
use zokrates_field::{Bls12_377Field, Bn128Field, Bw6_761Field, Field};
|
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
|
||||||
|
|
||||||
pub fn subcommand() -> App<'static, 'static> {
|
pub fn subcommand() -> App<'static, 'static> {
|
||||||
SubCommand::with_name("universal-setup")
|
SubCommand::with_name("universal-setup")
|
||||||
|
@ -63,6 +63,14 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
match parameters {
|
match parameters {
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => {
|
||||||
|
cli_universal_setup::<Bn128Field, Marlin, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::MARLIN) => {
|
||||||
|
cli_universal_setup::<Bls12_381Field, Marlin, Ark>(sub_matches)
|
||||||
|
}
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => {
|
||||||
cli_universal_setup::<Bls12_377Field, Marlin, Ark>(sub_matches)
|
cli_universal_setup::<Bls12_377Field, Marlin, Ark>(sub_matches)
|
||||||
|
@ -71,10 +79,6 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => {
|
||||||
cli_universal_setup::<Bw6_761Field, Marlin, Ark>(sub_matches)
|
cli_universal_setup::<Bw6_761Field, Marlin, Ark>(sub_matches)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "ark")]
|
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => {
|
|
||||||
cli_universal_setup::<Bn128Field, Marlin, Ark>(sub_matches)
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,30 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
cli_verify::<Bls12_381Field, G16, Bellman>(sub_matches)
|
cli_verify::<Bls12_381Field, G16, Bellman>(sub_matches)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::G16) => {
|
||||||
|
cli_verify::<Bn128Field, G16, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::G16) => {
|
||||||
|
cli_verify::<Bls12_381Field, G16, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::G16) => {
|
||||||
|
cli_verify::<Bls12_377Field, G16, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::G16) => {
|
||||||
|
cli_verify::<Bw6_761Field, G16, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
||||||
|
cli_verify::<Bn128Field, GM17, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::GM17) => {
|
||||||
|
cli_verify::<Bls12_381Field, GM17, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => {
|
||||||
cli_verify::<Bls12_377Field, GM17, Ark>(sub_matches)
|
cli_verify::<Bls12_377Field, GM17, Ark>(sub_matches)
|
||||||
}
|
}
|
||||||
|
@ -86,8 +110,12 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
cli_verify::<Bw6_761Field, GM17, Ark>(sub_matches)
|
cli_verify::<Bw6_761Field, GM17, Ark>(sub_matches)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => {
|
||||||
cli_verify::<Bn128Field, GM17, Ark>(sub_matches)
|
cli_verify::<Bn128Field, Marlin, Ark>(sub_matches)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ark")]
|
||||||
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_381, SchemeParameter::MARLIN) => {
|
||||||
|
cli_verify::<Bls12_381Field, Marlin, Ark>(sub_matches)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "ark")]
|
#[cfg(feature = "ark")]
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => {
|
||||||
|
@ -97,10 +125,6 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => {
|
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => {
|
||||||
cli_verify::<Bw6_761Field, Marlin, Ark>(sub_matches)
|
cli_verify::<Bw6_761Field, Marlin, Ark>(sub_matches)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "ark")]
|
|
||||||
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => {
|
|
||||||
cli_verify::<Bn128Field, Marlin, Ark>(sub_matches)
|
|
||||||
}
|
|
||||||
#[cfg(feature = "libsnark")]
|
#[cfg(feature = "libsnark")]
|
||||||
Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => {
|
||||||
cli_verify::<Bn128Field, GM17, Libsnark>(sub_matches)
|
cli_verify::<Bn128Field, GM17, Libsnark>(sub_matches)
|
||||||
|
|
|
@ -10,9 +10,9 @@ use crate::ir::{ProgIterator, Statement, Witness};
|
||||||
use crate::proof_system::ark::{get_random_seed, Computation};
|
use crate::proof_system::ark::{get_random_seed, Computation};
|
||||||
use crate::proof_system::ark::{parse_fr, parse_g1, parse_g2, parse_g2_fq};
|
use crate::proof_system::ark::{parse_fr, parse_g1, parse_g2, parse_g2_fq};
|
||||||
use crate::proof_system::ark::{serialization, Ark};
|
use crate::proof_system::ark::{serialization, Ark};
|
||||||
use crate::proof_system::gm17::{NotBw6_761Field, ProofPoints, VerificationKey, GM17};
|
use crate::proof_system::gm17::{ProofPoints, VerificationKey, GM17};
|
||||||
use crate::proof_system::Scheme;
|
|
||||||
use crate::proof_system::{Backend, NonUniversalBackend, Proof, SetupKeypair};
|
use crate::proof_system::{Backend, NonUniversalBackend, Proof, SetupKeypair};
|
||||||
|
use crate::proof_system::{NotBw6_761Field, Scheme};
|
||||||
use ark_bw6_761::BW6_761;
|
use ark_bw6_761::BW6_761;
|
||||||
use rand_0_7::SeedableRng;
|
use rand_0_7::SeedableRng;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::proof_system::{Backend, NonUniversalBackend, Proof, SetupKeypair};
|
use crate::proof_system::{Backend, NonUniversalBackend, NotBw6_761Field, Proof, SetupKeypair};
|
||||||
use ark_crypto_primitives::SNARK;
|
use ark_crypto_primitives::SNARK;
|
||||||
use ark_groth16::{
|
use ark_groth16::{
|
||||||
prepare_verifying_key, verify_proof, Groth16, PreparedVerifyingKey, Proof as ArkProof,
|
prepare_verifying_key, verify_proof, Groth16, PreparedVerifyingKey, Proof as ArkProof,
|
||||||
ProvingKey, VerifyingKey,
|
ProvingKey, VerifyingKey,
|
||||||
};
|
};
|
||||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
|
||||||
use zokrates_field::ArkFieldExtensions;
|
|
||||||
use zokrates_field::Field;
|
use zokrates_field::Field;
|
||||||
|
use zokrates_field::{ArkFieldExtensions, Bw6_761Field};
|
||||||
|
|
||||||
use crate::ir::{ProgIterator, Statement, Witness};
|
use crate::ir::{ProgIterator, Statement, Witness};
|
||||||
use crate::proof_system::ark::Computation;
|
use crate::proof_system::ark::Computation;
|
||||||
|
@ -14,11 +14,12 @@ use crate::proof_system::ark::{get_random_seed, parse_fr, serialization, Ark};
|
||||||
use crate::proof_system::ark::{parse_g1, parse_g2};
|
use crate::proof_system::ark::{parse_g1, parse_g2};
|
||||||
use crate::proof_system::groth16::{ProofPoints, VerificationKey, G16};
|
use crate::proof_system::groth16::{ProofPoints, VerificationKey, G16};
|
||||||
use crate::proof_system::Scheme;
|
use crate::proof_system::Scheme;
|
||||||
|
use ark_bw6_761::BW6_761;
|
||||||
use rand_0_7::SeedableRng;
|
use rand_0_7::SeedableRng;
|
||||||
|
|
||||||
const G16_WARNING: &str = "WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.";
|
const G16_WARNING: &str = "WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.";
|
||||||
|
|
||||||
impl<T: Field + ArkFieldExtensions> Backend<T, G16> for Ark {
|
impl<T: Field + ArkFieldExtensions + NotBw6_761Field> Backend<T, G16> for Ark {
|
||||||
fn generate_proof<I: IntoIterator<Item = Statement<T>>>(
|
fn generate_proof<I: IntoIterator<Item = Statement<T>>>(
|
||||||
program: ProgIterator<T, I>,
|
program: ProgIterator<T, I>,
|
||||||
witness: Witness<T>,
|
witness: Witness<T>,
|
||||||
|
@ -88,7 +89,7 @@ impl<T: Field + ArkFieldExtensions> Backend<T, G16> for Ark {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Field + ArkFieldExtensions> NonUniversalBackend<T, G16> for Ark {
|
impl<T: Field + ArkFieldExtensions + NotBw6_761Field> NonUniversalBackend<T, G16> for Ark {
|
||||||
fn setup<I: IntoIterator<Item = Statement<T>>>(
|
fn setup<I: IntoIterator<Item = Statement<T>>>(
|
||||||
program: ProgIterator<T, I>,
|
program: ProgIterator<T, I>,
|
||||||
) -> SetupKeypair<<G16 as Scheme<T>>::VerificationKey> {
|
) -> SetupKeypair<<G16 as Scheme<T>>::VerificationKey> {
|
||||||
|
@ -113,3 +114,101 @@ impl<T: Field + ArkFieldExtensions> NonUniversalBackend<T, G16> for Ark {
|
||||||
SetupKeypair::new(vk, pk_vec)
|
SetupKeypair::new(vk, pk_vec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Backend<Bw6_761Field, G16> for Ark {
|
||||||
|
fn generate_proof<I: IntoIterator<Item = Statement<Bw6_761Field>>>(
|
||||||
|
program: ProgIterator<Bw6_761Field, I>,
|
||||||
|
witness: Witness<Bw6_761Field>,
|
||||||
|
proving_key: Vec<u8>,
|
||||||
|
) -> Proof<<G16 as Scheme<Bw6_761Field>>::ProofPoints> {
|
||||||
|
println!("{}", G16_WARNING);
|
||||||
|
|
||||||
|
let computation = Computation::with_witness(program, witness);
|
||||||
|
|
||||||
|
let inputs = computation
|
||||||
|
.public_inputs_values()
|
||||||
|
.iter()
|
||||||
|
.map(parse_fr::<Bw6_761Field>)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let pk =
|
||||||
|
ProvingKey::<BW6_761>::deserialize_uncompressed(&mut proving_key.as_slice()).unwrap();
|
||||||
|
|
||||||
|
let rng = &mut rand_0_7::rngs::StdRng::from_seed(get_random_seed().unwrap());
|
||||||
|
let proof = Groth16::<BW6_761>::prove(&pk, computation, rng).unwrap();
|
||||||
|
|
||||||
|
let proof_points = ProofPoints {
|
||||||
|
a: parse_g1::<Bw6_761Field>(&proof.a),
|
||||||
|
b: parse_g2::<Bw6_761Field>(&proof.b),
|
||||||
|
c: parse_g1::<Bw6_761Field>(&proof.c),
|
||||||
|
};
|
||||||
|
|
||||||
|
Proof::new(proof_points, inputs)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify(
|
||||||
|
vk: <G16 as Scheme<Bw6_761Field>>::VerificationKey,
|
||||||
|
proof: Proof<<G16 as Scheme<Bw6_761Field>>::ProofPoints>,
|
||||||
|
) -> bool {
|
||||||
|
let vk = VerifyingKey {
|
||||||
|
alpha_g1: serialization::to_g1::<Bw6_761Field>(vk.alpha),
|
||||||
|
beta_g2: serialization::to_g2::<Bw6_761Field>(vk.beta),
|
||||||
|
gamma_g2: serialization::to_g2::<Bw6_761Field>(vk.gamma),
|
||||||
|
delta_g2: serialization::to_g2::<Bw6_761Field>(vk.delta),
|
||||||
|
gamma_abc_g1: vk
|
||||||
|
.gamma_abc
|
||||||
|
.into_iter()
|
||||||
|
.map(serialization::to_g1::<Bw6_761Field>)
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let pvk: PreparedVerifyingKey<BW6_761> = prepare_verifying_key(&vk);
|
||||||
|
let ark_proof = ArkProof {
|
||||||
|
a: serialization::to_g1::<Bw6_761Field>(proof.proof.a),
|
||||||
|
b: serialization::to_g2::<Bw6_761Field>(proof.proof.b),
|
||||||
|
c: serialization::to_g1::<Bw6_761Field>(proof.proof.c),
|
||||||
|
};
|
||||||
|
|
||||||
|
let public_inputs: Vec<_> = proof
|
||||||
|
.inputs
|
||||||
|
.iter()
|
||||||
|
.map(|s| {
|
||||||
|
Bw6_761Field::try_from_str(s.trim_start_matches("0x"), 16)
|
||||||
|
.unwrap()
|
||||||
|
.into_ark()
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
verify_proof(&pvk, &ark_proof, &public_inputs).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NonUniversalBackend<Bw6_761Field, G16> for Ark {
|
||||||
|
fn setup<I: IntoIterator<Item = Statement<Bw6_761Field>>>(
|
||||||
|
program: ProgIterator<Bw6_761Field, I>,
|
||||||
|
) -> SetupKeypair<<G16 as Scheme<Bw6_761Field>>::VerificationKey> {
|
||||||
|
println!("{}", G16_WARNING);
|
||||||
|
|
||||||
|
let computation = Computation::without_witness(program);
|
||||||
|
|
||||||
|
let rng = &mut rand_0_7::rngs::StdRng::from_seed(get_random_seed().unwrap());
|
||||||
|
let (pk, vk) = Groth16::<BW6_761>::circuit_specific_setup(computation, rng).unwrap();
|
||||||
|
|
||||||
|
let mut pk_vec: Vec<u8> = Vec::new();
|
||||||
|
pk.serialize_uncompressed(&mut pk_vec).unwrap();
|
||||||
|
|
||||||
|
let vk = VerificationKey {
|
||||||
|
alpha: parse_g1::<Bw6_761Field>(&vk.alpha_g1),
|
||||||
|
beta: parse_g2::<Bw6_761Field>(&vk.beta_g2),
|
||||||
|
gamma: parse_g2::<Bw6_761Field>(&vk.gamma_g2),
|
||||||
|
delta: parse_g2::<Bw6_761Field>(&vk.delta_g2),
|
||||||
|
gamma_abc: vk
|
||||||
|
.gamma_abc_g1
|
||||||
|
.iter()
|
||||||
|
.map(parse_g1::<Bw6_761Field>)
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
|
||||||
|
SetupKeypair::new(vk, pk_vec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,12 @@ pub use self::solidity::*;
|
||||||
use crate::ir;
|
use crate::ir;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use zokrates_field::Field;
|
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Field};
|
||||||
|
|
||||||
|
pub trait NotBw6_761Field {}
|
||||||
|
impl NotBw6_761Field for Bls12_377Field {}
|
||||||
|
impl NotBw6_761Field for Bls12_381Field {}
|
||||||
|
impl NotBw6_761Field for Bn128Field {}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct SetupKeypair<V> {
|
pub struct SetupKeypair<V> {
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
use crate::proof_system::scheme::{NonUniversalScheme, Scheme};
|
use crate::proof_system::scheme::{NonUniversalScheme, Scheme};
|
||||||
use crate::proof_system::solidity::{solidity_pairing_lib, SOLIDITY_G2_ADDITION_LIB};
|
use crate::proof_system::solidity::{solidity_pairing_lib, SOLIDITY_G2_ADDITION_LIB};
|
||||||
use crate::proof_system::{
|
use crate::proof_system::{
|
||||||
G1Affine, G2Affine, G2AffineFq, SolidityCompatibleField, SolidityCompatibleScheme,
|
G1Affine, G2Affine, G2AffineFq, NotBw6_761Field, SolidityCompatibleField,
|
||||||
|
SolidityCompatibleScheme,
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
|
use zokrates_field::{Bw6_761Field, Field};
|
||||||
|
|
||||||
pub trait NotBw6_761Field {}
|
|
||||||
impl NotBw6_761Field for Bls12_377Field {}
|
|
||||||
impl NotBw6_761Field for Bls12_381Field {}
|
|
||||||
impl NotBw6_761Field for Bn128Field {}
|
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
pub struct GM17;
|
pub struct GM17;
|
||||||
|
|
Loading…
Reference in a new issue