From 5b20449a9100ddbeb4211ba65e631cd6a9d6f0b6 Mon Sep 17 00:00:00 2001 From: schaeff Date: Thu, 22 Aug 2019 13:48:34 +0200 Subject: [PATCH 01/27] extract testing into test crate --- Cargo.lock | 9 ++ Cargo.toml | 1 + zokrates_stdlib/Cargo.toml | 10 +- zokrates_stdlib/build.rs | 38 +----- zokrates_stdlib/tests/integration.rs | 6 - zokrates_stdlib/tests/test_template | 44 ------- zokrates_stdlib/tests/utils/mod.rs | 68 ----------- zokrates_test/Cargo.toml | 17 +++ zokrates_test/src/lib.rs | 165 +++++++++++++++++++++++++++ zokrates_test/test_template | 9 ++ 10 files changed, 206 insertions(+), 161 deletions(-) delete mode 100644 zokrates_stdlib/tests/test_template delete mode 100644 zokrates_stdlib/tests/utils/mod.rs create mode 100644 zokrates_test/Cargo.toml create mode 100644 zokrates_test/src/lib.rs create mode 100644 zokrates_test/test_template diff --git a/Cargo.lock b/Cargo.lock index 1cda6472..f1af15f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2311,6 +2311,7 @@ dependencies = [ "zokrates_embed 0.1.0", "zokrates_field 0.3.3", "zokrates_pest_ast 0.1.2", + "zokrates_test 0.1.0", ] [[package]] @@ -2379,6 +2380,14 @@ dependencies = [ [[package]] name = "zokrates_stdlib" version = "0.1.3" +dependencies = [ + "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zokrates_test 0.1.0", +] + +[[package]] +name = "zokrates_test" +version = "0.1.0" dependencies = [ "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index eaa81f0e..99a03964 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ members = [ "zokrates_github_resolver", "zokrates_stdlib", "zokrates_embed", + "zokrates_test", ] \ No newline at end of file diff --git a/zokrates_stdlib/Cargo.toml b/zokrates_stdlib/Cargo.toml index c2a6743b..1c86b1d2 100644 --- a/zokrates_stdlib/Cargo.toml +++ b/zokrates_stdlib/Cargo.toml @@ -5,13 +5,9 @@ authors = ["Stefan Deml ", "schaeff "] edition = "2018" [dev-dependencies] -zokrates_field = { version = "0.3", path = "../zokrates_field" } -zokrates_core = { version = "0.3", path = "../zokrates_core" } -zokrates_fs_resolver = { version = "0.4", path = "../zokrates_fs_resolver" } -serde = "1.0" -serde_derive = "1.0" -serde_json = "1.0" +zokrates_test = { version = "0.1", path = "../zokrates_test" } [build-dependencies] -glob = "0.3.0" fs_extra = "1.1.0" +zokrates_test = { version = "0.1", path = "../zokrates_test" } + diff --git a/zokrates_stdlib/build.rs b/zokrates_stdlib/build.rs index 1c5857f1..2486e116 100644 --- a/zokrates_stdlib/build.rs +++ b/zokrates_stdlib/build.rs @@ -4,13 +4,14 @@ use std::env; use std::fs::File; use std::io::{BufWriter, Write}; use std::path::{Path, PathBuf}; +use zokrates_test::write_tests; fn main() { // export stdlib folder to OUT_DIR export_stdlib(); // generate tests - write_tests(); + write_tests(Path::new("./tests/bench/")); } fn export_stdlib() { @@ -19,38 +20,3 @@ fn export_stdlib() { options.overwrite = true; copy_items(&vec!["stdlib"], out_dir, &options).unwrap(); } - -fn write_tests() { - use glob::glob; - - let out_dir = env::var("OUT_DIR").unwrap(); - let destination = Path::new(&out_dir).join("tests.rs"); - let test_file = File::create(&destination).unwrap(); - let mut writer = BufWriter::new(test_file); - - for directory in glob("./tests/bench/**/*.json").unwrap() { - write_test(&mut writer, &directory.unwrap()); - } -} - -fn write_test(test_file: &mut W, test_path: &PathBuf) { - let test_name = format!( - "test_{}", - test_path - .strip_prefix("tests/bench") - .unwrap() - .display() - .to_string() - .replace("/", "_") - .replace(".json", "") - .replace(".", "") - ); - - write!( - test_file, - include_str!("./tests/test_template"), - test_name = test_name, - test_path = test_path.display() - ) - .unwrap(); -} diff --git a/zokrates_stdlib/tests/integration.rs b/zokrates_stdlib/tests/integration.rs index ec1b3acc..0471b27a 100644 --- a/zokrates_stdlib/tests/integration.rs +++ b/zokrates_stdlib/tests/integration.rs @@ -1,7 +1 @@ -#[macro_use] -extern crate serde_derive; - -#[macro_use] -mod utils; - include!(concat!(env!("OUT_DIR"), "/tests.rs")); diff --git a/zokrates_stdlib/tests/test_template b/zokrates_stdlib/tests/test_template deleted file mode 100644 index af48b620..00000000 --- a/zokrates_stdlib/tests/test_template +++ /dev/null @@ -1,44 +0,0 @@ -#[test] -#[ignore] -#[allow(non_snake_case)] -fn {test_name}() {{ - use zokrates_field::field::{{Field, FieldPrime}}; - use std::path::PathBuf; - use zokrates_fs_resolver::resolve; - use zokrates_core::compile::compile; - use std::fs::File; - use std::io::{{BufReader, Read}}; - - let t: utils::Tests = serde_json::from_reader( - BufReader::new( - File::open( - &PathBuf::from("{test_path}") - ).unwrap() - ) - ).unwrap(); - - let mut code_reader = BufReader::new(File::open(&t.entry_point).unwrap()); - - let bin = compile( - &mut code_reader, - Some(t.entry_point.parent().unwrap().to_str().unwrap().to_string()), - Some(resolve) - ).unwrap(); - - for test in t.tests.into_iter() {{ - let input = &test.input.values; - let output = bin.execute(&input.iter().map(|v| FieldPrime::try_from_dec_str(&v.clone()).unwrap()).collect()); - - match utils::compare(output, test.output) {{ - Err(e) => {{ - let mut code = File::open(&t.entry_point).unwrap(); - let mut s = String::new(); - code.read_to_string(&mut s).unwrap(); - let context = format!("\n{{}}\nCalled with input ({{}})\n", s, input.iter().map(|i| format!("{{}}", i)).collect::>().join(", ")); - panic!("{{}}{{}}", context, e) - }}, - Ok(..) => {{}} - }}; - }} -}} - diff --git a/zokrates_stdlib/tests/utils/mod.rs b/zokrates_stdlib/tests/utils/mod.rs deleted file mode 100644 index 11ff8911..00000000 --- a/zokrates_stdlib/tests/utils/mod.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::path::PathBuf; -use zokrates_core::ir; -use zokrates_field::field::{Field, FieldPrime}; - -#[derive(Serialize, Deserialize)] -pub struct Tests { - pub entry_point: PathBuf, - pub tests: Vec, -} - -#[derive(Serialize, Deserialize)] -pub struct Input { - pub values: Vec, -} - -#[derive(Serialize, Deserialize)] -pub struct Test { - pub input: Input, - pub output: TestResult, -} - -pub type TestResult = Result; - -#[derive(PartialEq, Debug)] -pub struct ComparableResult(Result, ir::Error>); - -#[derive(Serialize, Deserialize)] -pub struct Output { - values: Vec, -} - -type Val = String; - -impl From> for ComparableResult { - fn from(r: ir::ExecutionResult) -> ComparableResult { - ComparableResult(r.map(|v| v.return_values())) - } -} - -impl From for ComparableResult { - fn from(r: TestResult) -> ComparableResult { - ComparableResult(r.map(|v| { - v.values - .iter() - .map(|v| FieldPrime::try_from_dec_str(v).unwrap()) - .collect() - })) - } -} - -pub fn compare( - result: ir::ExecutionResult, - expected: TestResult, -) -> Result<(), String> { - // extract outputs from result - let result = ComparableResult::from(result); - // deserialize expected result - let expected = ComparableResult::from(expected); - - if result != expected { - return Err(format!( - "Expected {:?} but found {:?}", - expected.0, result.0 - )); - } - - Ok(()) -} diff --git a/zokrates_test/Cargo.toml b/zokrates_test/Cargo.toml new file mode 100644 index 00000000..9adb9f2f --- /dev/null +++ b/zokrates_test/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "zokrates_test" +version = "0.1.0" +authors = ["schaeff "] +edition = "2018" + +[dependencies] +zokrates_field = { version = "0.3", path = "../zokrates_field" } +zokrates_core = { version = "0.3", path = "../zokrates_core" } +zokrates_fs_resolver = { version = "0.4", path = "../zokrates_fs_resolver" } +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0" +glob = "0.3.0" +fs_extra = "1.1.0" + +[lib] diff --git a/zokrates_test/src/lib.rs b/zokrates_test/src/lib.rs new file mode 100644 index 00000000..847b27a6 --- /dev/null +++ b/zokrates_test/src/lib.rs @@ -0,0 +1,165 @@ +#[macro_use] +extern crate serde_derive; + +use std::path::PathBuf; +use zokrates_core::ir; +use zokrates_field::field::{Field, FieldPrime}; + +#[derive(Serialize, Deserialize)] +struct Tests { + pub entry_point: PathBuf, + pub tests: Vec, +} + +#[derive(Serialize, Deserialize)] +struct Input { + pub values: Vec, +} + +#[derive(Serialize, Deserialize)] +struct Test { + pub input: Input, + pub output: TestResult, +} + +type TestResult = Result; + +#[derive(PartialEq, Debug)] +struct ComparableResult(Result, ir::Error>); + +#[derive(Serialize, Deserialize)] +struct Output { + values: Vec, +} + +type Val = String; + +impl From> for ComparableResult { + fn from(r: ir::ExecutionResult) -> ComparableResult { + ComparableResult(r.map(|v| v.return_values())) + } +} + +impl From for ComparableResult { + fn from(r: TestResult) -> ComparableResult { + ComparableResult(r.map(|v| { + v.values + .iter() + .map(|v| FieldPrime::try_from_dec_str(v).unwrap()) + .collect() + })) + } +} + +fn compare(result: ir::ExecutionResult, expected: TestResult) -> Result<(), String> { + // extract outputs from result + let result = ComparableResult::from(result); + // deserialize expected result + let expected = ComparableResult::from(expected); + + if result != expected { + return Err(format!( + "Expected {:?} but found {:?}", + expected.0, result.0 + )); + } + + Ok(()) +} + +use std::io::{BufReader, Read}; +use zokrates_core::compile::compile; +use zokrates_fs_resolver::resolve; + +pub fn test_inner(test_path: &str) { + let t: Tests = + serde_json::from_reader(BufReader::new(File::open(Path::new(test_path)).unwrap())).unwrap(); + + let mut code_reader = BufReader::new(File::open(&t.entry_point).unwrap()); + + let bin = compile( + &mut code_reader, + Some( + t.entry_point + .parent() + .unwrap() + .to_str() + .unwrap() + .to_string(), + ), + Some(resolve), + ) + .unwrap(); + + for test in t.tests.into_iter() { + let input = &test.input.values; + let output = bin.execute( + &input + .iter() + .map(|v| FieldPrime::try_from_dec_str(&v.clone()).unwrap()) + .collect(), + ); + + match compare(output, test.output) { + Err(e) => { + let mut code = File::open(&t.entry_point).unwrap(); + let mut s = String::new(); + code.read_to_string(&mut s).unwrap(); + let context = format!( + "\n{}\nCalled with input ({})\n", + s, + input + .iter() + .map(|i| format!("{}", i)) + .collect::>() + .join(", ") + ); + panic!("{}{}", context, e) + } + Ok(..) => {} + }; + } +} + +use std::env; +use std::fs::File; +use std::io::{BufWriter, Write}; +use std::path::Path; + +pub fn write_tests(base: &Path) { + use glob::glob; + + let out_dir = env::var("OUT_DIR").unwrap(); + let destination = Path::new(&out_dir).join("tests.rs"); + let test_file = File::create(&destination).unwrap(); + let mut writer = BufWriter::new(test_file); + + for p in glob(base.join("**/*.json").to_str().unwrap()).unwrap() { + write_test(&mut writer, &p.unwrap(), &base); + } +} + +fn write_test(test_file: &mut W, test_path: &Path, base_path: &Path) { + println!("{:?}", test_path); + println!("{:?}", base_path); + + let test_name = format!( + "test_{}", + test_path + .strip_prefix(base_path.strip_prefix("./").unwrap()) + .unwrap() + .display() + .to_string() + .replace("/", "_") + .replace(".json", "") + .replace(".", "") + ); + + write!( + test_file, + include_str!("../test_template"), + test_name = test_name, + test_path = test_path.display() + ) + .unwrap(); +} diff --git a/zokrates_test/test_template b/zokrates_test/test_template new file mode 100644 index 00000000..7a9c9f79 --- /dev/null +++ b/zokrates_test/test_template @@ -0,0 +1,9 @@ +#[test] +#[ignore] +#[allow(non_snake_case)] +fn {test_name}() {{ + use zokrates_test::test_inner; + + test_inner("{test_path}") +}} + From 3b228385f6dae87ff611935f96c20515a51a2f13 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 11 Sep 2019 20:03:12 +0200 Subject: [PATCH 02/27] add comments --- zokrates_core/src/absy/from_ast.rs | 4 ++++ zokrates_core/src/semantics.rs | 2 ++ zokrates_core/src/typed_absy/mod.rs | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 9d48c1c0..6fa3a135 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -451,6 +451,10 @@ impl<'ast, T: Field> From> for absy::ExpressionNod let id_str = expression.id.span.as_str(); let id = absy::ExpressionNode::from(expression.id); + // pest::PostFixExpression contains an array of "accesses": `a(34)[42]` is represented as `[a, [Call(34), Select(42)]]`, but absy::ExpressionNode + // is recursive, so it is `Select(Call(a, 34), 42)`. We apply this transformation here + + // we start with the id, and we fold the array of accesses by wrapping the current value expression.accesses.into_iter().fold(id, |acc, a| match a { pest::Access::Call(a) => match acc.value { absy::Expression::Identifier(_) => absy::Expression::FunctionCall( diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 3caeb262..c603b544 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -662,7 +662,9 @@ impl<'ast> Checker<'ast> { let size = e.size(); match e.into_inner() { // if we're doing a spread over an inline array, we return the inside of the array: ...[x, y, z] == x, y, z + // this is not strictly needed, but it makes spreads memory linear rather than quadratic ArrayExpressionInner::Value(v) => Ok(v), + // otherwise we return a[0], ..., a[a.size() -1 ] e => Ok((0..size) .map(|i| match &ty { Type::FieldElement => FieldElementExpression::Select( diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 9e2f05fc..319942d2 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -541,6 +541,11 @@ pub enum BooleanExpression<'ast, T: Field> { ), } +/// An expression of type `array` +/// # Remarks +/// * Contrary to basic types which represented as enums, we wrap an enum `ArrayExpressionInner` in a struct in order to keep track of the type (content and size) +/// of the array. Only using an enum would require generics, which would propagate up to TypedExpression which we want to keep simple, hence this "runtime" +/// type checking #[derive(Clone, PartialEq, Hash, Eq)] pub struct ArrayExpression<'ast, T: Field> { size: usize, @@ -593,7 +598,9 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> { } // Downcasts - +// Due to the fact that we keep TypedExpression simple, we end up with ArrayExpressionInner::Value whose elements are any TypedExpression, but we enforce by +// construction that these elements are of the type declared in the corresponding ArrayExpression. As we know this by construction, we can downcast the TypedExpression to the correct type +// ArrayExpression { type: Type::FieldElement, size: 42, inner: [TypedExpression::FieldElement(FieldElementExpression), ...]} <- the fact that inner only contains field elements is not enforced by the rust type system impl<'ast, T: Field> TryFrom> for FieldElementExpression<'ast, T> { type Error = (); From 9521d5822a232e1da20447ec633abc2d59a41366 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 17 Sep 2019 12:10:59 +0200 Subject: [PATCH 03/27] create zokrates_core_test crate and move zokrates_core tests there --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + zokrates_core/tests/integration.rs | 17 ----------------- zokrates_core_test/Cargo.toml | 14 ++++++++++++++ zokrates_core_test/build.rs | 7 +++++++ zokrates_core_test/src/lib.rs | 1 + .../tests/bench/add.code | 0 .../tests/bench/add.json | 1 + .../tests/bench/array_if.code | 0 .../tests/bench/array_if.json | 1 + .../tests/bench/assert_one.code | 0 .../tests/bench/assert_one.json | 1 + .../tests/bench/fact_up_to_4.code | 0 .../tests/bench/fact_up_to_4.json | 1 + .../tests/bench/split.code | 0 .../tests/bench/split.json | 1 + .../tests/bench/spread_slice.code | 0 .../tests/bench/spread_slice.json | 1 + zokrates_core_test/tests/integration.rs | 1 + .../tests/utils/mod.rs | 0 20 files changed, 37 insertions(+), 17 deletions(-) delete mode 100644 zokrates_core/tests/integration.rs create mode 100644 zokrates_core_test/Cargo.toml create mode 100644 zokrates_core_test/build.rs create mode 100644 zokrates_core_test/src/lib.rs rename {zokrates_core => zokrates_core_test}/tests/bench/add.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/add.json (87%) rename {zokrates_core => zokrates_core_test}/tests/bench/array_if.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/array_if.json (85%) rename {zokrates_core => zokrates_core_test}/tests/bench/assert_one.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/assert_one.json (78%) rename {zokrates_core => zokrates_core_test}/tests/bench/fact_up_to_4.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/fact_up_to_4.json (91%) rename {zokrates_core => zokrates_core_test}/tests/bench/split.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/split.json (99%) rename {zokrates_core => zokrates_core_test}/tests/bench/spread_slice.code (100%) rename {zokrates_core => zokrates_core_test}/tests/bench/spread_slice.json (79%) create mode 100644 zokrates_core_test/tests/integration.rs rename {zokrates_core => zokrates_core_test}/tests/utils/mod.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f1af15f3..5126aede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2311,6 +2311,13 @@ dependencies = [ "zokrates_embed 0.1.0", "zokrates_field 0.3.3", "zokrates_pest_ast 0.1.2", +] + +[[package]] +name = "zokrates_core_test" +version = "0.1.0" +dependencies = [ + "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "zokrates_test 0.1.0", ] diff --git a/Cargo.toml b/Cargo.toml index 99a03964..bf1ca2ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ members = [ "zokrates_stdlib", "zokrates_embed", "zokrates_test", + "zokrates_core_test", ] \ No newline at end of file diff --git a/zokrates_core/tests/integration.rs b/zokrates_core/tests/integration.rs deleted file mode 100644 index 5feda566..00000000 --- a/zokrates_core/tests/integration.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern crate serde_json; -#[macro_use] -extern crate serde_derive; -extern crate zokrates_core; -extern crate zokrates_field; - -#[macro_use] -mod utils; - -zokrates_test! { - add, - assert_one, - array_if, - fact_up_to_4, - split, - spread_slice, -} diff --git a/zokrates_core_test/Cargo.toml b/zokrates_core_test/Cargo.toml new file mode 100644 index 00000000..f6908f14 --- /dev/null +++ b/zokrates_core_test/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "zokrates_core_test" +version = "0.1.0" +authors = ["schaeff "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dev-dependencies] +zokrates_test = { version = "0.1", path = "../zokrates_test" } + +[build-dependencies] +fs_extra = "1.1.0" +zokrates_test = { version = "0.1", path = "../zokrates_test" } diff --git a/zokrates_core_test/build.rs b/zokrates_core_test/build.rs new file mode 100644 index 00000000..a8370471 --- /dev/null +++ b/zokrates_core_test/build.rs @@ -0,0 +1,7 @@ +use std::path::Path; +use zokrates_test::write_tests; + +fn main() { + // generate tests + write_tests(Path::new("./tests/bench/")); +} diff --git a/zokrates_core_test/src/lib.rs b/zokrates_core_test/src/lib.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/zokrates_core_test/src/lib.rs @@ -0,0 +1 @@ + diff --git a/zokrates_core/tests/bench/add.code b/zokrates_core_test/tests/bench/add.code similarity index 100% rename from zokrates_core/tests/bench/add.code rename to zokrates_core_test/tests/bench/add.code diff --git a/zokrates_core/tests/bench/add.json b/zokrates_core_test/tests/bench/add.json similarity index 87% rename from zokrates_core/tests/bench/add.json rename to zokrates_core_test/tests/bench/add.json index f7407d67..11811aeb 100644 --- a/zokrates_core/tests/bench/add.json +++ b/zokrates_core_test/tests/bench/add.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/add.code", "tests": [ { "input": { diff --git a/zokrates_core/tests/bench/array_if.code b/zokrates_core_test/tests/bench/array_if.code similarity index 100% rename from zokrates_core/tests/bench/array_if.code rename to zokrates_core_test/tests/bench/array_if.code diff --git a/zokrates_core/tests/bench/array_if.json b/zokrates_core_test/tests/bench/array_if.json similarity index 85% rename from zokrates_core/tests/bench/array_if.json rename to zokrates_core_test/tests/bench/array_if.json index 2351274a..95e7a6fa 100644 --- a/zokrates_core/tests/bench/array_if.json +++ b/zokrates_core_test/tests/bench/array_if.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/array_if.code", "tests": [ { "input": { diff --git a/zokrates_core/tests/bench/assert_one.code b/zokrates_core_test/tests/bench/assert_one.code similarity index 100% rename from zokrates_core/tests/bench/assert_one.code rename to zokrates_core_test/tests/bench/assert_one.code diff --git a/zokrates_core/tests/bench/assert_one.json b/zokrates_core_test/tests/bench/assert_one.json similarity index 78% rename from zokrates_core/tests/bench/assert_one.json rename to zokrates_core_test/tests/bench/assert_one.json index 5709a87f..010f5a5f 100644 --- a/zokrates_core/tests/bench/assert_one.json +++ b/zokrates_core_test/tests/bench/assert_one.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/assert_one.code", "tests": [ { "input": { diff --git a/zokrates_core/tests/bench/fact_up_to_4.code b/zokrates_core_test/tests/bench/fact_up_to_4.code similarity index 100% rename from zokrates_core/tests/bench/fact_up_to_4.code rename to zokrates_core_test/tests/bench/fact_up_to_4.code diff --git a/zokrates_core/tests/bench/fact_up_to_4.json b/zokrates_core_test/tests/bench/fact_up_to_4.json similarity index 91% rename from zokrates_core/tests/bench/fact_up_to_4.json rename to zokrates_core_test/tests/bench/fact_up_to_4.json index 64defc31..51765f21 100644 --- a/zokrates_core/tests/bench/fact_up_to_4.json +++ b/zokrates_core_test/tests/bench/fact_up_to_4.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/fact_up_to_4.code", "tests": [ { "input": { diff --git a/zokrates_core/tests/bench/split.code b/zokrates_core_test/tests/bench/split.code similarity index 100% rename from zokrates_core/tests/bench/split.code rename to zokrates_core_test/tests/bench/split.code diff --git a/zokrates_core/tests/bench/split.json b/zokrates_core_test/tests/bench/split.json similarity index 99% rename from zokrates_core/tests/bench/split.json rename to zokrates_core_test/tests/bench/split.json index 09b22093..57b3e07d 100644 --- a/zokrates_core/tests/bench/split.json +++ b/zokrates_core_test/tests/bench/split.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/split.code", "tests": [ { "input": { diff --git a/zokrates_core/tests/bench/spread_slice.code b/zokrates_core_test/tests/bench/spread_slice.code similarity index 100% rename from zokrates_core/tests/bench/spread_slice.code rename to zokrates_core_test/tests/bench/spread_slice.code diff --git a/zokrates_core/tests/bench/spread_slice.json b/zokrates_core_test/tests/bench/spread_slice.json similarity index 79% rename from zokrates_core/tests/bench/spread_slice.json rename to zokrates_core_test/tests/bench/spread_slice.json index 107996fb..2939b7ea 100644 --- a/zokrates_core/tests/bench/spread_slice.json +++ b/zokrates_core_test/tests/bench/spread_slice.json @@ -1,4 +1,5 @@ { + "entry_point": "./tests/bench/spread_slice.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/integration.rs b/zokrates_core_test/tests/integration.rs new file mode 100644 index 00000000..0471b27a --- /dev/null +++ b/zokrates_core_test/tests/integration.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/tests.rs")); diff --git a/zokrates_core/tests/utils/mod.rs b/zokrates_core_test/tests/utils/mod.rs similarity index 100% rename from zokrates_core/tests/utils/mod.rs rename to zokrates_core_test/tests/utils/mod.rs From 6a524cec69ebc52b6b7251699d2e9d4e39f0031a Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 17 Sep 2019 12:24:24 +0200 Subject: [PATCH 04/27] fix warnings --- zokrates_stdlib/build.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zokrates_stdlib/build.rs b/zokrates_stdlib/build.rs index 2486e116..33d77ca3 100644 --- a/zokrates_stdlib/build.rs +++ b/zokrates_stdlib/build.rs @@ -1,9 +1,7 @@ use fs_extra::copy_items; use fs_extra::dir::CopyOptions; use std::env; -use std::fs::File; -use std::io::{BufWriter, Write}; -use std::path::{Path, PathBuf}; +use std::path::Path; use zokrates_test::write_tests; fn main() { From 3b6c7bddf77fd40bec2ec585c1095c4725af2eda Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 17 Sep 2019 13:08:00 +0200 Subject: [PATCH 05/27] don't ignore tests --- zokrates_test/test_template | 1 - 1 file changed, 1 deletion(-) diff --git a/zokrates_test/test_template b/zokrates_test/test_template index 7a9c9f79..85716cb8 100644 --- a/zokrates_test/test_template +++ b/zokrates_test/test_template @@ -1,5 +1,4 @@ #[test] -#[ignore] #[allow(non_snake_case)] fn {test_name}() {{ use zokrates_test::test_inner; From b17f34e41506a25bad1a27c4f6f7f574505cd6e3 Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Tue, 17 Sep 2019 18:05:09 +0200 Subject: [PATCH 06/27] Documentation on extended array types --- zokrates_book/src/concepts/types.md | 66 +++++++++++++++++-- zokrates_cli/examples/book/array.code | 3 +- .../examples/book/multidim_array.code | 9 +++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 zokrates_cli/examples/book/multidim_array.code diff --git a/zokrates_book/src/concepts/types.md b/zokrates_book/src/concepts/types.md index cf4a85aa..23264b1a 100644 --- a/zokrates_book/src/concepts/types.md +++ b/zokrates_book/src/concepts/types.md @@ -1,8 +1,10 @@ ## Types -ZoKrates currently exposes three types: +ZoKrates currently exposes two primitive types and a complex array type: -### `field` +### Primitive Types + +#### `field` This is the most basic type in ZoKrates, and it represents a positive integer in `[0, p - 1]` where `p` is a (large) prime number. @@ -14,7 +16,7 @@ While `field` values mostly behave like unsigned integers, one should keep in mi {{#include ../../../zokrates_cli/examples/book/field_overflow.code}} ``` -### `bool` +#### `bool` ZoKrates has limited support for booleans, to the extent that they can only be used as the condition in `if ... else ... endif` expressions. @@ -22,10 +24,64 @@ You can use them for equality checks, inequality checks and inequality checks be Note that while equality checks are cheap, inequality checks should be use wisely as they are orders of magnitude more expensive. -### `field[n]` +### Complex Types -Static arrays of `field` can be instantiated with a constant size, and their elements can be accessed and updated: +#### Arrays + +ZoKrates supports static arrays, i.e., their length needs to be known at compile time. +Arrays can contain elements of any type and have arbitrary dimensions. + +The following examples code shows examples of how to use arrays: ```zokrates {{#include ../../../zokrates_cli/examples/book/array.code}} ``` + +##### Declaration and Initialization +An array is defined by appending `[]` to a type literal representing the type of the array's elements. + +Initialization always needs to happen in the same statement than declaration, unless the array is declared within a function's signature. + +For initialization, a list of comma-separated values is provided within brackets `[]`. + +ZoKrates offers a special shorthand syntax to initialize an array with a constant value: +`[value;repetitions]` + + +The following code provides examples for declaration and initialization: +```zokrates + field[3] a = [1, 2, 3] // initialize a field array with field values + bool[13] b = [false; 13] // initialize a bool array with value false +``` + +##### Multidimensional Arrays + +As an array can contain any type of elements, it can contain arrays again. +There is a special syntax to declare such multi-dimensional arrays, i.e., arrays of arrays. +To declare an array of an inner array, i.e., and array of elements of a type, prepend brackets `[size]` to the declaration of the inner array. +In summary, this leads to the following scheme for array declarations: +`data_type[size of 1st dimension][size of 2nd dimension]`. +Consider the following example: + +```zokrates +{{#include ../../../zokrates_cli/examples/book/multidim_array.code}} +``` + +##### Spreads and Slices +ZoKrates provides some syntactic sugar to retrieve subsets of arrays. + +###### Spreads +The spread operator `...` applied to an copies the elements of an existing array. +This can be used to conveniently compose new arrays, as shown in the following example: +``` +field[3] = [1, 2, 3] +field[4] c = [...a, 4] // initialize an array copying values from `a`, followed by 4 +``` + +###### Slices +An array can also be assigned to by creating a copy of a subset of an existing array. +This operation is called slicing, and the following example shows how to slice in ZoKrates: +``` +field[3] a = [1, 2, 3] +field[2] b = a[1..3] // initialize an array copying a slice from `a` +``` diff --git a/zokrates_cli/examples/book/array.code b/zokrates_cli/examples/book/array.code index b83a1a9a..5f3293fa 100644 --- a/zokrates_cli/examples/book/array.code +++ b/zokrates_cli/examples/book/array.code @@ -1,7 +1,8 @@ def main() -> (field): - field[3] a = [1, 2, 3] // initialize an array with values + field[3] a = [1, 2, 3] // initialize a field array with field values a[2] = 4 // set a member to a value field[4] b = [42; 4] // initialize an array of 4 values all equal to 42 field[4] c = [...a, 4] // initialize an array copying values from `a`, followed by 4 field[2] d = a[1..3] // initialize an array copying a slice from `a` + bool[3] e = [true, true || false, true] // initialize a boolean array return a[0] + b[1] + c[2] diff --git a/zokrates_cli/examples/book/multidim_array.code b/zokrates_cli/examples/book/multidim_array.code new file mode 100644 index 00000000..b39c29ae --- /dev/null +++ b/zokrates_cli/examples/book/multidim_array.code @@ -0,0 +1,9 @@ +def main() -> (field): + + // Array of two elements of array of 3 elements + field[2][3] a = [[1, 2, 3],[4, 5, 6]] + + field[3] b = a[0] // should be [1, 2, 3] + + // allowed access [0..2][0..3] + return a[1][2] \ No newline at end of file From c49a97c154f07324c0f9ef5c6c65b4763be0ea54 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 18 Sep 2019 10:35:39 +0200 Subject: [PATCH 07/27] reverse array declaration dimensions, fix tests --- zokrates_cli/examples/arrays/value.code | 4 ++-- zokrates_core/src/absy/from_ast.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/zokrates_cli/examples/arrays/value.code b/zokrates_cli/examples/arrays/value.code index f1300aa9..d09822b9 100644 --- a/zokrates_cli/examples/arrays/value.code +++ b/zokrates_cli/examples/arrays/value.code @@ -1,10 +1,10 @@ def main() -> (): field[3] a = [1, 2, 3] bool[3] b = [true, true, false] - field[2][3] c = [[1, 2], [3, 4], [5, 6]] + field[3][2] c = [[1, 2], [3, 4], [5, 6]] field[3] aa = [...a] bool[3] bb = [...b] - field[2][3] cc = [...c] + field[3][2] cc = [...c] return \ No newline at end of file diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 6fa3a135..45868143 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -551,6 +551,7 @@ impl<'ast> From> for Type { e.span().as_str() ), }) + .rev() .fold(None, |acc, s| match acc { None => Some(Type::array(inner_type.clone(), s)), Some(acc) => Some(Type::array(acc, s)), @@ -715,11 +716,11 @@ mod tests { ), ( "field[2][3]", - types::Type::Array(box Type::Array(box types::Type::FieldElement, 2), 3), + types::Type::Array(box Type::Array(box types::Type::FieldElement, 3), 2), ), ( "bool[2][3]", - types::Type::Array(box Type::Array(box types::Type::Boolean, 2), 3), + types::Type::Array(box Type::Array(box types::Type::Boolean, 3), 2), ), ]; From 92a969597476afa81cc8a4dc2603e92bb61d038f Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 18 Sep 2019 10:47:17 +0200 Subject: [PATCH 08/27] rename bench to tests --- zokrates_core_test/build.rs | 2 +- .../tests/{bench => tests}/add.code | 0 .../tests/{bench => tests}/add.json | 2 +- .../tests/{bench => tests}/array_if.code | 0 .../tests/{bench => tests}/array_if.json | 2 +- .../tests/{bench => tests}/assert_one.code | 0 .../tests/{bench => tests}/assert_one.json | 2 +- .../tests/{bench => tests}/fact_up_to_4.code | 0 .../tests/{bench => tests}/fact_up_to_4.json | 2 +- .../tests/{bench => tests}/split.code | 0 .../tests/{bench => tests}/split.json | 2 +- .../tests/{bench => tests}/spread_slice.code | 0 .../tests/{bench => tests}/spread_slice.json | 2 +- zokrates_core_test/tests/utils/mod.rs | 121 ------------------ zokrates_stdlib/build.rs | 2 +- .../tests/{bench => tests}/and.json | 0 .../{bench => tests}/ecc/edwardsAdd.code | 0 .../{bench => tests}/ecc/edwardsAdd.json | 2 +- .../{bench => tests}/ecc/edwardsCompress.code | 0 .../{bench => tests}/ecc/edwardsCompress.json | 2 +- .../{bench => tests}/ecc/edwardsOnCurve.code | 0 .../{bench => tests}/ecc/edwardsOnCurve.json | 2 +- .../ecc/edwardsOrderCheck.code | 0 .../ecc/edwardsOrderCheck.json | 2 +- .../ecc/edwardsScalarMult.code | 0 .../ecc/edwardsScalarMult.json | 2 +- .../ecc/proofOfOwnership.code | 0 .../ecc/proofOfOwnership.json | 2 +- .../hashes/pedersen/512bit.code | 0 .../hashes/pedersen/512bit.json | 2 +- .../hashes/pedersen/6bit.code | 0 .../hashes/pedersen/6bit.json | 2 +- .../hashes/sha256/512bit.code | 0 .../hashes/sha256/512bit.json | 2 +- .../hashes/sha256/512bitPacked.code | 0 .../hashes/sha256/512bitPacked.json | 0 .../hashes/sha256/512bitPacked2.json | 2 +- .../hashes/sha256/512bitPadded.code | 0 .../hashes/sha256/512bitPadded.json | 2 +- .../hashes/utils/256bitsDirectionHelper.code | 0 .../hashes/utils/256bitsDirectionHelper.json | 2 +- .../tests/{bench => tests}/or.json | 0 .../signatures/verifyEddsa.code | 0 .../signatures/verifyEddsa.json | 2 +- .../utils/multiplexer/256bit.code | 0 .../utils/multiplexer/256bit.json | 2 +- .../utils/multiplexer/2bit.code | 0 .../utils/multiplexer/2bit.json | 2 +- .../utils/multiplexer/lookup1bit.code | 0 .../utils/multiplexer/lookup1bit.json | 2 +- .../utils/multiplexer/lookup2bit.code | 0 .../utils/multiplexer/lookup2bit.json | 2 +- .../utils/multiplexer/lookup3bitSigned.code | 0 .../utils/multiplexer/lookup3bitSigned.json | 2 +- .../utils/pack/nonStrictUnpack256.code | 0 .../utils/pack/nonStrictUnpack256.json | 2 +- .../{bench => tests}/utils/pack/pack128.code | 0 .../{bench => tests}/utils/pack/pack128.json | 2 +- .../utils/pack/unpack128.code | 0 .../utils/pack/unpack128.json | 2 +- zokrates_test/src/lib.rs | 3 +- 61 files changed, 31 insertions(+), 151 deletions(-) rename zokrates_core_test/tests/{bench => tests}/add.code (100%) rename zokrates_core_test/tests/{bench => tests}/add.json (87%) rename zokrates_core_test/tests/{bench => tests}/array_if.code (100%) rename zokrates_core_test/tests/{bench => tests}/array_if.json (85%) rename zokrates_core_test/tests/{bench => tests}/assert_one.code (100%) rename zokrates_core_test/tests/{bench => tests}/assert_one.json (78%) rename zokrates_core_test/tests/{bench => tests}/fact_up_to_4.code (100%) rename zokrates_core_test/tests/{bench => tests}/fact_up_to_4.json (91%) rename zokrates_core_test/tests/{bench => tests}/split.code (100%) rename zokrates_core_test/tests/{bench => tests}/split.json (99%) rename zokrates_core_test/tests/{bench => tests}/spread_slice.code (100%) rename zokrates_core_test/tests/{bench => tests}/spread_slice.json (79%) delete mode 100644 zokrates_core_test/tests/utils/mod.rs rename zokrates_stdlib/tests/{bench => tests}/and.json (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsAdd.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsAdd.json (69%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsCompress.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsCompress.json (67%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsOnCurve.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsOnCurve.json (68%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsOrderCheck.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsOrderCheck.json (67%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsScalarMult.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/edwardsScalarMult.json (67%) rename zokrates_stdlib/tests/{bench => tests}/ecc/proofOfOwnership.code (100%) rename zokrates_stdlib/tests/{bench => tests}/ecc/proofOfOwnership.json (67%) rename zokrates_stdlib/tests/{bench => tests}/hashes/pedersen/512bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/pedersen/512bit.json (66%) rename zokrates_stdlib/tests/{bench => tests}/hashes/pedersen/6bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/pedersen/6bit.json (67%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bit.json (67%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bitPacked.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bitPacked.json (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bitPacked2.json (65%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bitPadded.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/sha256/512bitPadded.json (65%) rename zokrates_stdlib/tests/{bench => tests}/hashes/utils/256bitsDirectionHelper.code (100%) rename zokrates_stdlib/tests/{bench => tests}/hashes/utils/256bitsDirectionHelper.json (67%) rename zokrates_stdlib/tests/{bench => tests}/or.json (100%) rename zokrates_stdlib/tests/{bench => tests}/signatures/verifyEddsa.code (100%) rename zokrates_stdlib/tests/{bench => tests}/signatures/verifyEddsa.json (66%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/256bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/256bit.json (65%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/2bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/2bit.json (66%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup1bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup1bit.json (66%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup2bit.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup2bit.json (66%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup3bitSigned.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/multiplexer/lookup3bitSigned.json (67%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/nonStrictUnpack256.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/nonStrictUnpack256.json (66%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/pack128.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/pack128.json (68%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/unpack128.code (100%) rename zokrates_stdlib/tests/{bench => tests}/utils/pack/unpack128.json (67%) diff --git a/zokrates_core_test/build.rs b/zokrates_core_test/build.rs index a8370471..73362299 100644 --- a/zokrates_core_test/build.rs +++ b/zokrates_core_test/build.rs @@ -3,5 +3,5 @@ use zokrates_test::write_tests; fn main() { // generate tests - write_tests(Path::new("./tests/bench/")); + write_tests("./tests/tests/"); } diff --git a/zokrates_core_test/tests/bench/add.code b/zokrates_core_test/tests/tests/add.code similarity index 100% rename from zokrates_core_test/tests/bench/add.code rename to zokrates_core_test/tests/tests/add.code diff --git a/zokrates_core_test/tests/bench/add.json b/zokrates_core_test/tests/tests/add.json similarity index 87% rename from zokrates_core_test/tests/bench/add.json rename to zokrates_core_test/tests/tests/add.json index 11811aeb..76935916 100644 --- a/zokrates_core_test/tests/bench/add.json +++ b/zokrates_core_test/tests/tests/add.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/add.code", + "entry_point": "./tests/tests/add.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/bench/array_if.code b/zokrates_core_test/tests/tests/array_if.code similarity index 100% rename from zokrates_core_test/tests/bench/array_if.code rename to zokrates_core_test/tests/tests/array_if.code diff --git a/zokrates_core_test/tests/bench/array_if.json b/zokrates_core_test/tests/tests/array_if.json similarity index 85% rename from zokrates_core_test/tests/bench/array_if.json rename to zokrates_core_test/tests/tests/array_if.json index 95e7a6fa..fcb35110 100644 --- a/zokrates_core_test/tests/bench/array_if.json +++ b/zokrates_core_test/tests/tests/array_if.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/array_if.code", + "entry_point": "./tests/tests/array_if.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/bench/assert_one.code b/zokrates_core_test/tests/tests/assert_one.code similarity index 100% rename from zokrates_core_test/tests/bench/assert_one.code rename to zokrates_core_test/tests/tests/assert_one.code diff --git a/zokrates_core_test/tests/bench/assert_one.json b/zokrates_core_test/tests/tests/assert_one.json similarity index 78% rename from zokrates_core_test/tests/bench/assert_one.json rename to zokrates_core_test/tests/tests/assert_one.json index 010f5a5f..9a7d4ed4 100644 --- a/zokrates_core_test/tests/bench/assert_one.json +++ b/zokrates_core_test/tests/tests/assert_one.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/assert_one.code", + "entry_point": "./tests/tests/assert_one.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/bench/fact_up_to_4.code b/zokrates_core_test/tests/tests/fact_up_to_4.code similarity index 100% rename from zokrates_core_test/tests/bench/fact_up_to_4.code rename to zokrates_core_test/tests/tests/fact_up_to_4.code diff --git a/zokrates_core_test/tests/bench/fact_up_to_4.json b/zokrates_core_test/tests/tests/fact_up_to_4.json similarity index 91% rename from zokrates_core_test/tests/bench/fact_up_to_4.json rename to zokrates_core_test/tests/tests/fact_up_to_4.json index 51765f21..6c32ff24 100644 --- a/zokrates_core_test/tests/bench/fact_up_to_4.json +++ b/zokrates_core_test/tests/tests/fact_up_to_4.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/fact_up_to_4.code", + "entry_point": "./tests/tests/fact_up_to_4.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/bench/split.code b/zokrates_core_test/tests/tests/split.code similarity index 100% rename from zokrates_core_test/tests/bench/split.code rename to zokrates_core_test/tests/tests/split.code diff --git a/zokrates_core_test/tests/bench/split.json b/zokrates_core_test/tests/tests/split.json similarity index 99% rename from zokrates_core_test/tests/bench/split.json rename to zokrates_core_test/tests/tests/split.json index 57b3e07d..c05358a6 100644 --- a/zokrates_core_test/tests/bench/split.json +++ b/zokrates_core_test/tests/tests/split.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/split.code", + "entry_point": "./tests/tests/split.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/bench/spread_slice.code b/zokrates_core_test/tests/tests/spread_slice.code similarity index 100% rename from zokrates_core_test/tests/bench/spread_slice.code rename to zokrates_core_test/tests/tests/spread_slice.code diff --git a/zokrates_core_test/tests/bench/spread_slice.json b/zokrates_core_test/tests/tests/spread_slice.json similarity index 79% rename from zokrates_core_test/tests/bench/spread_slice.json rename to zokrates_core_test/tests/tests/spread_slice.json index 2939b7ea..b2291bc1 100644 --- a/zokrates_core_test/tests/bench/spread_slice.json +++ b/zokrates_core_test/tests/tests/spread_slice.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/spread_slice.code", + "entry_point": "./tests/tests/spread_slice.code", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/utils/mod.rs b/zokrates_core_test/tests/utils/mod.rs deleted file mode 100644 index bf4661c2..00000000 --- a/zokrates_core_test/tests/utils/mod.rs +++ /dev/null @@ -1,121 +0,0 @@ -extern crate serde_json; -extern crate zokrates_field; - -use std::io; -use zokrates_core::compile::{compile as generic_compile, CompileErrors}; -use zokrates_core::ir; -use zokrates_field::field::{Field, FieldPrime}; - -#[derive(Serialize, Deserialize)] -pub struct Tests { - pub tests: Vec, -} - -#[derive(Serialize, Deserialize)] -pub struct Input { - pub values: Vec, -} - -#[derive(Serialize, Deserialize)] -pub struct Test { - pub input: Input, - pub output: TestResult, -} - -pub type TestResult = Result; - -#[derive(PartialEq, Debug)] -pub struct ComparableResult(Result, ir::Error>); - -#[derive(Serialize, Deserialize)] -pub struct Output { - values: Vec, -} - -type Val = String; - -impl From> for ComparableResult { - fn from(r: ir::ExecutionResult) -> ComparableResult { - ComparableResult(r.map(|v| v.return_values())) - } -} - -impl From for ComparableResult { - fn from(r: TestResult) -> ComparableResult { - ComparableResult(r.map(|v| { - v.values - .iter() - .map(|v| FieldPrime::try_from_dec_str(v).unwrap()) - .collect() - })) - } -} - -pub fn compare( - result: ir::ExecutionResult, - expected: TestResult, -) -> Result<(), String> { - // extract outputs from result - let result = ComparableResult::from(result); - // deserialize expected result - let expected = ComparableResult::from(expected); - - if result != expected { - return Err(format!( - "Expected {:?} but found {:?}", - expected.0, result.0 - )); - } - - Ok(()) -} - -pub fn read_file(path: &str) -> String { - use std::fs::File; - use std::io::Read; - let mut file = File::open(format!("./tests/bench/{}", path)).expect("Unable to open the file"); - let mut contents = String::new(); - file.read_to_string(&mut contents) - .expect("Unable to read the file"); - - contents -} - -pub fn compile(code: &str) -> Result, CompileErrors> { - generic_compile::(&mut code.as_bytes(), None, None) -} - -macro_rules! zokrates_test { - ($($name:ident,)*) => { - $( - #[test] - fn $name() { - - use zokrates_field::field::{Field, FieldPrime}; - - let code_string = $crate::utils::read_file(&format!("./{}.code", stringify!($name))); - let test_string = $crate::utils::read_file(&format!("./{}.json", stringify!($name))); - - let bin = $crate::utils::compile(&code_string).unwrap(); - - let t: $crate::utils::Tests = serde_json::from_str(&test_string).unwrap(); - - for test in t.tests.into_iter() { - let input = &test.input.values; - let output = bin.execute(&input.iter().map(|v| FieldPrime::try_from_dec_str(v).unwrap()).collect()); - - let context = format!(" -{} - -Called with input ({}) - ", code_string, input.iter().map(|i| format!("{}", i)).collect::>().join(", ")); - - match $crate::utils::compare(output, test.output) { - Err(e) => panic!("{}{}", context, e), - Ok(..) => {} - }; - } - } - )* - }; -} diff --git a/zokrates_stdlib/build.rs b/zokrates_stdlib/build.rs index 33d77ca3..f48fcc8b 100644 --- a/zokrates_stdlib/build.rs +++ b/zokrates_stdlib/build.rs @@ -9,7 +9,7 @@ fn main() { export_stdlib(); // generate tests - write_tests(Path::new("./tests/bench/")); + write_tests("./tests/tests/"); } fn export_stdlib() { diff --git a/zokrates_stdlib/tests/bench/and.json b/zokrates_stdlib/tests/tests/and.json similarity index 100% rename from zokrates_stdlib/tests/bench/and.json rename to zokrates_stdlib/tests/tests/and.json diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsAdd.code b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/edwardsAdd.code rename to zokrates_stdlib/tests/tests/ecc/edwardsAdd.code diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsAdd.json b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json similarity index 69% rename from zokrates_stdlib/tests/bench/ecc/edwardsAdd.json rename to zokrates_stdlib/tests/tests/ecc/edwardsAdd.json index 7cb11a64..11457b30 100644 --- a/zokrates_stdlib/tests/bench/ecc/edwardsAdd.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/edwardsAdd.code", + "entry_point": "./tests/tests/ecc/edwardsAdd.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsCompress.code b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/edwardsCompress.code rename to zokrates_stdlib/tests/tests/ecc/edwardsCompress.code diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsCompress.json b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json similarity index 67% rename from zokrates_stdlib/tests/bench/ecc/edwardsCompress.json rename to zokrates_stdlib/tests/tests/ecc/edwardsCompress.json index c5ad4f53..b17a104e 100644 --- a/zokrates_stdlib/tests/bench/ecc/edwardsCompress.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/edwardsCompress.code", + "entry_point": "./tests/tests/ecc/edwardsCompress.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsOnCurve.code b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/edwardsOnCurve.code rename to zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.code diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsOnCurve.json b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json similarity index 68% rename from zokrates_stdlib/tests/bench/ecc/edwardsOnCurve.json rename to zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json index e4c42198..018d856a 100644 --- a/zokrates_stdlib/tests/bench/ecc/edwardsOnCurve.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/edwardsOnCurve.code", + "entry_point": "./tests/tests/ecc/edwardsOnCurve.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsOrderCheck.code b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/edwardsOrderCheck.code rename to zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.code diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsOrderCheck.json b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json similarity index 67% rename from zokrates_stdlib/tests/bench/ecc/edwardsOrderCheck.json rename to zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json index e38b3112..387bdaef 100644 --- a/zokrates_stdlib/tests/bench/ecc/edwardsOrderCheck.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/edwardsOrderCheck.code", + "entry_point": "./tests/tests/ecc/edwardsOrderCheck.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsScalarMult.code b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/edwardsScalarMult.code rename to zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.code diff --git a/zokrates_stdlib/tests/bench/ecc/edwardsScalarMult.json b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json similarity index 67% rename from zokrates_stdlib/tests/bench/ecc/edwardsScalarMult.json rename to zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json index 3d97c84d..029ae8a8 100644 --- a/zokrates_stdlib/tests/bench/ecc/edwardsScalarMult.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/edwardsScalarMult.code", + "entry_point": "./tests/tests/ecc/edwardsScalarMult.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/ecc/proofOfOwnership.code b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.code similarity index 100% rename from zokrates_stdlib/tests/bench/ecc/proofOfOwnership.code rename to zokrates_stdlib/tests/tests/ecc/proofOfOwnership.code diff --git a/zokrates_stdlib/tests/bench/ecc/proofOfOwnership.json b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json similarity index 67% rename from zokrates_stdlib/tests/bench/ecc/proofOfOwnership.json rename to zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json index 9d55955c..9a0c3833 100644 --- a/zokrates_stdlib/tests/bench/ecc/proofOfOwnership.json +++ b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/ecc/proofOfOwnership.code", + "entry_point": "./tests/tests/ecc/proofOfOwnership.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/pedersen/512bit.code b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/pedersen/512bit.code rename to zokrates_stdlib/tests/tests/hashes/pedersen/512bit.code diff --git a/zokrates_stdlib/tests/bench/hashes/pedersen/512bit.json b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json similarity index 66% rename from zokrates_stdlib/tests/bench/hashes/pedersen/512bit.json rename to zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json index b708a399..04bee370 100644 --- a/zokrates_stdlib/tests/bench/hashes/pedersen/512bit.json +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/pedersen/512bit.code", + "entry_point": "./tests/tests/hashes/pedersen/512bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/pedersen/6bit.code b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/pedersen/6bit.code rename to zokrates_stdlib/tests/tests/hashes/pedersen/6bit.code diff --git a/zokrates_stdlib/tests/bench/hashes/pedersen/6bit.json b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json similarity index 67% rename from zokrates_stdlib/tests/bench/hashes/pedersen/6bit.json rename to zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json index f4f2320e..a08d8cbb 100644 --- a/zokrates_stdlib/tests/bench/hashes/pedersen/6bit.json +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/pedersen/6bit.code", + "entry_point": "./tests/tests/hashes/pedersen/6bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bit.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bit.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bit.code diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bit.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json similarity index 67% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bit.json rename to zokrates_stdlib/tests/tests/hashes/sha256/512bit.json index af201acd..2d7cf5ff 100644 --- a/zokrates_stdlib/tests/bench/hashes/sha256/512bit.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/sha256/512bit.code", + "entry_point": "./tests/tests/hashes/sha256/512bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.code diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked.json rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked2.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json similarity index 65% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked2.json rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json index 55f11390..86b6c9a6 100644 --- a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPacked2.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/sha256/512bitPacked.code", + "entry_point": "./tests/tests/hashes/sha256/512bitPacked.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPadded.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bitPadded.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.code diff --git a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPadded.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json similarity index 65% rename from zokrates_stdlib/tests/bench/hashes/sha256/512bitPadded.json rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json index 7a54a824..e137fb71 100644 --- a/zokrates_stdlib/tests/bench/hashes/sha256/512bitPadded.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/sha256/512bitPadded.code", + "entry_point": "./tests/tests/hashes/sha256/512bitPadded.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/hashes/utils/256bitsDirectionHelper.code b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.code similarity index 100% rename from zokrates_stdlib/tests/bench/hashes/utils/256bitsDirectionHelper.code rename to zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.code diff --git a/zokrates_stdlib/tests/bench/hashes/utils/256bitsDirectionHelper.json b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json similarity index 67% rename from zokrates_stdlib/tests/bench/hashes/utils/256bitsDirectionHelper.json rename to zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json index 2e4816ce..a99cedcf 100644 --- a/zokrates_stdlib/tests/bench/hashes/utils/256bitsDirectionHelper.json +++ b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/hashes/utils/256bitsDirectionHelper.code", + "entry_point": "./tests/tests/hashes/utils/256bitsDirectionHelper.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/or.json b/zokrates_stdlib/tests/tests/or.json similarity index 100% rename from zokrates_stdlib/tests/bench/or.json rename to zokrates_stdlib/tests/tests/or.json diff --git a/zokrates_stdlib/tests/bench/signatures/verifyEddsa.code b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.code similarity index 100% rename from zokrates_stdlib/tests/bench/signatures/verifyEddsa.code rename to zokrates_stdlib/tests/tests/signatures/verifyEddsa.code diff --git a/zokrates_stdlib/tests/bench/signatures/verifyEddsa.json b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json similarity index 66% rename from zokrates_stdlib/tests/bench/signatures/verifyEddsa.json rename to zokrates_stdlib/tests/tests/signatures/verifyEddsa.json index 6ae3bcb2..c6887f83 100644 --- a/zokrates_stdlib/tests/bench/signatures/verifyEddsa.json +++ b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/signatures/verifyEddsa.code", + "entry_point": "./tests/tests/signatures/verifyEddsa.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/256bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/multiplexer/256bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/256bit.code diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/256bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json similarity index 65% rename from zokrates_stdlib/tests/bench/utils/multiplexer/256bit.json rename to zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json index 308fc2c4..834dfa5a 100644 --- a/zokrates_stdlib/tests/bench/utils/multiplexer/256bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/multiplexer/256bit.code", + "entry_point": "./tests/tests/utils/multiplexer/256bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/2bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/multiplexer/2bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/2bit.code diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/2bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json similarity index 66% rename from zokrates_stdlib/tests/bench/utils/multiplexer/2bit.json rename to zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json index e8c8d0f4..ff6ad3ca 100644 --- a/zokrates_stdlib/tests/bench/utils/multiplexer/2bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/multiplexer/2bit.code", + "entry_point": "./tests/tests/utils/multiplexer/2bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup1bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup1bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.code diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup1bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json similarity index 66% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup1bit.json rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json index 848ab6a9..deeef014 100644 --- a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup1bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/multiplexer/lookup1bit.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup1bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup2bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup2bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.code diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup2bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json similarity index 66% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup2bit.json rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json index ea6bb2f9..a594889e 100644 --- a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup2bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/multiplexer/lookup2bit.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup2bit.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup3bitSigned.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup3bitSigned.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.code diff --git a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup3bitSigned.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json similarity index 67% rename from zokrates_stdlib/tests/bench/utils/multiplexer/lookup3bitSigned.json rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json index fb88d312..3757c165 100644 --- a/zokrates_stdlib/tests/bench/utils/multiplexer/lookup3bitSigned.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/multiplexer/lookup3bitSigned.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup3bitSigned.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/pack/nonStrictUnpack256.code b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/pack/nonStrictUnpack256.code rename to zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.code diff --git a/zokrates_stdlib/tests/bench/utils/pack/nonStrictUnpack256.json b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json similarity index 66% rename from zokrates_stdlib/tests/bench/utils/pack/nonStrictUnpack256.json rename to zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json index 7a2f497c..9d6d2039 100644 --- a/zokrates_stdlib/tests/bench/utils/pack/nonStrictUnpack256.json +++ b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/pack/nonStrictUnpack256.code", + "entry_point": "./tests/tests/utils/pack/nonStrictUnpack256.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/pack/pack128.code b/zokrates_stdlib/tests/tests/utils/pack/pack128.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/pack/pack128.code rename to zokrates_stdlib/tests/tests/utils/pack/pack128.code diff --git a/zokrates_stdlib/tests/bench/utils/pack/pack128.json b/zokrates_stdlib/tests/tests/utils/pack/pack128.json similarity index 68% rename from zokrates_stdlib/tests/bench/utils/pack/pack128.json rename to zokrates_stdlib/tests/tests/utils/pack/pack128.json index 0bde19b2..beadfbc1 100644 --- a/zokrates_stdlib/tests/bench/utils/pack/pack128.json +++ b/zokrates_stdlib/tests/tests/utils/pack/pack128.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/pack/pack128.code", + "entry_point": "./tests/tests/utils/pack/pack128.code", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/bench/utils/pack/unpack128.code b/zokrates_stdlib/tests/tests/utils/pack/unpack128.code similarity index 100% rename from zokrates_stdlib/tests/bench/utils/pack/unpack128.code rename to zokrates_stdlib/tests/tests/utils/pack/unpack128.code diff --git a/zokrates_stdlib/tests/bench/utils/pack/unpack128.json b/zokrates_stdlib/tests/tests/utils/pack/unpack128.json similarity index 67% rename from zokrates_stdlib/tests/bench/utils/pack/unpack128.json rename to zokrates_stdlib/tests/tests/utils/pack/unpack128.json index c5c5d323..91ea3516 100644 --- a/zokrates_stdlib/tests/bench/utils/pack/unpack128.json +++ b/zokrates_stdlib/tests/tests/utils/pack/unpack128.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/bench/utils/pack/unpack128.code", + "entry_point": "./tests/tests/utils/pack/unpack128.code", "tests": [ { "input": { diff --git a/zokrates_test/src/lib.rs b/zokrates_test/src/lib.rs index 847b27a6..f6376522 100644 --- a/zokrates_test/src/lib.rs +++ b/zokrates_test/src/lib.rs @@ -126,9 +126,10 @@ use std::fs::File; use std::io::{BufWriter, Write}; use std::path::Path; -pub fn write_tests(base: &Path) { +pub fn write_tests(base: &str) { use glob::glob; + let base = Path::new(&base); let out_dir = env::var("OUT_DIR").unwrap(); let destination = Path::new(&out_dir).join("tests.rs"); let test_file = File::create(&destination).unwrap(); From 87597bd3b12948ca67968d4a94cdec216bbe4513 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 18 Sep 2019 10:58:38 +0200 Subject: [PATCH 09/27] fix warnings --- zokrates_core_test/build.rs | 1 - zokrates_stdlib/build.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/zokrates_core_test/build.rs b/zokrates_core_test/build.rs index 73362299..7248f9c8 100644 --- a/zokrates_core_test/build.rs +++ b/zokrates_core_test/build.rs @@ -1,4 +1,3 @@ -use std::path::Path; use zokrates_test::write_tests; fn main() { diff --git a/zokrates_stdlib/build.rs b/zokrates_stdlib/build.rs index f48fcc8b..b7abec95 100644 --- a/zokrates_stdlib/build.rs +++ b/zokrates_stdlib/build.rs @@ -1,7 +1,6 @@ use fs_extra::copy_items; use fs_extra::dir::CopyOptions; use std::env; -use std::path::Path; use zokrates_test::write_tests; fn main() { From 1731d046e7cbcb4e34d5388f0cb5e149cabfba38 Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Wed, 18 Sep 2019 18:55:17 +0200 Subject: [PATCH 10/27] updated documentation --- zokrates_book/src/reference/Testing.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zokrates_book/src/reference/Testing.md b/zokrates_book/src/reference/Testing.md index 3299790b..af26bdcb 100644 --- a/zokrates_book/src/reference/Testing.md +++ b/zokrates_book/src/reference/Testing.md @@ -1,6 +1,17 @@ # Testing +Before running any tests, make sure make sure your `ZOKRATES_HOME` environment variable is set correctly. +It has to point to `zokrates_stdlib/stdlib/` + ## Unit tests +In ZoKrates, unit tests comprise +- internal tests for all zokrates crates +- compilation tests for all examples in the `$ZOKRATES_HOME/` zokrates_cli example folder. These tests only ensure that the examples compile correctly. +- compilation + witness-computation tests. These tests compile the test cases, compute a witness and compare the result with a pre-defined expected result. +Such test cases exist for + - The zokrates_core crate in `zokrates_core_test/tests` + - The zokrates_stdlib crate in `zokrates_stdlib/tests` + Unit tests can be executed with the following command: ``` @@ -10,6 +21,7 @@ cargo test --release ## Integration tests Integration tests are excluded from `cargo test` by default. +They are defined in the `zokrates_cli` crate in `integration.rs` and use the test cases specified in `zokrates_cli/tests/code`. Before running integration tests: 1. Make sure your `$ZOKRATES_HOME` is set correctly @@ -19,6 +31,7 @@ Before running integration tests: ``` npm install -g solc ``` +3. You have an Ethereum node running on localhost with a JSON-RPC interface on the default port 8545 (`http://localhost:8545`). Integration tests can then be run with the following command: From 231828aabc2dd906a2062fd41d6ed3cd659143ec Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Thu, 19 Sep 2019 17:04:04 +0200 Subject: [PATCH 11/27] Update zokrates_book/src/reference/Testing.md Co-Authored-By: Thibaut Schaeffer --- zokrates_book/src/reference/Testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zokrates_book/src/reference/Testing.md b/zokrates_book/src/reference/Testing.md index af26bdcb..6526dbe9 100644 --- a/zokrates_book/src/reference/Testing.md +++ b/zokrates_book/src/reference/Testing.md @@ -6,7 +6,7 @@ It has to point to `zokrates_stdlib/stdlib/` ## Unit tests In ZoKrates, unit tests comprise - internal tests for all zokrates crates -- compilation tests for all examples in the `$ZOKRATES_HOME/` zokrates_cli example folder. These tests only ensure that the examples compile correctly. +- compilation tests for all examples in `zokrates_cli/examples`. These tests only ensure that the examples compile. - compilation + witness-computation tests. These tests compile the test cases, compute a witness and compare the result with a pre-defined expected result. Such test cases exist for - The zokrates_core crate in `zokrates_core_test/tests` @@ -41,4 +41,4 @@ cargo test --release -- --ignored If you want to run unit and integrations tests together, run the following command: ``` cargo test --release & cargo test --release -- --ignored -``` \ No newline at end of file +``` From d1eb337436e73d3e4641746ea1d6bb180d245d00 Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Thu, 19 Sep 2019 17:30:27 +0200 Subject: [PATCH 12/27] fixed documentation references --- zokrates_book/src/SUMMARY.md | 1 + zokrates_book/src/reference/index.md | 1 + 2 files changed, 2 insertions(+) diff --git a/zokrates_book/src/SUMMARY.md b/zokrates_book/src/SUMMARY.md index ccd426d6..66a36ace 100644 --- a/zokrates_book/src/SUMMARY.md +++ b/zokrates_book/src/SUMMARY.md @@ -18,5 +18,6 @@ - [Proving schemes](reference/proving_schemes.md) - [Verification](reference/verification.md) - [ZIR](reference/ir.md) + - [Testing](reference/testing.md) - [Tutorial: Proof of preimage](./sha256example.md) diff --git a/zokrates_book/src/reference/index.md b/zokrates_book/src/reference/index.md index 76d0c0e4..cb033c11 100644 --- a/zokrates_book/src/reference/index.md +++ b/zokrates_book/src/reference/index.md @@ -7,3 +7,4 @@ The reference covers the details of various areas of ZoKrates. - [Proving schemes](proving_schemes.md) - [Verification](verification.md) - [ZIR](ir.md) + - [Testing](testing.md) \ No newline at end of file From 805b4290ef764e3312f0a5c416ce4dda6da372ed Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 23 Sep 2019 10:51:02 +0200 Subject: [PATCH 13/27] address review comments --- zokrates_core/src/flatten/mod.rs | 14 ++++++-------- zokrates_core/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index f26fd946..9f21e223 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -28,11 +28,9 @@ pub struct Flattener<'ast, T: Field> { // We introduce a trait in order to make it possible to make flattening `e` generic over the type of `e` -#[rustfmt::skip] -trait Flatten<'ast, T: Field> - : TryFrom, Error: std::fmt::Debug> - + IfElse<'ast, T> - + Select<'ast, T> { +trait Flatten<'ast, T: Field>: + TryFrom, Error = ()> + IfElse<'ast, T> + Select<'ast, T> +{ fn flatten( self, flattener: &mut Flattener<'ast, T>, @@ -196,11 +194,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { res.into_iter().map(|r| r.into()).collect() } - /// Flatten a array selection expression + /// Flatten an array selection expression /// /// # Arguments /// - /// * `symbols` - Available functions in in this context + /// * `symbols` - Available functions in this context /// * `statements_flattened` - Vector where new flattened statements can be added. /// * `expression` - `TypedExpression` that will be flattened. /// # Remarks @@ -1054,7 +1052,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { /// /// * `symbols` - Available functions in in this context /// * `statements_flattened` - Vector where new flattened statements can be added. - /// * `expression` - `ArrayExpression` that will be flattened. + /// * `expr` - `ArrayExpression` that will be flattened. /// # Remarks /// * U is the inner type of the array fn flatten_array_expression>( diff --git a/zokrates_core/src/lib.rs b/zokrates_core/src/lib.rs index 9127d411..3b2894f2 100644 --- a/zokrates_core/src/lib.rs +++ b/zokrates_core/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(box_patterns, box_syntax, associated_type_bounds)] +#![feature(box_patterns, box_syntax)] extern crate num; extern crate num_bigint; From 79fea57be8232466ddf72b27def7630bbcfc6806 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 23 Sep 2019 18:33:08 +0200 Subject: [PATCH 14/27] clean, add boolean check to all boolean user input --- t.code | 16 --- u.code | 4 - zokrates_core/src/compile.rs | 2 - zokrates_core/src/flatten/mod.rs | 30 +---- .../src/static_analysis/constrain_inputs.rs | 120 ++++++++++++++++++ zokrates_core/src/static_analysis/mod.rs | 5 +- .../tests/tests/arrays/identity.code | 2 + .../tests/tests/arrays/identity.json | 38 ++++++ .../tests/tests/structs/identity.code | 7 + .../tests/tests/structs/identity.json | 38 ++++++ 10 files changed, 211 insertions(+), 51 deletions(-) delete mode 100644 t.code delete mode 100644 u.code create mode 100644 zokrates_core/src/static_analysis/constrain_inputs.rs create mode 100644 zokrates_core_test/tests/tests/arrays/identity.code create mode 100644 zokrates_core_test/tests/tests/arrays/identity.json create mode 100644 zokrates_core_test/tests/tests/structs/identity.code create mode 100644 zokrates_core_test/tests/tests/structs/identity.json diff --git a/t.code b/t.code deleted file mode 100644 index a38f522b..00000000 --- a/t.code +++ /dev/null @@ -1,16 +0,0 @@ -from "./u.code" import Fooo - -struct Bar { - a: field, - a: field, - c: field, -} - -struct Baz { - a: Bar -} - -def main(Bar a, Bar b, bool c) -> (Bar): - Bar bar = Bar { a: 1, b: 1, c: 1 } - return if false then a else bar fi - diff --git a/u.code b/u.code deleted file mode 100644 index f420f0f2..00000000 --- a/u.code +++ /dev/null @@ -1,4 +0,0 @@ -struct Foo { - a: field, - b: field[2], -} \ No newline at end of file diff --git a/zokrates_core/src/compile.rs b/zokrates_core/src/compile.rs index 82990bcf..861b76ca 100644 --- a/zokrates_core/src/compile.rs +++ b/zokrates_core/src/compile.rs @@ -138,8 +138,6 @@ pub fn compile>( let source = arena.alloc(source); - println!("{:?}", source); - let compiled = compile_program(source, location.clone(), resolve_option, &arena)?; // check semantics diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index f4a7d972..c92eb68b 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -1548,7 +1548,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { let arguments_flattened = funct .arguments .into_iter() - .flat_map(|p| self.use_parameter(&p, &mut statements_flattened)) + .flat_map(|p| self.use_parameter(&p)) .collect(); // flatten statements in functions and apply substitution @@ -1602,19 +1602,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { vars } - fn use_parameter( - &mut self, - parameter: &Parameter<'ast>, - statements: &mut Vec>, - ) -> Vec { + fn use_parameter(&mut self, parameter: &Parameter<'ast>) -> Vec { let variables = self.use_variable(¶meter.id); - match parameter.id.get_type() { - Type::Boolean => statements.extend(Self::boolean_constraint(&variables)), - Type::Array(box Type::Boolean, _) => { - statements.extend(Self::boolean_constraint(&variables)) - } - _ => {} - }; variables .into_iter() @@ -1635,21 +1624,6 @@ impl<'ast, T: Field> Flattener<'ast, T> { (0..count).map(|_| self.issue_new_variable()).collect() } - fn boolean_constraint(variables: &Vec) -> Vec> { - variables - .iter() - .map(|v| { - FlatStatement::Condition( - FlatExpression::Identifier(*v), - FlatExpression::Mult( - box FlatExpression::Identifier(*v), - box FlatExpression::Identifier(*v), - ), - ) - }) - .collect() - } - // create an internal variable. We do not register it in the layout fn use_sym(&mut self) -> FlatVariable { self.issue_new_variable() diff --git a/zokrates_core/src/static_analysis/constrain_inputs.rs b/zokrates_core/src/static_analysis/constrain_inputs.rs new file mode 100644 index 00000000..711024f7 --- /dev/null +++ b/zokrates_core/src/static_analysis/constrain_inputs.rs @@ -0,0 +1,120 @@ +//! Add runtime boolean checks on user inputs +//! Example: +//! ``` +//! struct Foo { +//! bar: bool +//! } +//! +//! def main(Foo f) -> (): +//! f.bar == f.bar && f.bar +//! return +//! ``` +//! @file unroll.rs +//! @author Thibaut Schaeffer +//! @date 2018 + +use crate::typed_absy::folder::Folder; +use crate::typed_absy::types::Type; +use crate::typed_absy::*; +use zokrates_field::field::Field; + +pub struct InputConstrainer<'ast, T: Field> { + constraints: Vec>, +} + +impl<'ast, T: Field> InputConstrainer<'ast, T> { + fn new() -> Self { + InputConstrainer { + constraints: vec![], + } + } + + pub fn constrain(p: TypedProgram) -> TypedProgram { + InputConstrainer::new().fold_program(p) + } + + fn constrain_expression(&mut self, e: TypedExpression<'ast, T>) { + match e { + TypedExpression::FieldElement(_) => {} + TypedExpression::Boolean(b) => self.constraints.push(TypedStatement::Condition( + b.clone().into(), + BooleanExpression::And(box b.clone(), box b).into(), + )), + TypedExpression::Array(a) => { + for i in 0..a.size() { + let e = match a.inner_type() { + Type::FieldElement => FieldElementExpression::select( + a.clone(), + FieldElementExpression::Number(T::from(i)), + ) + .into(), + Type::Boolean => BooleanExpression::select( + a.clone(), + FieldElementExpression::Number(T::from(i)), + ) + .into(), + Type::Array(..) => ArrayExpression::select( + a.clone(), + FieldElementExpression::Number(T::from(i)), + ) + .into(), + Type::Struct(..) => StructExpression::select( + a.clone(), + FieldElementExpression::Number(T::from(i)), + ) + .into(), + }; + + self.constrain_expression(e); + } + } + TypedExpression::Struct(s) => { + for (id, ty) in s.ty() { + let e = match ty { + Type::FieldElement => { + FieldElementExpression::member(s.clone(), id.clone()).into() + } + Type::Boolean => BooleanExpression::member(s.clone(), id.clone()).into(), + Type::Array(..) => ArrayExpression::member(s.clone(), id.clone()).into(), + Type::Struct(..) => StructExpression::member(s.clone(), id.clone()).into(), + }; + + self.constrain_expression(e); + } + } + } + } +} + +impl<'ast, T: Field> Folder<'ast, T> for InputConstrainer<'ast, T> { + fn fold_parameter(&mut self, p: Parameter<'ast>) -> Parameter<'ast> { + let v = p.id.clone(); + + let e = match v.get_type() { + Type::FieldElement => FieldElementExpression::Identifier(v.id).into(), + Type::Boolean => BooleanExpression::Identifier(v.id).into(), + Type::Struct(members) => StructExpressionInner::Identifier(v.id) + .annotate(members) + .into(), + Type::Array(box ty, size) => ArrayExpressionInner::Identifier(v.id) + .annotate(ty, size) + .into(), + }; + + self.constrain_expression(e); + + p + } + + fn fold_function(&mut self, f: TypedFunction<'ast, T>) -> TypedFunction<'ast, T> { + TypedFunction { + arguments: f + .arguments + .into_iter() + .map(|a| self.fold_parameter(a)) + .collect(), + statements: self.constraints.drain(..).chain(f.statements).collect(), + ..f + } + } +} diff --git a/zokrates_core/src/static_analysis/mod.rs b/zokrates_core/src/static_analysis/mod.rs index 386d4c49..e2c2e10d 100644 --- a/zokrates_core/src/static_analysis/mod.rs +++ b/zokrates_core/src/static_analysis/mod.rs @@ -4,11 +4,13 @@ //! @author Thibaut Schaeffer //! @date 2018 +mod constrain_inputs; mod flat_propagation; mod inline; mod propagation; mod unroll; +use self::constrain_inputs::InputConstrainer; use self::inline::Inliner; use self::propagation::Propagator; use self::unroll::Unroller; @@ -24,11 +26,12 @@ impl<'ast, T: Field> Analyse for TypedProgram<'ast, T> { fn analyse(self) -> Self { // unroll let r = Unroller::unroll(self); - println!("{}", r); // inline let r = Inliner::inline(r); // propagate let r = Propagator::propagate(r); + // constrain inputs + let r = InputConstrainer::constrain(r); r } } diff --git a/zokrates_core_test/tests/tests/arrays/identity.code b/zokrates_core_test/tests/tests/arrays/identity.code new file mode 100644 index 00000000..8c97930b --- /dev/null +++ b/zokrates_core_test/tests/tests/arrays/identity.code @@ -0,0 +1,2 @@ +def main(bool[3] a) -> (bool[3]): + return a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/arrays/identity.json b/zokrates_core_test/tests/tests/arrays/identity.json new file mode 100644 index 00000000..e6a36236 --- /dev/null +++ b/zokrates_core_test/tests/tests/arrays/identity.json @@ -0,0 +1,38 @@ +{ + "entry_point": "./tests/tests/arrays/identity.code", + "tests": [ + { + "input": { + "values": ["0", "0", "0"] + }, + "output": { + "Ok": { + "values": ["0", "0", "0"] + } + } + }, + { + "input": { + "values": ["1", "0", "1"] + }, + "output": { + "Ok": { + "values": ["1", "0", "1"] + } + } + }, + { + "input": { + "values": ["2", "1", "1"] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "4", + "right": "2" + } + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/structs/identity.code b/zokrates_core_test/tests/tests/structs/identity.code new file mode 100644 index 00000000..041e79ed --- /dev/null +++ b/zokrates_core_test/tests/tests/structs/identity.code @@ -0,0 +1,7 @@ +struct A { + a: field, + b: bool +} + +def main(A a) -> (A): + return a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/structs/identity.json b/zokrates_core_test/tests/tests/structs/identity.json new file mode 100644 index 00000000..db4b136e --- /dev/null +++ b/zokrates_core_test/tests/tests/structs/identity.json @@ -0,0 +1,38 @@ +{ + "entry_point": "./tests/tests/structs/identity.code", + "tests": [ + { + "input": { + "values": ["42", "0"] + }, + "output": { + "Ok": { + "values": ["42", "0"] + } + } + }, + { + "input": { + "values": ["42", "1"] + }, + "output": { + "Ok": { + "values": ["42", "1"] + } + } + }, + { + "input": { + "values": ["42", "3"] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "9", + "right": "3" + } + } + } + } + ] +} \ No newline at end of file From c815a32574a7cb256a749f8bbf28c32c5991886d Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 23 Sep 2019 18:48:59 +0200 Subject: [PATCH 15/27] remove test, fix comment --- zokrates_core/src/flatten/mod.rs | 52 ------------------- .../src/static_analysis/constrain_inputs.rs | 2 +- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index c92eb68b..6e55180e 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -1652,58 +1652,6 @@ mod tests { use crate::typed_absy::types::Type; use zokrates_field::field::FieldPrime; - mod boolean_checks { - use super::*; - - #[test] - fn boolean_arg() { - // def main(bool a): - // return a - // - // -> should flatten to - // - // def main(_0) -> (1): - // _0 * _0 == _0 - // return _0 - - let function: TypedFunction = TypedFunction { - arguments: vec![Parameter::private(Variable::boolean("a".into()))], - statements: vec![TypedStatement::Return(vec![BooleanExpression::Identifier( - "a".into(), - ) - .into()])], - signature: Signature::new() - .inputs(vec![Type::Boolean]) - .outputs(vec![Type::Boolean]), - }; - - let expected = FlatFunction { - arguments: vec![FlatParameter::private(FlatVariable::new(0))], - statements: vec![ - FlatStatement::Condition( - FlatExpression::Identifier(FlatVariable::new(0)), - FlatExpression::Mult( - box FlatExpression::Identifier(FlatVariable::new(0)), - box FlatExpression::Identifier(FlatVariable::new(0)), - ), - ), - FlatStatement::Return(FlatExpressionList { - expressions: vec![FlatExpression::Identifier(FlatVariable::new(0))], - }), - ], - signature: Signature::new() - .inputs(vec![Type::Boolean]) - .outputs(vec![Type::Boolean]), - }; - - let mut flattener = Flattener::new(); - - let flat_function = flattener.flatten_function(&mut HashMap::new(), function); - - assert_eq!(flat_function, expected); - } - } - #[test] fn powers_zero() { // def main(): diff --git a/zokrates_core/src/static_analysis/constrain_inputs.rs b/zokrates_core/src/static_analysis/constrain_inputs.rs index 711024f7..38995c30 100644 --- a/zokrates_core/src/static_analysis/constrain_inputs.rs +++ b/zokrates_core/src/static_analysis/constrain_inputs.rs @@ -1,6 +1,6 @@ //! Add runtime boolean checks on user inputs //! Example: -//! ``` +//! ```zokrates //! struct Foo { //! bar: bool //! } From ed300a9a2810ee9ad82c8e5aa95028bf941a1c5c Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 24 Sep 2019 12:05:43 +0200 Subject: [PATCH 16/27] change file endings --- .gitignore | 2 +- out.ztf | 3 + zokrates_book/src/concepts/comments.md | 2 +- zokrates_book/src/concepts/control_flow.md | 6 +- zokrates_book/src/concepts/functions.md | 8 +-- zokrates_book/src/concepts/imports.md | 8 +-- zokrates_book/src/concepts/stdlib.md | 12 ++-- zokrates_book/src/concepts/types.md | 6 +- zokrates_book/src/concepts/variables.md | 6 +- zokrates_book/src/gettingstarted.md | 6 +- zokrates_book/src/reference/cli.md | 14 ++-- zokrates_book/src/sha256example.md | 12 ++-- zokrates_cli/examples/{add.code => add.zok} | 0 ...nt_reassign.code => argument_reassign.zok} | 0 ...array_argument.code => array_argument.zok} | 0 .../{array_loop.code => array_loop.zok} | 0 ...loop_update.code => array_loop_update.zok} | 0 .../{boolean_array.code => boolean_array.zok} | 0 ...constant_array.code => constant_array.zok} | 0 .../examples/arrays/{cube.code => cube.zok} | 0 .../examples/arrays/{if_eq.code => if_eq.zok} | 0 ...it_with_value.code => init_with_value.zok} | 0 .../arrays/{lookup.code => lookup.zok} | 0 ...ltidim_update.code => multidim_update.zok} | 0 .../{return_array.code => return_array.zok} | 0 ...e_array.code => return_variable_array.zok} | 0 .../arrays/{slicefrom.code => slicefrom.zok} | 0 .../arrays/{update.code => update.zok} | 0 ...te_with_call.code => update_with_call.zok} | 0 .../examples/arrays/{value.code => value.zok} | 0 .../{wrap_select.code => wrap_select.zok} | 0 .../examples/book/{array.code => array.zok} | 0 .../book/{comments.code => comments.zok} | 0 .../book/{factorize.code => factorize.zok} | 0 ...field_overflow.code => field_overflow.zok} | 0 .../examples/book/{for.code => for.zok} | 0 .../book/{for_scope.code => for_scope.zok} | 0 ...laration.code => function_declaration.zok} | 0 ...function_scope.code => function_scope.zok} | 0 .../{hashexample.code => hashexample.zok} | 2 +- ...e_updated.code => hashexample_updated.zok} | 2 +- .../book/{if_else.code => if_else.zok} | 0 .../book/{multi_def.code => multi_def.zok} | 0 .../{multi_return.code => multi_return.zok} | 0 ...multidim_array.code => multidim_array.zok} | 0 .../{no_shadowing.code => no_shadowing.zok} | 0 .../{side_effects.code => side_effects.zok} | 0 ..._annotations.code => type_annotations.zok} | 0 .../examples/{bool_and.code => bool_and.zok} | 0 .../examples/{bool_not.code => bool_not.zok} | 0 .../examples/{bool_or.code => bool_or.zok} | 0 ...olean_literal.code => boolean_literal.zok} | 0 .../examples/{brackets.code => brackets.zok} | 0 .../examples/{comments.code => comments.zok} | 0 ...perators.code => comparison_operators.zok} | 0 .../{conditions.code => conditions.zok} | 0 .../dex/{decodeOrder.code => decodeOrder.zok} | 2 +- ...derBitwise.code => decodeOrderBitwise.zok} | 0 .../dex/{emptyOrder.code => emptyOrder.zok} | 0 ...isPartialOrder.code => isPartialOrder.zok} | 0 ...sThanPrice.code => limitLessThanPrice.zok} | 0 ...antBit.code => popLeastSignificantBit.zok} | 0 ...ade_example.code => ringtrade_example.zok} | 4 +- .../{empty-error.code => empty-error.zok} | 0 ...wer_base.code => forbidden_power_base.zok} | 0 ...of_for_scope.code => out_of_for_scope.zok} | 0 .../error/{shadowing.code => shadowing.zok} | 0 .../error/{unassigned.code => unassigned.zok} | 0 ...yntax-error.code => wrongsyntax-error.zok} | 0 .../{factorization.code => factorization.zok} | 0 .../examples/{flatten.code => flatten.zok} | 0 zokrates_cli/examples/{for.code => for.zok} | 0 .../{expressions.code => expressions.zok} | 0 .../{functions.code => functions.zok} | 0 ...lti_functions.code => multi_functions.zok} | 0 ...lti_shadowing.code => multi_shadowing.zok} | 0 ...rgs_multiple.code => no_args_multiple.zok} | 0 .../{shadowing.code => shadowing.zok} | 0 ...uivalent.code => functions_equivalent.zok} | 0 .../examples/{if_eq.code => if_eq.zok} | 0 .../examples/imports/{bar.code => bar.zok} | 0 .../examples/imports/{baz.code => baz.zok} | 0 .../examples/imports/{foo.code => foo.zok} | 2 +- .../imports/{import.code => import.zok} | 4 +- .../examples/imports/import_github.code | 6 -- ..._with_alias.code => import_with_alias.zok} | 2 +- ...left_side_call.code => left_side_call.zok} | 0 ...PathProof3.code => pedersenPathProof3.zok} | 10 +-- ...56PathProof3.code => sha256PathProof3.zok} | 6 +- ...Proof3.code => testpedersenPathProof3.zok} | 2 +- ...thProof3.code => testsha256PathProof3.zok} | 2 +- .../{multi_return.code => multi_return.zok} | 0 ...i_return_sum.code => multi_return_sum.zok} | 0 ..._witnesses.code => multiple_witnesses.zok} | 0 .../{n_choose_k.code => n_choose_k.zok} | 0 .../{no_flatten.code => no_flatten.zok} | 0 zokrates_cli/examples/{pow.code => pow.zok} | 0 .../{propagate.code => propagate.zok} | 0 ...propagate_call.code => propagate_call.zok} | 0 .../{reassignment.code => reassignment.zok} | 0 ..._exponent.code => reduceable_exponent.zok} | 0 ...plus_1.code => lt_overflow_max_plus_1.zok} | 0 ...s_one.code => lt_overflow_p_minus_one.zok} | 0 ...dxorandxorand.code => andxorandxorand.zok} | 4 +- .../examples/sha256/binary/andxornotand.code | 8 --- .../examples/sha256/binary/andxornotand.zok | 8 +++ .../binary/{fulladd.code => fulladd.zok} | 4 +- .../binary/{halfadd.code => halfadd.zok} | 4 +- .../sha256/bitwise/32/{and.code => and.zok} | 2 +- ...dxorandxorand.code => andxorandxorand.zok} | 2 +- .../{andxornotand.code => andxornotand.zok} | 2 +- .../sha256/bitwise/32/{not.code => not.zok} | 2 +- .../sha256/bitwise/32/{xor.code => xor.zok} | 2 +- .../sha256/utils/32/{add.code => add.zok} | 2 +- ...17xar19xars10.code => ar17xar19xars10.zok} | 2 +- .../{ar2xar13xar22.code => ar2xar13xar22.zok} | 2 +- .../{ar6xar11xar25.code => ar6xar11xar25.zok} | 2 +- .../{ar7xar18xars3.code => ar7xar18xars3.zok} | 2 +- ...ssion_round.code => compression_round.zok} | 10 +-- .../utils/32/{extend.code => extend.zok} | 6 +- .../{simple_add.code => simple_add.zok} | 0 .../{simple_ifelse.code => simple_ifelse.zok} | 0 .../{simple_mul.code => simple_mul.zok} | 0 ...comments.code => spaces_tabs_comments.zok} | 0 zokrates_cli/examples/{sub.code => sub.zok} | 0 .../{sudokuchecker.code => sudokuchecker.zok} | 0 .../examples/{synonyms.code => synonyms.zok} | 0 .../examples/{taxation.code => taxation.zok} | 0 .../examples/{test1.code => test1.zok} | 0 ...t_max_value.code => test_lt_max_value.zok} | 0 .../examples/{waldo.code => waldo.zok} | 0 .../examples/{wavelets.code => wavelets.zok} | 0 zokrates_cli/src/bin.rs | 10 +-- .../{arithmetics.code => arithmetics.zok} | 0 .../{if_else_false.code => if_else_false.zok} | 0 .../{if_else_true.code => if_else_true.zok} | 0 ...ltidim_update.code => multidim_update.zok} | 0 .../code/{n_choose_k.code => n_choose_k.zok} | 0 .../code/{no_return.code => no_return.zok} | 0 .../{return_array.code => return_array.zok} | 0 .../code/{sha_round.code => sha_round.zok} | 0 .../code/{simple_add.code => simple_add.zok} | 0 .../code/{simple_mul.code => simple_mul.zok} | 0 .../code/{taxation.code => taxation.zok} | 0 zokrates_cli/tests/integration.rs | 2 +- zokrates_core/src/imports.rs | 8 +-- zokrates_core/src/semantics.rs | 6 +- zokrates_core_test/tests/tests/add.json | 2 +- .../tests/tests/{add.code => add.zok} | 0 zokrates_core_test/tests/tests/array_if.json | 2 +- .../tests/{array_if.code => array_if.zok} | 0 .../tests/tests/assert_one.json | 2 +- .../tests/{assert_one.code => assert_one.zok} | 0 .../tests/tests/fact_up_to_4.json | 2 +- .../{fact_up_to_4.code => fact_up_to_4.zok} | 0 zokrates_core_test/tests/tests/split.json | 2 +- .../tests/tests/{split.code => split.zok} | 0 .../tests/tests/spread_slice.json | 2 +- .../{spread_slice.code => spread_slice.zok} | 0 zokrates_fs_resolver/src/lib.rs | 71 +++++++------------ zokrates_github_resolver/src/lib.rs | 33 ++++----- .../static/{foo.code => foo.zok} | 0 zokrates_parser/src/lib.rs | 4 +- zokrates_pest_ast/src/lib.rs | 5 +- ...jubjubParams.code => babyjubjubParams.zok} | 0 .../ecc/{edwardsAdd.code => edwardsAdd.zok} | 2 +- ...wardsCompress.code => edwardsCompress.zok} | 2 +- .../{edwardsNegate.code => edwardsNegate.zok} | 2 +- ...edwardsOnCurve.code => edwardsOnCurve.zok} | 0 ...sOrderCheck.code => edwardsOrderCheck.zok} | 6 +- ...sScalarMult.code => edwardsScalarMult.zok} | 4 +- ...fOfOwnership.code => proofOfOwnership.zok} | 6 +- .../pedersen/{512bit.code => 512bit.zok} | 10 +-- .../hashes/pedersen/{6bit.code => 6bit.zok} | 8 +-- .../sha256/{1024bit.code => 1024bit.zok} | 4 +- .../{1024bitPadded.code => 1024bitPadded.zok} | 2 +- .../sha256/{1536bit.code => 1536bit.zok} | 4 +- .../{256bitPadded.code => 256bitPadded.zok} | 2 +- .../hashes/sha256/{512bit.code => 512bit.zok} | 6 +- .../{512bitPacked.code => 512bitPacked.zok} | 6 +- .../{512bitPadded.code => 512bitPadded.zok} | 2 +- .../{IVconstants.code => IVconstants.zok} | 0 ...BoolCheck.code => shaRoundNoBoolCheck.zok} | 0 ...Helper.code => 256bitsDirectionHelper.zok} | 0 .../{verifyEddsa.code => verifyEddsa.zok} | 12 ++-- .../stdlib/utils/binary/{and.code => and.zok} | 0 .../utils/binary/{isbool.code => isbool.zok} | 0 .../stdlib/utils/binary/{not.code => not.zok} | 0 .../stdlib/utils/binary/{or.code => or.zok} | 4 +- .../stdlib/utils/binary/{xor.code => xor.zok} | 0 ...1024to256array.code => 1024to256array.zok} | 0 .../multiplexer/{256bit.code => 256bit.zok} | 0 .../utils/multiplexer/{2bit.code => 2bit.zok} | 0 .../{lookup1bit.code => lookup1bit.zok} | 0 .../{lookup2bit.code => lookup2bit.zok} | 0 ...up3bitSigned.code => lookup3bitSigned.zok} | 2 +- ...tUnpack256.code => nonStrictUnpack256.zok} | 0 .../utils/pack/{pack128.code => pack128.zok} | 0 .../utils/pack/{pack256.code => pack256.zok} | 0 .../pack/{unpack128.code => unpack128.zok} | 0 zokrates_stdlib/tests/tests/and.json | 2 +- .../tests/tests/ecc/edwardsAdd.json | 2 +- .../ecc/{edwardsAdd.code => edwardsAdd.zok} | 6 +- .../tests/tests/ecc/edwardsCompress.json | 2 +- ...wardsCompress.code => edwardsCompress.zok} | 4 +- .../tests/tests/ecc/edwardsOnCurve.json | 2 +- ...edwardsOnCurve.code => edwardsOnCurve.zok} | 4 +- .../tests/tests/ecc/edwardsOrderCheck.json | 2 +- ...sOrderCheck.code => edwardsOrderCheck.zok} | 4 +- .../tests/tests/ecc/edwardsScalarMult.json | 2 +- ...sScalarMult.code => edwardsScalarMult.zok} | 4 +- .../tests/tests/ecc/proofOfOwnership.json | 2 +- ...fOfOwnership.code => proofOfOwnership.zok} | 8 +-- .../tests/tests/hashes/pedersen/512bit.json | 2 +- .../pedersen/{512bit.code => 512bit.zok} | 2 +- .../tests/tests/hashes/pedersen/6bit.json | 2 +- .../hashes/pedersen/{6bit.code => 6bit.zok} | 2 +- .../tests/tests/hashes/sha256/512bit.json | 2 +- .../hashes/sha256/{512bit.code => 512bit.zok} | 2 +- .../tests/hashes/sha256/512bitPacked.json | 2 +- .../{512bitPacked.code => 512bitPacked.zok} | 2 +- .../tests/hashes/sha256/512bitPacked2.json | 2 +- .../tests/hashes/sha256/512bitPadded.json | 2 +- .../{512bitPadded.code => 512bitPadded.zok} | 2 +- .../hashes/utils/256bitsDirectionHelper.json | 2 +- ...Helper.code => 256bitsDirectionHelper.zok} | 2 +- zokrates_stdlib/tests/tests/or.json | 2 +- .../tests/tests/signatures/verifyEddsa.json | 2 +- .../{verifyEddsa.code => verifyEddsa.zok} | 4 +- .../tests/tests/utils/multiplexer/256bit.json | 2 +- .../multiplexer/{256bit.code => 256bit.zok} | 2 +- .../tests/tests/utils/multiplexer/2bit.json | 2 +- .../utils/multiplexer/{2bit.code => 2bit.zok} | 2 +- .../tests/utils/multiplexer/lookup1bit.json | 2 +- .../{lookup1bit.code => lookup1bit.zok} | 2 +- .../tests/utils/multiplexer/lookup2bit.json | 2 +- .../{lookup2bit.code => lookup2bit.zok} | 2 +- .../utils/multiplexer/lookup3bitSigned.json | 2 +- ...up3bitSigned.code => lookup3bitSigned.zok} | 2 +- .../tests/utils/pack/nonStrictUnpack256.json | 2 +- ...tUnpack256.code => nonStrictUnpack256.zok} | 2 +- .../tests/tests/utils/pack/pack128.json | 2 +- .../utils/pack/{pack128.code => pack128.zok} | 2 +- .../tests/tests/utils/pack/unpack128.json | 2 +- .../pack/{unpack128.code => unpack128.zok} | 2 +- 245 files changed, 259 insertions(+), 279 deletions(-) create mode 100644 out.ztf rename zokrates_cli/examples/{add.code => add.zok} (100%) rename zokrates_cli/examples/{argument_reassign.code => argument_reassign.zok} (100%) rename zokrates_cli/examples/arrays/{array_argument.code => array_argument.zok} (100%) rename zokrates_cli/examples/arrays/{array_loop.code => array_loop.zok} (100%) rename zokrates_cli/examples/arrays/{array_loop_update.code => array_loop_update.zok} (100%) rename zokrates_cli/examples/arrays/{boolean_array.code => boolean_array.zok} (100%) rename zokrates_cli/examples/arrays/{constant_array.code => constant_array.zok} (100%) rename zokrates_cli/examples/arrays/{cube.code => cube.zok} (100%) rename zokrates_cli/examples/arrays/{if_eq.code => if_eq.zok} (100%) rename zokrates_cli/examples/arrays/{init_with_value.code => init_with_value.zok} (100%) rename zokrates_cli/examples/arrays/{lookup.code => lookup.zok} (100%) rename zokrates_cli/examples/arrays/{multidim_update.code => multidim_update.zok} (100%) rename zokrates_cli/examples/arrays/{return_array.code => return_array.zok} (100%) rename zokrates_cli/examples/arrays/{return_variable_array.code => return_variable_array.zok} (100%) rename zokrates_cli/examples/arrays/{slicefrom.code => slicefrom.zok} (100%) rename zokrates_cli/examples/arrays/{update.code => update.zok} (100%) rename zokrates_cli/examples/arrays/{update_with_call.code => update_with_call.zok} (100%) rename zokrates_cli/examples/arrays/{value.code => value.zok} (100%) rename zokrates_cli/examples/arrays/{wrap_select.code => wrap_select.zok} (100%) rename zokrates_cli/examples/book/{array.code => array.zok} (100%) rename zokrates_cli/examples/book/{comments.code => comments.zok} (100%) rename zokrates_cli/examples/book/{factorize.code => factorize.zok} (100%) rename zokrates_cli/examples/book/{field_overflow.code => field_overflow.zok} (100%) rename zokrates_cli/examples/book/{for.code => for.zok} (100%) rename zokrates_cli/examples/book/{for_scope.code => for_scope.zok} (100%) rename zokrates_cli/examples/book/{function_declaration.code => function_declaration.zok} (100%) rename zokrates_cli/examples/book/{function_scope.code => function_scope.zok} (100%) rename zokrates_cli/examples/book/{hashexample.code => hashexample.zok} (70%) rename zokrates_cli/examples/book/{hashexample_updated.code => hashexample_updated.zok} (80%) rename zokrates_cli/examples/book/{if_else.code => if_else.zok} (100%) rename zokrates_cli/examples/book/{multi_def.code => multi_def.zok} (100%) rename zokrates_cli/examples/book/{multi_return.code => multi_return.zok} (100%) rename zokrates_cli/examples/book/{multidim_array.code => multidim_array.zok} (100%) rename zokrates_cli/examples/book/{no_shadowing.code => no_shadowing.zok} (100%) rename zokrates_cli/examples/book/{side_effects.code => side_effects.zok} (100%) rename zokrates_cli/examples/book/{type_annotations.code => type_annotations.zok} (100%) rename zokrates_cli/examples/{bool_and.code => bool_and.zok} (100%) rename zokrates_cli/examples/{bool_not.code => bool_not.zok} (100%) rename zokrates_cli/examples/{bool_or.code => bool_or.zok} (100%) rename zokrates_cli/examples/{boolean_literal.code => boolean_literal.zok} (100%) rename zokrates_cli/examples/{brackets.code => brackets.zok} (100%) rename zokrates_cli/examples/{comments.code => comments.zok} (100%) rename zokrates_cli/examples/{comparison_operators.code => comparison_operators.zok} (100%) rename zokrates_cli/examples/{conditions.code => conditions.zok} (100%) rename zokrates_cli/examples/dex/{decodeOrder.code => decodeOrder.zok} (96%) rename zokrates_cli/examples/dex/{decodeOrderBitwise.code => decodeOrderBitwise.zok} (100%) rename zokrates_cli/examples/dex/{emptyOrder.code => emptyOrder.zok} (100%) rename zokrates_cli/examples/dex/{isPartialOrder.code => isPartialOrder.zok} (100%) rename zokrates_cli/examples/dex/{limitLessThanPrice.code => limitLessThanPrice.zok} (100%) rename zokrates_cli/examples/dex/{popLeastSignificantBit.code => popLeastSignificantBit.zok} (100%) rename zokrates_cli/examples/dex/{ringtrade_example.code => ringtrade_example.zok} (98%) rename zokrates_cli/examples/error/{empty-error.code => empty-error.zok} (100%) rename zokrates_cli/examples/error/{forbidden_power_base.code => forbidden_power_base.zok} (100%) rename zokrates_cli/examples/error/{out_of_for_scope.code => out_of_for_scope.zok} (100%) rename zokrates_cli/examples/error/{shadowing.code => shadowing.zok} (100%) rename zokrates_cli/examples/error/{unassigned.code => unassigned.zok} (100%) rename zokrates_cli/examples/error/{wrongsyntax-error.code => wrongsyntax-error.zok} (100%) rename zokrates_cli/examples/{factorization.code => factorization.zok} (100%) rename zokrates_cli/examples/{flatten.code => flatten.zok} (100%) rename zokrates_cli/examples/{for.code => for.zok} (100%) rename zokrates_cli/examples/functions/{expressions.code => expressions.zok} (100%) rename zokrates_cli/examples/functions/{functions.code => functions.zok} (100%) rename zokrates_cli/examples/functions/{multi_functions.code => multi_functions.zok} (100%) rename zokrates_cli/examples/functions/{multi_shadowing.code => multi_shadowing.zok} (100%) rename zokrates_cli/examples/functions/{no_args_multiple.code => no_args_multiple.zok} (100%) rename zokrates_cli/examples/functions/{shadowing.code => shadowing.zok} (100%) rename zokrates_cli/examples/{functions_equivalent.code => functions_equivalent.zok} (100%) rename zokrates_cli/examples/{if_eq.code => if_eq.zok} (100%) rename zokrates_cli/examples/imports/{bar.code => bar.zok} (100%) rename zokrates_cli/examples/imports/{baz.code => baz.zok} (100%) rename zokrates_cli/examples/imports/{foo.code => foo.zok} (64%) rename zokrates_cli/examples/imports/{import.code => import.zok} (52%) delete mode 100644 zokrates_cli/examples/imports/import_github.code rename zokrates_cli/examples/imports/{import_with_alias.code => import_with_alias.zok} (58%) rename zokrates_cli/examples/{left_side_call.code => left_side_call.zok} (100%) rename zokrates_cli/examples/merkleTree/{pedersenPathProof3.code => pedersenPathProof3.zok} (77%) rename zokrates_cli/examples/merkleTree/{sha256PathProof3.code => sha256PathProof3.zok} (87%) rename zokrates_cli/examples/merkleTree/{testpedersenPathProof3.code => testpedersenPathProof3.zok} (98%) rename zokrates_cli/examples/merkleTree/{testsha256PathProof3.code => testsha256PathProof3.zok} (98%) rename zokrates_cli/examples/{multi_return.code => multi_return.zok} (100%) rename zokrates_cli/examples/{multi_return_sum.code => multi_return_sum.zok} (100%) rename zokrates_cli/examples/{multiple_witnesses.code => multiple_witnesses.zok} (100%) rename zokrates_cli/examples/{n_choose_k.code => n_choose_k.zok} (100%) rename zokrates_cli/examples/{no_flatten.code => no_flatten.zok} (100%) rename zokrates_cli/examples/{pow.code => pow.zok} (100%) rename zokrates_cli/examples/{propagate.code => propagate.zok} (100%) rename zokrates_cli/examples/{propagate_call.code => propagate_call.zok} (100%) rename zokrates_cli/examples/{reassignment.code => reassignment.zok} (100%) rename zokrates_cli/examples/{reduceable_exponent.code => reduceable_exponent.zok} (100%) rename zokrates_cli/examples/runtime_errors/{lt_overflow_max_plus_1.code => lt_overflow_max_plus_1.zok} (100%) rename zokrates_cli/examples/runtime_errors/{lt_overflow_p_minus_one.code => lt_overflow_p_minus_one.zok} (100%) rename zokrates_cli/examples/sha256/binary/{andxorandxorand.code => andxorandxorand.zok} (60%) delete mode 100644 zokrates_cli/examples/sha256/binary/andxornotand.code create mode 100644 zokrates_cli/examples/sha256/binary/andxornotand.zok rename zokrates_cli/examples/sha256/binary/{fulladd.code => fulladd.zok} (70%) rename zokrates_cli/examples/sha256/binary/{halfadd.code => halfadd.zok} (53%) rename zokrates_cli/examples/sha256/bitwise/32/{and.code => and.zok} (87%) rename zokrates_cli/examples/sha256/bitwise/32/{andxorandxorand.code => andxorandxorand.zok} (82%) rename zokrates_cli/examples/sha256/bitwise/32/{andxornotand.code => andxornotand.zok} (83%) rename zokrates_cli/examples/sha256/bitwise/32/{not.code => not.zok} (86%) rename zokrates_cli/examples/sha256/bitwise/32/{xor.code => xor.zok} (87%) rename zokrates_cli/examples/sha256/utils/32/{add.code => add.zok} (89%) rename zokrates_cli/examples/sha256/utils/32/{ar17xar19xars10.code => ar17xar19xars10.zok} (95%) rename zokrates_cli/examples/sha256/utils/32/{ar2xar13xar22.code => ar2xar13xar22.zok} (95%) rename zokrates_cli/examples/sha256/utils/32/{ar6xar11xar25.code => ar6xar11xar25.zok} (95%) rename zokrates_cli/examples/sha256/utils/32/{ar7xar18xars3.code => ar7xar18xars3.zok} (95%) rename zokrates_cli/examples/sha256/utils/32/{compression_round.code => compression_round.zok} (80%) rename zokrates_cli/examples/sha256/utils/32/{extend.code => extend.zok} (82%) rename zokrates_cli/examples/{simple_add.code => simple_add.zok} (100%) rename zokrates_cli/examples/{simple_ifelse.code => simple_ifelse.zok} (100%) rename zokrates_cli/examples/{simple_mul.code => simple_mul.zok} (100%) rename zokrates_cli/examples/{spaces_tabs_comments.code => spaces_tabs_comments.zok} (100%) rename zokrates_cli/examples/{sub.code => sub.zok} (100%) rename zokrates_cli/examples/{sudokuchecker.code => sudokuchecker.zok} (100%) rename zokrates_cli/examples/{synonyms.code => synonyms.zok} (100%) rename zokrates_cli/examples/{taxation.code => taxation.zok} (100%) rename zokrates_cli/examples/{test1.code => test1.zok} (100%) rename zokrates_cli/examples/{test_lt_max_value.code => test_lt_max_value.zok} (100%) rename zokrates_cli/examples/{waldo.code => waldo.zok} (100%) rename zokrates_cli/examples/{wavelets.code => wavelets.zok} (100%) rename zokrates_cli/tests/code/{arithmetics.code => arithmetics.zok} (100%) rename zokrates_cli/tests/code/{if_else_false.code => if_else_false.zok} (100%) rename zokrates_cli/tests/code/{if_else_true.code => if_else_true.zok} (100%) rename zokrates_cli/tests/code/{multidim_update.code => multidim_update.zok} (100%) rename zokrates_cli/tests/code/{n_choose_k.code => n_choose_k.zok} (100%) rename zokrates_cli/tests/code/{no_return.code => no_return.zok} (100%) rename zokrates_cli/tests/code/{return_array.code => return_array.zok} (100%) rename zokrates_cli/tests/code/{sha_round.code => sha_round.zok} (100%) rename zokrates_cli/tests/code/{simple_add.code => simple_add.zok} (100%) rename zokrates_cli/tests/code/{simple_mul.code => simple_mul.zok} (100%) rename zokrates_cli/tests/code/{taxation.code => taxation.zok} (100%) rename zokrates_core_test/tests/tests/{add.code => add.zok} (100%) rename zokrates_core_test/tests/tests/{array_if.code => array_if.zok} (100%) rename zokrates_core_test/tests/tests/{assert_one.code => assert_one.zok} (100%) rename zokrates_core_test/tests/tests/{fact_up_to_4.code => fact_up_to_4.zok} (100%) rename zokrates_core_test/tests/tests/{split.code => split.zok} (100%) rename zokrates_core_test/tests/tests/{spread_slice.code => spread_slice.zok} (100%) rename zokrates_github_resolver/static/{foo.code => foo.zok} (100%) rename zokrates_stdlib/stdlib/ecc/{babyjubjubParams.code => babyjubjubParams.zok} (100%) rename zokrates_stdlib/stdlib/ecc/{edwardsAdd.code => edwardsAdd.zok} (92%) rename zokrates_stdlib/stdlib/ecc/{edwardsCompress.code => edwardsCompress.zok} (89%) rename zokrates_stdlib/stdlib/ecc/{edwardsNegate.code => edwardsNegate.zok} (85%) rename zokrates_stdlib/stdlib/ecc/{edwardsOnCurve.code => edwardsOnCurve.zok} (100%) rename zokrates_stdlib/stdlib/ecc/{edwardsOrderCheck.code => edwardsOrderCheck.zok} (87%) rename zokrates_stdlib/stdlib/ecc/{edwardsScalarMult.code => edwardsScalarMult.zok} (91%) rename zokrates_stdlib/stdlib/ecc/{proofOfOwnership.code => proofOfOwnership.zok} (85%) rename zokrates_stdlib/stdlib/hashes/pedersen/{512bit.code => 512bit.zok} (99%) rename zokrates_stdlib/stdlib/hashes/pedersen/{6bit.code => 6bit.zok} (89%) rename zokrates_stdlib/stdlib/hashes/sha256/{1024bit.code => 1024bit.zok} (78%) rename zokrates_stdlib/stdlib/hashes/sha256/{1024bitPadded.code => 1024bitPadded.zok} (98%) rename zokrates_stdlib/stdlib/hashes/sha256/{1536bit.code => 1536bit.zok} (81%) rename zokrates_stdlib/stdlib/hashes/sha256/{256bitPadded.code => 256bitPadded.zok} (97%) rename zokrates_stdlib/stdlib/hashes/sha256/{512bit.code => 512bit.zok} (70%) rename zokrates_stdlib/stdlib/hashes/sha256/{512bitPacked.code => 512bitPacked.zok} (81%) rename zokrates_stdlib/stdlib/hashes/sha256/{512bitPadded.code => 512bitPadded.zok} (98%) rename zokrates_stdlib/stdlib/hashes/sha256/{IVconstants.code => IVconstants.zok} (100%) rename zokrates_stdlib/stdlib/hashes/sha256/{shaRoundNoBoolCheck.code => shaRoundNoBoolCheck.zok} (100%) rename zokrates_stdlib/stdlib/hashes/utils/{256bitsDirectionHelper.code => 256bitsDirectionHelper.zok} (100%) rename zokrates_stdlib/stdlib/signatures/{verifyEddsa.code => verifyEddsa.zok} (85%) rename zokrates_stdlib/stdlib/utils/binary/{and.code => and.zok} (100%) rename zokrates_stdlib/stdlib/utils/binary/{isbool.code => isbool.zok} (100%) rename zokrates_stdlib/stdlib/utils/binary/{not.code => not.zok} (100%) rename zokrates_stdlib/stdlib/utils/binary/{or.code => or.zok} (59%) rename zokrates_stdlib/stdlib/utils/binary/{xor.code => xor.zok} (100%) rename zokrates_stdlib/stdlib/utils/casts/{1024to256array.code => 1024to256array.zok} (100%) rename zokrates_stdlib/stdlib/utils/multiplexer/{256bit.code => 256bit.zok} (100%) rename zokrates_stdlib/stdlib/utils/multiplexer/{2bit.code => 2bit.zok} (100%) rename zokrates_stdlib/stdlib/utils/multiplexer/{lookup1bit.code => lookup1bit.zok} (100%) rename zokrates_stdlib/stdlib/utils/multiplexer/{lookup2bit.code => lookup2bit.zok} (100%) rename zokrates_stdlib/stdlib/utils/multiplexer/{lookup3bitSigned.code => lookup3bitSigned.zok} (88%) rename zokrates_stdlib/stdlib/utils/pack/{nonStrictUnpack256.code => nonStrictUnpack256.zok} (100%) rename zokrates_stdlib/stdlib/utils/pack/{pack128.code => pack128.zok} (100%) rename zokrates_stdlib/stdlib/utils/pack/{pack256.code => pack256.zok} (100%) rename zokrates_stdlib/stdlib/utils/pack/{unpack128.code => unpack128.zok} (100%) rename zokrates_stdlib/tests/tests/ecc/{edwardsAdd.code => edwardsAdd.zok} (85%) rename zokrates_stdlib/tests/tests/ecc/{edwardsCompress.code => edwardsCompress.zok} (89%) rename zokrates_stdlib/tests/tests/ecc/{edwardsOnCurve.code => edwardsOnCurve.zok} (83%) rename zokrates_stdlib/tests/tests/ecc/{edwardsOrderCheck.code => edwardsOrderCheck.zok} (89%) rename zokrates_stdlib/tests/tests/ecc/{edwardsScalarMult.code => edwardsScalarMult.zok} (98%) rename zokrates_stdlib/tests/tests/ecc/{proofOfOwnership.code => proofOfOwnership.zok} (82%) rename zokrates_stdlib/tests/tests/hashes/pedersen/{512bit.code => 512bit.zok} (98%) rename zokrates_stdlib/tests/tests/hashes/pedersen/{6bit.code => 6bit.zok} (91%) rename zokrates_stdlib/tests/tests/hashes/sha256/{512bit.code => 512bit.zok} (98%) rename zokrates_stdlib/tests/tests/hashes/sha256/{512bitPacked.code => 512bitPacked.zok} (93%) rename zokrates_stdlib/tests/tests/hashes/sha256/{512bitPadded.code => 512bitPadded.zok} (98%) rename zokrates_stdlib/tests/tests/hashes/utils/{256bitsDirectionHelper.code => 256bitsDirectionHelper.zok} (99%) rename zokrates_stdlib/tests/tests/signatures/{verifyEddsa.code => verifyEddsa.zok} (95%) rename zokrates_stdlib/tests/tests/utils/multiplexer/{256bit.code => 256bit.zok} (98%) rename zokrates_stdlib/tests/tests/utils/multiplexer/{2bit.code => 2bit.zok} (88%) rename zokrates_stdlib/tests/tests/utils/multiplexer/{lookup1bit.code => lookup1bit.zok} (83%) rename zokrates_stdlib/tests/tests/utils/multiplexer/{lookup2bit.code => lookup2bit.zok} (91%) rename zokrates_stdlib/tests/tests/utils/multiplexer/{lookup3bitSigned.code => lookup3bitSigned.zok} (95%) rename zokrates_stdlib/tests/tests/utils/pack/{nonStrictUnpack256.code => nonStrictUnpack256.zok} (98%) rename zokrates_stdlib/tests/tests/utils/pack/{pack128.code => pack128.zok} (97%) rename zokrates_stdlib/tests/tests/utils/pack/{unpack128.code => unpack128.zok} (96%) diff --git a/.gitignore b/.gitignore index 08062cd8..5468c136 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ # ZoKrates default files out -out.code +out.zok out.wit proof.json proving.key diff --git a/out.ztf b/out.ztf new file mode 100644 index 00000000..17a2fd30 --- /dev/null +++ b/out.ztf @@ -0,0 +1,3 @@ +def main(_0) -> (1): + (1 * ~one) * (28 * ~one + 10 * _0) == 1 * ~out_0 + return ~out_0 diff --git a/zokrates_book/src/concepts/comments.md b/zokrates_book/src/concepts/comments.md index 268a2f4b..cd06cfeb 100644 --- a/zokrates_book/src/concepts/comments.md +++ b/zokrates_book/src/concepts/comments.md @@ -3,5 +3,5 @@ Comments can be added with double-slashes. ```zokrates -{{#include ../../../zokrates_cli/examples/book/comments.code}} +{{#include ../../../zokrates_cli/examples/book/comments.zok}} ``` \ No newline at end of file diff --git a/zokrates_book/src/concepts/control_flow.md b/zokrates_book/src/concepts/control_flow.md index 24b1c2f1..bfebf346 100644 --- a/zokrates_book/src/concepts/control_flow.md +++ b/zokrates_book/src/concepts/control_flow.md @@ -9,7 +9,7 @@ Function calls can help make programs clearer and more modular. However, using f Arguments are passed by value. ```zokrates -{{#include ../../../zokrates_cli/examples/book/side_effects.code}} +{{#include ../../../zokrates_cli/examples/book/side_effects.zok}} ``` ### If expressions @@ -17,7 +17,7 @@ Arguments are passed by value. An if expression allows you to branch your code depending on a condition. ```zokrates -{{#include ../../../zokrates_cli/examples/book/if_else.code}} +{{#include ../../../zokrates_cli/examples/book/if_else.zok}} ``` The condition supports `<`, `<=`, `>`, `>=`, `==`, which can be combined with the boolean operators `&&`, `||` and `!`. @@ -29,7 +29,7 @@ The condition supports `<`, `<=`, `>`, `>=`, `==`, which can be combined with th For loops are available with the following syntax: ```zokrates -{{#include ../../../zokrates_cli/examples/book/for.code}} +{{#include ../../../zokrates_cli/examples/book/for.zok}} ``` The bounds have to be known at compile time, so only constants are allowed. diff --git a/zokrates_book/src/concepts/functions.md b/zokrates_book/src/concepts/functions.md index 3a3bf85a..be307bae 100644 --- a/zokrates_book/src/concepts/functions.md +++ b/zokrates_book/src/concepts/functions.md @@ -3,14 +3,14 @@ A function has to be declared at the top level before it is called. ```zokrates -{{#include ../../../zokrates_cli/examples/book/function_declaration.code}} +{{#include ../../../zokrates_cli/examples/book/function_declaration.zok}} ``` A function's signature has to be explicitly provided. Functions can return many values by providing them as a comma-separated list. ```zokrates -{{#include ../../../zokrates_cli/examples/book/multi_return.code}} +{{#include ../../../zokrates_cli/examples/book/multi_return.zok}} ``` ### Inference @@ -18,11 +18,11 @@ Functions can return many values by providing them as a comma-separated list. When defining a variable as the return value of a function, types are optional: ```zokrates -{{#include ../../../zokrates_cli/examples/book/multi_def.code}} +{{#include ../../../zokrates_cli/examples/book/multi_def.zok}} ``` If there is an ambiguity, providing the types of some of the assigned variables is necessary. ```zokrates -{{#include ../../../zokrates_cli/examples/book/type_annotations.code}} +{{#include ../../../zokrates_cli/examples/book/type_annotations.zok}} ``` \ No newline at end of file diff --git a/zokrates_book/src/concepts/imports.md b/zokrates_book/src/concepts/imports.md index a8e93b6d..aeda193a 100644 --- a/zokrates_book/src/concepts/imports.md +++ b/zokrates_book/src/concepts/imports.md @@ -6,22 +6,22 @@ You can separate your code into multiple ZoKrates files using `import` statement You can import a resource in the same folder directly, like this: ```zokrates -import "./mycode.code" +import "./mycode.zok" ``` There also is a handy syntax to import from the parent directory: ```zokrates -import "../mycode.code" +import "../mycode.zok" ``` Also imports further up the file-system are supported: ```zokrates -import "../../../mycode.code" +import "../../../mycode.zok" ``` You can also choose to rename the imported resource, like so: ```zokrates -import "./mycode.code" as abc +import "./mycode.zok" as abc ``` ### Absolute Imports diff --git a/zokrates_book/src/concepts/stdlib.md b/zokrates_book/src/concepts/stdlib.md index b648db8d..150afd97 100644 --- a/zokrates_book/src/concepts/stdlib.md +++ b/zokrates_book/src/concepts/stdlib.md @@ -9,7 +9,7 @@ The following section highlights a subset of available imports: #### sha256 ```zokrates -import "hashes/sha256/512Padded.code" +import "hashes/sha256/512Padded.zok" ``` A function that takes 2 `field[256]` arrays as inputs and returns their sha256 compression function as an array of 256 field elements. @@ -17,18 +17,18 @@ A function that takes 2 `field[256]` arrays as inputs and returns their sha256 c #### sha256compression ```zokrates -import "hashes/sha256/512bit.code" +import "hashes/sha256/512bit.zok" ``` A function that takes 2 `field[256]` arrays as inputs and returns their sha256 compression function as an array of 256 field elements. The difference with `sha256` is that no padding is added at the end of the message, which makes it more efficient but also less compatible with Solidity. -There also is support for 2-round (1024-bit input) and and 3-round (1536-bit input) variants, using `hashes/1024bit.code` or `hashes/1536bit.code` respectively. +There also is support for 2-round (1024-bit input) and and 3-round (1536-bit input) variants, using `hashes/1024bit.zok` or `hashes/1536bit.zok` respectively. #### sha256packed ```zokrates -import "hashes/sha256/512bitPacked.code" +import "hashes/sha256/512bitPacked.zok" ``` A function that takes an array of 4 field elements as inputs, unpacks each of them to 128 bits (big endian), concatenates them and applies sha256. It then returns an array of 2 field elements, each representing 128 bits of the result. @@ -38,7 +38,7 @@ A function that takes an array of 4 field elements as inputs, unpacks each of th #### Proof of private-key ownership ```zokrates -import "ecc/proofOfOwnership.code" +import "ecc/proofOfOwnership.zok" ``` Verifies match of a given public/private keypair. Checks if the following equation holds for the provided keypair: @@ -48,7 +48,7 @@ where `G` is the chosen base point of the subgroup and `*` denotes scalar multip #### Signature verification ```zokrates -import "signatures/verifyEddsa.code" +import "signatures/verifyEddsa.zok" ``` Verifies an EdDSA Signature. Checks the correctness of a given EdDSA Signature `(R,S)` for the provided public key `A` and message `(M0, M1)`. Check out this [python repository](https://github.com/Zokrates/pycrypto) for tooling to create valid signatures. diff --git a/zokrates_book/src/concepts/types.md b/zokrates_book/src/concepts/types.md index 23264b1a..d75698de 100644 --- a/zokrates_book/src/concepts/types.md +++ b/zokrates_book/src/concepts/types.md @@ -13,7 +13,7 @@ The prime `p` is set to `2188824287183927522224640574525727508854836440041603434 While `field` values mostly behave like unsigned integers, one should keep in mind that they overflow at `p` and not some power of 2, so that we have: ```zokrates -{{#include ../../../zokrates_cli/examples/book/field_overflow.code}} +{{#include ../../../zokrates_cli/examples/book/field_overflow.zok}} ``` #### `bool` @@ -34,7 +34,7 @@ Arrays can contain elements of any type and have arbitrary dimensions. The following examples code shows examples of how to use arrays: ```zokrates -{{#include ../../../zokrates_cli/examples/book/array.code}} +{{#include ../../../zokrates_cli/examples/book/array.zok}} ``` ##### Declaration and Initialization @@ -64,7 +64,7 @@ In summary, this leads to the following scheme for array declarations: Consider the following example: ```zokrates -{{#include ../../../zokrates_cli/examples/book/multidim_array.code}} +{{#include ../../../zokrates_cli/examples/book/multidim_array.zok}} ``` ##### Spreads and Slices diff --git a/zokrates_book/src/concepts/variables.md b/zokrates_book/src/concepts/variables.md index dab25416..8d58da06 100644 --- a/zokrates_book/src/concepts/variables.md +++ b/zokrates_book/src/concepts/variables.md @@ -7,7 +7,7 @@ Variables are mutable, and always passed by value to functions. Shadowing is not allowed. ```zokrates -{{#include ../../../zokrates_cli/examples/book/no_shadowing.code}} +{{#include ../../../zokrates_cli/examples/book/no_shadowing.zok}} ``` ### Scope @@ -16,11 +16,11 @@ Shadowing is not allowed. Functions have their own scope ```zokrates -{{#include ../../../zokrates_cli/examples/book/function_scope.code}} +{{#include ../../../zokrates_cli/examples/book/function_scope.zok}} ``` #### For-loop For-loops have their own scope ```zokrates -{{#include ../../../zokrates_cli/examples/book/for_scope.code}} +{{#include ../../../zokrates_cli/examples/book/for_scope.zok}} ``` \ No newline at end of file diff --git a/zokrates_book/src/gettingstarted.md b/zokrates_book/src/gettingstarted.md index 3cc94af6..6e0bad85 100644 --- a/zokrates_book/src/gettingstarted.md +++ b/zokrates_book/src/gettingstarted.md @@ -33,10 +33,10 @@ cd target/release ## Hello ZoKrates! -First, create the text-file `root.code` and implement your program. In this example, we will prove knowledge of the square root `a` of a number `b`: +First, create the text-file `root.zok` and implement your program. In this example, we will prove knowledge of the square root `a` of a number `b`: ```zokrates -{{#include ../../zokrates_cli/examples/book/factorize.code}} +{{#include ../../zokrates_cli/examples/book/factorize.zok}} ``` Some observations: @@ -47,7 +47,7 @@ Then run the different phases of the protocol: ```bash # compile -./zokrates compile -i root.code +./zokrates compile -i root.zok # perform the setup phase ./zokrates setup # execute the program diff --git a/zokrates_book/src/reference/cli.md b/zokrates_book/src/reference/cli.md index 66d6ee8e..5ca9a53f 100644 --- a/zokrates_book/src/reference/cli.md +++ b/zokrates_book/src/reference/cli.md @@ -10,12 +10,12 @@ You can see an overview of the available subcommands by running ## `compile` ```sh -./zokrates compile -i /path/to/add.code +./zokrates compile -i /path/to/add.zok ``` -Compiles a `.code` file into ZoKrates internal representation of arithmetic circuits. +Compiles a `.zok` file into ZoKrates internal representation of arithmetic circuits. -Creates a compiled `.code` file at `./out.code`. +Creates a compiled `.zok` file at `./out.zok`. ## `compute-witness` @@ -23,7 +23,7 @@ Creates a compiled `.code` file at `./out.code`. ./zokrates compute-witness -a 1 2 3 ``` -Computes a witness for the compiled program found at `./out.code` and arguments to the program. +Computes a witness for the compiled program found at `./out.zok` and arguments to the program. A witness is a valid assignment of the variables, which include the results of the computation. Arguments to the program are passed as a space-separated list with the `-a` flag, or over `stdin`. @@ -35,7 +35,7 @@ Creates a witness file at `./witness` ./zokrates setup ``` -Generates a trusted setup for the compiled program found at `./out.code`. +Generates a trusted setup for the compiled program found at `./out.zok`. Creates a proving key and a verifying key at `./proving.key` and `./verifying.key`. These keys are derived from a source of randomness, commonly referred to as “toxic waste”. Anyone having access to the source of randomness can produce fake proofs that will be accepted by a verifier following the protocol. @@ -46,7 +46,7 @@ These keys are derived from a source of randomness, commonly referred to as “t ./zokrates export-verifier ``` -Using the verifying key at `./verifying.key`, generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program at `./out.code`. +Using the verifying key at `./verifying.key`, generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program at `./out.zok`. Creates a verifier contract at `./verifier.sol`. @@ -56,7 +56,7 @@ Creates a verifier contract at `./verifier.sol`. ./zokrates generate-proof ``` -Using the proving key at `./proving.key`, generates a proof for a computation of the compiled program `./out.code` resulting in `./witness`. +Using the proving key at `./proving.key`, generates a proof for a computation of the compiled program `./out.zok` resulting in `./witness`. Returns the proof, for example: diff --git a/zokrates_book/src/sha256example.md b/zokrates_book/src/sha256example.md index e4373208..38572546 100644 --- a/zokrates_book/src/sha256example.md +++ b/zokrates_book/src/sha256example.md @@ -13,10 +13,10 @@ Make sure you have followed the instructions in the [Getting Started](gettingsta We will start this tutorial by using ZoKrates to compute the hash for an arbitrarily chosen preimage, being the number `5` in this example. -First, we create a new file named `hashexample.code` with the following content: +First, we create a new file named `hashexample.zok` with the following content: ```zokrates -{{#include ../../zokrates_cli/examples/book/hashexample.code}} +{{#include ../../zokrates_cli/examples/book/hashexample.zok}} ``` The first line imports the `sha256packed` function from the ZoKrates standard library. @@ -32,7 +32,7 @@ Having our problem described in ZoKrates' DSL, we can now continue using ZoKrate First, we compile the program into an arithmetic circuit using the `compile` command. ```sh -./zokrates compile -i hashexample.code +./zokrates compile -i hashexample.zok ``` As a next step we can create a witness file using the following command: @@ -67,10 +67,10 @@ Let's recall our goal: Peggy wants to prove that she knows a preimage for a dige To make it work, the two parties have to follow their roles in the protocol: -First, Victor has to specify what hash he is interested in. Therefore, we have to adjust the zkSNARK circuit, compiled by ZoKrates, such that in addition to computing the digest, it also validates it against the digest of interest, provided by Victor. This leads to the following update for `hashexample.code`: +First, Victor has to specify what hash he is interested in. Therefore, we have to adjust the zkSNARK circuit, compiled by ZoKrates, such that in addition to computing the digest, it also validates it against the digest of interest, provided by Victor. This leads to the following update for `hashexample.zok`: ```zokrates -{{#include ../../zokrates_cli/examples/book/hashexample_updated.code}} +{{#include ../../zokrates_cli/examples/book/hashexample_updated.zok}} ``` Note that we now compare the result of `sha256packed` with the hard-coded correct solution defined by Victor. The lines which we added are treated as assertions: the verifier will not accept a proof where these constraints were not satisfied. Clearly, this program only returns 1 if all of the computed bits are equal. @@ -78,7 +78,7 @@ Note that we now compare the result of `sha256packed` with the hard-coded correc So, having defined the program, Victor is now ready to compile the code: ```sh -./zokrates compile -i hashexample.code +./zokrates compile -i hashexample.zok ``` Based on that Victor can run the setup phase and export verifier smart contract as a Solidity file: diff --git a/zokrates_cli/examples/add.code b/zokrates_cli/examples/add.zok similarity index 100% rename from zokrates_cli/examples/add.code rename to zokrates_cli/examples/add.zok diff --git a/zokrates_cli/examples/argument_reassign.code b/zokrates_cli/examples/argument_reassign.zok similarity index 100% rename from zokrates_cli/examples/argument_reassign.code rename to zokrates_cli/examples/argument_reassign.zok diff --git a/zokrates_cli/examples/arrays/array_argument.code b/zokrates_cli/examples/arrays/array_argument.zok similarity index 100% rename from zokrates_cli/examples/arrays/array_argument.code rename to zokrates_cli/examples/arrays/array_argument.zok diff --git a/zokrates_cli/examples/arrays/array_loop.code b/zokrates_cli/examples/arrays/array_loop.zok similarity index 100% rename from zokrates_cli/examples/arrays/array_loop.code rename to zokrates_cli/examples/arrays/array_loop.zok diff --git a/zokrates_cli/examples/arrays/array_loop_update.code b/zokrates_cli/examples/arrays/array_loop_update.zok similarity index 100% rename from zokrates_cli/examples/arrays/array_loop_update.code rename to zokrates_cli/examples/arrays/array_loop_update.zok diff --git a/zokrates_cli/examples/arrays/boolean_array.code b/zokrates_cli/examples/arrays/boolean_array.zok similarity index 100% rename from zokrates_cli/examples/arrays/boolean_array.code rename to zokrates_cli/examples/arrays/boolean_array.zok diff --git a/zokrates_cli/examples/arrays/constant_array.code b/zokrates_cli/examples/arrays/constant_array.zok similarity index 100% rename from zokrates_cli/examples/arrays/constant_array.code rename to zokrates_cli/examples/arrays/constant_array.zok diff --git a/zokrates_cli/examples/arrays/cube.code b/zokrates_cli/examples/arrays/cube.zok similarity index 100% rename from zokrates_cli/examples/arrays/cube.code rename to zokrates_cli/examples/arrays/cube.zok diff --git a/zokrates_cli/examples/arrays/if_eq.code b/zokrates_cli/examples/arrays/if_eq.zok similarity index 100% rename from zokrates_cli/examples/arrays/if_eq.code rename to zokrates_cli/examples/arrays/if_eq.zok diff --git a/zokrates_cli/examples/arrays/init_with_value.code b/zokrates_cli/examples/arrays/init_with_value.zok similarity index 100% rename from zokrates_cli/examples/arrays/init_with_value.code rename to zokrates_cli/examples/arrays/init_with_value.zok diff --git a/zokrates_cli/examples/arrays/lookup.code b/zokrates_cli/examples/arrays/lookup.zok similarity index 100% rename from zokrates_cli/examples/arrays/lookup.code rename to zokrates_cli/examples/arrays/lookup.zok diff --git a/zokrates_cli/examples/arrays/multidim_update.code b/zokrates_cli/examples/arrays/multidim_update.zok similarity index 100% rename from zokrates_cli/examples/arrays/multidim_update.code rename to zokrates_cli/examples/arrays/multidim_update.zok diff --git a/zokrates_cli/examples/arrays/return_array.code b/zokrates_cli/examples/arrays/return_array.zok similarity index 100% rename from zokrates_cli/examples/arrays/return_array.code rename to zokrates_cli/examples/arrays/return_array.zok diff --git a/zokrates_cli/examples/arrays/return_variable_array.code b/zokrates_cli/examples/arrays/return_variable_array.zok similarity index 100% rename from zokrates_cli/examples/arrays/return_variable_array.code rename to zokrates_cli/examples/arrays/return_variable_array.zok diff --git a/zokrates_cli/examples/arrays/slicefrom.code b/zokrates_cli/examples/arrays/slicefrom.zok similarity index 100% rename from zokrates_cli/examples/arrays/slicefrom.code rename to zokrates_cli/examples/arrays/slicefrom.zok diff --git a/zokrates_cli/examples/arrays/update.code b/zokrates_cli/examples/arrays/update.zok similarity index 100% rename from zokrates_cli/examples/arrays/update.code rename to zokrates_cli/examples/arrays/update.zok diff --git a/zokrates_cli/examples/arrays/update_with_call.code b/zokrates_cli/examples/arrays/update_with_call.zok similarity index 100% rename from zokrates_cli/examples/arrays/update_with_call.code rename to zokrates_cli/examples/arrays/update_with_call.zok diff --git a/zokrates_cli/examples/arrays/value.code b/zokrates_cli/examples/arrays/value.zok similarity index 100% rename from zokrates_cli/examples/arrays/value.code rename to zokrates_cli/examples/arrays/value.zok diff --git a/zokrates_cli/examples/arrays/wrap_select.code b/zokrates_cli/examples/arrays/wrap_select.zok similarity index 100% rename from zokrates_cli/examples/arrays/wrap_select.code rename to zokrates_cli/examples/arrays/wrap_select.zok diff --git a/zokrates_cli/examples/book/array.code b/zokrates_cli/examples/book/array.zok similarity index 100% rename from zokrates_cli/examples/book/array.code rename to zokrates_cli/examples/book/array.zok diff --git a/zokrates_cli/examples/book/comments.code b/zokrates_cli/examples/book/comments.zok similarity index 100% rename from zokrates_cli/examples/book/comments.code rename to zokrates_cli/examples/book/comments.zok diff --git a/zokrates_cli/examples/book/factorize.code b/zokrates_cli/examples/book/factorize.zok similarity index 100% rename from zokrates_cli/examples/book/factorize.code rename to zokrates_cli/examples/book/factorize.zok diff --git a/zokrates_cli/examples/book/field_overflow.code b/zokrates_cli/examples/book/field_overflow.zok similarity index 100% rename from zokrates_cli/examples/book/field_overflow.code rename to zokrates_cli/examples/book/field_overflow.zok diff --git a/zokrates_cli/examples/book/for.code b/zokrates_cli/examples/book/for.zok similarity index 100% rename from zokrates_cli/examples/book/for.code rename to zokrates_cli/examples/book/for.zok diff --git a/zokrates_cli/examples/book/for_scope.code b/zokrates_cli/examples/book/for_scope.zok similarity index 100% rename from zokrates_cli/examples/book/for_scope.code rename to zokrates_cli/examples/book/for_scope.zok diff --git a/zokrates_cli/examples/book/function_declaration.code b/zokrates_cli/examples/book/function_declaration.zok similarity index 100% rename from zokrates_cli/examples/book/function_declaration.code rename to zokrates_cli/examples/book/function_declaration.zok diff --git a/zokrates_cli/examples/book/function_scope.code b/zokrates_cli/examples/book/function_scope.zok similarity index 100% rename from zokrates_cli/examples/book/function_scope.code rename to zokrates_cli/examples/book/function_scope.zok diff --git a/zokrates_cli/examples/book/hashexample.code b/zokrates_cli/examples/book/hashexample.zok similarity index 70% rename from zokrates_cli/examples/book/hashexample.code rename to zokrates_cli/examples/book/hashexample.zok index 94cc3d88..ba90147e 100644 --- a/zokrates_cli/examples/book/hashexample.code +++ b/zokrates_cli/examples/book/hashexample.zok @@ -1,4 +1,4 @@ -import "hashes/sha256/512bitPacked.code" as sha256packed +import "hashes/sha256/512bitPacked" as sha256packed def main(private field a, private field b, private field c, private field d) -> (field[2]): h = sha256packed([a, b, c, d]) diff --git a/zokrates_cli/examples/book/hashexample_updated.code b/zokrates_cli/examples/book/hashexample_updated.zok similarity index 80% rename from zokrates_cli/examples/book/hashexample_updated.code rename to zokrates_cli/examples/book/hashexample_updated.zok index e396cb1e..b7daee58 100644 --- a/zokrates_cli/examples/book/hashexample_updated.code +++ b/zokrates_cli/examples/book/hashexample_updated.zok @@ -1,4 +1,4 @@ -import "hashes/sha256/512bitPacked.code" as sha256packed +import "hashes/sha256/512bitPacked" as sha256packed def main(private field a, private field b, private field c, private field d) -> (field): h = sha256packed([a, b, c, d]) diff --git a/zokrates_cli/examples/book/if_else.code b/zokrates_cli/examples/book/if_else.zok similarity index 100% rename from zokrates_cli/examples/book/if_else.code rename to zokrates_cli/examples/book/if_else.zok diff --git a/zokrates_cli/examples/book/multi_def.code b/zokrates_cli/examples/book/multi_def.zok similarity index 100% rename from zokrates_cli/examples/book/multi_def.code rename to zokrates_cli/examples/book/multi_def.zok diff --git a/zokrates_cli/examples/book/multi_return.code b/zokrates_cli/examples/book/multi_return.zok similarity index 100% rename from zokrates_cli/examples/book/multi_return.code rename to zokrates_cli/examples/book/multi_return.zok diff --git a/zokrates_cli/examples/book/multidim_array.code b/zokrates_cli/examples/book/multidim_array.zok similarity index 100% rename from zokrates_cli/examples/book/multidim_array.code rename to zokrates_cli/examples/book/multidim_array.zok diff --git a/zokrates_cli/examples/book/no_shadowing.code b/zokrates_cli/examples/book/no_shadowing.zok similarity index 100% rename from zokrates_cli/examples/book/no_shadowing.code rename to zokrates_cli/examples/book/no_shadowing.zok diff --git a/zokrates_cli/examples/book/side_effects.code b/zokrates_cli/examples/book/side_effects.zok similarity index 100% rename from zokrates_cli/examples/book/side_effects.code rename to zokrates_cli/examples/book/side_effects.zok diff --git a/zokrates_cli/examples/book/type_annotations.code b/zokrates_cli/examples/book/type_annotations.zok similarity index 100% rename from zokrates_cli/examples/book/type_annotations.code rename to zokrates_cli/examples/book/type_annotations.zok diff --git a/zokrates_cli/examples/bool_and.code b/zokrates_cli/examples/bool_and.zok similarity index 100% rename from zokrates_cli/examples/bool_and.code rename to zokrates_cli/examples/bool_and.zok diff --git a/zokrates_cli/examples/bool_not.code b/zokrates_cli/examples/bool_not.zok similarity index 100% rename from zokrates_cli/examples/bool_not.code rename to zokrates_cli/examples/bool_not.zok diff --git a/zokrates_cli/examples/bool_or.code b/zokrates_cli/examples/bool_or.zok similarity index 100% rename from zokrates_cli/examples/bool_or.code rename to zokrates_cli/examples/bool_or.zok diff --git a/zokrates_cli/examples/boolean_literal.code b/zokrates_cli/examples/boolean_literal.zok similarity index 100% rename from zokrates_cli/examples/boolean_literal.code rename to zokrates_cli/examples/boolean_literal.zok diff --git a/zokrates_cli/examples/brackets.code b/zokrates_cli/examples/brackets.zok similarity index 100% rename from zokrates_cli/examples/brackets.code rename to zokrates_cli/examples/brackets.zok diff --git a/zokrates_cli/examples/comments.code b/zokrates_cli/examples/comments.zok similarity index 100% rename from zokrates_cli/examples/comments.code rename to zokrates_cli/examples/comments.zok diff --git a/zokrates_cli/examples/comparison_operators.code b/zokrates_cli/examples/comparison_operators.zok similarity index 100% rename from zokrates_cli/examples/comparison_operators.code rename to zokrates_cli/examples/comparison_operators.zok diff --git a/zokrates_cli/examples/conditions.code b/zokrates_cli/examples/conditions.zok similarity index 100% rename from zokrates_cli/examples/conditions.code rename to zokrates_cli/examples/conditions.zok diff --git a/zokrates_cli/examples/dex/decodeOrder.code b/zokrates_cli/examples/dex/decodeOrder.zok similarity index 96% rename from zokrates_cli/examples/dex/decodeOrder.code rename to zokrates_cli/examples/dex/decodeOrder.zok index 3bca63d2..db917f29 100644 --- a/zokrates_cli/examples/dex/decodeOrder.code +++ b/zokrates_cli/examples/dex/decodeOrder.zok @@ -1,4 +1,4 @@ -import "./popLeastSignificantBit.code" +import "./popLeastSignificantBit" def main(field order) -> (field, field, field, field): // MSB diff --git a/zokrates_cli/examples/dex/decodeOrderBitwise.code b/zokrates_cli/examples/dex/decodeOrderBitwise.zok similarity index 100% rename from zokrates_cli/examples/dex/decodeOrderBitwise.code rename to zokrates_cli/examples/dex/decodeOrderBitwise.zok diff --git a/zokrates_cli/examples/dex/emptyOrder.code b/zokrates_cli/examples/dex/emptyOrder.zok similarity index 100% rename from zokrates_cli/examples/dex/emptyOrder.code rename to zokrates_cli/examples/dex/emptyOrder.zok diff --git a/zokrates_cli/examples/dex/isPartialOrder.code b/zokrates_cli/examples/dex/isPartialOrder.zok similarity index 100% rename from zokrates_cli/examples/dex/isPartialOrder.code rename to zokrates_cli/examples/dex/isPartialOrder.zok diff --git a/zokrates_cli/examples/dex/limitLessThanPrice.code b/zokrates_cli/examples/dex/limitLessThanPrice.zok similarity index 100% rename from zokrates_cli/examples/dex/limitLessThanPrice.code rename to zokrates_cli/examples/dex/limitLessThanPrice.zok diff --git a/zokrates_cli/examples/dex/popLeastSignificantBit.code b/zokrates_cli/examples/dex/popLeastSignificantBit.zok similarity index 100% rename from zokrates_cli/examples/dex/popLeastSignificantBit.code rename to zokrates_cli/examples/dex/popLeastSignificantBit.zok diff --git a/zokrates_cli/examples/dex/ringtrade_example.code b/zokrates_cli/examples/dex/ringtrade_example.zok similarity index 98% rename from zokrates_cli/examples/dex/ringtrade_example.code rename to zokrates_cli/examples/dex/ringtrade_example.zok index f1f19c38..44f50479 100644 --- a/zokrates_cli/examples/dex/ringtrade_example.code +++ b/zokrates_cli/examples/dex/ringtrade_example.zok @@ -1,5 +1,5 @@ -import "./decodeOrder.code" -import "./limitLessThanPrice.code" +import "./decodeOrder" +import "./limitLessThanPrice" def tupleForTokensWithValue(field value) -> (field[3]): return [value, value, value] diff --git a/zokrates_cli/examples/error/empty-error.code b/zokrates_cli/examples/error/empty-error.zok similarity index 100% rename from zokrates_cli/examples/error/empty-error.code rename to zokrates_cli/examples/error/empty-error.zok diff --git a/zokrates_cli/examples/error/forbidden_power_base.code b/zokrates_cli/examples/error/forbidden_power_base.zok similarity index 100% rename from zokrates_cli/examples/error/forbidden_power_base.code rename to zokrates_cli/examples/error/forbidden_power_base.zok diff --git a/zokrates_cli/examples/error/out_of_for_scope.code b/zokrates_cli/examples/error/out_of_for_scope.zok similarity index 100% rename from zokrates_cli/examples/error/out_of_for_scope.code rename to zokrates_cli/examples/error/out_of_for_scope.zok diff --git a/zokrates_cli/examples/error/shadowing.code b/zokrates_cli/examples/error/shadowing.zok similarity index 100% rename from zokrates_cli/examples/error/shadowing.code rename to zokrates_cli/examples/error/shadowing.zok diff --git a/zokrates_cli/examples/error/unassigned.code b/zokrates_cli/examples/error/unassigned.zok similarity index 100% rename from zokrates_cli/examples/error/unassigned.code rename to zokrates_cli/examples/error/unassigned.zok diff --git a/zokrates_cli/examples/error/wrongsyntax-error.code b/zokrates_cli/examples/error/wrongsyntax-error.zok similarity index 100% rename from zokrates_cli/examples/error/wrongsyntax-error.code rename to zokrates_cli/examples/error/wrongsyntax-error.zok diff --git a/zokrates_cli/examples/factorization.code b/zokrates_cli/examples/factorization.zok similarity index 100% rename from zokrates_cli/examples/factorization.code rename to zokrates_cli/examples/factorization.zok diff --git a/zokrates_cli/examples/flatten.code b/zokrates_cli/examples/flatten.zok similarity index 100% rename from zokrates_cli/examples/flatten.code rename to zokrates_cli/examples/flatten.zok diff --git a/zokrates_cli/examples/for.code b/zokrates_cli/examples/for.zok similarity index 100% rename from zokrates_cli/examples/for.code rename to zokrates_cli/examples/for.zok diff --git a/zokrates_cli/examples/functions/expressions.code b/zokrates_cli/examples/functions/expressions.zok similarity index 100% rename from zokrates_cli/examples/functions/expressions.code rename to zokrates_cli/examples/functions/expressions.zok diff --git a/zokrates_cli/examples/functions/functions.code b/zokrates_cli/examples/functions/functions.zok similarity index 100% rename from zokrates_cli/examples/functions/functions.code rename to zokrates_cli/examples/functions/functions.zok diff --git a/zokrates_cli/examples/functions/multi_functions.code b/zokrates_cli/examples/functions/multi_functions.zok similarity index 100% rename from zokrates_cli/examples/functions/multi_functions.code rename to zokrates_cli/examples/functions/multi_functions.zok diff --git a/zokrates_cli/examples/functions/multi_shadowing.code b/zokrates_cli/examples/functions/multi_shadowing.zok similarity index 100% rename from zokrates_cli/examples/functions/multi_shadowing.code rename to zokrates_cli/examples/functions/multi_shadowing.zok diff --git a/zokrates_cli/examples/functions/no_args_multiple.code b/zokrates_cli/examples/functions/no_args_multiple.zok similarity index 100% rename from zokrates_cli/examples/functions/no_args_multiple.code rename to zokrates_cli/examples/functions/no_args_multiple.zok diff --git a/zokrates_cli/examples/functions/shadowing.code b/zokrates_cli/examples/functions/shadowing.zok similarity index 100% rename from zokrates_cli/examples/functions/shadowing.code rename to zokrates_cli/examples/functions/shadowing.zok diff --git a/zokrates_cli/examples/functions_equivalent.code b/zokrates_cli/examples/functions_equivalent.zok similarity index 100% rename from zokrates_cli/examples/functions_equivalent.code rename to zokrates_cli/examples/functions_equivalent.zok diff --git a/zokrates_cli/examples/if_eq.code b/zokrates_cli/examples/if_eq.zok similarity index 100% rename from zokrates_cli/examples/if_eq.code rename to zokrates_cli/examples/if_eq.zok diff --git a/zokrates_cli/examples/imports/bar.code b/zokrates_cli/examples/imports/bar.zok similarity index 100% rename from zokrates_cli/examples/imports/bar.code rename to zokrates_cli/examples/imports/bar.zok diff --git a/zokrates_cli/examples/imports/baz.code b/zokrates_cli/examples/imports/baz.zok similarity index 100% rename from zokrates_cli/examples/imports/baz.code rename to zokrates_cli/examples/imports/baz.zok diff --git a/zokrates_cli/examples/imports/foo.code b/zokrates_cli/examples/imports/foo.zok similarity index 64% rename from zokrates_cli/examples/imports/foo.code rename to zokrates_cli/examples/imports/foo.zok index 9b2256b4..6e2e0540 100644 --- a/zokrates_cli/examples/imports/foo.code +++ b/zokrates_cli/examples/imports/foo.zok @@ -1,4 +1,4 @@ -import "./baz.code" +import "./baz" def main() -> (field): return baz() \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import.code b/zokrates_cli/examples/imports/import.zok similarity index 52% rename from zokrates_cli/examples/imports/import.code rename to zokrates_cli/examples/imports/import.zok index 6f708d24..eb495d4f 100644 --- a/zokrates_cli/examples/imports/import.code +++ b/zokrates_cli/examples/imports/import.zok @@ -1,5 +1,5 @@ -import "./foo.code" -import "./bar.code" +import "./foo" +import "./bar" def main() -> (field): return foo() + bar() \ No newline at end of file diff --git a/zokrates_cli/examples/imports/import_github.code b/zokrates_cli/examples/imports/import_github.code deleted file mode 100644 index ec30f95e..00000000 --- a/zokrates_cli/examples/imports/import_github.code +++ /dev/null @@ -1,6 +0,0 @@ -// See also mock URLs in zokrates_github_resolver -import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/foo.code" -import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/bar.code" - -def main() -> (field): - return foo() + bar() diff --git a/zokrates_cli/examples/imports/import_with_alias.code b/zokrates_cli/examples/imports/import_with_alias.zok similarity index 58% rename from zokrates_cli/examples/imports/import_with_alias.code rename to zokrates_cli/examples/imports/import_with_alias.zok index 38e1b0c7..2feb96ea 100644 --- a/zokrates_cli/examples/imports/import_with_alias.code +++ b/zokrates_cli/examples/imports/import_with_alias.zok @@ -1,4 +1,4 @@ -import "./foo.code" as d +import "./foo" as d def main() -> (field): return d() \ No newline at end of file diff --git a/zokrates_cli/examples/left_side_call.code b/zokrates_cli/examples/left_side_call.zok similarity index 100% rename from zokrates_cli/examples/left_side_call.code rename to zokrates_cli/examples/left_side_call.zok diff --git a/zokrates_cli/examples/merkleTree/pedersenPathProof3.code b/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok similarity index 77% rename from zokrates_cli/examples/merkleTree/pedersenPathProof3.code rename to zokrates_cli/examples/merkleTree/pedersenPathProof3.zok index cebd967a..4f8fdaed 100644 --- a/zokrates_cli/examples/merkleTree/pedersenPathProof3.code +++ b/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok @@ -1,8 +1,8 @@ -import "hashes/pedersen/512bit.code" as hash -import "ecc/edwardsCompress.code" as edwardsCompress -import "ecc/babyjubjubParams.code" as context -import "hashes/utils/256bitsDirectionHelper.code" as multiplex -import "utils/binary/not.code" as NOT +import "hashes/pedersen/512bit" as hash +import "ecc/edwardsCompress" as edwardsCompress +import "ecc/babyjubjubParams" as context +import "hashes/utils/256bitsDirectionHelper" as multiplex +import "utils/binary/not" as NOT // Merke-Tree inclusion proof for tree depth 3 using SNARK efficient pedersen hashes // directionSelector=> 1/true if current digest is on the rhs of the hash def main(field[256] rootDigest, private field[256] leafDigest, private field[3] directionSelector, field[256] PathDigest0, private field[256] PathDigest1, private field[256] PathDigest2) -> (field): diff --git a/zokrates_cli/examples/merkleTree/sha256PathProof3.code b/zokrates_cli/examples/merkleTree/sha256PathProof3.zok similarity index 87% rename from zokrates_cli/examples/merkleTree/sha256PathProof3.code rename to zokrates_cli/examples/merkleTree/sha256PathProof3.zok index 901ff5d3..f8f570c6 100644 --- a/zokrates_cli/examples/merkleTree/sha256PathProof3.code +++ b/zokrates_cli/examples/merkleTree/sha256PathProof3.zok @@ -1,6 +1,6 @@ -import "hashes/sha256/512bit.code" as sha256 -import "utils/multiplexer/256bit.code" as multiplex -import "utils/binary/not.code" as NOT +import "hashes/sha256/512bit" as sha256 +import "utils/multiplexer/256bit" as multiplex +import "utils/binary/not" as NOT // Merke-Tree inclusion proof for tree depth 3 diff --git a/zokrates_cli/examples/merkleTree/testpedersenPathProof3.code b/zokrates_cli/examples/merkleTree/testpedersenPathProof3.zok similarity index 98% rename from zokrates_cli/examples/merkleTree/testpedersenPathProof3.code rename to zokrates_cli/examples/merkleTree/testpedersenPathProof3.zok index b006f686..c71b809c 100644 --- a/zokrates_cli/examples/merkleTree/testpedersenPathProof3.code +++ b/zokrates_cli/examples/merkleTree/testpedersenPathProof3.zok @@ -1,4 +1,4 @@ -import "./pedersenPathProof3.code" +import "./pedersenPathProof3" // Merke-Tree inclusion proof for tree depth 3 // def main(field treeDepth, field[256] rootDigest, private field[256] leafDigest, private field[2] directionSelector, field[256] PathDigest0, private field[256] PathDigest1) -> (field): def main() -> (field): diff --git a/zokrates_cli/examples/merkleTree/testsha256PathProof3.code b/zokrates_cli/examples/merkleTree/testsha256PathProof3.zok similarity index 98% rename from zokrates_cli/examples/merkleTree/testsha256PathProof3.code rename to zokrates_cli/examples/merkleTree/testsha256PathProof3.zok index 60ef13c0..586e082c 100644 --- a/zokrates_cli/examples/merkleTree/testsha256PathProof3.code +++ b/zokrates_cli/examples/merkleTree/testsha256PathProof3.zok @@ -1,4 +1,4 @@ -import "./sha256PathProof3.code" as merkleTreeProof +import "./sha256PathProof3" as merkleTreeProof def main() -> (field): field treeDepth = 3 diff --git a/zokrates_cli/examples/multi_return.code b/zokrates_cli/examples/multi_return.zok similarity index 100% rename from zokrates_cli/examples/multi_return.code rename to zokrates_cli/examples/multi_return.zok diff --git a/zokrates_cli/examples/multi_return_sum.code b/zokrates_cli/examples/multi_return_sum.zok similarity index 100% rename from zokrates_cli/examples/multi_return_sum.code rename to zokrates_cli/examples/multi_return_sum.zok diff --git a/zokrates_cli/examples/multiple_witnesses.code b/zokrates_cli/examples/multiple_witnesses.zok similarity index 100% rename from zokrates_cli/examples/multiple_witnesses.code rename to zokrates_cli/examples/multiple_witnesses.zok diff --git a/zokrates_cli/examples/n_choose_k.code b/zokrates_cli/examples/n_choose_k.zok similarity index 100% rename from zokrates_cli/examples/n_choose_k.code rename to zokrates_cli/examples/n_choose_k.zok diff --git a/zokrates_cli/examples/no_flatten.code b/zokrates_cli/examples/no_flatten.zok similarity index 100% rename from zokrates_cli/examples/no_flatten.code rename to zokrates_cli/examples/no_flatten.zok diff --git a/zokrates_cli/examples/pow.code b/zokrates_cli/examples/pow.zok similarity index 100% rename from zokrates_cli/examples/pow.code rename to zokrates_cli/examples/pow.zok diff --git a/zokrates_cli/examples/propagate.code b/zokrates_cli/examples/propagate.zok similarity index 100% rename from zokrates_cli/examples/propagate.code rename to zokrates_cli/examples/propagate.zok diff --git a/zokrates_cli/examples/propagate_call.code b/zokrates_cli/examples/propagate_call.zok similarity index 100% rename from zokrates_cli/examples/propagate_call.code rename to zokrates_cli/examples/propagate_call.zok diff --git a/zokrates_cli/examples/reassignment.code b/zokrates_cli/examples/reassignment.zok similarity index 100% rename from zokrates_cli/examples/reassignment.code rename to zokrates_cli/examples/reassignment.zok diff --git a/zokrates_cli/examples/reduceable_exponent.code b/zokrates_cli/examples/reduceable_exponent.zok similarity index 100% rename from zokrates_cli/examples/reduceable_exponent.code rename to zokrates_cli/examples/reduceable_exponent.zok diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.code b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok similarity index 100% rename from zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.code rename to zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.code b/zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok similarity index 100% rename from zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.code rename to zokrates_cli/examples/runtime_errors/lt_overflow_p_minus_one.zok diff --git a/zokrates_cli/examples/sha256/binary/andxorandxorand.code b/zokrates_cli/examples/sha256/binary/andxorandxorand.zok similarity index 60% rename from zokrates_cli/examples/sha256/binary/andxorandxorand.code rename to zokrates_cli/examples/sha256/binary/andxorandxorand.zok index 1da72b7a..5094c306 100644 --- a/zokrates_cli/examples/sha256/binary/andxorandxorand.code +++ b/zokrates_cli/examples/sha256/binary/andxorandxorand.zok @@ -1,7 +1,7 @@ // ANDXORANDXORAND -import "utils/binary/xor.code" as XOR -import "utils/binary/and.code" as AND +import "utils/binary/xor" as XOR +import "utils/binary/and" as AND def main(field a, field b, field c) -> (field): return XOR(XOR(AND(a, b), AND(a, c)), AND(b, c)) \ No newline at end of file diff --git a/zokrates_cli/examples/sha256/binary/andxornotand.code b/zokrates_cli/examples/sha256/binary/andxornotand.code deleted file mode 100644 index 41bb5737..00000000 --- a/zokrates_cli/examples/sha256/binary/andxornotand.code +++ /dev/null @@ -1,8 +0,0 @@ -// ANDXORNOTAND - -import "utils/binary/and.code" as AND -import "utils/binary/xor.code" as XOR -import "utils/binary/not.code" as NOT - -def main(field a, field b, field c) -> (field): - return XOR(AND(a, b), AND(NOT(a), c)) diff --git a/zokrates_cli/examples/sha256/binary/andxornotand.zok b/zokrates_cli/examples/sha256/binary/andxornotand.zok new file mode 100644 index 00000000..fcb5b462 --- /dev/null +++ b/zokrates_cli/examples/sha256/binary/andxornotand.zok @@ -0,0 +1,8 @@ +// ANDXORNOTAND + +import "utils/binary/and" as AND +import "utils/binary/xor" as XOR +import "utils/binary/not" as NOT + +def main(field a, field b, field c) -> (field): + return XOR(AND(a, b), AND(NOT(a), c)) diff --git a/zokrates_cli/examples/sha256/binary/fulladd.code b/zokrates_cli/examples/sha256/binary/fulladd.zok similarity index 70% rename from zokrates_cli/examples/sha256/binary/fulladd.code rename to zokrates_cli/examples/sha256/binary/fulladd.zok index 375b8506..fbf13de5 100644 --- a/zokrates_cli/examples/sha256/binary/fulladd.code +++ b/zokrates_cli/examples/sha256/binary/fulladd.zok @@ -1,7 +1,7 @@ // FULLADD -import "./halfadd.code" as HALFADD -import "utils/binary/or.code" as OR +import "./halfadd" as HALFADD +import "utils/binary/or" as OR def main(field a, field b, field car) -> (field, field): out1, car1 = HALFADD(a, b) diff --git a/zokrates_cli/examples/sha256/binary/halfadd.code b/zokrates_cli/examples/sha256/binary/halfadd.zok similarity index 53% rename from zokrates_cli/examples/sha256/binary/halfadd.code rename to zokrates_cli/examples/sha256/binary/halfadd.zok index 4cfc96a7..15f0e6ec 100644 --- a/zokrates_cli/examples/sha256/binary/halfadd.code +++ b/zokrates_cli/examples/sha256/binary/halfadd.zok @@ -1,7 +1,7 @@ // HALFADD -import "utils/binary/xor.code" as XOR -import "utils/binary/and.code" as AND +import "utils/binary/xor" as XOR +import "utils/binary/and" as AND def main(field a, field b) -> (field, field): return XOR(a, b), AND(a, b) \ No newline at end of file diff --git a/zokrates_cli/examples/sha256/bitwise/32/and.code b/zokrates_cli/examples/sha256/bitwise/32/and.zok similarity index 87% rename from zokrates_cli/examples/sha256/bitwise/32/and.code rename to zokrates_cli/examples/sha256/bitwise/32/and.zok index f92320fe..7a36796f 100644 --- a/zokrates_cli/examples/sha256/bitwise/32/and.code +++ b/zokrates_cli/examples/sha256/bitwise/32/and.zok @@ -1,6 +1,6 @@ // AND -import "utils/binary/and.code" as AND +import "utils/binary/and" as AND def main(field[32] b, field[32] c) -> (field[32]): field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.code b/zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.zok similarity index 82% rename from zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.code rename to zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.zok index 13160f6c..334c5ba1 100644 --- a/zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.code +++ b/zokrates_cli/examples/sha256/bitwise/32/andxorandxorand.zok @@ -1,6 +1,6 @@ // ANDXORANDXORAND -import "./../../binary/andxorandxorand.code" as ANDXORANDXORAND +import "./../../binary/andxorandxorand" as ANDXORANDXORAND def main(field[32] b, field[32] c, field[32] d) -> (field[32]): field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/bitwise/32/andxornotand.code b/zokrates_cli/examples/sha256/bitwise/32/andxornotand.zok similarity index 83% rename from zokrates_cli/examples/sha256/bitwise/32/andxornotand.code rename to zokrates_cli/examples/sha256/bitwise/32/andxornotand.zok index ee23cb4e..f053e5aa 100644 --- a/zokrates_cli/examples/sha256/bitwise/32/andxornotand.code +++ b/zokrates_cli/examples/sha256/bitwise/32/andxornotand.zok @@ -1,6 +1,6 @@ // ANDXORNOTAND -import "./../../binary/andxornotand.code" as ANDXORNOTAND +import "./../../binary/andxornotand" as ANDXORNOTAND def main(field[32] b, field[32] c, field[32] d) -> (field[32]): field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/bitwise/32/not.code b/zokrates_cli/examples/sha256/bitwise/32/not.zok similarity index 86% rename from zokrates_cli/examples/sha256/bitwise/32/not.code rename to zokrates_cli/examples/sha256/bitwise/32/not.zok index ce235a0d..32fcddec 100644 --- a/zokrates_cli/examples/sha256/bitwise/32/not.code +++ b/zokrates_cli/examples/sha256/bitwise/32/not.zok @@ -1,6 +1,6 @@ // NOT -import "utils/binary/not.code" as NOT +import "utils/binary/not" as NOT def main(field[32] b) -> (field[32]): field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/bitwise/32/xor.code b/zokrates_cli/examples/sha256/bitwise/32/xor.zok similarity index 87% rename from zokrates_cli/examples/sha256/bitwise/32/xor.code rename to zokrates_cli/examples/sha256/bitwise/32/xor.zok index 6cd0d324..036c74f0 100644 --- a/zokrates_cli/examples/sha256/bitwise/32/xor.code +++ b/zokrates_cli/examples/sha256/bitwise/32/xor.zok @@ -1,6 +1,6 @@ // XOR -import "utils/binary/xor.code" as XOR +import "utils/binary/xor" as XOR def main(field[32] b, field[32] c) -> (field[32]): field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/utils/32/add.code b/zokrates_cli/examples/sha256/utils/32/add.zok similarity index 89% rename from zokrates_cli/examples/sha256/utils/32/add.code rename to zokrates_cli/examples/sha256/utils/32/add.zok index 61b76142..f7b6c7c4 100644 --- a/zokrates_cli/examples/sha256/utils/32/add.code +++ b/zokrates_cli/examples/sha256/utils/32/add.zok @@ -1,6 +1,6 @@ // ADD -import "../../binary/fulladd.code" as FULLADD +import "../../binary/fulladd" as FULLADD def main(field[32] b, field[32] c) -> (field[32]): field[33] car = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.code b/zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.zok similarity index 95% rename from zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.code rename to zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.zok index 3e7cc187..b736d169 100644 --- a/zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.code +++ b/zokrates_cli/examples/sha256/utils/32/ar17xar19xars10.zok @@ -1,6 +1,6 @@ // AR17XAR19XAR10 -import "../../bitwise/32/xor.code" as XOR +import "../../bitwise/32/xor" as XOR def RR17(field[32] b) -> (field[32]): return [b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14]] diff --git a/zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.code b/zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.zok similarity index 95% rename from zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.code rename to zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.zok index bcea4d75..57f5e319 100644 --- a/zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.code +++ b/zokrates_cli/examples/sha256/utils/32/ar2xar13xar22.zok @@ -1,6 +1,6 @@ // AR2XAR13XAR22 -import "../../bitwise/32/xor.code" as XOR +import "../../bitwise/32/xor" as XOR def RR2(field[32] b) -> (field[32]): return [b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29]] diff --git a/zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.code b/zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.zok similarity index 95% rename from zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.code rename to zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.zok index f70779bd..a23c9134 100644 --- a/zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.code +++ b/zokrates_cli/examples/sha256/utils/32/ar6xar11xar25.zok @@ -1,6 +1,6 @@ // AR6XAR11XAR25 -import "../../bitwise/32/xor.code" as XOR +import "../../bitwise/32/xor" as XOR def RR6(field[32] b) -> (field[32]): return [b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25]] diff --git a/zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.code b/zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.zok similarity index 95% rename from zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.code rename to zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.zok index 772075b1..6c523303 100644 --- a/zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.code +++ b/zokrates_cli/examples/sha256/utils/32/ar7xar18xars3.zok @@ -1,6 +1,6 @@ // AR7XAR18XAR3 -import "../../bitwise/32/xor.code" as XOR +import "../../bitwise/32/xor" as XOR def RR7(field[32] b) -> (field[32]): return [b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24]] diff --git a/zokrates_cli/examples/sha256/utils/32/compression_round.code b/zokrates_cli/examples/sha256/utils/32/compression_round.zok similarity index 80% rename from zokrates_cli/examples/sha256/utils/32/compression_round.code rename to zokrates_cli/examples/sha256/utils/32/compression_round.zok index 7816202f..100c2cd8 100644 --- a/zokrates_cli/examples/sha256/utils/32/compression_round.code +++ b/zokrates_cli/examples/sha256/utils/32/compression_round.zok @@ -1,10 +1,10 @@ // COMPRESSION ROUND -import "./ar6xar11xar25.code" as AR6XAR11XAR25 -import "./ar2xar13xar22.code" as AR2XAR13XAR22 -import "../../bitwise/32/andxornotand.code" as ANDXORNOTAND -import "../../bitwise/32/andxorandxorand.code" as ANDXORANDXORAND -import "./add.code" as ADD2 +import "./ar6xar11xar25" as AR6XAR11XAR25 +import "./ar2xar13xar22" as AR2XAR13XAR22 +import "../../bitwise/32/andxornotand" as ANDXORNOTAND +import "../../bitwise/32/andxorandxorand" as ANDXORANDXORAND +import "./add" as ADD2 def ADD5(field[32] a, field[32] b, field[32] c, field[32] d, field[32] e) -> (field[32]): ab = ADD2(a, b) diff --git a/zokrates_cli/examples/sha256/utils/32/extend.code b/zokrates_cli/examples/sha256/utils/32/extend.zok similarity index 82% rename from zokrates_cli/examples/sha256/utils/32/extend.code rename to zokrates_cli/examples/sha256/utils/32/extend.zok index 2005799d..f6964efa 100644 --- a/zokrates_cli/examples/sha256/utils/32/extend.code +++ b/zokrates_cli/examples/sha256/utils/32/extend.zok @@ -1,8 +1,8 @@ // EXTEND -import "./ar7xar18xars3.code" as AR7XAR18XAR3 -import "./ar17xar19xars10.code" as AR17XAR19XAR10 -import "./add.code" as ADD +import "./ar7xar18xars3" as AR7XAR18XAR3 +import "./ar17xar19xars10" as AR17XAR19XAR10 +import "./add" as ADD def ADD(field[32] a, field[32] b, field[32] c, field[32] d) -> (field[32]): ab = ADD(a, b) diff --git a/zokrates_cli/examples/simple_add.code b/zokrates_cli/examples/simple_add.zok similarity index 100% rename from zokrates_cli/examples/simple_add.code rename to zokrates_cli/examples/simple_add.zok diff --git a/zokrates_cli/examples/simple_ifelse.code b/zokrates_cli/examples/simple_ifelse.zok similarity index 100% rename from zokrates_cli/examples/simple_ifelse.code rename to zokrates_cli/examples/simple_ifelse.zok diff --git a/zokrates_cli/examples/simple_mul.code b/zokrates_cli/examples/simple_mul.zok similarity index 100% rename from zokrates_cli/examples/simple_mul.code rename to zokrates_cli/examples/simple_mul.zok diff --git a/zokrates_cli/examples/spaces_tabs_comments.code b/zokrates_cli/examples/spaces_tabs_comments.zok similarity index 100% rename from zokrates_cli/examples/spaces_tabs_comments.code rename to zokrates_cli/examples/spaces_tabs_comments.zok diff --git a/zokrates_cli/examples/sub.code b/zokrates_cli/examples/sub.zok similarity index 100% rename from zokrates_cli/examples/sub.code rename to zokrates_cli/examples/sub.zok diff --git a/zokrates_cli/examples/sudokuchecker.code b/zokrates_cli/examples/sudokuchecker.zok similarity index 100% rename from zokrates_cli/examples/sudokuchecker.code rename to zokrates_cli/examples/sudokuchecker.zok diff --git a/zokrates_cli/examples/synonyms.code b/zokrates_cli/examples/synonyms.zok similarity index 100% rename from zokrates_cli/examples/synonyms.code rename to zokrates_cli/examples/synonyms.zok diff --git a/zokrates_cli/examples/taxation.code b/zokrates_cli/examples/taxation.zok similarity index 100% rename from zokrates_cli/examples/taxation.code rename to zokrates_cli/examples/taxation.zok diff --git a/zokrates_cli/examples/test1.code b/zokrates_cli/examples/test1.zok similarity index 100% rename from zokrates_cli/examples/test1.code rename to zokrates_cli/examples/test1.zok diff --git a/zokrates_cli/examples/test_lt_max_value.code b/zokrates_cli/examples/test_lt_max_value.zok similarity index 100% rename from zokrates_cli/examples/test_lt_max_value.code rename to zokrates_cli/examples/test_lt_max_value.zok diff --git a/zokrates_cli/examples/waldo.code b/zokrates_cli/examples/waldo.zok similarity index 100% rename from zokrates_cli/examples/waldo.code rename to zokrates_cli/examples/waldo.zok diff --git a/zokrates_cli/examples/wavelets.code b/zokrates_cli/examples/wavelets.zok similarity index 100% rename from zokrates_cli/examples/wavelets.code rename to zokrates_cli/examples/wavelets.zok diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 6e62adf5..9ea4b0b8 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -57,7 +57,7 @@ fn cli() -> Result<(), String> { .author("Jacob Eberhardt, Thibaut Schaeffer, Stefan Deml") .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 '.code' file for debugging and binary file") + .about("Compiles into flattened conditions. Produces two files: human-readable '.zok' file for debugging and binary file") .arg(Arg::with_name("input") .short("i") .long("input") @@ -270,7 +270,7 @@ fn cli() -> Result<(), String> { let bin_output_path = Path::new(sub_matches.value_of("output").unwrap()); - let hr_output_path = bin_output_path.to_path_buf().with_extension("code"); + let hr_output_path = bin_output_path.to_path_buf().with_extension("ztf"); let file = File::open(path.clone()).unwrap(); @@ -541,7 +541,7 @@ mod tests { #[test] fn examples() { - for p in glob("./examples/**/*.code").expect("Failed to read glob pattern") { + for p in glob("./examples/**/*.zok").expect("Failed to read glob pattern") { let path = match p { Ok(x) => x, Err(why) => panic!("Error: {:?}", why), @@ -572,7 +572,7 @@ mod tests { #[test] fn examples_with_input_success() { //these examples should compile and run - for p in glob("./examples/test*.code").expect("Failed to read glob pattern") { + for p in glob("./examples/test*.zok").expect("Failed to read glob pattern") { let path = match p { Ok(x) => x, Err(why) => panic!("Error: {:?}", why), @@ -604,7 +604,7 @@ mod tests { #[should_panic] fn examples_with_input_failure() { //these examples should compile but not run - for p in glob("./examples/runtime_errors/*.code").expect("Failed to read glob pattern") { + for p in glob("./examples/runtime_errors/*.zok").expect("Failed to read glob pattern") { let path = match p { Ok(x) => x, Err(why) => panic!("Error: {:?}", why), diff --git a/zokrates_cli/tests/code/arithmetics.code b/zokrates_cli/tests/code/arithmetics.zok similarity index 100% rename from zokrates_cli/tests/code/arithmetics.code rename to zokrates_cli/tests/code/arithmetics.zok diff --git a/zokrates_cli/tests/code/if_else_false.code b/zokrates_cli/tests/code/if_else_false.zok similarity index 100% rename from zokrates_cli/tests/code/if_else_false.code rename to zokrates_cli/tests/code/if_else_false.zok diff --git a/zokrates_cli/tests/code/if_else_true.code b/zokrates_cli/tests/code/if_else_true.zok similarity index 100% rename from zokrates_cli/tests/code/if_else_true.code rename to zokrates_cli/tests/code/if_else_true.zok diff --git a/zokrates_cli/tests/code/multidim_update.code b/zokrates_cli/tests/code/multidim_update.zok similarity index 100% rename from zokrates_cli/tests/code/multidim_update.code rename to zokrates_cli/tests/code/multidim_update.zok diff --git a/zokrates_cli/tests/code/n_choose_k.code b/zokrates_cli/tests/code/n_choose_k.zok similarity index 100% rename from zokrates_cli/tests/code/n_choose_k.code rename to zokrates_cli/tests/code/n_choose_k.zok diff --git a/zokrates_cli/tests/code/no_return.code b/zokrates_cli/tests/code/no_return.zok similarity index 100% rename from zokrates_cli/tests/code/no_return.code rename to zokrates_cli/tests/code/no_return.zok diff --git a/zokrates_cli/tests/code/return_array.code b/zokrates_cli/tests/code/return_array.zok similarity index 100% rename from zokrates_cli/tests/code/return_array.code rename to zokrates_cli/tests/code/return_array.zok diff --git a/zokrates_cli/tests/code/sha_round.code b/zokrates_cli/tests/code/sha_round.zok similarity index 100% rename from zokrates_cli/tests/code/sha_round.code rename to zokrates_cli/tests/code/sha_round.zok diff --git a/zokrates_cli/tests/code/simple_add.code b/zokrates_cli/tests/code/simple_add.zok similarity index 100% rename from zokrates_cli/tests/code/simple_add.code rename to zokrates_cli/tests/code/simple_add.zok diff --git a/zokrates_cli/tests/code/simple_mul.code b/zokrates_cli/tests/code/simple_mul.zok similarity index 100% rename from zokrates_cli/tests/code/simple_mul.code rename to zokrates_cli/tests/code/simple_mul.zok diff --git a/zokrates_cli/tests/code/taxation.code b/zokrates_cli/tests/code/taxation.zok similarity index 100% rename from zokrates_cli/tests/code/taxation.code rename to zokrates_cli/tests/code/taxation.zok diff --git a/zokrates_cli/tests/integration.rs b/zokrates_cli/tests/integration.rs index ed76fe44..972685ad 100644 --- a/zokrates_cli/tests/integration.rs +++ b/zokrates_cli/tests/integration.rs @@ -27,7 +27,7 @@ mod integration { if path.extension().unwrap() == "witness" { let program_name = Path::new(Path::new(path.file_stem().unwrap()).file_stem().unwrap()); - let prog = dir.join(program_name).with_extension("code"); + let prog = dir.join(program_name).with_extension("zok"); let witness = dir.join(program_name).with_extension("expected.witness"); let args = dir.join(program_name).with_extension("arguments.json"); test_compile_and_witness(program_name.to_str().unwrap(), &prog, &args, &witness); diff --git a/zokrates_core/src/imports.rs b/zokrates_core/src/imports.rs index 2b34ba60..f9818eca 100644 --- a/zokrates_core/src/imports.rs +++ b/zokrates_core/src/imports.rs @@ -235,9 +235,9 @@ mod tests { #[test] fn create_with_no_alias() { assert_eq!( - Import::new("./foo/bar/baz.code"), + Import::new("./foo/bar/baz.zok"), Import { - source: "./foo/bar/baz.code", + source: "./foo/bar/baz.zok", alias: None, } ); @@ -246,9 +246,9 @@ mod tests { #[test] fn create_with_alias() { assert_eq!( - Import::new_with_alias("./foo/bar/baz.code", &"myalias"), + Import::new_with_alias("./foo/bar/baz.zok", &"myalias"), Import { - source: "./foo/bar/baz.code", + source: "./foo/bar/baz.zok", alias: Some("myalias"), } ); diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index c603b544..3c129f5f 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1366,12 +1366,12 @@ mod tests { #[test] fn imported_symbol() { - // foo.code + // foo.zok // def main() -> (field): // return 1 - // bar.code - // from "./foo.code" import main + // bar.zok + // from "./foo.zok" import main // after semantic check, `bar` should import a checked function diff --git a/zokrates_core_test/tests/tests/add.json b/zokrates_core_test/tests/tests/add.json index 76935916..ebc660a9 100644 --- a/zokrates_core_test/tests/tests/add.json +++ b/zokrates_core_test/tests/tests/add.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/add.code", + "entry_point": "./tests/tests/add.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/add.code b/zokrates_core_test/tests/tests/add.zok similarity index 100% rename from zokrates_core_test/tests/tests/add.code rename to zokrates_core_test/tests/tests/add.zok diff --git a/zokrates_core_test/tests/tests/array_if.json b/zokrates_core_test/tests/tests/array_if.json index fcb35110..6cfec59b 100644 --- a/zokrates_core_test/tests/tests/array_if.json +++ b/zokrates_core_test/tests/tests/array_if.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/array_if.code", + "entry_point": "./tests/tests/array_if.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/array_if.code b/zokrates_core_test/tests/tests/array_if.zok similarity index 100% rename from zokrates_core_test/tests/tests/array_if.code rename to zokrates_core_test/tests/tests/array_if.zok diff --git a/zokrates_core_test/tests/tests/assert_one.json b/zokrates_core_test/tests/tests/assert_one.json index 9a7d4ed4..2a8a099d 100644 --- a/zokrates_core_test/tests/tests/assert_one.json +++ b/zokrates_core_test/tests/tests/assert_one.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/assert_one.code", + "entry_point": "./tests/tests/assert_one.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/assert_one.code b/zokrates_core_test/tests/tests/assert_one.zok similarity index 100% rename from zokrates_core_test/tests/tests/assert_one.code rename to zokrates_core_test/tests/tests/assert_one.zok diff --git a/zokrates_core_test/tests/tests/fact_up_to_4.json b/zokrates_core_test/tests/tests/fact_up_to_4.json index 6c32ff24..b3936a18 100644 --- a/zokrates_core_test/tests/tests/fact_up_to_4.json +++ b/zokrates_core_test/tests/tests/fact_up_to_4.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/fact_up_to_4.code", + "entry_point": "./tests/tests/fact_up_to_4.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/fact_up_to_4.code b/zokrates_core_test/tests/tests/fact_up_to_4.zok similarity index 100% rename from zokrates_core_test/tests/tests/fact_up_to_4.code rename to zokrates_core_test/tests/tests/fact_up_to_4.zok diff --git a/zokrates_core_test/tests/tests/split.json b/zokrates_core_test/tests/tests/split.json index c05358a6..f1d5cfb8 100644 --- a/zokrates_core_test/tests/tests/split.json +++ b/zokrates_core_test/tests/tests/split.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/split.code", + "entry_point": "./tests/tests/split.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/split.code b/zokrates_core_test/tests/tests/split.zok similarity index 100% rename from zokrates_core_test/tests/tests/split.code rename to zokrates_core_test/tests/tests/split.zok diff --git a/zokrates_core_test/tests/tests/spread_slice.json b/zokrates_core_test/tests/tests/spread_slice.json index b2291bc1..afedb079 100644 --- a/zokrates_core_test/tests/tests/spread_slice.json +++ b/zokrates_core_test/tests/tests/spread_slice.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/spread_slice.code", + "entry_point": "./tests/tests/spread_slice.zok", "tests": [ { "input": { diff --git a/zokrates_core_test/tests/tests/spread_slice.code b/zokrates_core_test/tests/tests/spread_slice.zok similarity index 100% rename from zokrates_core_test/tests/tests/spread_slice.code rename to zokrates_core_test/tests/tests/spread_slice.zok diff --git a/zokrates_fs_resolver/src/lib.rs b/zokrates_fs_resolver/src/lib.rs index f8f8a53a..0d136b88 100644 --- a/zokrates_fs_resolver/src/lib.rs +++ b/zokrates_fs_resolver/src/lib.rs @@ -24,7 +24,7 @@ fn resolve_with_location<'a>( let source = Path::new(source); // paths starting with `./` or `../` are interpreted relative to the current file - // other paths `abc/def.code` are interpreted relative to $ZOKRATES_HOME + // other paths `abc/def` are interpreted relative to $ZOKRATES_HOME let base = match source.components().next() { Some(Component::CurDir) | Some(Component::ParentDir) => PathBuf::from(location), _ => PathBuf::from( @@ -32,7 +32,7 @@ fn resolve_with_location<'a>( ), }; - let path_owned = base.join(PathBuf::from(source)); + let path_owned = base.join(PathBuf::from(source)).with_extension("zok"); if path_owned.is_dir() { return Err(io::Error::new(io::ErrorKind::Other, "Not a file")); @@ -60,9 +60,17 @@ mod tests { #[test] fn valid_path_with_location() { - let (_, next_location, alias) = resolve(Some(String::from("./src")), &"./lib.rs").unwrap(); - assert_eq!(next_location, String::from("./src")); - assert_eq!(alias, String::from("lib")); + use std::io::Write; + + // create a source folder with a zok file + let folder = tempfile::tempdir().unwrap(); + let file_path = folder.path().join("bar.zok"); + let mut file = File::create(file_path).unwrap(); + writeln!(file, "some code").unwrap(); + let (_, next_location, alias) = + resolve(Some(folder.path().to_str().unwrap().to_string()), &"./bar").unwrap(); + assert_eq!(next_location, folder.path().to_str().unwrap().to_string()); + assert_eq!(alias, String::from("bar")); } #[test] @@ -73,13 +81,13 @@ mod tests { #[test] fn non_existing_file() { - let res = resolve(Some(String::from("./src")), &"./rubbish.rs"); + let res = resolve(Some(String::from("./src")), &"./rubbish"); assert!(res.is_err()); } #[test] fn invalid_location() { - let res = resolve(Some(String::from(",8!-$2abc")), &"./foo.code"); + let res = resolve(Some(String::from(",8!-$2abc")), &"./foo.zok"); assert!(res.is_err()); } @@ -95,31 +103,6 @@ mod tests { assert!(res.is_err()); } - #[test] - #[should_panic] - fn no_file_name_without_stdlib() { - // an empty string is interpreted relative to the HOME folder. If there's none, panic - std::env::remove_var(ZOKRATES_HOME); - let _res = resolve(Some(String::from(".")), &""); - } - - #[test] - fn no_file_name_with_stdlib() { - use std::io::Write; - - // create a HOME folder with a code file - let zokrates_home_folder = tempfile::tempdir().unwrap(); - let file_path = zokrates_home_folder.path().join("bar.code"); - let mut file = File::create(file_path).unwrap(); - writeln!(file, "").unwrap(); - - // assign HOME folder to ZOKRATES_HOME - std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path()); - - let res = resolve(Some(String::from(".")), &""); - assert!(res.is_err()); - } - #[test] fn treat_relative_as_local() { use std::io::BufRead; @@ -127,13 +110,13 @@ mod tests { // create a HOME folder with a code file let zokrates_home_folder = tempfile::tempdir().unwrap(); - let file_path = zokrates_home_folder.path().join("bar.code"); + let file_path = zokrates_home_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); // create a user folder with a code file let source_folder = tempfile::tempdir().unwrap(); - let file_path = source_folder.path().join("bar.code"); + let file_path = source_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); @@ -148,7 +131,7 @@ mod tests { .to_string_lossy() .to_string(), ), - &"./bar.code", + &"./bar.zok", ); assert!(result.is_ok()); let mut code = String::new(); @@ -164,13 +147,13 @@ mod tests { // create a HOME folder with a code file let zokrates_home_folder = tempfile::tempdir().unwrap(); - let file_path = zokrates_home_folder.path().join("bar.code"); + let file_path = zokrates_home_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); // create a user folder with a code file let source_folder = tempfile::tempdir().unwrap(); - let file_path = source_folder.path().join("bar.code"); + let file_path = source_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); @@ -185,7 +168,7 @@ mod tests { .to_string_lossy() .to_string(), ), - &"bar.code", + &"bar.zok", ); assert!(result.is_ok()); let mut code = String::new(); @@ -202,7 +185,7 @@ mod tests { // create a user folder with a code file let source_folder = tempfile::tempdir().unwrap(); let source_subfolder = tempfile::tempdir_in(&source_folder).unwrap(); - let file_path = source_folder.path().join("bar.code"); + let file_path = source_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); @@ -214,7 +197,7 @@ mod tests { .to_string_lossy() .to_string(), ), - &"../bar.code", + &"../bar.zok", ); assert!(result.is_ok()); let mut code = String::new(); @@ -229,21 +212,21 @@ mod tests { // create a HOME folder let zokrates_home_folder = tempfile::tempdir().unwrap(); - let file_path = zokrates_home_folder.path().join("bar.code"); + let file_path = zokrates_home_folder.path().join("bar.zok"); let mut file = File::create(file_path).unwrap(); writeln!(file, "").unwrap(); // assign HOME folder to ZOKRATES_HOME std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path()); - let result = resolve(Some("/path/to/user/folder".to_string()), &"./bar.code"); + let result = resolve(Some("/path/to/user/folder".to_string()), &"./bar.zok"); assert!(result.is_err()); } #[test] fn fail_if_not_found_in_std() { std::env::set_var(ZOKRATES_HOME, ""); - let result = resolve(Some("/path/to/source".to_string()), &"bar.code"); + let result = resolve(Some("/path/to/source".to_string()), &"bar.zok"); assert!(result.is_err()); } @@ -251,6 +234,6 @@ mod tests { #[should_panic] fn panic_if_home_not_set() { std::env::remove_var(ZOKRATES_HOME); - let _ = resolve(Some("/path/to/source".to_string()), &"bar.code"); + let _ = resolve(Some("/path/to/source".to_string()), &"bar.zok"); } } diff --git a/zokrates_github_resolver/src/lib.rs b/zokrates_github_resolver/src/lib.rs index c9fd6cec..9b27b658 100644 --- a/zokrates_github_resolver/src/lib.rs +++ b/zokrates_github_resolver/src/lib.rs @@ -4,17 +4,17 @@ //! //! To import file from github, use following syntax: //! ```zokrates -//! import "github:user/repo/branch/path/to/file.code" +//! import "github:user/repo/branch/path/to/file.zok" //! ``` //! //! For example: //! ```zokrates -//! import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3.code" as merkleTreeProof +//! import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3.zok" as merkleTreeProof //! ``` //! -//! Example above imports file `zokrates_cli/examples/merkleTree/sha256PathProof3.code` located at ZoKrates +//! Example above imports file `zokrates_cli/examples/merkleTree/sha256PathProof3.zok` located at ZoKrates //! repository's `master` branch by downloading from URL: -//! https://raw.githubusercontent.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3.code +//! https://raw.githubusercontent.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3.zok //! use reqwest; @@ -112,12 +112,13 @@ fn download_from_github( path: &str, ) -> Result { let url = format!( - "{github}/{root}/{repo}/{branch}/{path}", + "{github}/{root}/{repo}/{branch}/{path}{extension}", github = github, root = root, repo = repo, branch = branch, - path = path + path = path, + extension = ".zok" ); download_url(&url) @@ -153,15 +154,15 @@ mod tests { fn init_github_mock() -> (Mock, Mock) { let m1 = mockito::mock( "GET", - "/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/foo.code", + "/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/foo.zok", ) .with_status(200) - .with_body_from_file("./static/foo.code") + .with_body_from_file("./static/foo.zok") .create(); let m2 = mockito::mock( "GET", - "/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/notfound.code", + "/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/notfound.zok", ) .with_status(404) .create(); @@ -172,7 +173,7 @@ mod tests { #[test] pub fn import_simple() { let res = parse_input_path(Path::new( - "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import.code", + "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import", )) .unwrap(); let (root, repo, branch, path) = res; @@ -180,15 +181,15 @@ mod tests { assert_eq!(root, "Zokrates"); assert_eq!(repo, "ZoKrates"); assert_eq!(branch, "master"); - assert_eq!(path, "zokrates_cli/examples/imports/import.code"); + assert_eq!(path, "zokrates_cli/examples/imports/import"); } #[test] #[should_panic] pub fn import_no_branch() { - // Correct syntax should be: github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import.code + // Correct syntax should be: github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import.zok // but branch name is not specified - parse_input_path(Path::new("github.com/Zokrates/ZoKrates/test.code")).unwrap(); + parse_input_path(Path::new("github.com/Zokrates/ZoKrates/test")).unwrap(); } #[test] @@ -196,7 +197,7 @@ mod tests { pub fn import_relative_paths() { // Relative paths should not be allowed parse_input_path(Path::new( - "github.com/Zokrates/ZoKrates/master/examples/../imports.code", + "github.com/Zokrates/ZoKrates/master/examples/../imports", )) .unwrap(); } @@ -206,7 +207,7 @@ mod tests { let (_m0, _m1) = init_github_mock(); let res = resolve( Some("".to_string()), - &"github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/foo.code", + &"github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/foo", ); assert!(res.is_ok()); } @@ -216,7 +217,7 @@ mod tests { let (_m0, _m1) = init_github_mock(); assert!(resolve( Some("".to_string()), - &"github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/notfound.code" + &"github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/notfound" ) .is_err()); } diff --git a/zokrates_github_resolver/static/foo.code b/zokrates_github_resolver/static/foo.zok similarity index 100% rename from zokrates_github_resolver/static/foo.code rename to zokrates_github_resolver/static/foo.zok diff --git a/zokrates_parser/src/lib.rs b/zokrates_parser/src/lib.rs index 6e92d8b1..96112e5d 100644 --- a/zokrates_parser/src/lib.rs +++ b/zokrates_parser/src/lib.rs @@ -27,9 +27,9 @@ mod tests { use glob::glob; use std::fs; use std::io::Read; - // Traverse all .code files in examples dir + // Traverse all .zok files in examples dir for entry in - glob("../zokrates_cli/examples/**/*.code").expect("Failed to read glob pattern") + glob("../zokrates_cli/examples/**/*.zok").expect("Failed to read glob pattern") { match entry { Ok(path) => { diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 8eacafc6..401256f7 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -641,9 +641,8 @@ mod tests { use glob::glob; use std::fs; use std::io::Read; - // Traverse all .code files in examples dir - for entry in - glob("../zokrates_cli/examples/**/*.code").expect("Failed to read glob pattern") + // Traverse all .zok files in examples dir + for entry in glob("../zokrates_cli/examples/**/*.zok").expect("Failed to read glob pattern") { match entry { Ok(path) => { diff --git a/zokrates_stdlib/stdlib/ecc/babyjubjubParams.code b/zokrates_stdlib/stdlib/ecc/babyjubjubParams.zok similarity index 100% rename from zokrates_stdlib/stdlib/ecc/babyjubjubParams.code rename to zokrates_stdlib/stdlib/ecc/babyjubjubParams.zok diff --git a/zokrates_stdlib/stdlib/ecc/edwardsAdd.code b/zokrates_stdlib/stdlib/ecc/edwardsAdd.zok similarity index 92% rename from zokrates_stdlib/stdlib/ecc/edwardsAdd.code rename to zokrates_stdlib/stdlib/ecc/edwardsAdd.zok index 9027fcc1..99de1522 100644 --- a/zokrates_stdlib/stdlib/ecc/edwardsAdd.code +++ b/zokrates_stdlib/stdlib/ecc/edwardsAdd.zok @@ -1,4 +1,4 @@ -import "ecc/babyjubjubParams.code" as context +import "ecc/babyjubjubParams" as context // Add two points on a twisted Edwards curve // Curve parameters are defined with the last argument // https://en.wikipedia.org/wiki/Twisted_Edwards_curve#Addition_on_twisted_Edwards_curves diff --git a/zokrates_stdlib/stdlib/ecc/edwardsCompress.code b/zokrates_stdlib/stdlib/ecc/edwardsCompress.zok similarity index 89% rename from zokrates_stdlib/stdlib/ecc/edwardsCompress.code rename to zokrates_stdlib/stdlib/ecc/edwardsCompress.zok index 15426dac..7b874e7b 100644 --- a/zokrates_stdlib/stdlib/ecc/edwardsCompress.code +++ b/zokrates_stdlib/stdlib/ecc/edwardsCompress.zok @@ -1,4 +1,4 @@ -import "utils/pack/nonStrictUnpack256.code" as unpack256 +import "utils/pack/nonStrictUnpack256" as unpack256 // Compress JubJub Curve Point to 256bit array using big endianness bit order // Python reference code from pycrypto: // def compress(self): diff --git a/zokrates_stdlib/stdlib/ecc/edwardsNegate.code b/zokrates_stdlib/stdlib/ecc/edwardsNegate.zok similarity index 85% rename from zokrates_stdlib/stdlib/ecc/edwardsNegate.code rename to zokrates_stdlib/stdlib/ecc/edwardsNegate.zok index 49911c5d..af6d8156 100644 --- a/zokrates_stdlib/stdlib/ecc/edwardsNegate.code +++ b/zokrates_stdlib/stdlib/ecc/edwardsNegate.zok @@ -1,4 +1,4 @@ -import "ecc/babyjubjubParams.code" as context +import "ecc/babyjubjubParams" as context // Negate a point on an Edwards curve // Curve parameters are defined with the last argument // Twisted Edwards Curves, BBJLP-2008, section 2 pg 2 diff --git a/zokrates_stdlib/stdlib/ecc/edwardsOnCurve.code b/zokrates_stdlib/stdlib/ecc/edwardsOnCurve.zok similarity index 100% rename from zokrates_stdlib/stdlib/ecc/edwardsOnCurve.code rename to zokrates_stdlib/stdlib/ecc/edwardsOnCurve.zok diff --git a/zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.code b/zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.zok similarity index 87% rename from zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.code rename to zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.zok index 9ebb1293..ca0c5daf 100644 --- a/zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.code +++ b/zokrates_stdlib/stdlib/ecc/edwardsOrderCheck.zok @@ -1,6 +1,6 @@ -import "ecc/edwardsAdd.code" as add -import "ecc/edwardsScalarMult.code" as multiply -import "utils/pack/nonStrictUnpack256.code" as unpack256 +import "ecc/edwardsAdd" as add +import "ecc/edwardsScalarMult" as multiply +import "utils/pack/nonStrictUnpack256" as unpack256 // Verifies that the point is not one of the low-order points. // If any of the points is multiplied by the cofactor, the resulting point // will be infinity. diff --git a/zokrates_stdlib/stdlib/ecc/edwardsScalarMult.code b/zokrates_stdlib/stdlib/ecc/edwardsScalarMult.zok similarity index 91% rename from zokrates_stdlib/stdlib/ecc/edwardsScalarMult.code rename to zokrates_stdlib/stdlib/ecc/edwardsScalarMult.zok index b7cea471..ccd32539 100644 --- a/zokrates_stdlib/stdlib/ecc/edwardsScalarMult.code +++ b/zokrates_stdlib/stdlib/ecc/edwardsScalarMult.zok @@ -1,5 +1,5 @@ -import "ecc/edwardsAdd.code" as add -import "ecc/edwardsOnCurve.code" as assertOnCurve +import "ecc/edwardsAdd" as add +import "ecc/edwardsOnCurve" as assertOnCurve // Function that implements scalar multiplication for a fixed base point // Curve parameters are defined with the last argument // The exponent is hard-coded to a 256bit scalar, hence we allow wrapping around the group for certain diff --git a/zokrates_stdlib/stdlib/ecc/proofOfOwnership.code b/zokrates_stdlib/stdlib/ecc/proofOfOwnership.zok similarity index 85% rename from zokrates_stdlib/stdlib/ecc/proofOfOwnership.code rename to zokrates_stdlib/stdlib/ecc/proofOfOwnership.zok index 96d9ad4b..f6b0c1fd 100644 --- a/zokrates_stdlib/stdlib/ecc/proofOfOwnership.code +++ b/zokrates_stdlib/stdlib/ecc/proofOfOwnership.zok @@ -1,6 +1,6 @@ -import "ecc/edwardsAdd.code" as add -import "ecc/edwardsScalarMult.code" as multiply -import "utils/pack/nonStrictUnpack256.code" as unpack256 +import "ecc/edwardsAdd" as add +import "ecc/edwardsScalarMult" as multiply +import "utils/pack/nonStrictUnpack256" as unpack256 /// Verifies match of a given public/private keypair. /// diff --git a/zokrates_stdlib/stdlib/hashes/pedersen/512bit.code b/zokrates_stdlib/stdlib/hashes/pedersen/512bit.zok similarity index 99% rename from zokrates_stdlib/stdlib/hashes/pedersen/512bit.code rename to zokrates_stdlib/stdlib/hashes/pedersen/512bit.zok index 861ce33a..ea704854 100644 --- a/zokrates_stdlib/stdlib/hashes/pedersen/512bit.code +++ b/zokrates_stdlib/stdlib/hashes/pedersen/512bit.zok @@ -1,8 +1,8 @@ -import "utils/multiplexer/lookup3bitSigned.code" as sel3s -import "utils/multiplexer/lookup2bit.code" as sel2 -import "ecc/babyjubjubParams.code" as context -import "ecc/edwardsAdd.code" as add -import "ecc/edwardsCompress.code" as edwardsCompress +import "utils/multiplexer/lookup3bitSigned" as sel3s +import "utils/multiplexer/lookup2bit" as sel2 +import "ecc/babyjubjubParams" as context +import "ecc/edwardsAdd" as add +import "ecc/edwardsCompress" as edwardsCompress // Code to export generators used in this example: // import bitstring diff --git a/zokrates_stdlib/stdlib/hashes/pedersen/6bit.code b/zokrates_stdlib/stdlib/hashes/pedersen/6bit.zok similarity index 89% rename from zokrates_stdlib/stdlib/hashes/pedersen/6bit.code rename to zokrates_stdlib/stdlib/hashes/pedersen/6bit.zok index 6189accd..ca535350 100644 --- a/zokrates_stdlib/stdlib/hashes/pedersen/6bit.code +++ b/zokrates_stdlib/stdlib/hashes/pedersen/6bit.zok @@ -1,7 +1,7 @@ -import "utils/multiplexer/lookup3bitSigned.code" as sel3s -import "utils/multiplexer/lookup2bit.code" as sel2 -import "ecc/babyjubjubParams.code" as context -import "ecc/edwardsAdd.code" as add +import "utils/multiplexer/lookup3bitSigned" as sel3s +import "utils/multiplexer/lookup2bit" as sel2 +import "ecc/babyjubjubParams" as context +import "ecc/edwardsAdd" as add def main(field[6] e) -> (field[2]): context = context() diff --git a/zokrates_stdlib/stdlib/hashes/sha256/1024bit.code b/zokrates_stdlib/stdlib/hashes/sha256/1024bit.zok similarity index 78% rename from zokrates_stdlib/stdlib/hashes/sha256/1024bit.code rename to zokrates_stdlib/stdlib/hashes/sha256/1024bit.zok index 49b48007..7ac2ab77 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/1024bit.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/1024bit.zok @@ -1,5 +1,5 @@ -import "./IVconstants.code" as IVconstants -import "./shaRoundNoBoolCheck.code" as sha256 +import "./IVconstants" as IVconstants +import "./shaRoundNoBoolCheck" as sha256 // A function that takes 4 field[256] arrays as inputs // and applies 2 rounds of sha256 compression. diff --git a/zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.code b/zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.zok similarity index 98% rename from zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.code rename to zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.zok index 4191d150..9d73110b 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/1024bitPadded.zok @@ -1,4 +1,4 @@ -import "./1536bit.code" as sha256 +import "./1536bit" as sha256 // Take two field[256] arrays as input // and returns their sha256 full round output as an array of 256 field elements. def main(field[256] a, field[256] b, field[256] c, field[256] d) -> (field[256]): diff --git a/zokrates_stdlib/stdlib/hashes/sha256/1536bit.code b/zokrates_stdlib/stdlib/hashes/sha256/1536bit.zok similarity index 81% rename from zokrates_stdlib/stdlib/hashes/sha256/1536bit.code rename to zokrates_stdlib/stdlib/hashes/sha256/1536bit.zok index 176b4c99..bcb3c008 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/1536bit.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/1536bit.zok @@ -1,5 +1,5 @@ -import "./IVconstants.code" as IVconstants -import "./shaRoundNoBoolCheck.code" as sha256 +import "./IVconstants" as IVconstants +import "./shaRoundNoBoolCheck" as sha256 // A function that takes 6 field[256] arrays as inputs // and applies 3 rounds of sha256 compression. diff --git a/zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.code b/zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.zok similarity index 97% rename from zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.code rename to zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.zok index 87c5b918..8c572edb 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/256bitPadded.zok @@ -1,4 +1,4 @@ -import "./512bit.code" as sha256 +import "./512bit" as sha256 // A function that takes 1 field[256] array as input // and returns the sha256 full round output as an array of 256 field elements. diff --git a/zokrates_stdlib/stdlib/hashes/sha256/512bit.code b/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok similarity index 70% rename from zokrates_stdlib/stdlib/hashes/sha256/512bit.code rename to zokrates_stdlib/stdlib/hashes/sha256/512bit.zok index 1b54b001..6ace46d9 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/512bit.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok @@ -1,9 +1,9 @@ -import "./IVconstants.code" as IVconstants -import "./shaRoundNoBoolCheck.code" as sha256 +import "./IVconstants" as IVconstants +import "./shaRoundNoBoolCheck" as sha256 // A function that takes 2 field[256] arrays as inputs // and returns their sha256 compression function as an array of 256 field elements. -// In contrast to full_round.code no padding is being applied +// In contrast to full_round no padding is being applied def main(field[256] a, field[256] b) -> (field[256]): // a and b is NOT checked to be of type bool diff --git a/zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.code b/zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.zok similarity index 81% rename from zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.code rename to zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.zok index 33172393..37b3305b 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/512bitPacked.zok @@ -1,6 +1,6 @@ -import "../../utils/pack/pack128.code" as pack128 -import "../../utils/pack/unpack128.code" as unpack128 -import "./512bitPadded.code" as sha256 +import "../../utils/pack/pack128" as pack128 +import "../../utils/pack/unpack128" as unpack128 +import "./512bitPadded" as sha256 // A function that takes an array of 4 field elements as inputs, unpacks each of them to 128 // bits (big endian), concatenates them and applies sha256. // It then returns an array of two field elements, each representing 128 bits of the result. diff --git a/zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.code b/zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.zok similarity index 98% rename from zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.code rename to zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.zok index da271974..5ea988e2 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.code +++ b/zokrates_stdlib/stdlib/hashes/sha256/512bitPadded.zok @@ -1,4 +1,4 @@ -import "./1024bit.code" as sha256 +import "./1024bit" as sha256 // A function that takes 2 field[256] arrays as inputs // and returns their sha256 full round output as an array of 256 field elements. diff --git a/zokrates_stdlib/stdlib/hashes/sha256/IVconstants.code b/zokrates_stdlib/stdlib/hashes/sha256/IVconstants.zok similarity index 100% rename from zokrates_stdlib/stdlib/hashes/sha256/IVconstants.code rename to zokrates_stdlib/stdlib/hashes/sha256/IVconstants.zok diff --git a/zokrates_stdlib/stdlib/hashes/sha256/shaRoundNoBoolCheck.code b/zokrates_stdlib/stdlib/hashes/sha256/shaRoundNoBoolCheck.zok similarity index 100% rename from zokrates_stdlib/stdlib/hashes/sha256/shaRoundNoBoolCheck.code rename to zokrates_stdlib/stdlib/hashes/sha256/shaRoundNoBoolCheck.zok diff --git a/zokrates_stdlib/stdlib/hashes/utils/256bitsDirectionHelper.code b/zokrates_stdlib/stdlib/hashes/utils/256bitsDirectionHelper.zok similarity index 100% rename from zokrates_stdlib/stdlib/hashes/utils/256bitsDirectionHelper.code rename to zokrates_stdlib/stdlib/hashes/utils/256bitsDirectionHelper.zok diff --git a/zokrates_stdlib/stdlib/signatures/verifyEddsa.code b/zokrates_stdlib/stdlib/signatures/verifyEddsa.zok similarity index 85% rename from zokrates_stdlib/stdlib/signatures/verifyEddsa.code rename to zokrates_stdlib/stdlib/signatures/verifyEddsa.zok index 343e40ce..2d88b4e1 100644 --- a/zokrates_stdlib/stdlib/signatures/verifyEddsa.code +++ b/zokrates_stdlib/stdlib/signatures/verifyEddsa.zok @@ -1,9 +1,9 @@ -import "hashes/sha256/1024bitPadded.code" as sha256 -import "ecc/edwardsScalarMult.code" as scalarMult -import "ecc/edwardsAdd.code" as add -import "utils/pack/nonStrictUnpack256.code" as unpack256 -import "ecc/edwardsOnCurve.code" as onCurve -import "ecc/edwardsOrderCheck.code" as orderCheck +import "hashes/sha256/1024bitPadded" as sha256 +import "ecc/edwardsScalarMult" as scalarMult +import "ecc/edwardsAdd" as add +import "utils/pack/nonStrictUnpack256" as unpack256 +import "ecc/edwardsOnCurve" as onCurve +import "ecc/edwardsOrderCheck" as orderCheck /// Verifies an EdDSA Signature. /// diff --git a/zokrates_stdlib/stdlib/utils/binary/and.code b/zokrates_stdlib/stdlib/utils/binary/and.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/binary/and.code rename to zokrates_stdlib/stdlib/utils/binary/and.zok diff --git a/zokrates_stdlib/stdlib/utils/binary/isbool.code b/zokrates_stdlib/stdlib/utils/binary/isbool.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/binary/isbool.code rename to zokrates_stdlib/stdlib/utils/binary/isbool.zok diff --git a/zokrates_stdlib/stdlib/utils/binary/not.code b/zokrates_stdlib/stdlib/utils/binary/not.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/binary/not.code rename to zokrates_stdlib/stdlib/utils/binary/not.zok diff --git a/zokrates_stdlib/stdlib/utils/binary/or.code b/zokrates_stdlib/stdlib/utils/binary/or.zok similarity index 59% rename from zokrates_stdlib/stdlib/utils/binary/or.code rename to zokrates_stdlib/stdlib/utils/binary/or.zok index 9a9ce47f..a06088ac 100644 --- a/zokrates_stdlib/stdlib/utils/binary/or.code +++ b/zokrates_stdlib/stdlib/utils/binary/or.zok @@ -1,7 +1,7 @@ // OR -import "./and.code" as AND -import "./not.code" as NOT +import "./and" as AND +import "./not" as NOT def main(field x, field y) -> (field): return NOT(AND(NOT(x), NOT(y))) \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/utils/binary/xor.code b/zokrates_stdlib/stdlib/utils/binary/xor.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/binary/xor.code rename to zokrates_stdlib/stdlib/utils/binary/xor.zok diff --git a/zokrates_stdlib/stdlib/utils/casts/1024to256array.code b/zokrates_stdlib/stdlib/utils/casts/1024to256array.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/casts/1024to256array.code rename to zokrates_stdlib/stdlib/utils/casts/1024to256array.zok diff --git a/zokrates_stdlib/stdlib/utils/multiplexer/256bit.code b/zokrates_stdlib/stdlib/utils/multiplexer/256bit.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/multiplexer/256bit.code rename to zokrates_stdlib/stdlib/utils/multiplexer/256bit.zok diff --git a/zokrates_stdlib/stdlib/utils/multiplexer/2bit.code b/zokrates_stdlib/stdlib/utils/multiplexer/2bit.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/multiplexer/2bit.code rename to zokrates_stdlib/stdlib/utils/multiplexer/2bit.zok diff --git a/zokrates_stdlib/stdlib/utils/multiplexer/lookup1bit.code b/zokrates_stdlib/stdlib/utils/multiplexer/lookup1bit.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/multiplexer/lookup1bit.code rename to zokrates_stdlib/stdlib/utils/multiplexer/lookup1bit.zok diff --git a/zokrates_stdlib/stdlib/utils/multiplexer/lookup2bit.code b/zokrates_stdlib/stdlib/utils/multiplexer/lookup2bit.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/multiplexer/lookup2bit.code rename to zokrates_stdlib/stdlib/utils/multiplexer/lookup2bit.zok diff --git a/zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.code b/zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.zok similarity index 88% rename from zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.code rename to zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.zok index d5894a96..b4b79f1f 100644 --- a/zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.code +++ b/zokrates_stdlib/stdlib/utils/multiplexer/lookup3bitSigned.zok @@ -1,4 +1,4 @@ -import "./lookup2bit.code" as lookup +import "./lookup2bit" as lookup // /** // * Three-bit window lookup (2bits + signature bit) in 2bit table // * using two constraints. Maps the bits `b` to a list of constants `c` diff --git a/zokrates_stdlib/stdlib/utils/pack/nonStrictUnpack256.code b/zokrates_stdlib/stdlib/utils/pack/nonStrictUnpack256.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/pack/nonStrictUnpack256.code rename to zokrates_stdlib/stdlib/utils/pack/nonStrictUnpack256.zok diff --git a/zokrates_stdlib/stdlib/utils/pack/pack128.code b/zokrates_stdlib/stdlib/utils/pack/pack128.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/pack/pack128.code rename to zokrates_stdlib/stdlib/utils/pack/pack128.zok diff --git a/zokrates_stdlib/stdlib/utils/pack/pack256.code b/zokrates_stdlib/stdlib/utils/pack/pack256.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/pack/pack256.code rename to zokrates_stdlib/stdlib/utils/pack/pack256.zok diff --git a/zokrates_stdlib/stdlib/utils/pack/unpack128.code b/zokrates_stdlib/stdlib/utils/pack/unpack128.zok similarity index 100% rename from zokrates_stdlib/stdlib/utils/pack/unpack128.code rename to zokrates_stdlib/stdlib/utils/pack/unpack128.zok diff --git a/zokrates_stdlib/tests/tests/and.json b/zokrates_stdlib/tests/tests/and.json index 5234c410..64273a19 100644 --- a/zokrates_stdlib/tests/tests/and.json +++ b/zokrates_stdlib/tests/tests/and.json @@ -1,5 +1,5 @@ { - "entry_point": "./stdlib/utils/binary/and.code", + "entry_point": "./stdlib/utils/binary/and.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json index 11457b30..c7e6c571 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/edwardsAdd.code", + "entry_point": "./tests/tests/ecc/edwardsAdd.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsAdd.code b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.zok similarity index 85% rename from zokrates_stdlib/tests/tests/ecc/edwardsAdd.code rename to zokrates_stdlib/tests/tests/ecc/edwardsAdd.zok index 4641c266..6c5ac9fe 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsAdd.code +++ b/zokrates_stdlib/tests/tests/ecc/edwardsAdd.zok @@ -1,6 +1,6 @@ -import "ecc/edwardsAdd.code" as add -import "ecc/edwardsNegate.code" as neg -import "ecc/babyjubjubParams.code" as context +import "ecc/edwardsAdd" as add +import "ecc/edwardsNegate" as neg +import "ecc/babyjubjubParams" as context // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json index b17a104e..e4d6e067 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/edwardsCompress.code", + "entry_point": "./tests/tests/ecc/edwardsCompress.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsCompress.code b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.zok similarity index 89% rename from zokrates_stdlib/tests/tests/ecc/edwardsCompress.code rename to zokrates_stdlib/tests/tests/ecc/edwardsCompress.zok index 38aaed31..6a18be1b 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsCompress.code +++ b/zokrates_stdlib/tests/tests/ecc/edwardsCompress.zok @@ -1,5 +1,5 @@ -import "ecc/edwardsCompress.code" as edwardsCompress -import "ecc/babyjubjubParams.code" as context +import "ecc/edwardsCompress" as edwardsCompress +import "ecc/babyjubjubParams" as context // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json index 018d856a..c4bf025e 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/edwardsOnCurve.code", + "entry_point": "./tests/tests/ecc/edwardsOnCurve.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.code b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.zok similarity index 83% rename from zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.code rename to zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.zok index 5da13a9a..7f92a8bc 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.code +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOnCurve.zok @@ -1,5 +1,5 @@ -import "ecc/babyjubjubParams.code" as context -import "ecc/edwardsOnCurve.code" as onCurve +import "ecc/babyjubjubParams" as context +import "ecc/edwardsOnCurve" as onCurve // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json index 387bdaef..55f1af76 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/edwardsOrderCheck.code", + "entry_point": "./tests/tests/ecc/edwardsOrderCheck.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.code b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.zok similarity index 89% rename from zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.code rename to zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.zok index 1a2456f1..641f557c 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.code +++ b/zokrates_stdlib/tests/tests/ecc/edwardsOrderCheck.zok @@ -1,5 +1,5 @@ -import "ecc/edwardsOrderCheck.code" as orderCheck -import "ecc/babyjubjubParams.code" as context +import "ecc/edwardsOrderCheck" as orderCheck +import "ecc/babyjubjubParams" as context // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json index 029ae8a8..be2699b9 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json +++ b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/edwardsScalarMult.code", + "entry_point": "./tests/tests/ecc/edwardsScalarMult.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.code b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.zok similarity index 98% rename from zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.code rename to zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.zok index 8c6cdbd8..00f08260 100644 --- a/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.code +++ b/zokrates_stdlib/tests/tests/ecc/edwardsScalarMult.zok @@ -1,5 +1,5 @@ -import "ecc/babyjubjubParams.code" as context -import "ecc/edwardsScalarMult.code" as mul +import "ecc/babyjubjubParams" as context +import "ecc/edwardsScalarMult" as mul // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json index 9a0c3833..08148630 100644 --- a/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json +++ b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/ecc/proofOfOwnership.code", + "entry_point": "./tests/tests/ecc/proofOfOwnership.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.code b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.zok similarity index 82% rename from zokrates_stdlib/tests/tests/ecc/proofOfOwnership.code rename to zokrates_stdlib/tests/tests/ecc/proofOfOwnership.zok index 50ef0eb2..9e8a2f95 100644 --- a/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.code +++ b/zokrates_stdlib/tests/tests/ecc/proofOfOwnership.zok @@ -1,7 +1,7 @@ -import "ecc/babyjubjubParams.code" as context -import "ecc/proofOfOwnership.code" as proofOfOwnership -import "ecc/edwardsScalarMult.code" as multiply -import "utils/pack/nonStrictUnpack256.code" as unpack256 +import "ecc/babyjubjubParams" as context +import "ecc/proofOfOwnership" as proofOfOwnership +import "ecc/edwardsScalarMult" as multiply +import "utils/pack/nonStrictUnpack256" as unpack256 // Code to create test cases: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json index 04bee370..18627080 100644 --- a/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/pedersen/512bit.code", + "entry_point": "./tests/tests/hashes/pedersen/512bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.code b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.zok similarity index 98% rename from zokrates_stdlib/tests/tests/hashes/pedersen/512bit.code rename to zokrates_stdlib/tests/tests/hashes/pedersen/512bit.zok index 22053482..3cdd32d8 100644 --- a/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.code +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/512bit.zok @@ -12,7 +12,7 @@ // entropy_bits = bitstring.BitArray(bytes=entropy).bin // digest_bits = bitstring.BitArray(bytes=digest.compress()).bin -import "hashes/pedersen/512bit.code" as pedersen +import "hashes/pedersen/512bit" as pedersen def main() -> (field): diff --git a/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json index a08d8cbb..9104faf1 100644 --- a/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/pedersen/6bit.code", + "entry_point": "./tests/tests/hashes/pedersen/6bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.code b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.zok similarity index 91% rename from zokrates_stdlib/tests/tests/hashes/pedersen/6bit.code rename to zokrates_stdlib/tests/tests/hashes/pedersen/6bit.zok index f6e2fedd..832c9d2b 100644 --- a/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.code +++ b/zokrates_stdlib/tests/tests/hashes/pedersen/6bit.zok @@ -6,7 +6,7 @@ // bs = bitstring.BitArray('0b110000') // hasher.hash_bits(bs) -import "hashes/pedersen/6bit.code" as pedersen +import "hashes/pedersen/6bit" as pedersen def main() -> (field): diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json index 2d7cf5ff..672e60f9 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/sha256/512bit.code", + "entry_point": "./tests/tests/hashes/sha256/512bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bit.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.zok similarity index 98% rename from zokrates_stdlib/tests/tests/hashes/sha256/512bit.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bit.zok index cc943342..4c943001 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bit.code +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bit.zok @@ -1,4 +1,4 @@ -import "hashes/sha256/512bit.code" as sha256 +import "hashes/sha256/512bit" as sha256 def main() -> (field): field[256] a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json index 9d2cc47e..4dfa5270 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.json @@ -1,5 +1,5 @@ { - "entry_point": "./stdlib/hashes/sha256/512bitPacked.code", + "entry_point": "./stdlib/hashes/sha256/512bitPacked.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.zok similarity index 93% rename from zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.zok index 569b44b7..471a0376 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.code +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked.zok @@ -15,7 +15,7 @@ // int(digest[32:], 16) // # 65303172752238645975888084098459749904 -import "hashes/sha256/512bitPacked.code" as sha256packed +import "hashes/sha256/512bitPacked" as sha256packed def main() -> (field): field a = 0 diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json index 86b6c9a6..5d2cc9cd 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPacked2.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/sha256/512bitPacked.code", + "entry_point": "./tests/tests/hashes/sha256/512bitPacked.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json index e137fb71..5136a964 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/sha256/512bitPadded.code", + "entry_point": "./tests/tests/hashes/sha256/512bitPadded.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.code b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.zok similarity index 98% rename from zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.code rename to zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.zok index 06ba66e2..483c7b61 100644 --- a/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.code +++ b/zokrates_stdlib/tests/tests/hashes/sha256/512bitPadded.zok @@ -12,7 +12,7 @@ // bin(int(digest, 16)) // # '0b1100011001001000000111100010001011000101111111110100000101100100101011110110100000001011100011001111101010100101111010001110110100110001001000001110111011111111100010011100010011110011000001111100010010100110111110101010101011100000010110011100111000010000' -import "hashes/sha256/512bitPadded.code" as sha256 +import "hashes/sha256/512bitPadded" as sha256 def main() -> (field): field[256] a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json index a99cedcf..6fc884cb 100644 --- a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json +++ b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/hashes/utils/256bitsDirectionHelper.code", + "entry_point": "./tests/tests/hashes/utils/256bitsDirectionHelper.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.code b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok similarity index 99% rename from zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.code rename to zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok index 597958d8..89b39228 100644 --- a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.code +++ b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok @@ -12,7 +12,7 @@ // entropy_bits = bitstring.BitArray(bytes=entropy).bin // digest_bits = bitstring.BitArray(bytes=digest.compress()).bin -import "hashes/utils/256bitsDirectionHelper.code" as dicrection +import "hashes/utils/256bitsDirectionHelper" as dicrection def left() -> (field): diff --git a/zokrates_stdlib/tests/tests/or.json b/zokrates_stdlib/tests/tests/or.json index 020a3af7..6fa25fdc 100644 --- a/zokrates_stdlib/tests/tests/or.json +++ b/zokrates_stdlib/tests/tests/or.json @@ -1,5 +1,5 @@ { - "entry_point": "./stdlib/utils/binary/or.code", + "entry_point": "./stdlib/utils/binary/or.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json index c6887f83..f0a753d4 100644 --- a/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json +++ b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/signatures/verifyEddsa.code", + "entry_point": "./tests/tests/signatures/verifyEddsa.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/signatures/verifyEddsa.code b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.zok similarity index 95% rename from zokrates_stdlib/tests/tests/signatures/verifyEddsa.code rename to zokrates_stdlib/tests/tests/signatures/verifyEddsa.zok index bc4e79c3..382090db 100644 --- a/zokrates_stdlib/tests/tests/signatures/verifyEddsa.code +++ b/zokrates_stdlib/tests/tests/signatures/verifyEddsa.zok @@ -1,5 +1,5 @@ -import "signatures/verifyEddsa.code" as verifyEddsa -import "ecc/babyjubjubParams.code" as context +import "signatures/verifyEddsa" as verifyEddsa +import "ecc/babyjubjubParams" as context // Code to create test case: // https://github.com/Zokrates/pycrypto diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json index 834dfa5a..738c3f03 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/multiplexer/256bit.code", + "entry_point": "./tests/tests/utils/multiplexer/256bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.zok similarity index 98% rename from zokrates_stdlib/tests/tests/utils/multiplexer/256bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/256bit.zok index d95a02b8..ef907555 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.code +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/256bit.zok @@ -1,4 +1,4 @@ -import "utils/multiplexer/256bit.code" as multiplex +import "utils/multiplexer/256bit" as multiplex def left() -> (field): field bit = 0 //left diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json index ff6ad3ca..95cb4b28 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/multiplexer/2bit.code", + "entry_point": "./tests/tests/utils/multiplexer/2bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.zok similarity index 88% rename from zokrates_stdlib/tests/tests/utils/multiplexer/2bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/2bit.zok index 37b998ab..30d0e6c2 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.code +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/2bit.zok @@ -1,4 +1,4 @@ -import "utils/multiplexer/2bit.code" as multiplex +import "utils/multiplexer/2bit" as multiplex def left() -> (field): field bit = 0 //left diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json index deeef014..81068184 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/multiplexer/lookup1bit.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup1bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.zok similarity index 83% rename from zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.zok index f039dbe9..b602ea77 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.code +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup1bit.zok @@ -1,4 +1,4 @@ -import "utils/multiplexer/lookup1bit.code" as lookup +import "utils/multiplexer/lookup1bit" as lookup def left() -> (field): field sel = 0 //left diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json index a594889e..97866512 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/multiplexer/lookup2bit.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup2bit.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.zok similarity index 91% rename from zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.zok index 4e97abfe..7b3dae52 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.code +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup2bit.zok @@ -1,4 +1,4 @@ -import "utils/multiplexer/lookup2bit.code" as lookup +import "utils/multiplexer/lookup2bit" as lookup def first() -> (field): field[2] sel = [0,0] diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json index 3757c165..ddc4b935 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/multiplexer/lookup3bitSigned.code", + "entry_point": "./tests/tests/utils/multiplexer/lookup3bitSigned.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.code b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.zok similarity index 95% rename from zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.code rename to zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.zok index df5fc177..c3af4b44 100644 --- a/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.code +++ b/zokrates_stdlib/tests/tests/utils/multiplexer/lookup3bitSigned.zok @@ -1,4 +1,4 @@ -import "utils/multiplexer/lookup3bitSigned.code" as lookup +import "utils/multiplexer/lookup3bitSigned" as lookup def first() -> (field): field[3] sel = [0,0,0] diff --git a/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json index 9d6d2039..3f6a3ffb 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json +++ b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/pack/nonStrictUnpack256.code", + "entry_point": "./tests/tests/utils/pack/nonStrictUnpack256.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.code b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.zok similarity index 98% rename from zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.code rename to zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.zok index c9856333..44a32919 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.code +++ b/zokrates_stdlib/tests/tests/utils/pack/nonStrictUnpack256.zok @@ -1,4 +1,4 @@ -import "utils/pack/nonStrictUnpack256.code" as unpack256 +import "utils/pack/nonStrictUnpack256" as unpack256 def testFive() -> (field): diff --git a/zokrates_stdlib/tests/tests/utils/pack/pack128.json b/zokrates_stdlib/tests/tests/utils/pack/pack128.json index beadfbc1..f339e1be 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/pack128.json +++ b/zokrates_stdlib/tests/tests/utils/pack/pack128.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/pack/pack128.code", + "entry_point": "./tests/tests/utils/pack/pack128.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/pack/pack128.code b/zokrates_stdlib/tests/tests/utils/pack/pack128.zok similarity index 97% rename from zokrates_stdlib/tests/tests/utils/pack/pack128.code rename to zokrates_stdlib/tests/tests/utils/pack/pack128.zok index c6388662..604de3cf 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/pack128.code +++ b/zokrates_stdlib/tests/tests/utils/pack/pack128.zok @@ -1,4 +1,4 @@ -import "utils/pack/pack128.code" as pack128 +import "utils/pack/pack128" as pack128 def testFive() -> (field): diff --git a/zokrates_stdlib/tests/tests/utils/pack/unpack128.json b/zokrates_stdlib/tests/tests/utils/pack/unpack128.json index 91ea3516..81cec6a8 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/unpack128.json +++ b/zokrates_stdlib/tests/tests/utils/pack/unpack128.json @@ -1,5 +1,5 @@ { - "entry_point": "./tests/tests/utils/pack/unpack128.code", + "entry_point": "./tests/tests/utils/pack/unpack128.zok", "tests": [ { "input": { diff --git a/zokrates_stdlib/tests/tests/utils/pack/unpack128.code b/zokrates_stdlib/tests/tests/utils/pack/unpack128.zok similarity index 96% rename from zokrates_stdlib/tests/tests/utils/pack/unpack128.code rename to zokrates_stdlib/tests/tests/utils/pack/unpack128.zok index 087505ce..e4e66d31 100644 --- a/zokrates_stdlib/tests/tests/utils/pack/unpack128.code +++ b/zokrates_stdlib/tests/tests/utils/pack/unpack128.zok @@ -1,4 +1,4 @@ -import "utils/pack/unpack128.code" as unpack128 +import "utils/pack/unpack128" as unpack128 def testFive() -> (field): From eaa02642a40146dc171716c23180139d38face26 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 24 Sep 2019 16:06:26 +0200 Subject: [PATCH 17/27] add stf to gitignore --- .gitignore | 3 +-- out.ztf | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 out.ztf diff --git a/.gitignore b/.gitignore index 5468c136..30082090 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,7 @@ # ZoKrates default files out -out.zok -out.wit +out.ztf proof.json proving.key verification.key diff --git a/out.ztf b/out.ztf deleted file mode 100644 index 17a2fd30..00000000 --- a/out.ztf +++ /dev/null @@ -1,3 +0,0 @@ -def main(_0) -> (1): - (1 * ~one) * (28 * ~one + 10 * _0) == 1 * ~out_0 - return ~out_0 From 20f3a980fe947c60f54c34d9a1212e863534916c Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Tue, 24 Sep 2019 22:14:42 +0200 Subject: [PATCH 18/27] Struct doc with examples. Break current preliminary impl. as they have spec character. --- zokrates_book/src/concepts/types.md | 66 +++++++++++++++---- zokrates_cli/examples/book/struct_assign.code | 10 +++ zokrates_cli/examples/book/struct_init.code | 8 +++ zokrates_cli/examples/book/structs.code | 14 ++++ 4 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 zokrates_cli/examples/book/struct_assign.code create mode 100644 zokrates_cli/examples/book/struct_init.code create mode 100644 zokrates_cli/examples/book/structs.code diff --git a/zokrates_book/src/concepts/types.md b/zokrates_book/src/concepts/types.md index 23264b1a..5e64e1eb 100644 --- a/zokrates_book/src/concepts/types.md +++ b/zokrates_book/src/concepts/types.md @@ -1,10 +1,10 @@ -## Types +# Types -ZoKrates currently exposes two primitive types and a complex array type: +ZoKrates currently exposes two primitive types and two complex types: -### Primitive Types +## Primitive Types -#### `field` +### `field` This is the most basic type in ZoKrates, and it represents a positive integer in `[0, p - 1]` where `p` is a (large) prime number. @@ -16,7 +16,7 @@ While `field` values mostly behave like unsigned integers, one should keep in mi {{#include ../../../zokrates_cli/examples/book/field_overflow.code}} ``` -#### `bool` +### `bool` ZoKrates has limited support for booleans, to the extent that they can only be used as the condition in `if ... else ... endif` expressions. @@ -24,9 +24,11 @@ You can use them for equality checks, inequality checks and inequality checks be Note that while equality checks are cheap, inequality checks should be use wisely as they are orders of magnitude more expensive. -### Complex Types +## Complex Types -#### Arrays +ZoKrates provides two complex types, Arrays and Structs. + +### Arrays ZoKrates supports static arrays, i.e., their length needs to be known at compile time. Arrays can contain elements of any type and have arbitrary dimensions. @@ -37,10 +39,10 @@ The following examples code shows examples of how to use arrays: {{#include ../../../zokrates_cli/examples/book/array.code}} ``` -##### Declaration and Initialization +#### Declaration and Initialization An array is defined by appending `[]` to a type literal representing the type of the array's elements. -Initialization always needs to happen in the same statement than declaration, unless the array is declared within a function's signature. +Initialization always needs to happen in the same statement as declaration, unless the array is declared within a function's signature. For initialization, a list of comma-separated values is provided within brackets `[]`. @@ -54,7 +56,7 @@ The following code provides examples for declaration and initialization: bool[13] b = [false; 13] // initialize a bool array with value false ``` -##### Multidimensional Arrays +#### Multidimensional Arrays As an array can contain any type of elements, it can contain arrays again. There is a special syntax to declare such multi-dimensional arrays, i.e., arrays of arrays. @@ -67,10 +69,10 @@ Consider the following example: {{#include ../../../zokrates_cli/examples/book/multidim_array.code}} ``` -##### Spreads and Slices +#### Spreads and Slices ZoKrates provides some syntactic sugar to retrieve subsets of arrays. -###### Spreads +##### Spreads The spread operator `...` applied to an copies the elements of an existing array. This can be used to conveniently compose new arrays, as shown in the following example: ``` @@ -78,10 +80,48 @@ field[3] = [1, 2, 3] field[4] c = [...a, 4] // initialize an array copying values from `a`, followed by 4 ``` -###### Slices +##### Slices An array can also be assigned to by creating a copy of a subset of an existing array. This operation is called slicing, and the following example shows how to slice in ZoKrates: ``` field[3] a = [1, 2, 3] field[2] b = a[1..3] // initialize an array copying a slice from `a` ``` + +### Structs +A struct is a composite datatype representing a named collection of variables. +The contained variables can be of any type. + +The following code shows an example of how to use structs. + +```zokrates +{{#include ../../../zokrates_cli/examples/book/structs.code}} +``` + +#### Definition +Before a struct data type can be used, it needs to be defined. +A struct definition starts with the `struct` keyword followed by a name. Afterwards, a new-line separated list of variables is declared in curly braces `{}`. For example: + +```zokrates +struct Point { + field x + field y +} +``` + +#### Declaration and Initialization + +Initialization of a variable of a struct type always needs to happen in the same statement as declaration, unless the struct-typed variable is declared within a function's signature. + +The following example shows declaration and initialization of a variable of the `Point` struct type: + +```zokrates +{{#include ../../../zokrates_cli/examples/book/struct_init.code}} +``` + +#### Assignment +The variables within a struct instance, the so called members, can be accessed through the `.` operator as shown in the following extended example: + +```zokrates +{{#include ../../../zokrates_cli/examples/book/struct_assign.code}} +``` \ No newline at end of file diff --git a/zokrates_cli/examples/book/struct_assign.code b/zokrates_cli/examples/book/struct_assign.code new file mode 100644 index 00000000..c52794d1 --- /dev/null +++ b/zokrates_cli/examples/book/struct_assign.code @@ -0,0 +1,10 @@ +struct Point { + field x + field y +} + +def main(field a) -> (Point): + Point p = Point {x: 1, y: 0} + p.x = a + p.y = p.x + return p diff --git a/zokrates_cli/examples/book/struct_init.code b/zokrates_cli/examples/book/struct_init.code new file mode 100644 index 00000000..837afc84 --- /dev/null +++ b/zokrates_cli/examples/book/struct_init.code @@ -0,0 +1,8 @@ +struct Point { + field x + field y +} + +def main() -> (Point): + Point p = Point {x: 1, y: 0} + return p diff --git a/zokrates_cli/examples/book/structs.code b/zokrates_cli/examples/book/structs.code new file mode 100644 index 00000000..6abdccce --- /dev/null +++ b/zokrates_cli/examples/book/structs.code @@ -0,0 +1,14 @@ +struct Bar { + field[2] c + bool b +} + +struct Foo { + Bar a + bool b +} + +def main() -> (Foo): + Foo[2] f = [Foo { a: Bar { c: [0, 0], d: false }, b: true}, Foo { a: Bar {c: [0, 0], d: false}, b: true}] + f[0].a.c = [42, 43] + return f[0] From 47395d0b4b773c6e6b6b20c83e0f43a3535e30db Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 25 Sep 2019 12:06:11 +0200 Subject: [PATCH 19/27] change struct declaration syntax --- zokrates_cli/examples/book/structs.code | 2 +- zokrates_cli/examples/structs/add.code | 4 +- zokrates_cli/examples/structs/set_member.code | 8 ++-- .../tests/tests/structs/identity.code | 4 +- zokrates_parser/src/lib.rs | 42 +++++++++---------- zokrates_parser/src/zokrates.pest | 4 +- zokrates_pest_ast/src/lib.rs | 6 +-- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/zokrates_cli/examples/book/structs.code b/zokrates_cli/examples/book/structs.code index 6abdccce..a08399ba 100644 --- a/zokrates_cli/examples/book/structs.code +++ b/zokrates_cli/examples/book/structs.code @@ -1,6 +1,6 @@ struct Bar { field[2] c - bool b + bool d } struct Foo { diff --git a/zokrates_cli/examples/structs/add.code b/zokrates_cli/examples/structs/add.code index 3941f08f..5d1fd856 100644 --- a/zokrates_cli/examples/structs/add.code +++ b/zokrates_cli/examples/structs/add.code @@ -1,6 +1,6 @@ struct Point { - x: field, - y: field + field x + field y } def main(Point p, Point q) -> (Point): diff --git a/zokrates_cli/examples/structs/set_member.code b/zokrates_cli/examples/structs/set_member.code index 99872793..7cca5707 100644 --- a/zokrates_cli/examples/structs/set_member.code +++ b/zokrates_cli/examples/structs/set_member.code @@ -1,11 +1,11 @@ struct Bar { - c: field[2], - d: bool + field[2] c + bool d } struct Foo { - a: Bar, - b: bool + Bar a + bool b } def main() -> (Foo): diff --git a/zokrates_core_test/tests/tests/structs/identity.code b/zokrates_core_test/tests/tests/structs/identity.code index 041e79ed..e5441761 100644 --- a/zokrates_core_test/tests/tests/structs/identity.code +++ b/zokrates_core_test/tests/tests/structs/identity.code @@ -1,6 +1,6 @@ struct A { - a: field, - b: bool + field a + bool b } def main(A a) -> (A): diff --git a/zokrates_parser/src/lib.rs b/zokrates_parser/src/lib.rs index e0383a84..be385565 100644 --- a/zokrates_parser/src/lib.rs +++ b/zokrates_parser/src/lib.rs @@ -149,40 +149,40 @@ mod tests { fn parse_struct_def() { parses_to! { parser: ZoKratesParser, - input: "struct Foo { foo: field, bar: field[2] } + input: "struct Foo { field foo\n field[2] bar } ", rule: Rule::ty_struct_definition, tokens: [ - ty_struct_definition(0, 41, [ + ty_struct_definition(0, 39, [ identifier(7, 10), - struct_field(13, 23, [ - identifier(13, 16), - ty(18, 23, [ - ty_basic(18, 23, [ - ty_field(18, 23) + struct_field(13, 22, [ + ty(13, 18, [ + ty_basic(13, 18, [ + ty_field(13, 18) ]) - ]) + ]), + identifier(19, 22) ]), - struct_field(25, 39, [ - identifier(25, 28), - ty(30, 39, [ - ty_array(30, 39, [ - ty_basic_or_struct(30, 35, [ - ty_basic(30, 35, [ - ty_field(30, 35) + struct_field(24, 36, [ + ty(24, 33, [ + ty_array(24, 33, [ + ty_basic_or_struct(24, 29, [ + ty_basic(24, 29, [ + ty_field(24, 29) ]) ]), - expression(36, 37, [ - term(36, 37, [ - primary_expression(36, 37, [ - constant(36, 37, [ - decimal_number(36, 37) + expression(30, 31, [ + term(30, 31, [ + primary_expression(30, 31, [ + constant(30, 31, [ + decimal_number(30, 31) ]) ]) ]) ]) ]) - ]) + ]), + identifier(33, 36) ]) ]) ] diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 0c054478..40bc09dc 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -26,8 +26,8 @@ type_list = _{(ty ~ ("," ~ ty)*)?} ty_struct = { identifier } // type definitions ty_struct_definition = { "struct" ~ identifier ~ "{" ~ NEWLINE* ~ struct_field_list ~ NEWLINE* ~ "}" ~ NEWLINE* } -struct_field_list = _{(struct_field ~ ("," ~ NEWLINE* ~ struct_field)*)? ~ ","? } -struct_field = { identifier ~ ":" ~ ty } +struct_field_list = _{(struct_field ~ (NEWLINE+ ~ struct_field)*)? } +struct_field = { ty ~ identifier } vis_private = {"private"} vis_public = {"public"} diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 164d7962..e86541be 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -178,8 +178,8 @@ mod ast { #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::struct_field))] pub struct StructField<'ast> { - pub id: IdentifierExpression<'ast>, pub ty: Type<'ast>, + pub id: IdentifierExpression<'ast>, #[pest_ast(outer())] pub span: Span<'ast>, } @@ -1083,8 +1083,8 @@ mod tests { let source = r#"import "heyman" as yo struct Foo { - foo: field[2], - bar: Bar + field[2] foo + Bar bar } def main(private field[23] a) -> (bool[234 + 6]): From 58642a8615cad861c735b572b0e1b9a93cde302b Mon Sep 17 00:00:00 2001 From: Thibaut Schaeffer Date: Wed, 25 Sep 2019 12:14:41 +0200 Subject: [PATCH 20/27] Apply suggestions from code review Co-Authored-By: JacobEberhardt --- zokrates_github_resolver/src/lib.rs | 4 ++-- zokrates_stdlib/stdlib/hashes/sha256/512bit.zok | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zokrates_github_resolver/src/lib.rs b/zokrates_github_resolver/src/lib.rs index 9b27b658..45e0592b 100644 --- a/zokrates_github_resolver/src/lib.rs +++ b/zokrates_github_resolver/src/lib.rs @@ -9,7 +9,7 @@ //! //! For example: //! ```zokrates -//! import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3.zok" as merkleTreeProof +//! import "github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/merkleTree/sha256PathProof3" as merkleTreeProof //! ``` //! //! Example above imports file `zokrates_cli/examples/merkleTree/sha256PathProof3.zok` located at ZoKrates @@ -187,7 +187,7 @@ mod tests { #[test] #[should_panic] pub fn import_no_branch() { - // Correct syntax should be: github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import.zok + // Correct syntax should be: github.com/Zokrates/ZoKrates/master/zokrates_cli/examples/imports/import // but branch name is not specified parse_input_path(Path::new("github.com/Zokrates/ZoKrates/test")).unwrap(); } diff --git a/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok b/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok index 6ace46d9..1379ff79 100644 --- a/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok +++ b/zokrates_stdlib/stdlib/hashes/sha256/512bit.zok @@ -3,7 +3,7 @@ import "./shaRoundNoBoolCheck" as sha256 // A function that takes 2 field[256] arrays as inputs // and returns their sha256 compression function as an array of 256 field elements. -// In contrast to full_round no padding is being applied +// In contrast to full_round.zok no padding is being applied def main(field[256] a, field[256] b) -> (field[256]): // a and b is NOT checked to be of type bool @@ -12,4 +12,4 @@ def main(field[256] a, field[256] b) -> (field[256]): digest = sha256(a, b, IV) //digest is constraint to be of type bool - return digest \ No newline at end of file + return digest From 821686673595a1fc40ae9ad95946adfa1468cff0 Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 25 Sep 2019 12:15:19 +0200 Subject: [PATCH 21/27] fix import docs, fix stdlib test typo --- zokrates_book/src/concepts/imports.md | 10 +++++----- .../tests/hashes/utils/256bitsDirectionHelper.zok | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/zokrates_book/src/concepts/imports.md b/zokrates_book/src/concepts/imports.md index aeda193a..25d3dcb4 100644 --- a/zokrates_book/src/concepts/imports.md +++ b/zokrates_book/src/concepts/imports.md @@ -1,27 +1,27 @@ ## Imports -You can separate your code into multiple ZoKrates files using `import` statements: +You can separate your code into multiple ZoKrates files using `import` statements, ignoring the `.zok` extension of the imported file: ### Relative Imports You can import a resource in the same folder directly, like this: ```zokrates -import "./mycode.zok" +import "./mycode" ``` There also is a handy syntax to import from the parent directory: ```zokrates -import "../mycode.zok" +import "../mycode" ``` Also imports further up the file-system are supported: ```zokrates -import "../../../mycode.zok" +import "../../../mycode" ``` You can also choose to rename the imported resource, like so: ```zokrates -import "./mycode.zok" as abc +import "./mycode" as abc ``` ### Absolute Imports diff --git a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok index 89b39228..e3ae4a34 100644 --- a/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok +++ b/zokrates_stdlib/tests/tests/hashes/utils/256bitsDirectionHelper.zok @@ -12,13 +12,13 @@ // entropy_bits = bitstring.BitArray(bytes=entropy).bin // digest_bits = bitstring.BitArray(bytes=digest.compress()).bin -import "hashes/utils/256bitsDirectionHelper" as dicrection +import "hashes/utils/256bitsDirectionHelper" as direction def left() -> (field): field[256] a = [0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0] field[256] b = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1] - out = dicrection(0, a, b) + out = direction(0, a, b) out == [0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1] return 1 @@ -26,7 +26,7 @@ def right() -> (field): field[256] a = [0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0] field[256] b = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1] - out = dicrection(1, a, b) + out = direction(1, a, b) out == [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0] return 1 From f27df222e18f2395ad0afb84679803f05c02fea6 Mon Sep 17 00:00:00 2001 From: Thibaut Schaeffer Date: Wed, 25 Sep 2019 12:16:57 +0200 Subject: [PATCH 22/27] Update zokrates_github_resolver/src/lib.rs Co-Authored-By: JacobEberhardt --- zokrates_github_resolver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_github_resolver/src/lib.rs b/zokrates_github_resolver/src/lib.rs index 45e0592b..302e6494 100644 --- a/zokrates_github_resolver/src/lib.rs +++ b/zokrates_github_resolver/src/lib.rs @@ -4,7 +4,7 @@ //! //! To import file from github, use following syntax: //! ```zokrates -//! import "github:user/repo/branch/path/to/file.zok" +//! import "github:user/repo/branch/path/to/file" //! ``` //! //! For example: From 3b0b6959e343c6050cfd7470d7e42f473d1b2ef2 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 28 Sep 2019 18:24:29 +0200 Subject: [PATCH 23/27] change struct declaration syntax --- zokrates_cli/examples/book/structs.code | 2 +- zokrates_cli/examples/structs/add.code | 4 +- zokrates_cli/examples/structs/set_member.code | 8 ++-- .../tests/tests/structs/identity.code | 4 +- zokrates_parser/src/lib.rs | 42 +++++++++---------- zokrates_parser/src/zokrates.pest | 4 +- zokrates_pest_ast/src/lib.rs | 6 +-- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/zokrates_cli/examples/book/structs.code b/zokrates_cli/examples/book/structs.code index 6abdccce..a08399ba 100644 --- a/zokrates_cli/examples/book/structs.code +++ b/zokrates_cli/examples/book/structs.code @@ -1,6 +1,6 @@ struct Bar { field[2] c - bool b + bool d } struct Foo { diff --git a/zokrates_cli/examples/structs/add.code b/zokrates_cli/examples/structs/add.code index 3941f08f..5d1fd856 100644 --- a/zokrates_cli/examples/structs/add.code +++ b/zokrates_cli/examples/structs/add.code @@ -1,6 +1,6 @@ struct Point { - x: field, - y: field + field x + field y } def main(Point p, Point q) -> (Point): diff --git a/zokrates_cli/examples/structs/set_member.code b/zokrates_cli/examples/structs/set_member.code index 99872793..7cca5707 100644 --- a/zokrates_cli/examples/structs/set_member.code +++ b/zokrates_cli/examples/structs/set_member.code @@ -1,11 +1,11 @@ struct Bar { - c: field[2], - d: bool + field[2] c + bool d } struct Foo { - a: Bar, - b: bool + Bar a + bool b } def main() -> (Foo): diff --git a/zokrates_core_test/tests/tests/structs/identity.code b/zokrates_core_test/tests/tests/structs/identity.code index 041e79ed..e5441761 100644 --- a/zokrates_core_test/tests/tests/structs/identity.code +++ b/zokrates_core_test/tests/tests/structs/identity.code @@ -1,6 +1,6 @@ struct A { - a: field, - b: bool + field a + bool b } def main(A a) -> (A): diff --git a/zokrates_parser/src/lib.rs b/zokrates_parser/src/lib.rs index e0383a84..be385565 100644 --- a/zokrates_parser/src/lib.rs +++ b/zokrates_parser/src/lib.rs @@ -149,40 +149,40 @@ mod tests { fn parse_struct_def() { parses_to! { parser: ZoKratesParser, - input: "struct Foo { foo: field, bar: field[2] } + input: "struct Foo { field foo\n field[2] bar } ", rule: Rule::ty_struct_definition, tokens: [ - ty_struct_definition(0, 41, [ + ty_struct_definition(0, 39, [ identifier(7, 10), - struct_field(13, 23, [ - identifier(13, 16), - ty(18, 23, [ - ty_basic(18, 23, [ - ty_field(18, 23) + struct_field(13, 22, [ + ty(13, 18, [ + ty_basic(13, 18, [ + ty_field(13, 18) ]) - ]) + ]), + identifier(19, 22) ]), - struct_field(25, 39, [ - identifier(25, 28), - ty(30, 39, [ - ty_array(30, 39, [ - ty_basic_or_struct(30, 35, [ - ty_basic(30, 35, [ - ty_field(30, 35) + struct_field(24, 36, [ + ty(24, 33, [ + ty_array(24, 33, [ + ty_basic_or_struct(24, 29, [ + ty_basic(24, 29, [ + ty_field(24, 29) ]) ]), - expression(36, 37, [ - term(36, 37, [ - primary_expression(36, 37, [ - constant(36, 37, [ - decimal_number(36, 37) + expression(30, 31, [ + term(30, 31, [ + primary_expression(30, 31, [ + constant(30, 31, [ + decimal_number(30, 31) ]) ]) ]) ]) ]) - ]) + ]), + identifier(33, 36) ]) ]) ] diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 0c054478..40bc09dc 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -26,8 +26,8 @@ type_list = _{(ty ~ ("," ~ ty)*)?} ty_struct = { identifier } // type definitions ty_struct_definition = { "struct" ~ identifier ~ "{" ~ NEWLINE* ~ struct_field_list ~ NEWLINE* ~ "}" ~ NEWLINE* } -struct_field_list = _{(struct_field ~ ("," ~ NEWLINE* ~ struct_field)*)? ~ ","? } -struct_field = { identifier ~ ":" ~ ty } +struct_field_list = _{(struct_field ~ (NEWLINE+ ~ struct_field)*)? } +struct_field = { ty ~ identifier } vis_private = {"private"} vis_public = {"public"} diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 164d7962..e86541be 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -178,8 +178,8 @@ mod ast { #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::struct_field))] pub struct StructField<'ast> { - pub id: IdentifierExpression<'ast>, pub ty: Type<'ast>, + pub id: IdentifierExpression<'ast>, #[pest_ast(outer())] pub span: Span<'ast>, } @@ -1083,8 +1083,8 @@ mod tests { let source = r#"import "heyman" as yo struct Foo { - foo: field[2], - bar: Bar + field[2] foo + Bar bar } def main(private field[23] a) -> (bool[234 + 6]): From 6f6bbb4b619e6d517bc345c3175499ed66866acc Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Mon, 30 Sep 2019 11:59:02 +0200 Subject: [PATCH 24/27] cli fix + doc update --- out.code | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 out.code diff --git a/out.code b/out.code new file mode 100644 index 00000000..5d22bd6c --- /dev/null +++ b/out.code @@ -0,0 +1,19 @@ +def main(_0, _1, _2, _3) -> (2): + (21 * _0) * (1 * _1) == 1 * _4 + (1 * _4) * (1 * _2) == 1 * _5 + (1 * _5) * (1 * _3) == 1 * _6 + (1 * _0) * (1 * _3) == 1 * _7 + (1 * _2) * (1 * _1) == 1 * _8 + # _11 = Rust::Div(1 * ~one, 1 * ~one + 1 * _6) + (1 * _11) * (1 * ~one + 1 * _6) == 1 * ~one + # _12 = Rust::Div(1 * _7 + 1 * _8, 1 * ~one + 1 * _6) + (1 * ~one + 1 * _6) * (1 * _12) == 1 * _7 + 1 * _8 + (1 * _2) * (1 * _3) == 1 * _13 + (42 * _0) * (1 * _1) == 1 * _14 + # _17 = Rust::Div(1 * ~one, 1 * ~one + (-1) * _6) + (1 * _17) * (1 * ~one + (-1) * _6) == 1 * ~one + # _18 = Rust::Div(1 * _13 + (-1) * _14, 1 * ~one + (-1) * _6) + (1 * ~one + (-1) * _6) * (1 * _18) == 1 * _13 + (-1) * _14 + (1 * ~one) * (1 * _12) == 1 * ~out_0 + (1 * ~one) * (1 * _18) == 1 * ~out_1 + return ~out_0, ~out_1 From ef24980d6b9827774fe8f2dedcd0d2181bea107b Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Mon, 30 Sep 2019 11:59:17 +0200 Subject: [PATCH 25/27] cli fix + doc update --- zokrates_book/src/reference/cli.md | 13 +++++++------ zokrates_cli/src/bin.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/zokrates_book/src/reference/cli.md b/zokrates_book/src/reference/cli.md index 5ca9a53f..571bb3be 100644 --- a/zokrates_book/src/reference/cli.md +++ b/zokrates_book/src/reference/cli.md @@ -13,9 +13,10 @@ You can see an overview of the available subcommands by running ./zokrates compile -i /path/to/add.zok ``` -Compiles a `.zok` file into ZoKrates internal representation of arithmetic circuits. +Compiles a `.zok` source code file into ZoKrates internal representation of arithmetic circuits. -Creates a compiled `.zok` file at `./out.zok`. +Creates a compiled binary file at `./out`. +Unless the `--light` flag is set, a human readable `.ztf` file is generated, which displays the compilation output in ZoKrates Text Format. ## `compute-witness` @@ -23,7 +24,7 @@ Creates a compiled `.zok` file at `./out.zok`. ./zokrates compute-witness -a 1 2 3 ``` -Computes a witness for the compiled program found at `./out.zok` and arguments to the program. +Computes a witness for the compiled program found at `./out` and arguments to the program. A witness is a valid assignment of the variables, which include the results of the computation. Arguments to the program are passed as a space-separated list with the `-a` flag, or over `stdin`. @@ -35,7 +36,7 @@ Creates a witness file at `./witness` ./zokrates setup ``` -Generates a trusted setup for the compiled program found at `./out.zok`. +Generates a trusted setup for the compiled program found at `./out`. Creates a proving key and a verifying key at `./proving.key` and `./verifying.key`. These keys are derived from a source of randomness, commonly referred to as “toxic waste”. Anyone having access to the source of randomness can produce fake proofs that will be accepted by a verifier following the protocol. @@ -46,7 +47,7 @@ These keys are derived from a source of randomness, commonly referred to as “t ./zokrates export-verifier ``` -Using the verifying key at `./verifying.key`, generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program at `./out.zok`. +Using the verifying key at `./verifying.key`, generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program at `./out`. Creates a verifier contract at `./verifier.sol`. @@ -56,7 +57,7 @@ Creates a verifier contract at `./verifier.sol`. ./zokrates generate-proof ``` -Using the proving key at `./proving.key`, generates a proof for a computation of the compiled program `./out.zok` resulting in `./witness`. +Using the proving key at `./proving.key`, generates a proof for a computation of the compiled program `./out` resulting in `./witness`. Returns the proof, for example: diff --git a/zokrates_cli/src/bin.rs b/zokrates_cli/src/bin.rs index 9ea4b0b8..511a5ecb 100644 --- a/zokrates_cli/src/bin.rs +++ b/zokrates_cli/src/bin.rs @@ -57,7 +57,7 @@ fn cli() -> Result<(), String> { .author("Jacob Eberhardt, Thibaut Schaeffer, Stefan Deml") .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 '.zok' file for debugging and binary file") + .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") From aa5b3062867270d839775d03d9bbfaa55a7ab1c3 Mon Sep 17 00:00:00 2001 From: JacobEberhardt Date: Mon, 30 Sep 2019 12:01:45 +0200 Subject: [PATCH 26/27] remove compilation result --- out.code | 19 ------------------- .../src/reference/{Testing.md => testing.md} | 0 2 files changed, 19 deletions(-) delete mode 100644 out.code rename zokrates_book/src/reference/{Testing.md => testing.md} (100%) diff --git a/out.code b/out.code deleted file mode 100644 index 5d22bd6c..00000000 --- a/out.code +++ /dev/null @@ -1,19 +0,0 @@ -def main(_0, _1, _2, _3) -> (2): - (21 * _0) * (1 * _1) == 1 * _4 - (1 * _4) * (1 * _2) == 1 * _5 - (1 * _5) * (1 * _3) == 1 * _6 - (1 * _0) * (1 * _3) == 1 * _7 - (1 * _2) * (1 * _1) == 1 * _8 - # _11 = Rust::Div(1 * ~one, 1 * ~one + 1 * _6) - (1 * _11) * (1 * ~one + 1 * _6) == 1 * ~one - # _12 = Rust::Div(1 * _7 + 1 * _8, 1 * ~one + 1 * _6) - (1 * ~one + 1 * _6) * (1 * _12) == 1 * _7 + 1 * _8 - (1 * _2) * (1 * _3) == 1 * _13 - (42 * _0) * (1 * _1) == 1 * _14 - # _17 = Rust::Div(1 * ~one, 1 * ~one + (-1) * _6) - (1 * _17) * (1 * ~one + (-1) * _6) == 1 * ~one - # _18 = Rust::Div(1 * _13 + (-1) * _14, 1 * ~one + (-1) * _6) - (1 * ~one + (-1) * _6) * (1 * _18) == 1 * _13 + (-1) * _14 - (1 * ~one) * (1 * _12) == 1 * ~out_0 - (1 * ~one) * (1 * _18) == 1 * ~out_1 - return ~out_0, ~out_1 diff --git a/zokrates_book/src/reference/Testing.md b/zokrates_book/src/reference/testing.md similarity index 100% rename from zokrates_book/src/reference/Testing.md rename to zokrates_book/src/reference/testing.md From f305ded6464fd74dc7e77756587041d623e4706f Mon Sep 17 00:00:00 2001 From: Thibaut Date: Mon, 30 Sep 2019 13:49:54 +0200 Subject: [PATCH 27/27] allow newlines in inline defs --- zokrates_cli/examples/structs/add.code | 5 ++++- zokrates_cli/examples/structs/set_member.code | 17 ++++++++++++++++- zokrates_parser/src/zokrates.pest | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/zokrates_cli/examples/structs/add.code b/zokrates_cli/examples/structs/add.code index 5d1fd856..388ce158 100644 --- a/zokrates_cli/examples/structs/add.code +++ b/zokrates_cli/examples/structs/add.code @@ -10,4 +10,7 @@ def main(Point p, Point q) -> (Point): field dpxpyqxqy = d * p.x * p.y * q.x * q.y - return Point { x: (p.x * q.y + q.x * p.y) / (1 + dpxpyqxqy) , y: (q.x * q.y - a * p.x * p.y) / (1 - dpxpyqxqy) } + return Point { + x: (p.x * q.y + q.x * p.y) / (1 + dpxpyqxqy), + y: (q.x * q.y - a * p.x * p.y) / (1 - dpxpyqxqy) + } diff --git a/zokrates_cli/examples/structs/set_member.code b/zokrates_cli/examples/structs/set_member.code index 7cca5707..be326580 100644 --- a/zokrates_cli/examples/structs/set_member.code +++ b/zokrates_cli/examples/structs/set_member.code @@ -9,6 +9,21 @@ struct Foo { } def main() -> (Foo): - Foo[2] f = [Foo { a: Bar { c: [0, 0], d: false }, b: true}, Foo { a: Bar {c: [0, 0], d: false}, b: true}] + Foo[2] f = [ + Foo { + a: Bar { + c: [0, 0], + d: false + }, + b: true + }, + Foo { + a: Bar { + c: [0, 0], + d: false + }, + b: true + } + ] f[0].a.c = [42, 43] return f[0] diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 40bc09dc..7b62f2e6 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -79,8 +79,8 @@ inline_struct_expression = { identifier ~ "{" ~ NEWLINE* ~ inline_struct_member_ inline_struct_member_list = _{(inline_struct_member ~ ("," ~ NEWLINE* ~ inline_struct_member)*)? ~ ","? } inline_struct_member = { identifier ~ ":" ~ expression } -inline_array_expression = { "[" ~ inline_array_inner ~ "]" } -inline_array_inner = _{(spread_or_expression ~ ("," ~ spread_or_expression)*)?} +inline_array_expression = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]" } +inline_array_inner = _{(spread_or_expression ~ ("," ~ NEWLINE* ~ spread_or_expression)*)?} spread_or_expression = { spread | expression } range_or_expression = { range | expression } array_initializer_expression = { "[" ~ expression ~ ";" ~ constant ~ "]" }