diff --git a/Cargo.lock b/Cargo.lock index f1725fc4..59a707f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,7 +36,7 @@ dependencies = [ [[package]] name = "ark-bls12-377" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/curves#7f1fcd66967328a1c5a3d12f8b148d69f7d86888" +source = "git+https://github.com/arkworks-rs/curves#e7d7d01a027ce6445a8865a881f78ef6910815d8" dependencies = [ "ark-ec", "ark-ff", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "ark-bn254" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/curves#7f1fcd66967328a1c5a3d12f8b148d69f7d86888" +source = "git+https://github.com/arkworks-rs/curves#e7d7d01a027ce6445a8865a881f78ef6910815d8" dependencies = [ "ark-ec", "ark-ff", @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "ark-bw6-761" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/curves#7f1fcd66967328a1c5a3d12f8b148d69f7d86888" +source = "git+https://github.com/arkworks-rs/curves#e7d7d01a027ce6445a8865a881f78ef6910815d8" dependencies = [ "ark-bls12-377", "ark-ec", @@ -84,7 +84,7 @@ dependencies = [ [[package]] name = "ark-ec" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "ark-ff", "ark-serialize", @@ -98,7 +98,7 @@ dependencies = [ [[package]] name = "ark-ff" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "ark-ff-asm", "ark-ff-macros", @@ -114,21 +114,21 @@ dependencies = [ [[package]] name = "ark-ff-asm" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] name = "ark-ff-macros" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "num-bigint 0.3.1", "num-traits 0.2.14", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -150,7 +150,7 @@ dependencies = [ [[package]] name = "ark-poly" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "ark-ff", "ark-serialize", @@ -162,7 +162,7 @@ dependencies = [ [[package]] name = "ark-relations" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/snark#0648c547e4f9fda46a40ad0a4896652b87c2316b" +source = "git+https://github.com/arkworks-rs/snark#b4477552cf7ac41d6da48fb5bafc300864dc3669" dependencies = [ "ark-ff", "ark-std", @@ -172,7 +172,7 @@ dependencies = [ [[package]] name = "ark-serialize" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "ark-serialize-derive", "ark-std", @@ -181,17 +181,17 @@ dependencies = [ [[package]] name = "ark-serialize-derive" version = "0.1.1-alpha.0" -source = "git+https://github.com/arkworks-rs/algebra#eac2dd72fd048ea7eac00dabe2ba8bda84287a64" +source = "git+https://github.com/arkworks-rs/algebra#e00e5549dbc3629526070051a88e5310959ca52d" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] name = "ark-snark" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/snark#0648c547e4f9fda46a40ad0a4896652b87c2316b" +source = "git+https://github.com/arkworks-rs/snark#b4477552cf7ac41d6da48fb5bafc300864dc3669" dependencies = [ "ark-ff", "ark-relations", @@ -202,7 +202,10 @@ dependencies = [ [[package]] name = "ark-std" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/utils#f6974ac72f59339b7ab798a728a84c5a7b8bac45" +source = "git+https://github.com/arkworks-rs/utils#5cac2c78e8ddeea95c4eeea6832dd92f2dea36b9" +dependencies = [ + "rand 0.7.3", +] [[package]] name = "arrayref" @@ -287,7 +290,7 @@ dependencies = [ [[package]] name = "bench-utils" version = "0.1.0" -source = "git+https://github.com/arkworks-rs/utils#f6974ac72f59339b7ab798a728a84c5a7b8bac45" +source = "git+https://github.com/arkworks-rs/utils#5cac2c78e8ddeea95c4eeea6832dd92f2dea36b9" [[package]] name = "bincode" @@ -597,8 +600,8 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484" dependencies = [ - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -608,8 +611,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -700,8 +703,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", "synstructure", ] @@ -744,8 +747,8 @@ dependencies = [ "num-integer", "num-traits 0.2.14", "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -889,9 +892,9 @@ checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" [[package]] name = "git2" -version = "0.13.12" +version = "0.13.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6f1a0238d7f8f8fd5ee642f4ebac4dbc03e03d1f78fbe7a3ede35dcf7e2224" +checksum = "186dd99cc77576e58344ad614fa9bb27bad9d048f85de3ca850c1f4e8b048260" dependencies = [ "bitflags", "libc", @@ -987,9 +990,9 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libgit2-sys" -version = "0.12.14+1.1.0" +version = "0.12.16+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f25af58e6495f7caf2919d08f212de550cfa3ed2f5e744988938ea292b9f549" +checksum = "9f91b2f931ee975a98155195be8cd82d02e8e029d7d793d2bac1b8181ac97020" dependencies = [ "cc", "libc", @@ -1264,8 +1267,8 @@ dependencies = [ "pest", "pest_meta", "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -1295,8 +1298,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -1373,9 +1376,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" dependencies = [ "proc-macro2 1.0.24", ] @@ -1625,8 +1628,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", ] [[package]] @@ -1719,12 +1722,12 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.54" +version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" +checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.8", "unicode-xid 0.2.1", ] @@ -1735,8 +1738,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", "unicode-xid 0.2.1", ] @@ -1953,8 +1956,8 @@ dependencies = [ "lazy_static", "log", "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", "wasm-bindgen-shared", ] @@ -1976,7 +1979,7 @@ version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" dependencies = [ - "quote 1.0.7", + "quote 1.0.8", "wasm-bindgen-macro-support", ] @@ -1987,8 +1990,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2020,7 +2023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27e07b46b98024c2ba2f9e83a10c2ef0515f057f2da299c1762a2017de80438b" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.8", ] [[package]] @@ -2080,8 +2083,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3f369ddb18862aba61aa49bf31e74d29f0f162dec753063200e1dc084345d16" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.54", + "quote 1.0.8", + "syn 1.0.55", "synstructure", ] @@ -2107,6 +2110,7 @@ dependencies = [ "dirs", "fs_extra", "glob 0.2.11", + "lazy_static", "regex", "serde_json", "tempdir", diff --git a/zokrates_cli/Cargo.toml b/zokrates_cli/Cargo.toml index 85826cd6..1a1750cc 100644 --- a/zokrates_cli/Cargo.toml +++ b/zokrates_cli/Cargo.toml @@ -22,6 +22,7 @@ zokrates_core = { version = "0.5", path = "../zokrates_core", default-features = zokrates_fs_resolver = { version = "0.5", path = "../zokrates_fs_resolver"} serde_json = "1.0" dirs = "3.0.1" +lazy_static = "1.4.0" [dev-dependencies] glob = "0.2.11" diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 766bf50f..d8c6195c 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -4,41 +4,15 @@ // @author Dennis Kuhnert // @date 2017 +#[macro_use] +extern crate lazy_static; + mod constants; mod helpers; +mod ops; -use constants::*; -use helpers::*; - -use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; -use serde_json::{from_reader, to_writer_pretty, Value}; -use std::convert::TryFrom; -use std::env; -use std::fs::File; -use std::io::{stdin, BufReader, BufWriter, Read, Write}; -use std::path::{Path, PathBuf}; -use std::string::String; -use zokrates_abi::Encode; -use zokrates_core::compile::{check, compile, CompilationArtifacts, CompileError}; -use zokrates_core::ir::{self, ProgEnum}; - -use zokrates_core::proof_system::{ - gm17::GM17, groth16::G16, pghr13::PGHR13, SolidityCompatibleField, -}; -use zokrates_core::proof_system::{SolidityAbi, SolidityCompatibleScheme}; -use zokrates_core::typed_absy::abi::Abi; -use zokrates_core::typed_absy::{types::ConcreteSignature, ConcreteType}; -use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; -use zokrates_fs_resolver::FileSystemResolver; - -#[cfg(feature = "ark")] -use zokrates_core::proof_system::ark::Ark; -#[cfg(feature = "bellman")] -use zokrates_core::proof_system::bellman::Bellman; -#[cfg(feature = "libsnark")] -use zokrates_core::proof_system::libsnark::Libsnark; -#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] -use zokrates_core::proof_system::{Backend, Scheme}; +use clap::{App, AppSettings}; +use ops::*; fn main() { cli().unwrap_or_else(|e| { @@ -47,1023 +21,39 @@ fn main() { }) } -#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] -fn cli_generate_proof, B: Backend>( - program: ir::Prog, - sub_matches: &ArgMatches, -) -> Result<(), String> { - println!("Generating proof..."); - - // deserialize witness - let witness_path = Path::new(sub_matches.value_of("witness").unwrap()); - let witness_file = match File::open(&witness_path) { - Ok(file) => file, - Err(why) => panic!("Couldn't open {}: {}", witness_path.display(), why), - }; - - let witness = ir::Witness::read(witness_file) - .map_err(|why| format!("Could not load witness: {:?}", why))?; - - let pk_path = Path::new(sub_matches.value_of("proving-key-path").unwrap()); - let proof_path = Path::new(sub_matches.value_of("proof-path").unwrap()); - - let pk_file = File::open(&pk_path) - .map_err(|why| format!("Couldn't open {}: {}", pk_path.display(), why))?; - - let mut pk: Vec = Vec::new(); - let mut pk_reader = BufReader::new(pk_file); - pk_reader - .read_to_end(&mut pk) - .map_err(|why| format!("Couldn't read {}: {}", pk_path.display(), why))?; - - let proof = B::generate_proof(program, witness, pk); - let mut proof_file = File::create(proof_path).unwrap(); - - let proof = serde_json::to_string_pretty(&proof).unwrap(); - proof_file - .write(proof.as_bytes()) - .map_err(|why| format!("Couldn't write to {}: {}", proof_path.display(), why))?; - - println!("Proof:\n{}", proof); - - Ok(()) -} - -fn cli_export_verifier>( - sub_matches: &ArgMatches, -) -> Result<(), String> { - println!("Exporting verifier..."); - - // read vk file - let input_path = Path::new(sub_matches.value_of("input").unwrap()); - let input_file = File::open(&input_path) - .map_err(|why| format!("Couldn't open {}: {}", input_path.display(), why))?; - let reader = BufReader::new(input_file); - - let vk = serde_json::from_reader(reader) - .map_err(|why| format!("Couldn't deserialize verifying key: {}", why))?; - - let abi = SolidityAbi::from(sub_matches.value_of("solidity-abi").unwrap())?; - - let verifier = S::export_solidity_verifier(vk, abi); - - //write output file - let output_path = Path::new(sub_matches.value_of("output").unwrap()); - let output_file = File::create(&output_path) - .map_err(|why| format!("Couldn't create {}: {}", output_path.display(), why))?; - - let mut writer = BufWriter::new(output_file); - - writer - .write_all(&verifier.as_bytes()) - .map_err(|_| "Failed writing output to file.".to_string())?; - - println!("Finished exporting verifier."); - Ok(()) -} - -#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] -fn cli_setup, B: Backend>( - program: ir::Prog, - sub_matches: &ArgMatches, -) -> Result<(), String> { - println!("Performing setup..."); - - // print deserialized flattened program - if !sub_matches.is_present("light") { - println!("{}", program); - } - - // get paths for proving and verification keys - let pk_path = Path::new(sub_matches.value_of("proving-key-path").unwrap()); - let vk_path = Path::new(sub_matches.value_of("verification-key-path").unwrap()); - - // run setup phase - let keypair = B::setup(program); - - // write verification key - let mut vk_file = File::create(vk_path) - .map_err(|why| format!("couldn't create {}: {}", vk_path.display(), why))?; - vk_file - .write( - serde_json::to_string_pretty(&keypair.vk) - .unwrap() - .as_bytes(), - ) - .map_err(|why| format!("couldn't write to {}: {}", vk_path.display(), why))?; - - // write proving key - let mut pk_file = File::create(pk_path) - .map_err(|why| format!("couldn't create {}: {}", pk_path.display(), why))?; - pk_file - .write(keypair.pk.as_ref()) - .map_err(|why| format!("couldn't write to {}: {}", pk_path.display(), why))?; - - println!("Setup completed."); - - Ok(()) -} - -fn cli_compute(ir_prog: ir::Prog, sub_matches: &ArgMatches) -> Result<(), String> { - println!("Computing witness..."); - - // print deserialized flattened program - if !sub_matches.is_present("light") { - println!("{}", ir_prog); - } - - let is_stdin = sub_matches.is_present("stdin"); - let is_abi = sub_matches.is_present("abi"); - - if !is_stdin && is_abi { - return Err("ABI input as inline argument is not supported. Please use `--stdin`.".into()); - } - - let signature = match is_abi { - true => { - let path = Path::new(sub_matches.value_of("abi_spec").unwrap()); - let file = File::open(&path) - .map_err(|why| format!("couldn't open {}: {}", path.display(), why))?; - let mut reader = BufReader::new(file); - - let abi: Abi = from_reader(&mut reader).map_err(|why| why.to_string())?; - - abi.signature() - } - false => ConcreteSignature::new() - .inputs(vec![ - ConcreteType::FieldElement; - ir_prog.main.arguments.len() - ]) - .outputs(vec![ConcreteType::FieldElement; ir_prog.main.returns.len()]), - }; - - use zokrates_abi::Inputs; - - // get arguments - let arguments = match is_stdin { - // take inline arguments - false => { - let arguments = sub_matches.values_of("arguments"); - arguments - .map(|a| { - a.map(|x| T::try_from_dec_str(x).map_err(|_| x.to_string())) - .collect::, _>>() - }) - .unwrap_or_else(|| Ok(vec![])) - .map(Inputs::Raw) - } - // take stdin arguments - true => { - let mut stdin = stdin(); - let mut input = String::new(); - - match is_abi { - true => match stdin.read_to_string(&mut input) { - Ok(_) => { - use zokrates_abi::parse_strict; - - parse_strict(&input, signature.inputs) - .map(Inputs::Abi) - .map_err(|why| why.to_string()) - } - Err(_) => Err(String::from("???")), - }, - false => match ir_prog.arguments_count() { - 0 => Ok(Inputs::Raw(vec![])), - _ => match stdin.read_to_string(&mut input) { - Ok(_) => { - input.retain(|x| x != '\n'); - input - .split(' ') - .map(|x| T::try_from_dec_str(x).map_err(|_| x.to_string())) - .collect::, _>>() - .map(Inputs::Raw) - } - Err(_) => Err(String::from("???")), - }, - }, - } - } - } - .map_err(|e| format!("Could not parse argument: {}", e))?; - - let interpreter = ir::Interpreter::default(); - - let witness = interpreter - .execute(&ir_prog, &arguments.encode()) - .map_err(|e| format!("Execution failed: {}", e))?; - - use zokrates_abi::Decode; - - let results_json_value: serde_json::Value = - zokrates_abi::CheckedValues::decode(witness.return_values(), signature.outputs).into(); - - println!("\nWitness: \n\n{}", results_json_value); - - // write witness to file - let output_path = Path::new(sub_matches.value_of("output").unwrap()); - let output_file = File::create(&output_path) - .map_err(|why| format!("couldn't create {}: {}", output_path.display(), why))?; - - let writer = BufWriter::new(output_file); - - witness - .write(writer) - .map_err(|why| format!("could not save witness: {:?}", why))?; - - Ok(()) -} - -fn cli_compile(sub_matches: &ArgMatches) -> Result<(), String> { - println!("Compiling {}\n", sub_matches.value_of("input").unwrap()); - let path = PathBuf::from(sub_matches.value_of("input").unwrap()); - - let light = sub_matches.occurrences_of("light") > 0; - - let bin_output_path = Path::new(sub_matches.value_of("output").unwrap()); - - let abi_spec_path = Path::new(sub_matches.value_of("abi_spec").unwrap()); - - let hr_output_path = bin_output_path.to_path_buf().with_extension("ztf"); - - let file = File::open(path.clone()) - .map_err(|why| format!("Couldn't open input file {}: {}", path.display(), why))?; - - let mut reader = BufReader::new(file); - let mut source = String::new(); - reader.read_to_string(&mut source).unwrap(); - - let fmt_error = |e: &CompileError| { - let file = e.file().canonicalize().unwrap(); - format!( - "{}:{}", - file.strip_prefix(std::env::current_dir().unwrap()) - .unwrap_or_else(|_| file.as_path()) - .display(), - e.value() - ) - }; - - let resolver = - FileSystemResolver::with_stdlib_root(sub_matches.value_of("stdlib-path").unwrap()); - let artifacts: CompilationArtifacts = - compile(source, path, Some(&resolver)).map_err(|e| { - format!( - "Compilation failed:\n\n{}", - e.0.iter() - .map(|e| fmt_error(e)) - .collect::>() - .join("\n\n") - ) - })?; - - let program_flattened = artifacts.prog(); - - // number of constraints the flattened program will translate to. - let num_constraints = program_flattened.constraint_count(); - - // serialize flattened program and write to binary file - let bin_output_file = File::create(&bin_output_path) - .map_err(|why| format!("Couldn't create {}: {}", bin_output_path.display(), why))?; - - let mut writer = BufWriter::new(bin_output_file); - - program_flattened.serialize(&mut writer); - - // serialize ABI spec and write to JSON file - let abi_spec_file = File::create(&abi_spec_path) - .map_err(|why| format!("Couldn't create {}: {}", abi_spec_path.display(), why))?; - - let abi = artifacts.abi(); - - let mut writer = BufWriter::new(abi_spec_file); - - to_writer_pretty(&mut writer, &abi).map_err(|_| "Unable to write data to file.".to_string())?; - - if !light { - // write human-readable output file - let hr_output_file = File::create(&hr_output_path) - .map_err(|why| format!("Couldn't create {}: {}", hr_output_path.display(), why))?; - - let mut hrofb = BufWriter::new(hr_output_file); - writeln!(&mut hrofb, "{}", program_flattened) - .map_err(|_| "Unable to write data to file.".to_string())?; - hrofb - .flush() - .map_err(|_| "Unable to flush buffer.".to_string())?; - } - - if !light { - // debugging output - println!("Compiled program:\n{}", program_flattened); - } - - println!("Compiled code written to '{}'", bin_output_path.display()); - - if !light { - println!("Human readable code to '{}'", hr_output_path.display()); - } - - println!("Number of constraints: {}", num_constraints); - Ok(()) -} - -fn cli_check(sub_matches: &ArgMatches) -> Result<(), String> { - println!("Checking {}\n", sub_matches.value_of("input").unwrap()); - let path = PathBuf::from(sub_matches.value_of("input").unwrap()); - - let file = File::open(path.clone()) - .map_err(|why| format!("Couldn't open input file {}: {}", path.display(), why))?; - - let mut reader = BufReader::new(file); - let mut source = String::new(); - reader.read_to_string(&mut source).unwrap(); - - let fmt_error = |e: &CompileError| { - let file = e.file().canonicalize().unwrap(); - format!( - "{}:{}", - file.strip_prefix(std::env::current_dir().unwrap()) - .unwrap_or_else(|_| file.as_path()) - .display(), - e.value() - ) - }; - - let resolver = - FileSystemResolver::with_stdlib_root(sub_matches.value_of("stdlib-path").unwrap()); - let _ = check::(source, path, Some(&resolver)).map_err(|e| { - format!( - "Check failed:\n\n{}", - e.0.iter() - .map(|e| fmt_error(e)) - .collect::>() - .join("\n\n") - ) - })?; - - println!("Program checked, no errors found."); - - Ok(()) -} - -#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] -fn cli_verify, B: Backend>( - sub_matches: &ArgMatches, -) -> Result<(), String> { - let vk_path = Path::new(sub_matches.value_of("verification-key-path").unwrap()); - let vk_file = File::open(&vk_path) - .map_err(|why| format!("Couldn't open {}: {}", vk_path.display(), why))?; - - let vk_reader = BufReader::new(vk_file); - let vk = serde_json::from_reader(vk_reader) - .map_err(|why| format!("Couldn't deserialize verification key: {}", why))?; - - let proof_path = Path::new(sub_matches.value_of("proof-path").unwrap()); - let proof_file = File::open(&proof_path) - .map_err(|why| format!("Couldn't open {}: {}", proof_path.display(), why))?; - - let proof_reader = BufReader::new(proof_file); - let proof = serde_json::from_reader(proof_reader) - .map_err(|why| format!("Couldn't deserialize proof: {}", why))?; - - println!("Performing verification..."); - println!( - "The verification result is: {}", - match B::verify(vk, proof) { - true => "PASS", - false => "FAIL", - } - ); - - Ok(()) -} - fn cli() -> Result<(), String> { - const FLATTENED_CODE_DEFAULT_PATH: &str = "out"; - const ABI_SPEC_DEFAULT_PATH: &str = "abi.json"; - const VERIFICATION_KEY_DEFAULT_PATH: &str = "verification.key"; - const PROVING_KEY_DEFAULT_PATH: &str = "proving.key"; - const VERIFICATION_CONTRACT_DEFAULT_PATH: &str = "verifier.sol"; - const WITNESS_DEFAULT_PATH: &str = "witness"; - const JSON_PROOF_PATH: &str = "proof.json"; - let default_curve = env::var("ZOKRATES_CURVE").unwrap_or_else(|_| constants::BN128.into()); - let default_backend = - env::var("ZOKRATES_BACKEND").unwrap_or_else(|_| constants::BELLMAN.into()); - let default_scheme = - env::var("ZOKRATES_PROVING_SCHEME").unwrap_or_else(|_| constants::G16.into()); - let default_solidity_abi = "v1"; - let default_stdlib_path = dirs::home_dir() - .map(|p| p.join(".zokrates/stdlib")) - .unwrap(); - // cli specification using clap library let matches = App::new("ZoKrates") - .setting(AppSettings::SubcommandRequiredElseHelp) - .version(env!("CARGO_PKG_VERSION")) - .author("Jacob Eberhardt, Thibaut Schaeffer, Stefan Deml, Darko Macesic") - .about("Supports generation of zkSNARKs from high level language code including Smart Contracts for proof verification on the Ethereum Blockchain.\n'I know that I show nothing!'") - .subcommand(SubCommand::with_name("compile") - .about("Compiles into flattened conditions. Produces two files: human-readable '.ztf' file for debugging and binary file") - .arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the source code") - .value_name("FILE") - .takes_value(true) - .required(true) - ).arg(Arg::with_name("stdlib-path") - .long("stdlib-path") - .help("Path to the standard library") - .value_name("PATH") - .takes_value(true) - .required(false) - .env("ZOKRATES_STDLIB") - .default_value(default_stdlib_path.to_str().unwrap_or("")) - ).arg(Arg::with_name("abi_spec") - .short("s") - .long("abi_spec") - .help("Path of the ABI specification") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(ABI_SPEC_DEFAULT_PATH) - ).arg(Arg::with_name("output") - .short("o") - .long("output") - .help("Path of the output binary") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(FLATTENED_CODE_DEFAULT_PATH) - ).arg(Arg::with_name("curve") - .short("c") - .long("curve") - .help("Curve to be used in the compilation") - .takes_value(true) - .required(false) - .possible_values(CURVES) - .default_value(&default_curve) - ).arg(Arg::with_name("light") - .long("light") - .help("Skip logs and human readable output") - .required(false) - ) - ) - .subcommand(SubCommand::with_name("check") - .about("Checks a program for errors") - .arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the source code") - .value_name("FILE") - .takes_value(true) - .required(true) - ).arg(Arg::with_name("stdlib-path") - .long("stdlib-path") - .help("Path to the standard library") - .value_name("PATH") - .takes_value(true) - .required(false) - .env("ZOKRATES_STDLIB") - .default_value(default_stdlib_path.to_str().unwrap_or("")) - ).arg(Arg::with_name("curve") - .short("c") - .long("curve") - .help("Curve to be used in the compilation") - .takes_value(true) - .required(false) - .possible_values(CURVES) - .default_value(&default_curve) - ) - ) - .subcommand(SubCommand::with_name("setup") - .about("Performs a trusted setup for a given constraint system") - .arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the binary") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(FLATTENED_CODE_DEFAULT_PATH) - ).arg(Arg::with_name("proving-key-path") - .short("p") - .long("proving-key-path") - .help("Path of the generated proving key file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(PROVING_KEY_DEFAULT_PATH) - ).arg(Arg::with_name("verification-key-path") - .short("v") - .long("verification-key-path") - .help("Path of the generated verification key file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(VERIFICATION_KEY_DEFAULT_PATH) - ).arg(Arg::with_name("backend") - .short("b") - .long("backend") - .help("Backend to use") - .takes_value(true) - .required(false) - .possible_values(BACKENDS) - .default_value(&default_backend) - ).arg(Arg::with_name("proving-scheme") - .short("s") - .long("proving-scheme") - .help("Proving scheme to use in the setup") - .takes_value(true) - .required(false) - .possible_values(SCHEMES) - .default_value(&default_scheme) - ).arg(Arg::with_name("light") - .long("light") - .help("Skip logging the human-readable program and writing it to a file") - .required(false) - ) - ) - .subcommand(SubCommand::with_name("export-verifier") - .about("Exports a verifier as Solidity smart contract") - .arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the verifier") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(VERIFICATION_KEY_DEFAULT_PATH) - ).arg(Arg::with_name("output") - .short("o") - .long("output") - .help("Path of the output file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(VERIFICATION_CONTRACT_DEFAULT_PATH) - ).arg(Arg::with_name("curve") - .short("c") - .long("curve") - .help("Curve to be used to export the verifier") - .takes_value(true) - .required(false) - .possible_values(CURVES) - .default_value(&default_curve) - ).arg(Arg::with_name("proving-scheme") - .short("s") - .long("proving-scheme") - .help("Proving scheme to use to export the verifier") - .takes_value(true) - .required(false) - .possible_values(SCHEMES) - .default_value(&default_scheme) - ).arg(Arg::with_name("solidity-abi") - .short("a") - .long("solidity-abi") - .help("Flag for setting the version of the ABI Encoder used in the contract") - .takes_value(true) - .possible_values(&["v1", "v2"]) - .default_value(&default_solidity_abi) - .required(false) - ) - ) - .subcommand(SubCommand::with_name("compute-witness") - .about("Calculates a witness for a given constraint system") - .arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the binary") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(FLATTENED_CODE_DEFAULT_PATH) - ).arg(Arg::with_name("abi_spec") - .short("s") - .long("abi_spec") - .help("Path of the ABI specification") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(ABI_SPEC_DEFAULT_PATH) - ).arg(Arg::with_name("output") - .short("o") - .long("output") - .help("Path of the output file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(WITNESS_DEFAULT_PATH) - ).arg(Arg::with_name("arguments") - .short("a") - .long("arguments") - .help("Arguments for the program's main function, when not using ABI encoding. Expects a space-separated list of field elements like `-a 1 2 3`") - .takes_value(true) - .multiple(true) // allows multiple values - .required(false) - .conflicts_with("abi") - .conflicts_with("stdin") - ).arg(Arg::with_name("abi") - .long("abi") - .help("Use ABI encoding. Arguments are expected as a JSON object as specified at zokrates.github.io/toolbox/abi.html#abi-input-format") - .conflicts_with("arguments") - .required(false) - ).arg(Arg::with_name("stdin") - .long("stdin") - .help("Read arguments from stdin") - .conflicts_with("arguments") - .required(false) - ).arg(Arg::with_name("light") - .long("light") - .help("Skip logging the human-readable program") - .required(false) - ) - ) - .subcommand(SubCommand::with_name("generate-proof") - .about("Calculates a proof for a given constraint system and witness") - .arg(Arg::with_name("witness") - .short("w") - .long("witness") - .help("Path of the witness file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(WITNESS_DEFAULT_PATH) - ).arg(Arg::with_name("proving-key-path") - .short("p") - .long("proving-key-path") - .help("Path of the proving key file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(PROVING_KEY_DEFAULT_PATH) - ).arg(Arg::with_name("proof-path") - .short("j") - .long("proof-path") - .help("Path of the JSON proof file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(JSON_PROOF_PATH) - ).arg(Arg::with_name("input") - .short("i") - .long("input") - .help("Path of the binary") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(FLATTENED_CODE_DEFAULT_PATH) - ).arg(Arg::with_name("backend") - .short("b") - .long("backend") - .help("Backend to use") - .takes_value(true) - .required(false) - .possible_values(BACKENDS) - .default_value(&default_backend) - ).arg(Arg::with_name("proving-scheme") - .short("s") - .long("proving-scheme") - .help("Proving scheme to use to generate the proof") - .takes_value(true) - .required(false) - .possible_values(SCHEMES) - .default_value(&default_scheme) - ) - ) - .subcommand(SubCommand::with_name("print-proof") - .about("Prints proof in the chosen format") - .arg(Arg::with_name("proof-path") - .short("j") - .long("proof-path") - .help("Path of the JSON proof file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(JSON_PROOF_PATH) - ).arg(Arg::with_name("format") - .short("f") - .long("format") - .value_name("FORMAT") - .help("Format in which the proof should be printed") - .takes_value(true) - .possible_values(&["remix", "json"]) - .required(true) - ) - ) - .subcommand(SubCommand::with_name("verify") - .about("Verifies a given proof with the given verification key") - .arg(Arg::with_name("proof-path") - .short("j") - .long("proof-path") - .help("Path of the JSON proof file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(JSON_PROOF_PATH) - ).arg(Arg::with_name("verification-key-path") - .short("v") - .long("verification-key-path") - .help("Path of the generated verification key file") - .value_name("FILE") - .takes_value(true) - .required(false) - .default_value(VERIFICATION_KEY_DEFAULT_PATH) - ).arg(Arg::with_name("backend") - .short("b") - .long("backend") - .help("Backend to use") - .takes_value(true) - .required(false) - .possible_values(BACKENDS) - .default_value(&default_backend) - ).arg(Arg::with_name("proving-scheme") - .short("s") - .long("proving-scheme") - .help("Proving scheme to use in the setup. Available options are G16 (default), PGHR13 and GM17") - .takes_value(true) - .required(false) - .default_value(&default_scheme) - ).arg(Arg::with_name("curve") - .short("c") - .long("curve") - .help("Curve to be used in the verification") - .takes_value(true) - .required(false) - .possible_values(CURVES) - .default_value(&default_curve) - ) - ) - .get_matches(); + .setting(AppSettings::SubcommandRequiredElseHelp) + .version(env!("CARGO_PKG_VERSION")) + .author("Jacob Eberhardt, Thibaut Schaeffer, Stefan Deml, Darko Macesic") + .about("Supports generation of zkSNARKs from high level language code including Smart Contracts for proof verification on the Ethereum Blockchain.\n'I know that I show nothing!'") + .subcommands(vec![ + compile::subcommand(), + check::subcommand(), + compute_witness::subcommand(), + setup::subcommand(), + export_verifier::subcommand(), + generate_proof::subcommand(), + print_proof::subcommand(), + verify::subcommand()]) + .get_matches(); match matches.subcommand() { - ("compile", Some(sub_matches)) => { - let curve = CurveParameter::try_from(sub_matches.value_of("curve").unwrap())?; - match curve { - CurveParameter::Bn128 => cli_compile::(sub_matches)?, - CurveParameter::Bls12_377 => cli_compile::(sub_matches)?, - CurveParameter::Bls12_381 => cli_compile::(sub_matches)?, - CurveParameter::Bw6_761 => cli_compile::(sub_matches)?, - } - } - ("check", Some(sub_matches)) => { - let curve = CurveParameter::try_from(sub_matches.value_of("curve").unwrap())?; - match curve { - CurveParameter::Bn128 => cli_check::(sub_matches)?, - CurveParameter::Bls12_377 => cli_check::(sub_matches)?, - CurveParameter::Bls12_381 => cli_check::(sub_matches)?, - CurveParameter::Bw6_761 => cli_check::(sub_matches)?, - } - } - ("compute-witness", Some(sub_matches)) => { - // read compiled program - let path = Path::new(sub_matches.value_of("input").unwrap()); - let file = File::open(&path) - .map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; - - let mut reader = BufReader::new(file); - - match ProgEnum::deserialize(&mut reader)? { - ProgEnum::Bn128Program(p) => cli_compute(p, sub_matches)?, - ProgEnum::Bls12_377Program(p) => cli_compute(p, sub_matches)?, - ProgEnum::Bls12_381Program(p) => cli_compute(p, sub_matches)?, - ProgEnum::Bw6_761Program(p) => cli_compute(p, sub_matches)?, - } - } + ("compile", Some(sub_matches)) => compile::exec(sub_matches)?, + ("check", Some(sub_matches)) => check::exec(sub_matches)?, + ("compute-witness", Some(sub_matches)) => compute_witness::exec(sub_matches)?, #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("setup", Some(sub_matches)) => { - // read compiled program - let path = Path::new(sub_matches.value_of("input").unwrap()); - let file = File::open(&path) - .map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; - - let mut reader = BufReader::new(file); - let prog = ProgEnum::deserialize(&mut reader)?; - - 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, - }, - sub_matches.value_of("proving-scheme").unwrap(), - ))?; - - match parameters { - #[cfg(feature = "bellman")] - Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog { - ProgEnum::Bn128Program(p) => cli_setup::<_, G16, Bellman>(p, sub_matches), - ProgEnum::Bls12_381Program(p) => cli_setup::<_, G16, Bellman>(p, sub_matches), - _ => unreachable!(), - }, - #[cfg(feature = "ark")] - Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog { - ProgEnum::Bls12_377Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), - ProgEnum::Bw6_761Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), - ProgEnum::Bn128Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), - _ => unreachable!(), - }, - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::GM17, - ) => match prog { - ProgEnum::Bn128Program(p) => cli_setup::<_, GM17, Libsnark>(p, sub_matches), - _ => unreachable!(), - }, - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::PGHR13, - ) => match prog { - ProgEnum::Bn128Program(p) => cli_setup::<_, PGHR13, Libsnark>(p, sub_matches), - _ => unreachable!(), - }, - _ => unreachable!(), - }? - } - ("export-verifier", Some(sub_matches)) => { - let curve = sub_matches.value_of("curve").unwrap(); - let scheme = sub_matches.value_of("proving-scheme").unwrap(); - let curve_parameter = CurveParameter::try_from(curve)?; - let scheme_parameter = SchemeParameter::try_from(scheme)?; - - match (curve_parameter, scheme_parameter) { - (CurveParameter::Bn128, SchemeParameter::G16) => { - cli_export_verifier::(sub_matches) - } - (CurveParameter::Bn128, SchemeParameter::GM17) => { - cli_export_verifier::(sub_matches) - } - (CurveParameter::Bn128, SchemeParameter::PGHR13) => { - cli_export_verifier::(sub_matches) - } - _ => Err(format!("Could not export verifier with given parameters (curve: {}, scheme: {}): not supported", curve, scheme)) - }? - } + ("setup", Some(sub_matches)) => setup::exec(sub_matches)?, + ("export-verifier", Some(sub_matches)) => export_verifier::exec(sub_matches)?, #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("generate-proof", Some(sub_matches)) => { - let program_path = Path::new(sub_matches.value_of("input").unwrap()); - let program_file = File::open(&program_path) - .map_err(|why| format!("Couldn't open {}: {}", program_path.display(), why))?; - - let mut reader = BufReader::new(program_file); - let prog = ProgEnum::deserialize(&mut reader)?; - - 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, - }, - sub_matches.value_of("proving-scheme").unwrap(), - ))?; - - match parameters { - #[cfg(feature = "bellman")] - Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog { - ProgEnum::Bn128Program(p) => { - cli_generate_proof::<_, G16, Bellman>(p, sub_matches) - } - ProgEnum::Bls12_381Program(p) => { - cli_generate_proof::<_, G16, Bellman>(p, sub_matches) - } - _ => unreachable!(), - }, - #[cfg(feature = "ark")] - Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog { - 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::Bn128Program(p) => cli_generate_proof::<_, GM17, Ark>(p, sub_matches), - _ => unreachable!(), - }, - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::GM17, - ) => match prog { - ProgEnum::Bn128Program(p) => { - cli_generate_proof::<_, GM17, Libsnark>(p, sub_matches) - } - _ => unreachable!(), - }, - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::PGHR13, - ) => match prog { - ProgEnum::Bn128Program(p) => { - cli_generate_proof::<_, PGHR13, Libsnark>(p, sub_matches) - } - _ => unreachable!(), - }, - _ => unreachable!(), - }? - } - ("print-proof", Some(sub_matches)) => { - let format = sub_matches.value_of("format").unwrap(); - let path = Path::new(sub_matches.value_of("proof-path").unwrap()); - - let file = File::open(&path) - .map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; - - let proof_object: Value = - serde_json::from_reader(file).map_err(|why| format!("{:?}", why))?; - - match format { - "json" => { - println!("~~~~~~~~ Copy the output below for valid ABIv2 format ~~~~~~~~"); - println!(); - print!("{}", proof_object["proof"]); - print!(","); - println!("{}", proof_object["inputs"]); - println!(); - println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - } - "remix" => { - println!("~~~~~~~~ Copy the output below for valid ABIv1 format ~~~~~~~~"); - println!(); - - for (_, value) in proof_object["proof"].as_object().unwrap().iter() { - print!("{}", value); - print!(","); - } - - println!("{}", proof_object["inputs"]); - println!(); - println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - } - _ => unreachable!(), - } - } + ("generate-proof", Some(sub_matches)) => generate_proof::exec(sub_matches)?, + ("print-proof", Some(sub_matches)) => print_proof::exec(sub_matches)?, #[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] - ("verify", Some(sub_matches)) => { - let parameters = Parameters::try_from(( - sub_matches.value_of("backend").unwrap(), - sub_matches.value_of("curve").unwrap(), - sub_matches.value_of("proving-scheme").unwrap(), - ))?; - - match parameters { - #[cfg(feature = "bellman")] - Parameters( - BackendParameter::Bellman, - CurveParameter::Bn128, - SchemeParameter::G16, - ) => cli_verify::(sub_matches), - #[cfg(feature = "bellman")] - Parameters( - BackendParameter::Bellman, - CurveParameter::Bls12_381, - SchemeParameter::G16, - ) => cli_verify::(sub_matches), - #[cfg(feature = "ark")] - Parameters( - BackendParameter::Ark, - CurveParameter::Bls12_377, - SchemeParameter::GM17, - ) => cli_verify::(sub_matches), - #[cfg(feature = "ark")] - Parameters( - BackendParameter::Ark, - CurveParameter::Bw6_761, - SchemeParameter::GM17, - ) => cli_verify::(sub_matches), - #[cfg(feature = "ark")] - Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => { - cli_verify::(sub_matches) - } - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::GM17, - ) => cli_verify::(sub_matches), - #[cfg(feature = "libsnark")] - Parameters( - BackendParameter::Libsnark, - CurveParameter::Bn128, - SchemeParameter::PGHR13, - ) => cli_verify::(sub_matches), - _ => unreachable!(), - }? - } + ("verify", Some(sub_matches)) => verify::exec(sub_matches)?, _ => unreachable!(), - } + }; + Ok(()) } @@ -1071,7 +61,14 @@ fn cli() -> Result<(), String> { mod tests { extern crate glob; use self::glob::glob; - use super::*; + + use std::fs::File; + use std::io::{BufReader, Read}; + use std::string::String; + use zokrates_core::compile::{compile, CompilationArtifacts}; + use zokrates_core::ir; + use zokrates_field::Bn128Field; + use zokrates_fs_resolver::FileSystemResolver; #[test] fn compile_examples() { diff --git a/zokrates_cli/src/constants.rs b/zokrates_cli/src/constants.rs index 213763bd..4ea010a1 100644 --- a/zokrates_cli/src/constants.rs +++ b/zokrates_cli/src/constants.rs @@ -1,7 +1,24 @@ +pub const FLATTENED_CODE_DEFAULT_PATH: &str = "out"; +pub const ABI_SPEC_DEFAULT_PATH: &str = "abi.json"; +pub const VERIFICATION_KEY_DEFAULT_PATH: &str = "verification.key"; +pub const PROVING_KEY_DEFAULT_PATH: &str = "proving.key"; +pub const VERIFICATION_CONTRACT_DEFAULT_PATH: &str = "verifier.sol"; +pub const WITNESS_DEFAULT_PATH: &str = "witness"; +pub const JSON_PROOF_PATH: &str = "proof.json"; + 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")) + .unwrap() + .into_os_string() + .into_string() + .unwrap(); +} + pub const BACKENDS: &[&str] = if cfg!(feature = "libsnark") { if cfg!(feature = "ark") { if cfg!(feature = "bellman") { diff --git a/zokrates_cli/src/helpers.rs b/zokrates_cli/src/helpers.rs index a8cc0d6a..295b749b 100644 --- a/zokrates_cli/src/helpers.rs +++ b/zokrates_cli/src/helpers.rs @@ -1,6 +1,5 @@ -use core::convert::TryFrom; - use crate::constants::*; +use std::convert::TryFrom; #[derive(Debug)] pub enum CurveParameter { diff --git a/zokrates_cli/src/ops/check.rs b/zokrates_cli/src/ops/check.rs new file mode 100644 index 00000000..99186b86 --- /dev/null +++ b/zokrates_cli/src/ops/check.rs @@ -0,0 +1,101 @@ +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_core::compile::{check, CompileError}; +use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; +use zokrates_fs_resolver::FileSystemResolver; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("check") + .about("Checks a program for errors") + .arg( + Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the source code") + .value_name("FILE") + .takes_value(true) + .required(true), + ) + .arg( + Arg::with_name("stdlib-path") + .long("stdlib-path") + .help("Path to the standard library") + .value_name("PATH") + .takes_value(true) + .required(false) + .env("ZOKRATES_STDLIB") + .default_value(constants::DEFAULT_STDLIB_PATH.as_str()), + ) + .arg( + Arg::with_name("curve") + .short("c") + .long("curve") + .help("Curve to be used in the compilation") + .takes_value(true) + .required(false) + .possible_values(constants::CURVES) + .default_value(constants::BN128), + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let curve = CurveParameter::try_from(sub_matches.value_of("curve").unwrap())?; + match curve { + CurveParameter::Bn128 => cli_check::(sub_matches), + CurveParameter::Bls12_377 => cli_check::(sub_matches), + CurveParameter::Bls12_381 => cli_check::(sub_matches), + CurveParameter::Bw6_761 => cli_check::(sub_matches), + } +} + +fn cli_check(sub_matches: &ArgMatches) -> Result<(), String> { + println!("Checking {}\n", sub_matches.value_of("input").unwrap()); + let path = PathBuf::from(sub_matches.value_of("input").unwrap()); + + let file = File::open(path.clone()) + .map_err(|why| format!("Couldn't open input file {}: {}", path.display(), why))?; + + let mut reader = BufReader::new(file); + let mut source = String::new(); + reader.read_to_string(&mut source).unwrap(); + + let fmt_error = |e: &CompileError| { + let file = e.file().canonicalize().unwrap(); + format!( + "{}:{}", + file.strip_prefix(std::env::current_dir().unwrap()) + .unwrap_or(file.as_path()) + .display(), + e.value() + ) + }; + + let stdlib_path = sub_matches.value_of("stdlib-path").unwrap(); + match Path::new(stdlib_path).exists() { + true => Ok(()), + _ => Err(format!( + "Invalid standard library source path: {}", + stdlib_path + )), + }?; + + let resolver = FileSystemResolver::with_stdlib_root(stdlib_path); + let _ = check::(source, path, Some(&resolver)).map_err(|e| { + format!( + "Check failed:\n\n{}", + e.0.iter() + .map(|e| fmt_error(e)) + .collect::>() + .join("\n\n") + ) + })?; + + println!("Program checked, no errors found."); + + Ok(()) +} diff --git a/zokrates_cli/src/ops/compile.rs b/zokrates_cli/src/ops/compile.rs new file mode 100644 index 00000000..2cefb70f --- /dev/null +++ b/zokrates_cli/src/ops/compile.rs @@ -0,0 +1,169 @@ +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_core::compile::{compile, CompilationArtifacts, CompileError}; +use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; +use zokrates_fs_resolver::FileSystemResolver; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("compile") + .about("Compiles into flattened conditions. Produces two files: human-readable '.ztf' file for debugging and binary file") + .arg(Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the source code") + .value_name("FILE") + .takes_value(true) + .required(true) + ).arg(Arg::with_name("stdlib-path") + .long("stdlib-path") + .help("Path to the standard library") + .value_name("PATH") + .takes_value(true) + .required(false) + .env("ZOKRATES_STDLIB") + .default_value(constants::DEFAULT_STDLIB_PATH.as_str()) + ).arg(Arg::with_name("abi_spec") + .short("s") + .long("abi_spec") + .help("Path of the ABI specification") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::ABI_SPEC_DEFAULT_PATH) + ).arg(Arg::with_name("output") + .short("o") + .long("output") + .help("Path of the output binary") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::FLATTENED_CODE_DEFAULT_PATH) + ).arg(Arg::with_name("curve") + .short("c") + .long("curve") + .help("Curve to be used in the compilation") + .takes_value(true) + .required(false) + .possible_values(constants::CURVES) + .default_value(constants::BN128) + ).arg(Arg::with_name("light") + .long("light") + .help("Skip logs and human readable output") + .required(false) + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let curve = CurveParameter::try_from(sub_matches.value_of("curve").unwrap())?; + match curve { + CurveParameter::Bn128 => cli_compile::(sub_matches), + CurveParameter::Bls12_377 => cli_compile::(sub_matches), + CurveParameter::Bls12_381 => cli_compile::(sub_matches), + CurveParameter::Bw6_761 => cli_compile::(sub_matches), + } +} + +fn cli_compile(sub_matches: &ArgMatches) -> Result<(), String> { + println!("Compiling {}\n", sub_matches.value_of("input").unwrap()); + + let path = PathBuf::from(sub_matches.value_of("input").unwrap()); + let light = sub_matches.occurrences_of("light") > 0; + let bin_output_path = Path::new(sub_matches.value_of("output").unwrap()); + let abi_spec_path = Path::new(sub_matches.value_of("abi_spec").unwrap()); + let hr_output_path = bin_output_path.to_path_buf().with_extension("ztf"); + + let file = File::open(path.clone()) + .map_err(|why| format!("Couldn't open input file {}: {}", path.display(), why))?; + + let mut reader = BufReader::new(file); + let mut source = String::new(); + reader.read_to_string(&mut source).unwrap(); + + let fmt_error = |e: &CompileError| { + let file = e.file().canonicalize().unwrap(); + format!( + "{}:{}", + file.strip_prefix(std::env::current_dir().unwrap()) + .unwrap_or(file.as_path()) + .display(), + e.value() + ) + }; + + let stdlib_path = sub_matches.value_of("stdlib-path").unwrap(); + match Path::new(stdlib_path).exists() { + true => Ok(()), + _ => Err(format!( + "Invalid standard library source path: {}", + stdlib_path + )), + }?; + + let resolver = FileSystemResolver::with_stdlib_root(stdlib_path); + let artifacts: CompilationArtifacts = + compile(source, path, Some(&resolver)).map_err(|e| { + format!( + "Compilation failed:\n\n{}", + e.0.iter() + .map(|e| fmt_error(e)) + .collect::>() + .join("\n\n") + ) + })?; + + let program_flattened = artifacts.prog(); + + // number of constraints the flattened program will translate to. + let num_constraints = program_flattened.constraint_count(); + + // serialize flattened program and write to binary file + let bin_output_file = File::create(&bin_output_path) + .map_err(|why| format!("Couldn't create {}: {}", bin_output_path.display(), why))?; + + let mut writer = BufWriter::new(bin_output_file); + + program_flattened.serialize(&mut writer); + + // serialize ABI spec and write to JSON file + let abi_spec_file = File::create(&abi_spec_path) + .map_err(|why| format!("Couldn't create {}: {}", abi_spec_path.display(), why))?; + + let abi = artifacts.abi(); + + let mut writer = BufWriter::new(abi_spec_file); + + to_writer_pretty(&mut writer, &abi).map_err(|_| "Unable to write data to file.".to_string())?; + + if !light { + // write human-readable output file + let hr_output_file = File::create(&hr_output_path) + .map_err(|why| format!("Couldn't create {}: {}", hr_output_path.display(), why))?; + + let mut hrofb = BufWriter::new(hr_output_file); + write!(&mut hrofb, "{}\n", program_flattened) + .map_err(|_| "Unable to write data to file".to_string())?; + hrofb + .flush() + .map_err(|_| "Unable to flush buffer".to_string())?; + } + + if !light { + // debugging output + println!("Compiled program:\n{}", program_flattened); + } + + println!("Compiled code written to '{}'", bin_output_path.display()); + + if !light { + println!("Human readable code to '{}'", hr_output_path.display()); + } + + println!("Number of constraints: {}", num_constraints); + Ok(()) +} diff --git a/zokrates_cli/src/ops/compute_witness.rs b/zokrates_cli/src/ops/compute_witness.rs new file mode 100644 index 00000000..f1ba4554 --- /dev/null +++ b/zokrates_cli/src/ops/compute_witness.rs @@ -0,0 +1,192 @@ +use crate::constants::{ABI_SPEC_DEFAULT_PATH, FLATTENED_CODE_DEFAULT_PATH, WITNESS_DEFAULT_PATH}; +use clap::{App, Arg, ArgMatches, SubCommand}; +use serde_json::from_reader; +use std::fs::File; +use std::io::{stdin, BufReader, BufWriter, Read}; +use std::path::Path; +use zokrates_abi::Encode; +use zokrates_core::ir; +use zokrates_core::ir::ProgEnum; +use zokrates_core::typed_absy::abi::Abi; +use zokrates_core::typed_absy::{ConcreteSignature, ConcreteType}; +use zokrates_field::Field; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("compute-witness") + .about("Calculates a witness for a given constraint system") + .arg(Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the binary") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(FLATTENED_CODE_DEFAULT_PATH) + ).arg(Arg::with_name("abi_spec") + .short("s") + .long("abi_spec") + .help("Path of the ABI specification") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(ABI_SPEC_DEFAULT_PATH) + ).arg(Arg::with_name("output") + .short("o") + .long("output") + .help("Path of the output file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(WITNESS_DEFAULT_PATH) + ).arg(Arg::with_name("arguments") + .short("a") + .long("arguments") + .help("Arguments for the program's main function, when not using ABI encoding. Expects a space-separated list of field elements like `-a 1 2 3`") + .takes_value(true) + .multiple(true) // allows multiple values + .required(false) + .conflicts_with("abi") + .conflicts_with("stdin") + ).arg(Arg::with_name("abi") + .long("abi") + .help("Use ABI encoding. Arguments are expected as a JSON object as specified at zokrates.github.io/toolbox/abi.html#abi-input-format") + .conflicts_with("arguments") + .required(false) + ).arg(Arg::with_name("stdin") + .long("stdin") + .help("Read arguments from stdin") + .conflicts_with("arguments") + .required(false) + ).arg(Arg::with_name("light") + .long("light") + .help("Skip logging the human-readable program") + .required(false) + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + // read compiled program + let path = Path::new(sub_matches.value_of("input").unwrap()); + let file = + File::open(&path).map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; + + let mut reader = BufReader::new(file); + + match ProgEnum::deserialize(&mut reader)? { + ProgEnum::Bn128Program(p) => cli_compute(p, sub_matches), + ProgEnum::Bls12_377Program(p) => cli_compute(p, sub_matches), + ProgEnum::Bls12_381Program(p) => cli_compute(p, sub_matches), + ProgEnum::Bw6_761Program(p) => cli_compute(p, sub_matches), + } +} + +fn cli_compute(ir_prog: ir::Prog, sub_matches: &ArgMatches) -> Result<(), String> { + println!("Computing witness..."); + + // print deserialized flattened program + if !sub_matches.is_present("light") { + println!("{}", ir_prog); + } + + let is_stdin = sub_matches.is_present("stdin"); + let is_abi = sub_matches.is_present("abi"); + + if !is_stdin && is_abi { + return Err("ABI input as inline argument is not supported. Please use `--stdin`.".into()); + } + + let signature = match is_abi { + true => { + let path = Path::new(sub_matches.value_of("abi_spec").unwrap()); + let file = File::open(&path) + .map_err(|why| format!("couldn't open {}: {}", path.display(), why))?; + let mut reader = BufReader::new(file); + + let abi: Abi = from_reader(&mut reader).map_err(|why| why.to_string())?; + + abi.signature() + } + false => ConcreteSignature::new() + .inputs(vec![ + ConcreteType::FieldElement; + ir_prog.main.arguments.len() + ]) + .outputs(vec![ConcreteType::FieldElement; ir_prog.main.returns.len()]), + }; + + use zokrates_abi::Inputs; + + // get arguments + let arguments = match is_stdin { + // take inline arguments + false => { + let arguments = sub_matches.values_of("arguments"); + arguments + .map(|a| { + a.map(|x| T::try_from_dec_str(x).map_err(|_| x.to_string())) + .collect::, _>>() + }) + .unwrap_or(Ok(vec![])) + .map(|v| Inputs::Raw(v)) + } + // take stdin arguments + true => { + let mut stdin = stdin(); + let mut input = String::new(); + + match is_abi { + true => match stdin.read_to_string(&mut input) { + Ok(_) => { + use zokrates_abi::parse_strict; + + parse_strict(&input, signature.inputs) + .map(|parsed| Inputs::Abi(parsed)) + .map_err(|why| why.to_string()) + } + Err(_) => Err(String::from("???")), + }, + false => match ir_prog.arguments_count() { + 0 => Ok(Inputs::Raw(vec![])), + _ => match stdin.read_to_string(&mut input) { + Ok(_) => { + input.retain(|x| x != '\n'); + input + .split(" ") + .map(|x| T::try_from_dec_str(x).map_err(|_| x.to_string())) + .collect::, _>>() + .map(|v| Inputs::Raw(v)) + } + Err(_) => Err(String::from("???")), + }, + }, + } + } + } + .map_err(|e| format!("Could not parse argument: {}", e))?; + + let interpreter = ir::Interpreter::default(); + + let witness = interpreter + .execute(&ir_prog, &arguments.encode()) + .map_err(|e| format!("Execution failed: {}", e))?; + + use zokrates_abi::Decode; + + let results_json_value: serde_json::Value = + zokrates_abi::CheckedValues::decode(witness.return_values(), signature.outputs).into(); + + println!("\nWitness: \n\n{}", results_json_value); + + // write witness to file + let output_path = Path::new(sub_matches.value_of("output").unwrap()); + let output_file = File::create(&output_path) + .map_err(|why| format!("couldn't create {}: {}", output_path.display(), why))?; + + let writer = BufWriter::new(output_file); + + witness + .write(writer) + .map_err(|why| format!("could not save witness: {:?}", why))?; + + Ok(()) +} diff --git a/zokrates_cli/src/ops/export_verifier.rs b/zokrates_cli/src/ops/export_verifier.rs new file mode 100644 index 00000000..b4658c62 --- /dev/null +++ b/zokrates_cli/src/ops/export_verifier.rs @@ -0,0 +1,119 @@ +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_core::proof_system::*; +use zokrates_field::Bn128Field; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("export-verifier") + .about("Exports a verifier as Solidity smart contract") + .arg( + Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the verifier") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::VERIFICATION_KEY_DEFAULT_PATH), + ) + .arg( + Arg::with_name("output") + .short("o") + .long("output") + .help("Path of the output file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::VERIFICATION_CONTRACT_DEFAULT_PATH), + ) + .arg( + Arg::with_name("curve") + .short("c") + .long("curve") + .help("Curve to be used to export the verifier") + .takes_value(true) + .required(false) + .possible_values(constants::CURVES) + .default_value(constants::BN128), + ) + .arg( + Arg::with_name("proving-scheme") + .short("s") + .long("proving-scheme") + .help("Proving scheme to use to export the verifier") + .value_name("FILE") + .takes_value(true) + .required(false) + .possible_values(constants::SCHEMES) + .default_value(constants::G16), + ) + .arg( + Arg::with_name("solidity-abi") + .short("a") + .long("solidity-abi") + .help("Flag for setting the version of the ABI Encoder used in the contract") + .takes_value(true) + .possible_values(&["v1", "v2"]) + .default_value("v1") + .required(false), + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let curve = sub_matches.value_of("curve").unwrap(); + let scheme = sub_matches.value_of("proving-scheme").unwrap(); + + let curve_parameter = CurveParameter::try_from(curve)?; + let scheme_parameter = SchemeParameter::try_from(scheme)?; + + match (curve_parameter, scheme_parameter) { + (CurveParameter::Bn128, SchemeParameter::G16) => { + cli_export_verifier::(sub_matches) + } + (CurveParameter::Bn128, SchemeParameter::GM17) => { + cli_export_verifier::(sub_matches) + } + (CurveParameter::Bn128, SchemeParameter::PGHR13) => { + cli_export_verifier::(sub_matches) + } + _ => Err(format!("Could not export verifier with given parameters (curve: {}, scheme: {}): not supported", curve, scheme)) + } +} + +fn cli_export_verifier>( + sub_matches: &ArgMatches, +) -> Result<(), String> { + println!("Exporting verifier..."); + + // read vk file + let input_path = Path::new(sub_matches.value_of("input").unwrap()); + let input_file = File::open(&input_path) + .map_err(|why| format!("Couldn't open {}: {}", input_path.display(), why))?; + let reader = BufReader::new(input_file); + + let vk = serde_json::from_reader(reader) + .map_err(|why| format!("Couldn't deserialize verifying key: {}", why))?; + + let abi = SolidityAbi::from(sub_matches.value_of("solidity-abi").unwrap())?; + + let verifier = S::export_solidity_verifier(vk, abi); + + //write output file + let output_path = Path::new(sub_matches.value_of("output").unwrap()); + let output_file = File::create(&output_path) + .map_err(|why| format!("Couldn't create {}: {}", output_path.display(), why))?; + + let mut writer = BufWriter::new(output_file); + + writer + .write_all(&verifier.as_bytes()) + .map_err(|_| "Failed writing output to file".to_string())?; + + println!("Finished exporting verifier"); + Ok(()) +} diff --git a/zokrates_cli/src/ops/generate_proof.rs b/zokrates_cli/src/ops/generate_proof.rs new file mode 100644 index 00000000..3118a7d0 --- /dev/null +++ b/zokrates_cli/src/ops/generate_proof.rs @@ -0,0 +1,180 @@ +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_core::ir; +use zokrates_core::ir::ProgEnum; +#[cfg(feature = "ark")] +use zokrates_core::proof_system::ark::Ark; +#[cfg(feature = "bellman")] +use zokrates_core::proof_system::bellman::Bellman; +#[cfg(feature = "libsnark")] +use zokrates_core::proof_system::libsnark::Libsnark; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +use zokrates_core::proof_system::*; +use zokrates_field::Field; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("generate-proof") + .about("Calculates a proof for a given constraint system and witness") + .arg( + Arg::with_name("witness") + .short("w") + .long("witness") + .help("Path of the witness file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::WITNESS_DEFAULT_PATH), + ) + .arg( + Arg::with_name("proving-key-path") + .short("p") + .long("proving-key-path") + .help("Path of the proving key file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::PROVING_KEY_DEFAULT_PATH), + ) + .arg( + Arg::with_name("proof-path") + .short("j") + .long("proof-path") + .help("Path of the JSON proof file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::JSON_PROOF_PATH), + ) + .arg( + Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the binary") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::FLATTENED_CODE_DEFAULT_PATH), + ) + .arg( + Arg::with_name("backend") + .short("b") + .long("backend") + .help("Backend to use") + .takes_value(true) + .required(false) + .possible_values(constants::BACKENDS) + .default_value(constants::BELLMAN), + ) + .arg( + Arg::with_name("proving-scheme") + .short("s") + .long("proving-scheme") + .help("Proving scheme to use to generate the proof") + .value_name("FILE") + .takes_value(true) + .required(false) + .possible_values(constants::SCHEMES) + .default_value(constants::G16), + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let program_path = Path::new(sub_matches.value_of("input").unwrap()); + let program_file = File::open(&program_path) + .map_err(|why| format!("Couldn't open {}: {}", program_path.display(), why))?; + + let mut reader = BufReader::new(program_file); + let prog = ProgEnum::deserialize(&mut reader)?; + + 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, + }, + sub_matches.value_of("proving-scheme").unwrap(), + ))?; + + match parameters { + #[cfg(feature = "bellman")] + Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog { + ProgEnum::Bn128Program(p) => cli_generate_proof::<_, G16, Bellman>(p, sub_matches), + ProgEnum::Bls12_381Program(p) => cli_generate_proof::<_, G16, Bellman>(p, sub_matches), + _ => unreachable!(), + }, + #[cfg(feature = "ark")] + Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog { + 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::Bn128Program(p) => cli_generate_proof::<_, GM17, Ark>(p, sub_matches), + _ => unreachable!(), + }, + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => { + match prog { + ProgEnum::Bn128Program(p) => { + cli_generate_proof::<_, GM17, Libsnark>(p, sub_matches) + } + _ => unreachable!(), + } + } + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::PGHR13) => { + match prog { + ProgEnum::Bn128Program(p) => { + cli_generate_proof::<_, PGHR13, Libsnark>(p, sub_matches) + } + _ => unreachable!(), + } + } + _ => unreachable!(), + } +} + +fn cli_generate_proof, B: Backend>( + program: ir::Prog, + sub_matches: &ArgMatches, +) -> Result<(), String> { + println!("Generating proof..."); + + // deserialize witness + let witness_path = Path::new(sub_matches.value_of("witness").unwrap()); + let witness_file = match File::open(&witness_path) { + Ok(file) => file, + Err(why) => panic!("Couldn't open {}: {}", witness_path.display(), why), + }; + + let witness = ir::Witness::read(witness_file) + .map_err(|why| format!("Could not load witness: {:?}", why))?; + + let pk_path = Path::new(sub_matches.value_of("proving-key-path").unwrap()); + let proof_path = Path::new(sub_matches.value_of("proof-path").unwrap()); + + let pk_file = File::open(&pk_path) + .map_err(|why| format!("Couldn't open {}: {}", pk_path.display(), why))?; + + let mut pk: Vec = Vec::new(); + let mut pk_reader = BufReader::new(pk_file); + pk_reader + .read_to_end(&mut pk) + .map_err(|why| format!("Couldn't read {}: {}", pk_path.display(), why))?; + + let proof = B::generate_proof(program, witness, pk); + let mut proof_file = File::create(proof_path).unwrap(); + + let proof = serde_json::to_string_pretty(&proof).unwrap(); + proof_file + .write(proof.as_bytes()) + .map_err(|why| format!("Couldn't write to {}: {}", proof_path.display(), why))?; + + println!("Proof:\n{}", format!("{}", proof)); + + Ok(()) +} diff --git a/zokrates_cli/src/ops/mod.rs b/zokrates_cli/src/ops/mod.rs new file mode 100644 index 00000000..bb1748c8 --- /dev/null +++ b/zokrates_cli/src/ops/mod.rs @@ -0,0 +1,12 @@ +pub mod check; +pub mod compile; +pub mod compute_witness; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +pub mod export_verifier; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +pub mod generate_proof; +pub mod print_proof; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +pub mod setup; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +pub mod verify; diff --git a/zokrates_cli/src/ops/print_proof.rs b/zokrates_cli/src/ops/print_proof.rs new file mode 100644 index 00000000..190aee93 --- /dev/null +++ b/zokrates_cli/src/ops/print_proof.rs @@ -0,0 +1,68 @@ +use crate::constants::JSON_PROOF_PATH; +use clap::{App, Arg, ArgMatches, SubCommand}; +use serde_json::Value; +use std::fs::File; +use std::path::Path; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("print-proof") + .about("Prints proof in the chosen format") + .arg( + Arg::with_name("proof-path") + .short("j") + .long("proof-path") + .help("Path of the JSON proof file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(JSON_PROOF_PATH), + ) + .arg( + Arg::with_name("format") + .short("f") + .long("format") + .value_name("FORMAT") + .help("Format in which the proof should be printed") + .takes_value(true) + .possible_values(&["remix", "json"]) + .required(true), + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let format = sub_matches.value_of("format").unwrap(); + let path = Path::new(sub_matches.value_of("proof-path").unwrap()); + + let file = + File::open(&path).map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; + + let proof_object: Value = serde_json::from_reader(file).map_err(|why| format!("{:?}", why))?; + + match format { + "json" => { + println!("~~~~~~~~ Copy the output below for valid ABIv2 format ~~~~~~~~"); + println!(); + print!("{}", proof_object["proof"]); + print!(","); + println!("{}", proof_object["inputs"]); + println!(); + println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + } + "remix" => { + println!("~~~~~~~~ Copy the output below for valid ABIv1 format ~~~~~~~~"); + println!(); + + for (_, value) in proof_object["proof"].as_object().unwrap().iter() { + print!("{}", value); + print!(","); + } + + println!("{}", proof_object["inputs"]); + println!(); + println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + } + _ => unreachable!(), + } + + Ok(()) +} diff --git a/zokrates_cli/src/ops/setup.rs b/zokrates_cli/src/ops/setup.rs new file mode 100644 index 00000000..693b7819 --- /dev/null +++ b/zokrates_cli/src/ops/setup.rs @@ -0,0 +1,172 @@ +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_core::ir; +use zokrates_core::ir::ProgEnum; +#[cfg(feature = "ark")] +use zokrates_core::proof_system::ark::Ark; +#[cfg(feature = "bellman")] +use zokrates_core::proof_system::bellman::Bellman; +#[cfg(feature = "libsnark")] +use zokrates_core::proof_system::libsnark::Libsnark; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +use zokrates_core::proof_system::*; +use zokrates_field::Field; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("setup") + .about("Performs a trusted setup for a given constraint system") + .arg( + Arg::with_name("input") + .short("i") + .long("input") + .help("Path of the binary") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::FLATTENED_CODE_DEFAULT_PATH), + ) + .arg( + Arg::with_name("proving-key-path") + .short("p") + .long("proving-key-path") + .help("Path of the generated proving key file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::PROVING_KEY_DEFAULT_PATH), + ) + .arg( + Arg::with_name("verification-key-path") + .short("v") + .long("verification-key-path") + .help("Path of the generated verification key file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::VERIFICATION_KEY_DEFAULT_PATH), + ) + .arg( + Arg::with_name("backend") + .short("b") + .long("backend") + .help("Backend to use") + .takes_value(true) + .required(false) + .possible_values(constants::BACKENDS) + .default_value(constants::BELLMAN), + ) + .arg( + Arg::with_name("proving-scheme") + .short("s") + .long("proving-scheme") + .help("Proving scheme to use in the setup") + .takes_value(true) + .required(false) + .possible_values(constants::SCHEMES) + .default_value(constants::G16), + ) + .arg( + Arg::with_name("light") + .long("light") + .help("Skip logging the human-readable program and writing it to a file") + .required(false), + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + // read compiled program + let path = Path::new(sub_matches.value_of("input").unwrap()); + let file = + File::open(&path).map_err(|why| format!("Couldn't open {}: {}", path.display(), why))?; + + let mut reader = BufReader::new(file); + let prog = ProgEnum::deserialize(&mut reader)?; + + 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, + }, + sub_matches.value_of("proving-scheme").unwrap(), + ))?; + + match parameters { + #[cfg(feature = "bellman")] + Parameters(BackendParameter::Bellman, _, SchemeParameter::G16) => match prog { + ProgEnum::Bn128Program(p) => cli_setup::<_, G16, Bellman>(p, sub_matches), + ProgEnum::Bls12_381Program(p) => cli_setup::<_, G16, Bellman>(p, sub_matches), + _ => unreachable!(), + }, + #[cfg(feature = "ark")] + Parameters(BackendParameter::Ark, _, SchemeParameter::GM17) => match prog { + ProgEnum::Bls12_377Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), + ProgEnum::Bw6_761Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), + ProgEnum::Bn128Program(p) => cli_setup::<_, GM17, Ark>(p, sub_matches), + _ => unreachable!(), + }, + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => { + match prog { + ProgEnum::Bn128Program(p) => cli_setup::<_, GM17, Libsnark>(p, sub_matches), + _ => unreachable!(), + } + } + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::PGHR13) => { + match prog { + ProgEnum::Bn128Program(p) => cli_setup::<_, PGHR13, Libsnark>(p, sub_matches), + _ => unreachable!(), + } + } + _ => unreachable!(), + } +} + +fn cli_setup, B: Backend>( + program: ir::Prog, + sub_matches: &ArgMatches, +) -> Result<(), String> { + println!("Performing setup..."); + + // print deserialized flattened program + if !sub_matches.is_present("light") { + println!("{}", program); + } + + // get paths for proving and verification keys + let pk_path = Path::new(sub_matches.value_of("proving-key-path").unwrap()); + let vk_path = Path::new(sub_matches.value_of("verification-key-path").unwrap()); + + // run setup phase + let keypair = B::setup(program); + + // write verification key + let mut vk_file = File::create(vk_path) + .map_err(|why| format!("couldn't create {}: {}", vk_path.display(), why))?; + vk_file + .write( + serde_json::to_string_pretty(&keypair.vk) + .unwrap() + .as_bytes(), + ) + .map_err(|why| format!("couldn't write to {}: {}", vk_path.display(), why))?; + + // write proving key + let mut pk_file = File::create(pk_path) + .map_err(|why| format!("couldn't create {}: {}", pk_path.display(), why))?; + pk_file + .write(keypair.pk.as_ref()) + .map_err(|why| format!("couldn't write to {}: {}", pk_path.display(), why))?; + + println!("Setup completed."); + + Ok(()) +} diff --git a/zokrates_cli/src/ops/verify.rs b/zokrates_cli/src/ops/verify.rs new file mode 100644 index 00000000..aefd51b9 --- /dev/null +++ b/zokrates_cli/src/ops/verify.rs @@ -0,0 +1,133 @@ +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; +#[cfg(feature = "ark")] +use zokrates_core::proof_system::ark::Ark; +#[cfg(feature = "bellman")] +use zokrates_core::proof_system::bellman::Bellman; +#[cfg(feature = "libsnark")] +use zokrates_core::proof_system::libsnark::Libsnark; +#[cfg(any(feature = "bellman", feature = "ark", feature = "libsnark"))] +use zokrates_core::proof_system::*; +use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; + +pub fn subcommand() -> App<'static, 'static> { + SubCommand::with_name("verify") + .about("Verifies a given proof with the given verification key") + .arg(Arg::with_name("proof-path") + .short("j") + .long("proof-path") + .help("Path of the JSON proof file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::JSON_PROOF_PATH) + ).arg(Arg::with_name("verification-key-path") + .short("v") + .long("verification-key-path") + .help("Path of the generated verification key file") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(constants::VERIFICATION_KEY_DEFAULT_PATH) + ).arg(Arg::with_name("backend") + .short("b") + .long("backend") + .help("Backend to use") + .takes_value(true) + .required(false) + .possible_values(constants::BACKENDS) + .default_value(constants::BELLMAN) + ).arg(Arg::with_name("proving-scheme") + .short("s") + .long("proving-scheme") + .help("Proving scheme to use in the setup. Available options are G16 (default), PGHR13 and GM17") + .value_name("FILE") + .takes_value(true) + .required(false) + .default_value(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) + ) +} + +pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { + let parameters = Parameters::try_from(( + sub_matches.value_of("backend").unwrap(), + sub_matches.value_of("curve").unwrap(), + sub_matches.value_of("proving-scheme").unwrap(), + ))?; + + match parameters { + #[cfg(feature = "bellman")] + Parameters(BackendParameter::Bellman, CurveParameter::Bn128, SchemeParameter::G16) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "bellman")] + Parameters(BackendParameter::Bellman, CurveParameter::Bls12_381, SchemeParameter::G16) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "ark")] + Parameters(BackendParameter::Ark, CurveParameter::Bls12_377, SchemeParameter::GM17) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "ark")] + Parameters(BackendParameter::Ark, CurveParameter::Bw6_761, SchemeParameter::GM17) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "ark")] + Parameters(BackendParameter::Ark, CurveParameter::Bn128, SchemeParameter::GM17) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::GM17) => { + cli_verify::(sub_matches) + } + #[cfg(feature = "libsnark")] + Parameters(BackendParameter::Libsnark, CurveParameter::Bn128, SchemeParameter::PGHR13) => { + cli_verify::(sub_matches) + } + _ => unreachable!(), + } +} + +fn cli_verify, B: Backend>( + sub_matches: &ArgMatches, +) -> Result<(), String> { + let vk_path = Path::new(sub_matches.value_of("verification-key-path").unwrap()); + let vk_file = File::open(&vk_path) + .map_err(|why| format!("Couldn't open {}: {}", vk_path.display(), why))?; + + let vk_reader = BufReader::new(vk_file); + let vk = serde_json::from_reader(vk_reader) + .map_err(|why| format!("Couldn't deserialize verification key: {}", why))?; + + let proof_path = Path::new(sub_matches.value_of("proof-path").unwrap()); + let proof_file = File::open(&proof_path) + .map_err(|why| format!("Couldn't open {}: {}", proof_path.display(), why))?; + + let proof_reader = BufReader::new(proof_file); + let proof = serde_json::from_reader(proof_reader) + .map_err(|why| format!("Couldn't deserialize proof: {}", why))?; + + println!("Performing verification..."); + println!( + "The verification result is: {}", + match B::verify(vk, proof) { + true => "PASS", + false => "FAIL", + } + ); + + Ok(()) +} diff --git a/zokrates_core/src/proof_system/scheme/mod.rs b/zokrates_core/src/proof_system/scheme/mod.rs index f3ed498b..b9a09b80 100644 --- a/zokrates_core/src/proof_system/scheme/mod.rs +++ b/zokrates_core/src/proof_system/scheme/mod.rs @@ -6,6 +6,10 @@ pub mod gm17; pub mod groth16; pub mod pghr13; +pub use self::gm17::GM17; +pub use self::groth16::G16; +pub use self::pghr13::PGHR13; + pub trait Scheme { type VerificationKey: Serialize + DeserializeOwned; type ProofPoints: Serialize + DeserializeOwned; diff --git a/zokrates_js/Cargo.lock b/zokrates_js/Cargo.lock new file mode 100644 index 00000000..f0aad642 --- /dev/null +++ b/zokrates_js/Cargo.lock @@ -0,0 +1,1159 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + +[[package]] +name = "aho-corasick" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +dependencies = [ + "memchr", +] + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "backtrace" +version = "0.3.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bellman_ce" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ca1343d8690bb4d62e0665116bd4f109e33a642f86908ed107d226a402b0ef" +dependencies = [ + "bit-vec", + "byteorder", + "cfg-if", + "futures", + "num_cpus", + "pairing_ce", + "rand 0.4.6", + "web-sys", +] + +[[package]] +name = "bincode" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e" +dependencies = [ + "byteorder", + "num-traits 0.1.43", + "serde", +] + +[[package]] +name = "bincode" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "bit-vec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "bstr" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "csv" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" +dependencies = [ + "bstr", + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", + "failure_derive", +] + +[[package]] +name = "failure_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", + "synstructure", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "ff_ce" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c0a6a2c53b0bd6d8cae976816dc8a171e0554c03f304e3dac110473e0219fd" +dependencies = [ + "byteorder", + "hex", + "rand 0.4.6", +] + +[[package]] +name = "ff_ce" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4592897f75fd1bd178e5ec12d9d7df3d1943464feda2cbce1e708a484e82c8f6" +dependencies = [ + "byteorder", + "ff_derive_ce", + "hex", + "rand 0.4.6", +] + +[[package]] +name = "ff_derive_ce" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c052fa6d4c2f12305ec364bfb8ef884836f3f61ea015b202372ff996d1ac4b" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits 0.2.12", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "from-pest" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aba9389cedcba1fb3a2aa2ed00f584f2606bce8e0106614a17327a24513bc60f" +dependencies = [ + "pest", + "void", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "futures" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" + +[[package]] +name = "futures-executor" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" + +[[package]] +name = "futures-sink" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" + +[[package]] +name = "futures-task" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell", +] + +[[package]] +name = "futures-util" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" + +[[package]] +name = "hermit-abi" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "itertools" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "js-sys" +version = "0.3.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "miniz_oxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +dependencies = [ + "adler", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-integer", + "num-iter", + "num-traits 0.2.12", +] + +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.12", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg", + "num-traits 0.2.12", +] + +[[package]] +name = "num-iter" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.12", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.12", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" + +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "pairing_ce" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc00d65b1d29e0a067a967fcea83d8db261c149f76a557ba73f0304f01cdfde" +dependencies = [ + "byteorder", + "ff_ce 0.10.3", + "rand 0.4.6", +] + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest-ast" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbf404899169771dd6a32c84248b83cd67a26cc7cc957aac87661490e1227e4" +dependencies = [ + "itertools", + "proc-macro2 0.4.30", + "quote 0.6.13", + "single", + "syn 0.15.44", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + +[[package]] +name = "pin-project" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid 0.2.1", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2 1.0.18", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "reduce" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c8549eb79c1fc8c449cb18a2d9b7873a7cb1bf2fcbfe8a3ad8812320544341" + +[[package]] +name = "regex" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", + "utf8-ranges", +] + +[[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", +] + +[[package]] +name = "regex-syntax" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" +dependencies = [ + "ucd-util", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "serde_json" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "single" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd5add732a1ab689845591a1b50339cf5310b563e08dc5813c65991f30369ea2" +dependencies = [ + "failure", +] + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "unicode-xid 0.2.1", +] + +[[package]] +name = "synstructure" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", + "unicode-xid 0.2.1", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "typed-arena" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "ucd-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "utf8-ranges" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-bindgen" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" +dependencies = [ + "cfg-if", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" +dependencies = [ + "quote 1.0.7", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" + +[[package]] +name = "web-sys" +version = "0.3.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "zokrates_abi" +version = "0.1.2" +dependencies = [ + "serde", + "serde_derive", + "serde_json", + "zokrates_core", + "zokrates_field", +] + +[[package]] +name = "zokrates_common" +version = "0.1.0" + +[[package]] +name = "zokrates_core" +version = "0.5.2" +dependencies = [ + "bellman_ce", + "bincode 0.8.0", + "cfg-if", + "csv", + "ff_ce 0.9.0", + "hex", + "lazy_static", + "num", + "num-bigint", + "pairing_ce", + "rand 0.4.6", + "rand 0.7.3", + "reduce", + "regex", + "serde", + "serde_json", + "typed-arena", + "zokrates_common", + "zokrates_field", + "zokrates_pest_ast", +] + +[[package]] +name = "zokrates_field" +version = "0.3.7" +dependencies = [ + "bellman_ce", + "bincode 0.8.0", + "lazy_static", + "num-bigint", + "num-integer", + "num-traits 0.2.12", + "serde", + "serde_derive", + "serde_json", + "sha2", +] + +[[package]] +name = "zokrates_js" +version = "1.0.26" +dependencies = [ + "bincode 1.3.1", + "console_error_panic_hook", + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "zokrates_abi", + "zokrates_common", + "zokrates_core", + "zokrates_field", +] + +[[package]] +name = "zokrates_parser" +version = "0.1.5" +dependencies = [ + "pest", + "pest_derive", +] + +[[package]] +name = "zokrates_pest_ast" +version = "0.1.4" +dependencies = [ + "from-pest", + "lazy_static", + "pest", + "pest-ast", + "zokrates_parser", +]