diff --git a/changelogs/unreleased/988-schaeff b/changelogs/unreleased/988-schaeff new file mode 100644 index 000000000..ca5e87e22 --- /dev/null +++ b/changelogs/unreleased/988-schaeff @@ -0,0 +1 @@ +Introduce a check mode flag `--mode` and stop requiring a main function in `lib` mode diff --git a/zokrates_cli/examples/compile_errors/two_entry_points.zok b/zokrates_cli/examples/compile_errors/two_entry_points.zok new file mode 100644 index 000000000..5a95e67d0 --- /dev/null +++ b/zokrates_cli/examples/compile_errors/two_entry_points.zok @@ -0,0 +1,5 @@ +def main(): + return + +def main(field a): + return \ No newline at end of file diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index c3bb2e051..28c53be16 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -115,7 +115,7 @@ mod tests { use std::fs::File; use std::io::{BufReader, Read}; use std::string::String; - use zokrates_core::compile::{compile, CompilationArtifacts, CompileConfig}; + use zokrates_core::compile::{compile, BinCompilationArtifacts, CompileConfig}; use zokrates_core::ir; use zokrates_field::Bn128Field; use zokrates_fs_resolver::FileSystemResolver; @@ -189,7 +189,7 @@ mod tests { let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); - let artifacts: CompilationArtifacts = + let artifacts: BinCompilationArtifacts> = compile(source, path, Some(&resolver), &CompileConfig::default()).unwrap(); let interpreter = ir::Interpreter::default(); @@ -221,7 +221,7 @@ mod tests { let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap(); let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap()); - let artifacts: CompilationArtifacts = + let artifacts: BinCompilationArtifacts> = compile(source, path, Some(&resolver), &CompileConfig::default()).unwrap(); let interpreter = ir::Interpreter::default(); diff --git a/zokrates_cli/src/constants.rs b/zokrates_cli/src/constants.rs index 19b2edf4d..c7d4cb410 100644 --- a/zokrates_cli/src/constants.rs +++ b/zokrates_cli/src/constants.rs @@ -9,6 +9,10 @@ pub const UNIVERSAL_SETUP_DEFAULT_PATH: &str = "universal_setup.dat"; pub const UNIVERSAL_SETUP_DEFAULT_SIZE: &str = "10"; pub const SMTLIB2_DEFAULT_PATH: &str = "out.smt2"; +pub const COMPILATION_MODE_BIN: &str = "bin"; +pub const COMPILATION_MODE_LIB: &str = "lib"; +pub const COMPILATION_MODES: &[&str] = &[COMPILATION_MODE_BIN, COMPILATION_MODE_LIB]; + pub const BELLMAN: &str = "bellman"; pub const LIBSNARK: &str = "libsnark"; pub const ARK: &str = "ark"; diff --git a/zokrates_cli/src/ops/check.rs b/zokrates_cli/src/ops/check.rs index 324e8f2fe..23a3ea941 100644 --- a/zokrates_cli/src/ops/check.rs +++ b/zokrates_cli/src/ops/check.rs @@ -5,7 +5,7 @@ use std::convert::TryFrom; use std::fs::File; use std::io::{BufReader, Read}; use std::path::{Path, PathBuf}; -use zokrates_core::compile::{check, CompileConfig, CompileError}; +use zokrates_core::compile::{check, CompileConfig, CompileError, CompileMode}; use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; use zokrates_fs_resolver::FileSystemResolver; @@ -46,6 +46,13 @@ pub fn subcommand() -> App<'static, 'static> { .help("Isolate the execution of branches: a panic in a branch only makes the program panic if this branch is being logically executed") .required(false) ) + .arg(Arg::with_name("mode") + .long("mode") + .help("In which mode the compiler should be run") + .possible_values(constants::COMPILATION_MODES) + .required(false) + .default_value(constants::COMPILATION_MODE_BIN) + ) } pub fn exec(sub_matches: &ArgMatches) -> Result<(), String> { @@ -89,8 +96,15 @@ fn cli_check(sub_matches: &ArgMatches) -> Result<(), String> { )), }?; - let config = - CompileConfig::default().isolate_branches(sub_matches.is_present("isolate-branches")); + let mode = match sub_matches.value_of("mode").unwrap() { + constants::COMPILATION_MODE_BIN => CompileMode::Bin, + constants::COMPILATION_MODE_LIB => CompileMode::Lib, + _ => unreachable!(), + }; + + let config = CompileConfig::default() + .isolate_branches(sub_matches.is_present("isolate-branches")) + .mode(mode); let resolver = FileSystemResolver::with_stdlib_root(stdlib_path); let _ = check::(source, path, Some(&resolver), &config).map_err(|e| { diff --git a/zokrates_cli/src/ops/compile.rs b/zokrates_cli/src/ops/compile.rs index cfe177811..4a47e060c 100644 --- a/zokrates_cli/src/ops/compile.rs +++ b/zokrates_cli/src/ops/compile.rs @@ -6,7 +6,10 @@ 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, CompileConfig, CompileError}; +use zokrates_core::{ + compile::{compile, BinCompilationArtifacts, CompileConfig, CompileError, CompileMode}, + ir::Prog, +}; use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; use zokrates_fs_resolver::FileSystemResolver; @@ -130,14 +133,15 @@ fn cli_compile(sub_matches: &ArgMatches) -> Result<(), String> { let config = CompileConfig::default() .allow_unconstrained_variables(sub_matches.is_present("allow-unconstrained-variables")) - .isolate_branches(sub_matches.is_present("isolate-branches")); + .isolate_branches(sub_matches.is_present("isolate-branches")) + .mode(CompileMode::Bin); let resolver = FileSystemResolver::with_stdlib_root(stdlib_path); log::debug!("Compile"); - let artifacts: CompilationArtifacts = compile(source, path, Some(&resolver), &config) - .map_err(|e| { + let artifacts: BinCompilationArtifacts> = + compile(source, path, Some(&resolver), &config).map_err(|e| { format!( "Compilation failed:\n\n{}", e.0.iter() diff --git a/zokrates_core/src/compile.rs b/zokrates_core/src/compile.rs index fc721cfe4..960fdcee8 100644 --- a/zokrates_core/src/compile.rs +++ b/zokrates_core/src/compile.rs @@ -25,13 +25,19 @@ use zokrates_field::Field; use zokrates_pest_ast as pest; #[derive(Debug)] -pub struct CompilationArtifacts { - prog: ir::Prog, +pub struct BinCompilationArtifacts

{ + prog: P, abi: Abi, } -impl CompilationArtifacts { - pub fn prog(&self) -> &ir::Prog { +#[derive(Debug)] +pub enum CompilationArtifacts

{ + Bin(BinCompilationArtifacts

), + Lib, +} + +impl

BinCompilationArtifacts

{ + pub fn prog(&self) -> &P { &self.prog } @@ -162,9 +168,25 @@ impl fmt::Display for CompileErrorInner { } } +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] +pub enum CompileMode { + Bin, + Lib, +} + +impl Default for CompileMode { + fn default() -> Self { + Self::Bin + } +} + #[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct CompileConfig { + #[serde(default)] + pub mode: CompileMode, + #[serde(default)] pub allow_unconstrained_variables: bool, + #[serde(default)] pub isolate_branches: bool, } @@ -177,6 +199,10 @@ impl CompileConfig { self.isolate_branches = flag; self } + pub fn mode(mut self, mode: CompileMode) -> Self { + self.mode = mode; + self + } } type FilePath = PathBuf; @@ -186,37 +212,42 @@ pub fn compile>( location: FilePath, resolver: Option<&dyn Resolver>, config: &CompileConfig, -) -> Result, CompileErrors> { +) -> Result>, CompileErrors> { let arena = Arena::new(); - let (typed_ast, abi) = check_with_arena(source, location.clone(), resolver, config, &arena)?; - - // flatten input program - log::debug!("Flatten"); - let program_flattened = Flattener::flatten(typed_ast, config); - - // constant propagation after call resolution - log::debug!("Propagate flat program"); - let program_flattened = program_flattened.propagate(); - - // convert to ir - log::debug!("Convert to IR"); - let ir_prog = ir::Prog::from(program_flattened); - - // optimize - log::debug!("Optimise IR"); - let optimized_ir_prog = ir_prog.optimize(); - - // analyse ir (check constraints) - log::debug!("Analyse IR"); - let optimized_ir_prog = optimized_ir_prog - .analyse() - .map_err(|e| CompileErrorInner::from(e).in_file(location.as_path()))?; - - Ok(CompilationArtifacts { - prog: optimized_ir_prog, - abi, - }) + let artifacts = check_with_arena(source, location.clone(), resolver, config, &arena)?; + + match artifacts { + CompilationArtifacts::Lib => unreachable!(), + CompilationArtifacts::Bin(artifacts) => { + // flatten input program + log::debug!("Flatten"); + let program_flattened = Flattener::flatten(artifacts.prog, config); + + // constant propagation after call resolution + log::debug!("Propagate flat program"); + let program_flattened = program_flattened.propagate(); + + // convert to ir + log::debug!("Convert to IR"); + let ir_prog = ir::Prog::from(program_flattened); + + // optimize + log::debug!("Optimise IR"); + let optimized_ir_prog = ir_prog.optimize(); + + // analyse ir (check constraints) + log::debug!("Analyse IR"); + let optimized_ir_prog = optimized_ir_prog + .analyse() + .map_err(|e| CompileErrorInner::from(e).in_file(location.as_path()))?; + + Ok(BinCompilationArtifacts { + prog: optimized_ir_prog, + abi: artifacts.abi, + }) + } + } } pub fn check>( @@ -236,7 +267,7 @@ fn check_with_arena<'ast, T: Field, E: Into>( resolver: Option<&dyn Resolver>, config: &CompileConfig, arena: &'ast Arena, -) -> Result<(ZirProgram<'ast, T>, Abi), CompileErrors> { +) -> Result>, CompileErrors> { let source = arena.alloc(source); log::debug!("Parse program with entry file {}", location.display()); @@ -246,17 +277,27 @@ fn check_with_arena<'ast, T: Field, E: Into>( log::debug!("Check semantics"); // check semantics - let typed_ast = Checker::check(compiled) + let typed_ast = Checker::check(compiled, config.mode) .map_err(|errors| CompileErrors(errors.into_iter().map(CompileError::from).collect()))?; - let main_module = typed_ast.main.clone(); + match config.mode { + CompileMode::Bin => { + let main_module = typed_ast.main.clone(); + + log::debug!("Run static analysis"); - log::debug!("Run static analysis"); + // analyse (unroll and constant propagation) + let (prog, abi) = typed_ast.analyse(config).map_err(|e| { + CompileErrors(vec![CompileErrorInner::from(e).in_file(&main_module)]) + })?; - // analyse (unroll and constant propagation) - typed_ast - .analyse(config) - .map_err(|e| CompileErrors(vec![CompileErrorInner::from(e).in_file(&main_module)])) + Ok(CompilationArtifacts::Bin(BinCompilationArtifacts { + prog, + abi, + })) + } + CompileMode::Lib => Ok(CompilationArtifacts::Lib), + } } pub fn parse_program<'ast, T: Field, E: Into>( @@ -322,7 +363,7 @@ mod test { return foo() "# .to_string(); - let res: Result, CompileErrors> = compile( + let res: Result>, CompileErrors> = compile( source, "./path/to/file".into(), None::<&dyn Resolver>, @@ -341,7 +382,7 @@ mod test { return 1 "# .to_string(); - let res: Result, CompileErrors> = compile( + let res: Result>, CompileErrors> = compile( source, "./path/to/file".into(), None::<&dyn Resolver>, diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 937fbf174..a9e68cfba 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -6,6 +6,7 @@ use crate::absy::Identifier; use crate::absy::*; +use crate::compile::CompileMode; use crate::typed_absy::types::GGenericsAssignment; use crate::typed_absy::*; use crate::typed_absy::{DeclarationParameter, DeclarationVariable, Variable}; @@ -293,6 +294,7 @@ pub struct Checker<'ast, T> { scope: HashSet>, functions: HashSet>, level: usize, + mode: CompileMode, } impl<'ast, T: Field> Checker<'ast, T> { @@ -301,17 +303,27 @@ impl<'ast, T: Field> Checker<'ast, T> { return_types: None, scope: HashSet::new(), functions: HashSet::new(), + mode: CompileMode::default(), level: 0, } } + fn with_mode(mode: CompileMode) -> Self { + let mut checker = Checker::new(); + checker.mode = mode; + checker + } + /// Check a `Program` /// /// # Arguments /// /// * `prog` - The `Program` to be checked - pub fn check(prog: Program<'ast>) -> Result, Vec> { - Checker::new().check_program(prog) + pub fn check( + prog: Program<'ast>, + mode: CompileMode, + ) -> Result, Vec> { + Checker::with_mode(mode).check_program(prog) } fn check_program( @@ -334,14 +346,16 @@ impl<'ast, T: Field> Checker<'ast, T> { let main_id = program.main.clone(); - Checker::check_single_main(state.typed_modules.get(&program.main).unwrap()).map_err( - |inner| { - vec![Error { - inner, - module_id: main_id, - }] - }, - )?; + if self.mode == CompileMode::Bin { + Checker::check_entry_point(state.typed_modules.get(&program.main).unwrap()).map_err( + |inner| { + vec![Error { + inner, + module_id: main_id, + }] + }, + )? + }; Ok(TypedProgram { main: program.main, @@ -869,22 +883,30 @@ impl<'ast, T: Field> Checker<'ast, T> { Ok(()) } - fn check_single_main(module: &TypedModule) -> Result<(), ErrorInner> { - match module - .functions - .iter() - .filter(|(key, _)| key.id == "main") - .count() - { - 1 => Ok(()), - 0 => Err(ErrorInner { + fn check_entry_point(module: &TypedModule) -> Result<(), ErrorInner> { + let mut main_iterator = module.functions.iter().filter(|(key, _)| key.id == "main"); + + match main_iterator.next() { + Some((key, _)) => match key.signature.generics.len() { + 0 => match main_iterator.count() { + 0 => Ok(()), + n => Err(ErrorInner { + pos: None, + message: format!("Expected a single entry point, found {}", n + 1), + }), + }, + _ => Err(ErrorInner { + pos: None, + message: format!( + "Expected the entry point of the program `{}` not to have generics", + key + ), + }), + }, + None => Err(ErrorInner { pos: None, message: "No main function found".into(), }), - n => Err(ErrorInner { - pos: None, - message: format!("Only one main function allowed, found {}", n), - }), } } @@ -4008,6 +4030,7 @@ mod tests { functions, level, return_types: None, + mode: CompileMode::default(), } } @@ -5214,7 +5237,7 @@ mod tests { Err(vec![Error { inner: ErrorInner { pos: None, - message: "Only one main function allowed, found 2".into() + message: "Expected a single entry point, found 2".into() }, module_id: (*MODULE_ID).clone() }]) diff --git a/zokrates_core/src/static_analysis/reducer/mod.rs b/zokrates_core/src/static_analysis/reducer/mod.rs index 84790f29b..906e9bc35 100644 --- a/zokrates_core/src/static_analysis/reducer/mod.rs +++ b/zokrates_core/src/static_analysis/reducer/mod.rs @@ -51,7 +51,6 @@ pub enum Output { #[derive(Debug, Clone, PartialEq)] pub enum Error { Incompatible(String), - GenericsInMain, // TODO: give more details about what's blocking the progress NoProgress, LoopTooLarge(u128), @@ -65,7 +64,6 @@ impl fmt::Display for Error { "{}", s ), - Error::GenericsInMain => write!(f, "Cannot generate code for generic function"), Error::NoProgress => write!(f, "Failed to unroll or inline program. Check that main function arguments aren't used as array size or for-loop bounds"), Error::LoopTooLarge(size) => write!(f, "Found a loop of size {}, which is larger than the maximum allowed of {}. Check the loop bounds, especially for underflows", size, MAX_FOR_LOOP_SIZE), } @@ -500,30 +498,24 @@ pub fn reduce_program(p: TypedProgram) -> Result, E _ => unreachable!(), }; - match main_function.signature.generics.len() { - 0 => { - let main_function = reduce_function(main_function, GGenericsAssignment::default(), &p)?; - - Ok(TypedProgram { - main: p.main.clone(), - modules: vec![( - p.main.clone(), - TypedModule { - functions: vec![( - main_key.clone(), - TypedFunctionSymbol::Here(main_function), - )] - .into_iter() - .collect(), - constants: Default::default(), - }, - )] - .into_iter() - .collect(), - }) - } - _ => Err(Error::GenericsInMain), - } + assert!(main_function.signature.generics.is_empty()); + + let main_function = reduce_function(main_function, GGenericsAssignment::default(), &p)?; + + Ok(TypedProgram { + main: p.main.clone(), + modules: vec![( + p.main.clone(), + TypedModule { + functions: vec![(main_key.clone(), TypedFunctionSymbol::Here(main_function))] + .into_iter() + .collect(), + constants: Default::default(), + }, + )] + .into_iter() + .collect(), + }) } fn reduce_function<'ast, T: Field>( diff --git a/zokrates_core/tests/out_of_range.rs b/zokrates_core/tests/out_of_range.rs index c27e23614..a9ad621cb 100644 --- a/zokrates_core/tests/out_of_range.rs +++ b/zokrates_core/tests/out_of_range.rs @@ -6,8 +6,8 @@ use std::io; use zokrates_common::Resolver; use zokrates_core::compile::CompileConfig; use zokrates_core::{ - compile::{compile, CompilationArtifacts}, - ir::Interpreter, + compile::{compile, BinCompilationArtifacts}, + ir::{Interpreter, Prog}, }; use zokrates_field::Bn128Field; use zokrates_fs_resolver::FileSystemResolver; @@ -26,7 +26,7 @@ fn lt_field() { // the fact that `2*10000 - 2*5555` has two distinct bit decompositions // we chose the one which is out of range, ie the sum check features an overflow - let res: CompilationArtifacts = compile( + let res: BinCompilationArtifacts> = compile( source, "./path/to/file".into(), None::<&dyn Resolver>, @@ -58,7 +58,7 @@ fn lt_uint() { // the fact that `2*10000 - 2*5555` has two distinct bit decompositions // we chose the one which is out of range, ie the sum check features an overflow - let res: CompilationArtifacts = compile( + let res: BinCompilationArtifacts> = compile( source, "./path/to/file".into(), None::<&dyn Resolver>, @@ -99,7 +99,7 @@ fn unpack256() { ) .unwrap(); - let res: CompilationArtifacts = compile( + let res: BinCompilationArtifacts> = compile( source, "./path/to/file".into(), Some(&FileSystemResolver::with_stdlib_root( @@ -139,7 +139,7 @@ fn unpack256_unchecked() { ) .unwrap(); - let res: CompilationArtifacts = compile( + let res: BinCompilationArtifacts> = compile( source, "./path/to/file".into(), Some(&FileSystemResolver::with_stdlib_root( diff --git a/zokrates_core_test/tests/tests/panics/deep_branch.json b/zokrates_core_test/tests/tests/panics/deep_branch.json index 35d14e6ab..5a3315954 100644 --- a/zokrates_core_test/tests/tests/panics/deep_branch.json +++ b/zokrates_core_test/tests/tests/panics/deep_branch.json @@ -2,7 +2,6 @@ "entry_point": "./tests/tests/panics/deep_branch.zok", "curves": ["Bn128"], "config": { - "allow_unconstrained_variables": false, "isolate_branches": true }, "tests": [ diff --git a/zokrates_core_test/tests/tests/panics/internal_panic.json b/zokrates_core_test/tests/tests/panics/internal_panic.json index 644d6baa9..78b071c47 100644 --- a/zokrates_core_test/tests/tests/panics/internal_panic.json +++ b/zokrates_core_test/tests/tests/panics/internal_panic.json @@ -2,7 +2,6 @@ "entry_point": "./tests/tests/panics/internal_panic.zok", "curves": ["Bn128"], "config": { - "allow_unconstrained_variables": false, "isolate_branches": true }, "tests": [ diff --git a/zokrates_core_test/tests/tests/panics/panic_isolation.json b/zokrates_core_test/tests/tests/panics/panic_isolation.json index 1dc70fd5c..91dc43358 100644 --- a/zokrates_core_test/tests/tests/panics/panic_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_isolation.json @@ -1,7 +1,6 @@ { "entry_point": "./tests/tests/panics/panic_isolation.zok", "config": { - "allow_unconstrained_variables": false, "isolate_branches": true }, "curves": ["Bn128"], diff --git a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json index 063cb533b..5d4388963 100644 --- a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json @@ -1,7 +1,6 @@ { "entry_point": "./tests/tests/panics/panic_isolation.zok", "config": { - "allow_unconstrained_variables": false, "isolate_branches": false }, "curves": ["Bn128"], diff --git a/zokrates_js/Cargo.lock b/zokrates_js/Cargo.lock index 2566ac336..a6366074f 100644 --- a/zokrates_js/Cargo.lock +++ b/zokrates_js/Cargo.lock @@ -17,6 +17,17 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +[[package]] +name = "ahash" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +dependencies = [ + "getrandom 0.2.2", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.6.10" @@ -26,6 +37,219 @@ dependencies = [ "memchr", ] +[[package]] +name = "ark-bls12-377" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb89b97424403ec9cc22a1df0db748dd7396c9ba5fb5c71a6f0e10ae1d1a7449" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-r1cs-std", + "ark-std", +] + +[[package]] +name = "ark-bw6-761" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ad8d74a8e083a59defc4a226a19759691337006d5c9397dbd793af9e406418" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-crypto-primitives" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74b83a7e125e5c611e4a997123effb2f02e3fbc66531dd77751d3016ee920741" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-nonnative-field", + "ark-r1cs-std", + "ark-relations", + "ark-snark", + "ark-std", + "blake2", + "derivative", + "digest 0.9.0", + "tracing", +] + +[[package]] +name = "ark-ec" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56006994f509d76fbce6f6ffe3108f7191b4f3754ecd00bbae7cac20ec05020" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "num-traits 0.2.12", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4d8802d40fce9212c5c09be08f75c4b3becc0c488e87f60fff787b01250ce33" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "num-traits 0.2.12", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e8cb28c2137af1ef058aa59616db3f7df67dbb70bf2be4ee6920008cc30d98c" +dependencies = [ + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "ark-ff-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9c256a93a10ed9708c16a517d6dcfaba3d215c0d7fab44d29a9affefb5eeb8" +dependencies = [ + "num-bigint 0.4.1", + "num-traits 0.2.12", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "ark-gm17" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c9085a6c89aa65178aa2718b2efb62fd7c4dc23fe25285204e30b56e4cbfcac" +dependencies = [ + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-poly", + "ark-r1cs-std", + "ark-relations", + "ark-serialize", + "ark-std", + "derivative", + "tracing", +] + +[[package]] +name = "ark-nonnative-field" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17887af156e9911d1dba5b30d49256d508f82f6a4f765a6fad8b5c637b700353" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-r1cs-std", + "ark-relations", + "ark-std", + "derivative", + "num-bigint 0.4.1", + "num-integer", + "num-traits 0.2.12", + "tracing", +] + +[[package]] +name = "ark-poly" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6683d21645a2abb94034f6a14e708405e55d9597687952d54b2269922857a" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown", +] + +[[package]] +name = "ark-r1cs-std" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a90fea2b84ae4443983d56540360ea004cab952292b7a6535798b6b9dcb7f41" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-relations", + "ark-std", + "derivative", + "num-bigint 0.4.1", + "num-traits 0.2.12", + "tracing", +] + +[[package]] +name = "ark-relations" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a42f124f8dfff2b0561143c0c7ea48d7f7dc8d2c4c1e87eca14a27430c653c0b" +dependencies = [ + "ark-ff", + "ark-std", + "tracing", +] + +[[package]] +name = "ark-serialize" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e9b59329dc9b92086b3dc619f31cef4a0c802f10829b575a3666d48a48387d" +dependencies = [ + "ark-serialize-derive", + "ark-std", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ac3d78c750b01f5df5b2e76d106ed31487a93b3868f14a7f0eb3a74f45e1d8a" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "ark-snark" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39da26432fe584b0010741299820145ec69180fe9ea18ddf96946932763624a1" +dependencies = [ + "ark-ff", + "ark-relations", + "ark-std", +] + +[[package]] +name = "ark-std" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5b856a29bea7b810858116a596beee3d20fc4c5aeb240e8e5a8bca4845a470" +dependencies = [ + "rand 0.7.3", + "rand_xorshift", +] + [[package]] name = "arrayvec" version = "0.4.12" @@ -88,6 +312,17 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + [[package]] name = "blake2-rfc_bellman_edition" version = "0.0.1" @@ -108,7 +343,7 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array", + "generic-array 0.12.3", ] [[package]] @@ -184,6 +419,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + [[package]] name = "csv" version = "1.1.3" @@ -206,13 +451,33 @@ dependencies = [ "memchr", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + [[package]] name = "digest" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array", + "generic-array 0.12.3", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", ] [[package]] @@ -278,7 +543,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50c052fa6d4c2f12305ec364bfb8ef884836f3f61ea015b202372ff996d1ac4b" dependencies = [ - "num-bigint", + "num-bigint 0.2.6", "num-integer", "num-traits 0.2.12", "proc-macro2 1.0.18", @@ -391,6 +656,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -421,6 +696,15 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + [[package]] name = "hermit-abi" version = "0.1.15" @@ -531,11 +815,22 @@ dependencies = [ "serde", ] +[[package]] +name = "num-bigint" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e97c412795abf6c24ba30055a8f20642ea57ca12875220b854cfa501bf1e48" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.12", +] + [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", "num-traits 0.2.12", @@ -588,9 +883,9 @@ checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" [[package]] name = "once_cell" -version = "1.4.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -598,6 +893,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "pairing_ce" version = "0.21.1" @@ -685,6 +986,12 @@ dependencies = [ "syn 1.0.34", ] +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + [[package]] name = "pin-utils" version = "0.1.0" @@ -802,6 +1109,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_xorshift" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -854,6 +1170,15 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.5" @@ -869,7 +1194,7 @@ dependencies = [ "bellman_ce", "blake2-rfc_bellman_edition", "byteorder", - "digest", + "digest 0.8.1", "rand 0.4.6", "serde", "serde_derive", @@ -877,6 +1202,24 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "1.0.114" @@ -915,9 +1258,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" dependencies = [ "block-buffer", - "digest", + "digest 0.8.1", "fake-simd", - "opaque-debug", + "opaque-debug 0.2.3", ] [[package]] @@ -927,9 +1270,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" dependencies = [ "block-buffer", - "digest", + "digest 0.8.1", "fake-simd", - "opaque-debug", + "opaque-debug 0.2.3", ] [[package]] @@ -947,6 +1290,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "syn" version = "0.15.44" @@ -999,6 +1348,35 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tracing" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "tracing-core" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca517f43f0fb96e0c3072ed5c275fe5eece87e8cb52f4a77b69226d3b1c9df8" + [[package]] name = "typed-arena" version = "1.7.0" @@ -1041,6 +1419,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + [[package]] name = "void" version = "1.0.2" @@ -1147,9 +1531,30 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "zeroize" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "377db0846015f7ae377174787dd452e1c5f5a9050bc6f954911d01f116daa0cd" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c1e130bebaeab2f23886bf9acbaca14b092408c452543c857f66399cd6dab1" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", + "synstructure", +] + [[package]] name = "zokrates_abi" -version = "0.1.4" +version = "0.1.5" dependencies = [ "serde", "serde_derive", @@ -1164,7 +1569,7 @@ version = "0.1.0" [[package]] name = "zokrates_core" -version = "0.6.4" +version = "0.6.6" dependencies = [ "bellman_ce", "bincode", @@ -1174,8 +1579,9 @@ dependencies = [ "getrandom 0.2.2", "hex", "lazy_static", + "log", "num", - "num-bigint", + "num-bigint 0.2.6", "pairing_ce", "rand 0.4.6", "rand 0.7.3", @@ -1192,10 +1598,20 @@ dependencies = [ [[package]] name = "zokrates_embed" -version = "0.1.3" +version = "0.1.4" dependencies = [ + "ark-bls12-377", + "ark-bw6-761", + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-gm17", + "ark-r1cs-std", + "ark-relations", + "ark-std", "bellman_ce", "sapling-crypto_ce", + "zokrates_field", ] [[package]] @@ -1205,7 +1621,7 @@ dependencies = [ "bellman_ce", "bincode", "lazy_static", - "num-bigint", + "num-bigint 0.2.6", "num-integer", "num-traits 0.2.12", "serde", @@ -1216,7 +1632,7 @@ dependencies = [ [[package]] name = "zokrates_js" -version = "1.0.33" +version = "1.0.35" dependencies = [ "console_error_panic_hook", "js-sys", @@ -1231,7 +1647,7 @@ dependencies = [ [[package]] name = "zokrates_parser" -version = "0.2.2" +version = "0.2.4" dependencies = [ "pest", "pest_derive", @@ -1239,7 +1655,7 @@ dependencies = [ [[package]] name = "zokrates_pest_ast" -version = "0.2.2" +version = "0.2.3" dependencies = [ "from-pest", "lazy_static", diff --git a/zokrates_js/src/lib.rs b/zokrates_js/src/lib.rs index bad1275d8..8abe97c9f 100644 --- a/zokrates_js/src/lib.rs +++ b/zokrates_js/src/lib.rs @@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*; use zokrates_abi::{parse_strict, Decode, Encode, Inputs}; use zokrates_common::Resolver; use zokrates_core::compile::{ - compile as core_compile, CompilationArtifacts, CompileConfig, CompileError, + compile as core_compile, BinCompilationArtifacts, CompileConfig, CompileError, }; use zokrates_core::imports::Error; use zokrates_core::ir; @@ -106,7 +106,7 @@ pub fn compile( let config: CompileConfig = config.into_serde().unwrap_or_default(); let fmt_error = |e: &CompileError| format!("{}:{}", e.file().display(), e.value()); - let artifacts: CompilationArtifacts = core_compile( + let artifacts: BinCompilationArtifacts> = core_compile( source.as_string().unwrap(), PathBuf::from(location.as_string().unwrap()), Some(&resolver),