1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
This commit is contained in:
dark64 2021-11-25 20:07:17 +01:00
parent 70615505db
commit f2481d3dec
21 changed files with 498 additions and 342 deletions

1
Cargo.lock generated
View file

@ -2396,6 +2396,7 @@ dependencies = [
"serde_json",
"tempdir",
"zokrates_abi",
"zokrates_common",
"zokrates_core",
"zokrates_field",
"zokrates_fs_resolver",

View file

@ -22,6 +22,7 @@ zokrates_field = { version = "0.4", path = "../zokrates_field", default-features
zokrates_abi = { version = "0.1", path = "../zokrates_abi" }
zokrates_core = { version = "0.6", path = "../zokrates_core", default-features = false }
zokrates_fs_resolver = { version = "0.5", path = "../zokrates_fs_resolver"}
zokrates_common = { version = "0.1", path = "../zokrates_common"}
serde_json = "1.0"
dirs = "3.0.1"
lazy_static = "1.4.0"

View file

@ -10,7 +10,6 @@
extern crate lazy_static;
mod constants;
mod helpers;
mod ops;
use clap::{App, AppSettings, Arg};

View file

@ -9,10 +9,6 @@ pub const UNIVERSAL_SETUP_DEFAULT_PATH: &str = "universal_setup.dat";
pub const UNIVERSAL_SETUP_DEFAULT_SIZE: &str = "10";
pub const SMTLIB2_DEFAULT_PATH: &str = "out.smt2";
pub const BELLMAN: &str = "bellman";
pub const LIBSNARK: &str = "libsnark";
pub const ARK: &str = "ark";
lazy_static! {
pub static ref DEFAULT_STDLIB_PATH: String = dirs::home_dir()
.map(|p| p.join(".zokrates/stdlib"))
@ -21,42 +17,3 @@ lazy_static! {
.into_string()
.unwrap();
}
#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))]
pub const BACKENDS: &[&str] = if cfg!(feature = "libsnark") {
if cfg!(feature = "ark") {
if cfg!(feature = "bellman") {
&[BELLMAN, LIBSNARK, ARK]
} else {
&[LIBSNARK, ARK]
}
} else if cfg!(feature = "bellman") {
&[BELLMAN, LIBSNARK]
} else {
&[LIBSNARK]
}
} else if cfg!(feature = "ark") {
if cfg!(feature = "bellman") {
&[BELLMAN, ARK]
} else {
&[ARK]
}
} else if cfg!(feature = "bellman") {
&[BELLMAN]
} else {
&[]
};
pub const BN128: &str = "bn128";
pub const BLS12_381: &str = "bls12_381";
pub const BLS12_377: &str = "bls12_377";
pub const BW6_761: &str = "bw6_761";
pub const CURVES: &[&str] = &[BN128, BLS12_381, BLS12_377, BW6_761];
pub const G16: &str = "g16";
pub const PGHR13: &str = "pghr13";
pub const GM17: &str = "gm17";
pub const MARLIN: &str = "marlin";
pub const SCHEMES: &[&str] = &[G16, PGHR13, GM17, MARLIN];
pub const UNIVERSAL_SCHEMES: &[&str] = &[MARLIN];

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::CurveParameter;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::{Path, PathBuf};
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::CurveParameter;
use zokrates_core::compile::{check, CompileConfig, CompileError};
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
use zokrates_fs_resolver::FileSystemResolver;
@ -38,8 +39,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Curve to be used in the compilation")
.takes_value(true)
.required(false)
.possible_values(constants::CURVES)
.default_value(constants::BN128),
.possible_values(common_constants::CURVES)
.default_value(common_constants::BN128),
)
.arg(Arg::with_name("isolate-branches")
.long("isolate-branches")

View file

@ -1,11 +1,12 @@
use crate::constants;
use crate::helpers::CurveParameter;
use clap::{App, Arg, ArgMatches, SubCommand};
use serde_json::to_writer_pretty;
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufReader, BufWriter, Read, Write};
use std::path::{Path, PathBuf};
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::CurveParameter;
use zokrates_core::compile::{compile, CompilationArtifacts, CompileConfig, CompileError};
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
use zokrates_fs_resolver::FileSystemResolver;
@ -50,8 +51,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Curve to be used in the compilation")
.takes_value(true)
.required(false)
.possible_values(constants::CURVES)
.default_value(constants::BN128)
.possible_values(common_constants::CURVES)
.default_value(common_constants::BN128)
).arg(Arg::with_name("allow-unconstrained-variables")
.long("allow-unconstrained-variables")
.help("Allow unconstrained variables by inserting dummy constraints")

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::{CurveParameter, SchemeParameter};
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::path::Path;
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::{CurveParameter, SchemeParameter};
use zokrates_core::proof_system::*;
use zokrates_field::Bn128Field;
@ -38,8 +39,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Curve to be used to export the verifier")
.takes_value(true)
.required(false)
.possible_values(constants::CURVES)
.default_value(constants::BN128),
.possible_values(common_constants::CURVES)
.default_value(common_constants::BN128),
)
.arg(
Arg::with_name("proving-scheme")
@ -49,8 +50,8 @@ pub fn subcommand() -> App<'static, 'static> {
.value_name("FILE")
.takes_value(true)
.required(false)
.possible_values(constants::SCHEMES)
.default_value(constants::G16),
.possible_values(common_constants::SCHEMES)
.default_value(common_constants::G16),
)
}

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::*;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufReader, Read, Write};
use std::path::Path;
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::*;
use zokrates_core::ir;
use zokrates_core::ir::ProgEnum;
#[cfg(feature = "ark")]
@ -67,8 +68,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Backend to use")
.takes_value(true)
.required(false)
.possible_values(constants::BACKENDS)
.default_value(constants::BELLMAN),
.possible_values(common_constants::BACKENDS)
.default_value(common_constants::BELLMAN),
)
.arg(
Arg::with_name("proving-scheme")
@ -78,8 +79,8 @@ pub fn subcommand() -> App<'static, 'static> {
.value_name("FILE")
.takes_value(true)
.required(false)
.possible_values(constants::SCHEMES)
.default_value(constants::G16),
.possible_values(common_constants::SCHEMES)
.default_value(common_constants::G16),
)
}
@ -93,12 +94,7 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
let parameters = Parameters::try_from((
sub_matches.value_of("backend").unwrap(),
match prog {
ProgEnum::Bn128Program(_) => constants::BN128,
ProgEnum::Bls12_381Program(_) => constants::BLS12_381,
ProgEnum::Bls12_377Program(_) => constants::BLS12_377,
ProgEnum::Bw6_761Program(_) => constants::BW6_761,
},
prog.curve(),
sub_matches.value_of("proving-scheme").unwrap(),
))?;

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::*;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{BufReader, Write};
use std::path::Path;
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::*;
use zokrates_core::ir;
use zokrates_core::ir::ProgEnum;
#[cfg(feature = "ark")]
@ -57,8 +58,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Backend to use")
.takes_value(true)
.required(false)
.possible_values(constants::BACKENDS)
.default_value(constants::BELLMAN),
.possible_values(common_constants::BACKENDS)
.default_value(common_constants::BELLMAN),
)
.arg(
Arg::with_name("proving-scheme")
@ -67,8 +68,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Proving scheme to use in the setup")
.takes_value(true)
.required(false)
.possible_values(constants::SCHEMES)
.default_value(constants::G16),
.possible_values(common_constants::SCHEMES)
.default_value(common_constants::G16),
)
.arg(
Arg::with_name("universal-setup-path")
@ -93,12 +94,7 @@ pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
let parameters = Parameters::try_from((
sub_matches.value_of("backend").unwrap(),
match prog {
ProgEnum::Bn128Program(_) => constants::BN128,
ProgEnum::Bls12_377Program(_) => constants::BLS12_377,
ProgEnum::Bls12_381Program(_) => constants::BLS12_381,
ProgEnum::Bw6_761Program(_) => constants::BW6_761,
},
prog.curve(),
sub_matches.value_of("proving-scheme").unwrap(),
))?;

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::*;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::*;
#[cfg(feature = "ark")]
use zokrates_core::proof_system::ark::Ark;
#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))]
@ -21,8 +22,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Curve to be used in the universal setup")
.takes_value(true)
.required(false)
.possible_values(constants::CURVES)
.default_value(constants::BN128),
.possible_values(common_constants::CURVES)
.default_value(common_constants::BN128),
)
.arg(
Arg::with_name("universal-setup-path")
@ -41,8 +42,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Proving scheme to use in the setup")
.takes_value(true)
.required(false)
.possible_values(constants::UNIVERSAL_SCHEMES)
.default_value(constants::MARLIN),
.possible_values(common_constants::UNIVERSAL_SCHEMES)
.default_value(common_constants::MARLIN),
)
.arg(
Arg::with_name("size")
@ -57,7 +58,7 @@ pub fn subcommand() -> App<'static, 'static> {
pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> {
let parameters = Parameters::try_from((
constants::ARK,
common_constants::ARK,
sub_matches.value_of("curve").unwrap(),
sub_matches.value_of("proving-scheme").unwrap(),
))?;

View file

@ -1,10 +1,11 @@
use crate::constants;
use crate::helpers::*;
use clap::{App, Arg, ArgMatches, SubCommand};
use std::convert::TryFrom;
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use zokrates_common::constants as common_constants;
use zokrates_common::helpers::*;
#[cfg(feature = "ark")]
use zokrates_core::proof_system::ark::Ark;
#[cfg(feature = "bellman")]
@ -40,8 +41,8 @@ pub fn subcommand() -> App<'static, 'static> {
.help("Backend to use")
.takes_value(true)
.required(false)
.possible_values(constants::BACKENDS)
.default_value(constants::BELLMAN)
.possible_values(common_constants::BACKENDS)
.default_value(common_constants::BELLMAN)
).arg(Arg::with_name("proving-scheme")
.short("s")
.long("proving-scheme")
@ -49,15 +50,15 @@ pub fn subcommand() -> App<'static, 'static> {
.value_name("FILE")
.takes_value(true)
.required(false)
.default_value(constants::G16)
.default_value(common_constants::G16)
).arg(Arg::with_name("curve")
.short("c")
.long("curve")
.help("Curve to be used in the verification")
.takes_value(true)
.required(false)
.possible_values(constants::CURVES)
.default_value(constants::BN128)
.possible_values(common_constants::CURVES)
.default_value(common_constants::BN128)
)
}

View file

@ -6,4 +6,11 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["bellman", "ark"]
bellman = []
ark = []
libsnark = []
[dependencies]

View file

@ -0,0 +1,42 @@
pub const BELLMAN: &str = "bellman";
pub const ARK: &str = "ark";
pub const LIBSNARK: &str = "libsnark";
pub const BN128: &str = "bn128";
pub const BLS12_381: &str = "bls12_381";
pub const BLS12_377: &str = "bls12_377";
pub const BW6_761: &str = "bw6_761";
pub const G16: &str = "g16";
pub const PGHR13: &str = "pghr13";
pub const GM17: &str = "gm17";
pub const MARLIN: &str = "marlin";
#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))]
pub const BACKENDS: &[&str] = if cfg!(feature = "libsnark") {
if cfg!(feature = "ark") {
if cfg!(feature = "bellman") {
&[BELLMAN, LIBSNARK, ARK]
} else {
&[LIBSNARK, ARK]
}
} else if cfg!(feature = "bellman") {
&[BELLMAN, LIBSNARK]
} else {
&[LIBSNARK]
}
} else if cfg!(feature = "ark") {
if cfg!(feature = "bellman") {
&[BELLMAN, ARK]
} else {
&[ARK]
}
} else if cfg!(feature = "bellman") {
&[BELLMAN]
} else {
&[]
};
pub const CURVES: &[&str] = &[BN128, BLS12_381, BLS12_377, BW6_761];
pub const SCHEMES: &[&str] = &[G16, PGHR13, GM17, MARLIN];
pub const UNIVERSAL_SCHEMES: &[&str] = &[MARLIN];

View file

@ -1,3 +1,6 @@
pub mod constants;
pub mod helpers;
use std::path::PathBuf;
pub trait Resolver<E> {

View file

@ -65,6 +65,15 @@ impl ProgEnum {
Err(String::from("Wrong magic number"))
}
}
pub fn curve(&self) -> &'static str {
match self {
ProgEnum::Bls12_381Program(_) => Bls12_377Field::name(),
ProgEnum::Bn128Program(_) => Bn128Field::name(),
ProgEnum::Bls12_377Program(_) => Bls12_377Field::name(),
ProgEnum::Bw6_761Program(_) => Bw6_761Field::name(),
}
}
}
#[cfg(test)]

View file

@ -16,4 +16,7 @@ zokrates_core = { path = "../zokrates_core", features = ["wasm", "bellman", "ark
zokrates_common = { path = "../zokrates_common" }
zokrates_field = { path = "../zokrates_field", default-features = false, features = ["bellman"] }
zokrates_abi = { path = "../zokrates_abi" }
console_error_panic_hook = "0.1.6"
console_error_panic_hook = "0.1.6"
[package.metadata.wasm-pack.profile.release]
wasm-opt = false

View file

@ -1,5 +1,9 @@
declare module 'zokrates-js' {
export type Curve = "bn128" | "bls12_381" | "bls12_377" | "bw6_761";
export type Backend = "bellman" | "ark";
export type Scheme = "g16" | "gm17" | "marlin";
export type Fq = string;
export type Fq2 = [Fq, Fq];
@ -9,10 +13,10 @@ declare module 'zokrates-js' {
export type ResolveCallback = (location: string, path: string) => ResolverResult;
export interface CompileConfig {
allow_unconstrained_variables?: boolean,
isolate_branches?: boolean
}
export interface CompileConfig {
allow_unconstrained_variables?: boolean,
isolate_branches?: boolean
}
export interface CompileOptions {
location?: string,
@ -59,13 +63,23 @@ declare module 'zokrates-js' {
pk: ProvingKey,
}
export type Options = {
curve: Scheme,
backend: Backend,
scheme: Curve,
}
type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
export interface ZoKratesProvider {
compile(source: string, options?: CompileOptions): CompilationArtifacts;
setup(program: Uint8Array): SetupKeypair;
computeWitness(artifacts: CompilationArtifacts, args: any[]): ComputationResult;
exportSolidityVerifier(verificationKey: VerificationKey): string;
generateProof(program: Uint8Array, witness: string, provingKey: Uint8Array): Proof;
verify(verificationKey: VerificationKey, proof: Proof): boolean;
setup(program: Uint8Array, options: AtLeast<Options, "backend" | "scheme">): SetupKeypair;
setupWithSrs(srs: Uint8Array, program: Uint8Array, options: AtLeast<Options, "backend" | "scheme">): SetupKeypair;
universalSetup(curve: Curve, size: number): Uint8Array;
exportSolidityVerifier(verificationKey: VerificationKey, options: AtLeast<Options, "curve" | "scheme">): string;
generateProof(program: Uint8Array, witness: string, provingKey: Uint8Array, options: AtLeast<Options, "backend" | "scheme">): Proof;
verify(verificationKey: VerificationKey, proof: Proof, options: Options): boolean;
}
export interface Metadata {

View file

@ -1,9 +1,11 @@
use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
use std::convert::TryFrom;
use std::io::Cursor;
use std::path::PathBuf;
use wasm_bindgen::prelude::*;
use zokrates_abi::{parse_strict, Decode, Encode, Inputs};
use zokrates_common::helpers::{BackendParameter, CurveParameter, Parameters, SchemeParameter};
use zokrates_common::Resolver;
use zokrates_core::compile::{
compile as core_compile, CompilationArtifacts, CompileConfig, CompileError,
@ -82,136 +84,155 @@ impl<'a> Resolver<Error> for JsResolver<'a> {
}
}
pub fn setup<T: Field, S: NonUniversalScheme<T>, B: NonUniversalBackend<T, S>>(
program: ir::Prog<T>,
) -> JsValue {
let keypair = B::setup(program);
JsValue::from_serde(&keypair).unwrap()
}
mod internal {
use super::*;
pub fn setup_with_srs<T: Field, S: UniversalScheme<T>, B: UniversalBackend<T, S>>(
srs: &[u8],
program: ir::Prog<T>,
) -> Result<JsValue, JsValue> {
let keypair = B::setup(srs.to_vec(), program).map_err(|e| JsValue::from_str(&e))?;
Ok(JsValue::from_serde(&keypair).unwrap())
}
pub fn compile<T: Field>(
source: JsValue,
location: JsValue,
resolve_callback: &js_sys::Function,
config: JsValue,
) -> Result<JsValue, JsValue> {
let resolver = JsResolver::new(resolve_callback);
let fmt_error = |e: &CompileError| format!("{}:{}", e.file().display(), e.value());
pub fn universal_setup<T: Field, S: UniversalScheme<T>, B: UniversalBackend<T, S>>(
size: u32,
) -> JsValue {
let keypair = B::universal_setup(size);
JsValue::from_serde(&keypair).unwrap()
}
fn generate_proof<T: Field, S: Scheme<T>, B: Backend<T, S>>(
prog: ir::Prog<T>,
witness: JsValue,
pk: &[u8],
) -> Result<JsValue, JsValue> {
let str_witness = witness.as_string().unwrap();
let ir_witness: ir::Witness<T> = ir::Witness::read(str_witness.as_bytes())
.map_err(|err| JsValue::from_str(&format!("Could not read witness: {}", err)))?;
let proof = B::generate_proof(prog, ir_witness, pk.to_vec());
Ok(JsValue::from_serde(&proof).unwrap())
}
fn verify<T: Field, S: Scheme<T>, B: Backend<T, S>>(
vk: JsValue,
proof: JsValue,
) -> Result<JsValue, JsValue> {
let vk: S::VerificationKey = vk.into_serde().unwrap();
let proof: Proof<S::ProofPoints> = proof.into_serde().unwrap();
let result = B::verify(vk, proof);
Ok(JsValue::from_serde(&result).unwrap())
}
pub fn compile_source<T: Field>(
source: JsValue,
location: JsValue,
resolve_callback: &js_sys::Function,
config: JsValue,
) -> Result<JsValue, JsValue> {
let resolver = JsResolver::new(resolve_callback);
let fmt_error = |e: &CompileError| format!("{}:{}", e.file().display(), e.value());
let config: CompileConfig = config.into_serde().unwrap_or_default();
let artifacts: CompilationArtifacts<T> = core_compile(
source.as_string().unwrap(),
PathBuf::from(location.as_string().unwrap()),
Some(&resolver),
&config,
)
.map_err(|ce| {
JsValue::from_str(
&ce.0
.iter()
.map(|e| fmt_error(e))
.collect::<Vec<_>>()
.join("\n"),
let config: CompileConfig = config.into_serde().unwrap_or_default();
let artifacts: CompilationArtifacts<T> = core_compile(
source.as_string().unwrap(),
PathBuf::from(location.as_string().unwrap()),
Some(&resolver),
&config,
)
})?;
.map_err(|ce| {
JsValue::from_str(
&ce.0
.iter()
.map(|e| fmt_error(e))
.collect::<Vec<_>>()
.join("\n"),
)
})?;
let program = artifacts.prog();
let mut buffer = Cursor::new(vec![]);
program.serialize(&mut buffer);
let program = artifacts.prog();
let mut buffer = Cursor::new(vec![]);
program.serialize(&mut buffer);
let result = CompilationResult {
program: buffer.into_inner(),
abi: to_string_pretty(artifacts.abi()).unwrap(),
};
let result = CompilationResult {
program: buffer.into_inner(),
abi: to_string_pretty(artifacts.abi()).unwrap(),
};
Ok(JsValue::from_serde(&result).unwrap())
}
Ok(JsValue::from_serde(&result).unwrap())
}
fn compute<T: Field>(
program: ir::Prog<T>,
abi: JsValue,
args: JsValue,
) -> Result<JsValue, JsValue> {
let abi: Abi = serde_json::from_str(abi.as_string().unwrap().as_str())
.map_err(|err| JsValue::from_str(&format!("Could not deserialize abi: {}", err)))?;
pub fn compute<T: Field>(
program: ir::Prog<T>,
abi: JsValue,
args: JsValue,
) -> Result<JsValue, JsValue> {
let abi: Abi = serde_json::from_str(abi.as_string().unwrap().as_str())
.map_err(|err| JsValue::from_str(&format!("Could not deserialize abi: {}", err)))?;
let signature: Signature = abi.signature();
let input = args.as_string().unwrap();
let signature: Signature = abi.signature();
let input = args.as_string().unwrap();
let inputs = parse_strict(&input, signature.inputs)
.map(Inputs::Abi)
.map_err(|why| JsValue::from_str(&why.to_string()))?;
let inputs = parse_strict(&input, signature.inputs)
.map(Inputs::Abi)
.map_err(|why| JsValue::from_str(&why.to_string()))?;
let interpreter = ir::Interpreter::default();
let interpreter = ir::Interpreter::default();
let witness = interpreter
.execute(&program, &inputs.encode())
.map_err(|err| JsValue::from_str(&format!("Execution failed: {}", err)))?;
let witness = interpreter
.execute(&program, &inputs.encode())
.map_err(|err| JsValue::from_str(&format!("Execution failed: {}", err)))?;
let return_values: serde_json::Value =
zokrates_abi::Values::decode(witness.return_values(), signature.outputs).into_serde_json();
let return_values: serde_json::Value =
zokrates_abi::Values::decode(witness.return_values(), signature.outputs)
.into_serde_json();
let result = ComputationResult {
witness: format!("{}", witness),
output: to_string_pretty(&return_values).unwrap(),
};
let result = ComputationResult {
witness: format!("{}", witness),
output: to_string_pretty(&return_values).unwrap(),
};
Ok(JsValue::from_serde(&result).unwrap())
Ok(JsValue::from_serde(&result).unwrap())
}
pub fn setup_non_universal<T: Field, S: NonUniversalScheme<T>, B: NonUniversalBackend<T, S>>(
program: ir::Prog<T>,
) -> JsValue {
let keypair = B::setup(program);
JsValue::from_serde(&keypair).unwrap()
}
pub fn setup_universal<T: Field, S: UniversalScheme<T>, B: UniversalBackend<T, S>>(
srs: &[u8],
program: ir::Prog<T>,
) -> Result<JsValue, JsValue> {
let keypair = B::setup(srs.to_vec(), program).map_err(|e| JsValue::from_str(&e))?;
Ok(JsValue::from_serde(&keypair).unwrap())
}
pub fn universal_setup_of_size<T: Field, S: UniversalScheme<T>, B: UniversalBackend<T, S>>(
size: u32,
) -> Vec<u8> {
B::universal_setup(size)
}
pub fn generate_proof<T: Field, S: Scheme<T>, B: Backend<T, S>>(
prog: ir::Prog<T>,
witness: JsValue,
pk: &[u8],
) -> Result<JsValue, JsValue> {
let str_witness = witness.as_string().unwrap();
let ir_witness: ir::Witness<T> = ir::Witness::read(str_witness.as_bytes())
.map_err(|err| JsValue::from_str(&format!("Could not read witness: {}", err)))?;
let proof = B::generate_proof(prog, ir_witness, pk.to_vec());
Ok(JsValue::from_serde(&proof).unwrap())
}
pub fn verify<T: Field, S: Scheme<T>, B: Backend<T, S>>(
vk: JsValue,
proof: JsValue,
) -> Result<JsValue, JsValue> {
let vk: S::VerificationKey = vk.into_serde().unwrap();
let proof: Proof<S::ProofPoints> = proof.into_serde().unwrap();
let result = B::verify(vk, proof);
Ok(JsValue::from_serde(&result).unwrap())
}
}
#[wasm_bindgen]
pub fn compile(
curve: JsValue,
source: JsValue,
location: JsValue,
resolve_callback: &js_sys::Function,
config: JsValue,
options: JsValue,
) -> Result<JsValue, JsValue> {
match curve.as_string().unwrap().as_str() {
"bn128" => compile_source::<Bn128Field>(source, location, resolve_callback, config),
"bls12_381" => compile_source::<Bls12_381Field>(source, location, resolve_callback, config),
"bls12_377" => compile_source::<Bls12_377Field>(source, location, resolve_callback, config),
"bw6_761" => compile_source::<Bw6_761Field>(source, location, resolve_callback, config),
_ => unreachable!(),
let options: serde_json::Value = options.into_serde().unwrap();
let curve = CurveParameter::try_from(
options["curve"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `curve` in `options` object"))?,
)
.map_err(|e| JsValue::from_str(&e))?;
match curve {
CurveParameter::Bn128 => {
internal::compile::<Bn128Field>(source, location, resolve_callback, config)
}
CurveParameter::Bls12_381 => {
internal::compile::<Bls12_381Field>(source, location, resolve_callback, config)
}
CurveParameter::Bls12_377 => {
internal::compile::<Bls12_377Field>(source, location, resolve_callback, config)
}
CurveParameter::Bw6_761 => {
internal::compile::<Bw6_761Field>(source, location, resolve_callback, config)
}
}
}
@ -219,137 +240,225 @@ pub fn compile(
pub fn compute_witness(program: &[u8], abi: JsValue, args: JsValue) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => compute::<_>(p, abi, args),
ProgEnum::Bls12_381Program(p) => compute::<_>(p, abi, args),
ProgEnum::Bls12_377Program(p) => compute::<_>(p, abi, args),
ProgEnum::Bw6_761Program(p) => compute::<_>(p, abi, args),
ProgEnum::Bn128Program(p) => internal::compute::<_>(p, abi, args),
ProgEnum::Bls12_381Program(p) => internal::compute::<_>(p, abi, args),
ProgEnum::Bls12_377Program(p) => internal::compute::<_>(p, abi, args),
ProgEnum::Bw6_761Program(p) => internal::compute::<_>(p, abi, args),
}
}
#[wasm_bindgen]
pub fn bellman_groth16_export_solidity_verifier(vk: JsValue) -> Result<JsValue, JsValue> {
let verifier = <G16 as SolidityCompatibleScheme<Bn128Field>>::export_solidity_verifier(
vk.into_serde().unwrap(),
);
pub fn export_solidity_verifier(vk: JsValue, options: JsValue) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let curve = CurveParameter::try_from(
options["curve"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `curve` in `options` object"))?,
)
.map_err(|e| JsValue::from_str(&e))?;
let scheme = SchemeParameter::try_from(
options["scheme"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `scheme` in `options` object"))?,
)
.map_err(|e| JsValue::from_str(&e))?;
let verifier = match (curve, scheme) {
(CurveParameter::Bn128, SchemeParameter::G16) => Ok(<G16 as SolidityCompatibleScheme<
Bn128Field,
>>::export_solidity_verifier(
vk.into_serde().unwrap()
)),
(CurveParameter::Bn128, SchemeParameter::GM17) => Ok(<GM17 as SolidityCompatibleScheme<
Bn128Field,
>>::export_solidity_verifier(
vk.into_serde().unwrap()
)),
_ => Err(JsValue::from_str("Could not export solidity verifier")),
}?;
Ok(JsValue::from_str(verifier.as_str()))
}
#[wasm_bindgen]
pub fn bellman_groth16_setup(program: &[u8]) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => Ok(setup::<_, G16, Bellman>(p)),
ProgEnum::Bls12_381Program(p) => Ok(setup::<_, G16, Bellman>(p)),
_ => unreachable!(), // TODO: reachable
pub fn setup(program: &[u8], options: JsValue) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let backend = options["backend"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `backend` in `options` object"))?;
let scheme = options["scheme"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `scheme` in `options` object"))?;
let prog = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
let parameters =
Parameters::try_from((backend, prog.curve(), scheme)).map_err(|e| JsValue::from_str(&e))?;
match parameters {
Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog {
ProgEnum::Bn128Program(p) => Ok(internal::setup_non_universal::<_, G16, Bellman>(p)),
ProgEnum::Bls12_381Program(p) => {
Ok(internal::setup_non_universal::<_, G16, Bellman>(p))
}
_ => unreachable!(),
},
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
ProgEnum::Bn128Program(p) => Ok(internal::setup_non_universal::<_, GM17, Ark>(p)),
ProgEnum::Bls12_377Program(p) => Ok(internal::setup_non_universal::<_, GM17, Ark>(p)),
ProgEnum::Bw6_761Program(p) => Ok(internal::setup_non_universal::<_, GM17, Ark>(p)),
_ => unreachable!(),
},
_ => Err(JsValue::from_str("Unsupported combination of parameters")),
}
}
#[wasm_bindgen]
pub fn ark_gm17_setup(program: &[u8]) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => Ok(setup::<_, GM17, Ark>(p)),
ProgEnum::Bls12_377Program(p) => Ok(setup::<_, GM17, Ark>(p)),
ProgEnum::Bw6_761Program(p) => Ok(setup::<_, GM17, Ark>(p)),
_ => unreachable!(), // TODO: reachable
pub fn setup_with_srs(srs: &[u8], program: &[u8], options: JsValue) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let backend = options["backend"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `backend` in `options` object"))?;
let scheme = options["scheme"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `scheme` in `options` object"))?;
let prog = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
let parameters =
Parameters::try_from((backend, prog.curve(), scheme)).map_err(|e| JsValue::from_str(&e))?;
match parameters {
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => match prog {
ProgEnum::Bn128Program(p) => internal::setup_universal::<_, Marlin, Ark>(srs, p),
ProgEnum::Bls12_377Program(p) => internal::setup_universal::<_, Marlin, Ark>(srs, p),
ProgEnum::Bw6_761Program(p) => internal::setup_universal::<_, Marlin, Ark>(srs, p),
_ => unreachable!(),
},
_ => Err(JsValue::from_str("Unsupported combination of parameters")),
}
}
#[wasm_bindgen]
pub fn ark_marlin_setup(srs: &[u8], program: &[u8]) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => setup_with_srs::<_, Marlin, Ark>(srs, p),
ProgEnum::Bls12_377Program(p) => setup_with_srs::<_, Marlin, Ark>(srs, p),
ProgEnum::Bw6_761Program(p) => setup_with_srs::<_, Marlin, Ark>(srs, p),
_ => unreachable!(), // TODO: reachable
pub fn universal_setup(curve: JsValue, size: u32) -> Result<Vec<u8>, JsValue> {
let curve = CurveParameter::try_from(curve.as_string().unwrap().as_str())
.map_err(|e| JsValue::from_str(&e))?;
match curve {
CurveParameter::Bn128 => {
Ok(internal::universal_setup_of_size::<Bn128Field, Marlin, Ark>(size))
}
CurveParameter::Bls12_377 => Ok(internal::universal_setup_of_size::<
Bls12_377Field,
Marlin,
Ark,
>(size)),
CurveParameter::Bw6_761 => {
Ok(internal::universal_setup_of_size::<Bw6_761Field, Marlin, Ark>(size))
}
c => Err(JsValue::from_str(&format!(
"Unsupported curve `{:?}` provided in universal setup",
c
))),
}
}
#[wasm_bindgen]
pub fn ark_marlin_universal_setup(curve: JsValue, size: u32) -> Result<JsValue, JsValue> {
match curve.as_string().unwrap().as_str() {
"bn128" => Ok(universal_setup::<Bn128Field, Marlin, Ark>(size)),
"bls12_377" => Ok(universal_setup::<Bls12_377Field, Marlin, Ark>(size)),
"bw6_761" => Ok(universal_setup::<Bw6_761Field, Marlin, Ark>(size)),
pub fn generate_proof(
program: &[u8],
witness: JsValue,
pk: &[u8],
options: JsValue,
) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let backend = options["backend"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `backend` in `options` object"))?;
let scheme = options["scheme"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `scheme` in `options` object"))?;
let prog = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
let parameters =
Parameters::try_from((backend, prog.curve(), scheme)).map_err(|e| JsValue::from_str(&e))?;
match parameters {
Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog {
ProgEnum::Bn128Program(p) => {
internal::generate_proof::<_, G16, Bellman>(p, witness, pk)
}
ProgEnum::Bls12_381Program(p) => {
internal::generate_proof::<_, G16, Bellman>(p, witness, pk)
}
_ => unreachable!(),
},
Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog {
ProgEnum::Bn128Program(p) => internal::generate_proof::<_, GM17, Ark>(p, witness, pk),
ProgEnum::Bls12_377Program(p) => {
internal::generate_proof::<_, GM17, Ark>(p, witness, pk)
}
ProgEnum::Bw6_761Program(p) => internal::generate_proof::<_, GM17, Ark>(p, witness, pk),
_ => unreachable!(),
},
Parameters(BackendParameter::Ark, _, SchemeParameter::MARLIN) => match prog {
ProgEnum::Bn128Program(p) => internal::generate_proof::<_, Marlin, Ark>(p, witness, pk),
ProgEnum::Bls12_377Program(p) => {
internal::generate_proof::<_, Marlin, Ark>(p, witness, pk)
}
ProgEnum::Bw6_761Program(p) => {
internal::generate_proof::<_, Marlin, Ark>(p, witness, pk)
}
_ => unreachable!(),
},
_ => unreachable!(),
}
}
#[wasm_bindgen]
pub fn bellman_groth16_generate_proof(
program: &[u8],
witness: JsValue,
pk: &[u8],
) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => generate_proof::<_, G16, Bellman>(p, witness, pk),
ProgEnum::Bls12_381Program(p) => generate_proof::<_, G16, Bellman>(p, witness, pk),
_ => unreachable!(), // TODO: reachable
}
}
pub fn verify(vk: JsValue, proof: JsValue, options: JsValue) -> Result<JsValue, JsValue> {
let options: serde_json::Value = options.into_serde().unwrap();
let backend = options["backend"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `backend` in `options` object"))?;
#[wasm_bindgen]
pub fn ark_gm17_generate_proof(
program: &[u8],
witness: JsValue,
pk: &[u8],
) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => generate_proof::<_, GM17, Ark>(p, witness, pk),
ProgEnum::Bls12_377Program(p) => generate_proof::<_, GM17, Ark>(p, witness, pk),
ProgEnum::Bw6_761Program(p) => generate_proof::<_, GM17, Ark>(p, witness, pk),
_ => unreachable!(), // TODO: reachable
}
}
let curve = options["curve"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `curve` in `options` object"))?;
#[wasm_bindgen]
pub fn ark_marlin_generate_proof(
program: &[u8],
witness: JsValue,
pk: &[u8],
) -> Result<JsValue, JsValue> {
let p = ir::ProgEnum::deserialize(program).map_err(|err| JsValue::from_str(&err))?;
match p {
ProgEnum::Bn128Program(p) => generate_proof::<_, Marlin, Ark>(p, witness, pk),
ProgEnum::Bls12_377Program(p) => generate_proof::<_, Marlin, Ark>(p, witness, pk),
ProgEnum::Bw6_761Program(p) => generate_proof::<_, Marlin, Ark>(p, witness, pk),
_ => unreachable!(), // TODO: reachable
}
}
let scheme = options["scheme"]
.as_str()
.ok_or_else(|| JsValue::from_str("missing field `scheme` in `options` object"))?;
#[wasm_bindgen]
pub fn bellman_groth16_verify(
vk: JsValue,
proof: JsValue,
curve: JsValue,
) -> Result<JsValue, JsValue> {
match curve.as_string().unwrap().as_str() {
"bn128" => verify::<Bn128Field, G16, Bellman>(vk, proof),
"bls12_381" => verify::<Bls12_381Field, G16, Bellman>(vk, proof),
_ => unreachable!(), // TODO: reachable
}
}
let parameters = Parameters::try_from((backend, curve, scheme))?;
#[wasm_bindgen]
pub fn ark_gm17_verify(vk: JsValue, proof: JsValue, curve: JsValue) -> Result<JsValue, JsValue> {
match curve.as_string().unwrap().as_str() {
"bn128" => verify::<Bn128Field, GM17, Ark>(vk, proof),
"bls12_377" => verify::<Bls12_377Field, GM17, Ark>(vk, proof),
"bw6_761" => verify::<Bw6_761Field, GM17, Ark>(vk, proof),
_ => unreachable!(), // TODO: reachable
}
}
#[wasm_bindgen]
pub fn ark_marlin_verify(vk: JsValue, proof: JsValue, curve: JsValue) -> Result<JsValue, JsValue> {
match curve.as_string().unwrap().as_str() {
"bn128" => verify::<Bn128Field, Marlin, Ark>(vk, proof),
"bls12_377" => verify::<Bls12_377Field, Marlin, Ark>(vk, proof),
"bw6_761" => verify::<Bw6_761Field, Marlin, Ark>(vk, proof),
_ => unreachable!(), // TODO: reachable
match parameters {
Parameters(BackendParameter::Bellman, CurveParameter::Bn128, SchemeParameter::G16) => {
internal::verify::<Bn128Field, G16, Bellman>(vk, proof)
}
Parameters(BackendParameter::Bellman, CurveParameter::Bls12_381, SchemeParameter::G16) => {
internal::verify::<Bls12_381Field, G16, Bellman>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => {
internal::verify::<Bls12_377Field, GM17, Ark>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::GM17) => {
internal::verify::<Bw6_761Field, GM17, Ark>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => {
internal::verify::<Bn128Field, GM17, Ark>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::MARLIN) => {
internal::verify::<Bls12_377Field, Marlin, Ark>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::MARLIN) => {
internal::verify::<Bw6_761Field, Marlin, Ark>(vk, proof)
}
Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::MARLIN) => {
internal::verify::<Bn128Field, Marlin, Ark>(vk, proof)
}
_ => unreachable!(),
}
}

View file

@ -86,6 +86,12 @@ describe('tests', function() {
describe("bellman", () => {
describe("groth16", () => {
const options = {
backend: "bellman",
curve: "bn128",
scheme: "g16"
};
let artifacts;
let computationResult;
let keypair;
@ -100,39 +106,45 @@ describe('tests', function() {
it("setup", () => {
assert.doesNotThrow(() => {
keypair = zokrates.bellman.groth16.setup(artifacts.program);
keypair = zokrates.setup(artifacts.program, options);
});
});
it("generate proof", () => {
assert.doesNotThrow(() => {
proof = zokrates.bellman.groth16.generateProof(artifacts.program, computationResult.witness, keypair.pk);
proof = zokrates.generateProof(artifacts.program, computationResult.witness, keypair.pk, options);
assert.ok(proof !== undefined);
assert.deepEqual(proof.inputs, ["0x0000000000000000000000000000000000000000000000000000000000000004"]);
});
});
it("export solidity verifier", () => {
let verifier = zokrates.bellman.groth16.exportSolidityVerifier(keypair.vk);
let verifier = zokrates.exportSolidityVerifier(keypair.vk, options);
assert(verifier.length > 0);
});
it("verify with valid proof", () => {
assert.doesNotThrow(() => {
assert(zokrates.bellman.groth16.verify(keypair.vk, proof) === true);
assert(zokrates.verify(keypair.vk, proof, options) === true);
});
});
it("verify with invalid proof", () => {
// falsify proof
proof["proof"]["a"][0] = "0x0000000000000000000000000000000000000000000000000000000000000000";
assert(zokrates.bellman.groth16.verify(keypair.vk, proof) === false);
assert(zokrates.verify(keypair.vk, proof, options) === false);
});
});
});
describe("ark", () => {
describe("gm17", () => {
const options = {
backend: "ark",
curve: "bn128",
scheme: "gm17"
};
let artifacts;
let computationResult;
let keypair;
@ -147,13 +159,13 @@ describe('tests', function() {
it("setup", () => {
assert.doesNotThrow(() => {
keypair = zokrates.ark.gm17.setup(artifacts.program);
keypair = zokrates.setup(artifacts.program, options);
});
});
it("generate proof", () => {
assert.doesNotThrow(() => {
proof = zokrates.ark.gm17.generateProof(artifacts.program, computationResult.witness, keypair.pk);
proof = zokrates.generateProof(artifacts.program, computationResult.witness, keypair.pk, options);
assert.ok(proof !== undefined);
assert.deepEqual(proof.inputs, ["0x0000000000000000000000000000000000000000000000000000000000000004"]);
});
@ -161,18 +173,24 @@ describe('tests', function() {
it("verify with valid proof", () => {
assert.doesNotThrow(() => {
assert(zokrates.ark.gm17.verify(keypair.vk, proof) === true);
assert(zokrates.verify(keypair.vk, proof, options) === true);
});
});
it("verify with invalid proof", () => {
// falsify proof
proof["proof"]["a"][0] = "0x0000000000000000000000000000000000000000000000000000000000000000";
assert(zokrates.ark.gm17.verify(keypair.vk, proof) === false);
assert(zokrates.verify(keypair.vk, proof, options) === false);
});
});
describe("marlin", () => {
const options = {
backend: "ark",
curve: "bn128",
scheme: "marlin"
};
let artifacts;
let computationResult;
let keypair;
@ -187,14 +205,14 @@ describe('tests', function() {
it("setup", () => {
assert.doesNotThrow(() => {
const srs = zokrates.ark.marlin.universalSetup("bn128", 4);
keypair = zokrates.ark.marlin.setup(srs, artifacts.program);
const srs = zokrates.universalSetup("bn128", 4);
keypair = zokrates.setupWithSrs(srs, artifacts.program, options);
});
});
it("generate proof", () => {
assert.doesNotThrow(() => {
proof = zokrates.ark.marlin.generateProof(artifacts.program, computationResult.witness, keypair.pk);
proof = zokrates.generateProof(artifacts.program, computationResult.witness, keypair.pk, options);
assert.ok(proof !== undefined);
assert.deepEqual(proof.inputs, ["0x0000000000000000000000000000000000000000000000000000000000000001"]);
});
@ -202,14 +220,14 @@ describe('tests', function() {
it("verify with valid proof", () => {
assert.doesNotThrow(() => {
assert(zokrates.ark.marlin.verify(keypair.vk, proof) === true);
assert(zokrates.verify(keypair.vk, proof, options) === true);
});
});
it("verify with invalid proof", () => {
// falsify proof
proof["inputs"][0] = "0x0000000000000000000000000000000000000000000000000000000000000000";
assert(zokrates.ark.marlin.verify(keypair.vk, proof) === false);
assert(zokrates.verify(keypair.vk, proof, options) === false);
});
});
});

View file

@ -25,7 +25,6 @@ const getImportPath = (currentLocation, importLocation) => {
}
module.exports = (dep) => {
const { zokrates, stdlib } = dep;
const resolveFromStdlib = (currentLocation, importLocation) => {
@ -40,7 +39,7 @@ module.exports = (dep) => {
const callback = (currentLocation, importLocation) => {
return resolveFromStdlib(currentLocation, importLocation) || resolveCallback(currentLocation, importLocation);
};
const { program, abi } = zokrates.compile(curve, source, location, callback, config);
const { program, abi } = zokrates.compile(source, location, callback, config, { curve });
return {
program: new Uint8Array(program),
abi
@ -50,26 +49,23 @@ module.exports = (dep) => {
const { program, abi } = artifacts;
return zokrates.compute_witness(program, abi, JSON.stringify(Array.from(args)));
},
bellman: {
groth16: {
setup: (program) => zokrates.bellman_groth16_setup(program),
generateProof: (program, witness, provingKey) => zokrates.bellman_groth16_generate_proof(program, witness, provingKey),
exportSolidityVerifier: (vk) => zokrates.bellman_groth16_export_solidity_verifier(vk),
verify: (vk, proof, curve = "bn128") => zokrates.bellman_groth16_verify(vk, proof, curve)
}
setup: (program, options) => {
return zokrates.setup(program, options);
},
ark: {
gm17: {
setup: (program) => zokrates.ark_gm17_setup(program),
generateProof: (program, witness, provingKey) => zokrates.ark_gm17_generate_proof(program, witness, provingKey),
verify: (vk, proof, curve = "bn128") => zokrates.ark_gm17_verify(vk, proof, curve)
},
marlin: {
setup: (srs, program) => zokrates.ark_marlin_setup(srs, program),
universalSetup: (curve, size) => zokrates.ark_marlin_universal_setup(curve, size),
generateProof: (program, witness, provingKey) => zokrates.ark_marlin_generate_proof(program, witness, provingKey),
verify: (vk, proof, curve = "bn128") => zokrates.ark_marlin_verify(vk, proof, curve)
}
universalSetup: (curve, size) => {
return zokrates.universal_setup(curve, size);
},
setupWithSrs: (srs, program, options) => {
return zokrates.setup_with_srs(srs, program, options);
},
generateProof: (program, witness, provingKey, options) => {
return zokrates.generate_proof(program, witness, provingKey, options);
},
verify: (vk, proof, options) => {
return zokrates.verify(vk, proof, options);
},
exportSolidityVerifier: (vk, options) => {
return zokrates.export_solidity_verifier(vk, options);
}
}
};