From 16f2b4c3ac22440400c1252a42577c727fe3c403 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 6 Apr 2022 20:23:58 +0200 Subject: [PATCH] change syntax in cli/examples --- zokrates_cli/examples/add.zok | 12 ++- .../examples/alias/basic_aliasing.zok | 22 +++-- zokrates_cli/examples/alias/import_alias.zok | 22 +++-- .../examples/alias/struct_aliasing.zok | 21 ++-- zokrates_cli/examples/argument_reassign.zok | 12 ++- .../examples/array_generic_inference.zok | 19 ++-- zokrates_cli/examples/array_overload.zok | 15 +-- .../examples/arrays/array_argument.zok | 5 +- zokrates_cli/examples/arrays/array_loop.zok | 15 +-- .../examples/arrays/array_loop_update.zok | 15 +-- .../examples/arrays/boolean_array.zok | 20 ++-- .../examples/arrays/constant_array.zok | 7 +- zokrates_cli/examples/arrays/cube.zok | 21 ++-- zokrates_cli/examples/arrays/if_eq.zok | 5 +- .../examples/arrays/init_with_value.zok | 5 +- .../examples/arrays/large_equality.zok | 10 +- zokrates_cli/examples/arrays/lookup.zok | 5 +- zokrates_cli/examples/arrays/multi_init.zok | 10 +- .../examples/arrays/multidim_update.zok | 9 +- zokrates_cli/examples/arrays/repeat.zok | 9 +- zokrates_cli/examples/arrays/return_array.zok | 10 +- .../examples/arrays/return_variable_array.zok | 5 +- zokrates_cli/examples/arrays/slicefrom.zok | 21 ++-- zokrates_cli/examples/arrays/update.zok | 19 ++-- .../examples/arrays/update_with_call.zok | 18 ++-- zokrates_cli/examples/arrays/value.zok | 17 ++-- zokrates_cli/examples/arrays/wrap_select.zok | 14 +-- zokrates_cli/examples/assign_to_element.zok | 20 ++-- zokrates_cli/examples/book/abi.zok | 11 ++- zokrates_cli/examples/book/array.zok | 21 ++-- zokrates_cli/examples/book/assert.zok | 7 +- zokrates_cli/examples/book/bubblesort.zok | 32 +++--- zokrates_cli/examples/book/comments.zok | 7 +- .../examples/book/constant_definition.zok | 7 +- .../examples/book/constant_reference.zok | 9 +- zokrates_cli/examples/book/declaration.zok | 11 ++- .../book/explicit_generic_parameters.zok | 18 ++-- zokrates_cli/examples/book/factorize.zok | 7 +- zokrates_cli/examples/book/field_overflow.zok | 9 +- zokrates_cli/examples/book/for.zok | 17 ++-- zokrates_cli/examples/book/for_scope.zok | 13 +-- .../examples/book/function_declaration.zok | 10 +- zokrates_cli/examples/book/function_scope.zok | 14 +-- zokrates_cli/examples/book/generic_call.zok | 12 ++- .../book/generic_function_declaration.zok | 12 ++- zokrates_cli/examples/book/generics.zok | 18 ++-- .../examples/book/mpc_tutorial/circuit.zok | 5 +- zokrates_cli/examples/book/multi_def.zok | 18 ++-- zokrates_cli/examples/book/multi_return.zok | 5 +- zokrates_cli/examples/book/multidim_array.zok | 11 ++- .../examples/book/multiline_comments.zok | 5 +- zokrates_cli/examples/book/no_shadowing.zok | 11 ++- zokrates_cli/examples/book/not_equal.zok | 5 +- .../examples/book/numeric_inference.zok | 13 +-- .../examples/book/rng_tutorial/get_hash.zok | 9 +- .../examples/book/rng_tutorial/reveal_bit.zok | 27 +++--- .../book/sha256_tutorial/hashexample.zok | 9 +- .../sha256_tutorial/hashexample_updated.zok | 13 +-- zokrates_cli/examples/book/side_effects.zok | 18 ++-- zokrates_cli/examples/book/struct_assign.zok | 15 +-- zokrates_cli/examples/book/struct_init.zok | 12 ++- zokrates_cli/examples/book/structs.zok | 18 ++-- zokrates_cli/examples/book/tuples.zok | 10 +- zokrates_cli/examples/book/type_aliases.zok | 17 ++-- .../examples/book/type_annotations.zok | 17 ++-- zokrates_cli/examples/bool_and.zok | 13 +-- zokrates_cli/examples/bool_not.zok | 7 +- zokrates_cli/examples/bool_or.zok | 12 +-- zokrates_cli/examples/boolean_literal.zok | 5 +- zokrates_cli/examples/brackets.zok | 9 +- zokrates_cli/examples/call_in_const.zok | 18 ++-- zokrates_cli/examples/call_in_const_aux.zok | 16 +-- zokrates_cli/examples/call_in_constant.zok | 12 ++- zokrates_cli/examples/comments.zok | 13 +-- .../examples/comparison_operators.zok | 15 +-- .../compile_errors/ambiguous_generic_call.zok | 21 ++-- .../ambiguous_generic_call_too_strict.zok | 21 ++-- .../examples/compile_errors/assertion.zok | 7 +- .../assertion_unequal_arrays.zok | 7 +- .../const_complex_type_mismatch.zok | 13 +-- ...onstant_array_size_type_mismatch_field.zok | 7 +- .../constant_array_size_type_mismatch_u8.zok | 7 +- .../compile_errors/constant_assignment.zok | 9 +- .../constant_reduction_fail.zok | 9 +- .../compile_errors/constant_type_error.zok | 7 +- .../compile_errors/declare_non_identifier.zok | 7 +- .../examples/compile_errors/div_by_zero.zok | 7 +- .../compile_errors/double_negation.zok | 7 +- .../examples/compile_errors/double_power.zok | 7 +- .../compile_errors/embed_type_mismatch.zok | 9 +- .../compile_errors/generics/assertion.zok | 15 +-- .../generics/assign_size_mismatch.zok | 15 +-- .../generics/concrete_length_mismatch.zok | 7 +- .../generics/conflicting_call.zok | 20 ++-- .../generics/conflicting_constant.zok | 12 ++- .../generics/conflicting_functions.zok | 15 +-- .../generics/duplicate_struct_generic.zok | 7 +- .../generics/generic_in_main.zok | 5 +- .../generics/generic_inference.zok | 9 +- .../generics/generics_in_main.zok | 5 +- .../compile_errors/generics/incompatible.zok | 10 +- .../generics/infer_return_call_generics.zok | 10 +- .../compile_errors/generics/no_weak_eq.zok | 7 +- .../generics/non_conflicting_call.zok | 21 ++-- .../generics/numerical_struct_generic.zok | 7 +- .../generics/struct_generic_mismatch.zok | 7 +- .../generics/undeclared_struct_generic.zok | 7 +- .../generics/unused_struct_generic.zok | 5 +- .../compile_errors/keyword_as_identifier.zok | 6 +- .../compile_errors/loop_too_large.zok | 8 +- .../examples/compile_errors/no_return.zok | 7 +- .../compile_errors/no_struct_equivalence.zok | 5 +- .../examples/compile_errors/out_of_bounds.zok | 9 +- .../compile_errors/out_of_bounds_read.zok | 14 +-- .../compile_errors/out_of_bounds_write.zok | 14 +-- .../compile_errors/out_of_for_scope.zok | 8 +- .../examples/compile_errors/shadowing.zok | 14 +-- .../struct_member_type_mismatch_field.zok | 16 +-- .../struct_member_type_mismatch_u8.zok | 16 +-- .../compile_errors/ternary_precedence.zok | 7 +- .../compile_errors/too_many_arguments.zok | 10 +- .../compile_errors/too_many_generics.zok | 10 +- .../compile_errors/too_many_return.zok | 5 +- .../examples/compile_errors/two_return.zok | 7 +- .../examples/compile_errors/unassigned.zok | 9 +- .../compile_errors/unpack_value_too_large.zok | 9 +- .../compile_errors/variable_constant_lt.zok | 7 +- .../compile_errors/variable_shift.zok | 6 +- .../compile_errors/wrong_member_type.zok | 11 ++- .../compile_errors/wrongsyntax-error.zok | 16 --- .../examples/complex_call_in_constant.zok | 24 ++--- zokrates_cli/examples/conditions.zok | 26 ++--- zokrates_cli/examples/constant_in_sig.zok | 15 +-- .../constant_index_on_spread_inline.zok | 5 +- zokrates_cli/examples/decimal_literal.zok | 9 +- .../examples/empty_spread_propagation.zok | 23 ++--- zokrates_cli/examples/explicit_generic.zok | 12 ++- zokrates_cli/examples/factorization.zok | 9 +- zokrates_cli/examples/flatten.zok | 12 ++- zokrates_cli/examples/for.zok | 21 ++-- .../examples/functions/expressions.zok | 19 ++-- zokrates_cli/examples/functions/functions.zok | 13 ++- .../examples/functions/lt_comparison.zok | 32 +++--- .../examples/functions/multi_functions.zok | 26 ++--- .../examples/functions/multi_shadowing.zok | 21 ++-- .../examples/functions/no_args_multiple.zok | 19 ++-- zokrates_cli/examples/functions/shadowing.zok | 13 ++- .../examples/functions_equivalent.zok | 7 +- zokrates_cli/examples/if_eq.zok | 7 -- zokrates_cli/examples/imports/bar.zok | 9 +- zokrates_cli/examples/imports/baz.zok | 7 +- zokrates_cli/examples/imports/foo.zok | 17 ++-- .../examples/imports/import_constants.zok | 11 ++- .../examples/imports/import_functions.zok | 11 ++- .../examples/imports/import_multiple.zok | 9 +- .../examples/imports/import_structs.zok | 15 +-- .../examples/imports/import_with_alias.zok | 15 +-- .../examples/imports/inliner_state.zok | 14 +-- .../examples/imports/inliner_state_aux.zok | 7 +- zokrates_cli/examples/left_side_call.zok | 13 ++- .../merkleTree/pedersenPathProof3.zok | 22 ++--- .../examples/merkleTree/sha256PathProof3.zok | 27 +++--- zokrates_cli/examples/multi_return.zok | 14 +-- zokrates_cli/examples/multi_return_sum.zok | 13 ++- zokrates_cli/examples/multiple_witnesses.zok | 8 +- zokrates_cli/examples/n_choose_k.zok | 24 ++--- zokrates_cli/examples/no_flatten.zok | 12 ++- zokrates_cli/examples/pow.zok | 33 ++++--- zokrates_cli/examples/pragma.zok | 5 +- zokrates_cli/examples/propagate.zok | 19 ++-- zokrates_cli/examples/propagate_call.zok | 14 +-- zokrates_cli/examples/reassignment.zok | 16 +-- zokrates_cli/examples/reduceable_exponent.zok | 7 +- .../runtime_errors/div_zero_field.zok | 7 +- .../examples/runtime_errors/div_zero_uint.zok | 7 +- .../runtime_errors/lt_overflow_max_plus_1.zok | 11 ++- .../lt_overflow_max_plus_1_sym.zok | 11 ++- zokrates_cli/examples/simple_add.zok | 5 +- zokrates_cli/examples/simple_conditional.zok | 8 ++ zokrates_cli/examples/simple_ifelse.zok | 7 -- zokrates_cli/examples/simple_mul.zok | 6 +- .../examples/spaces_tabs_comments.zok | 18 ++-- .../examples/struct_generic_inference.zok | 20 ++-- zokrates_cli/examples/structs/add.zok | 18 ++-- .../examples/structs/constant_in_member.zok | 13 +-- zokrates_cli/examples/structs/generic.zok | 15 +-- .../examples/structs/nested_access.zok | 11 ++- zokrates_cli/examples/structs/set_member.zok | 17 ++-- zokrates_cli/examples/sub.zok | 13 +-- .../examples/sudoku/prime_sudoku_checker.zok | 74 +++++++------- .../examples/sudoku/sudoku_checker.zok | 97 ++++++++++--------- zokrates_cli/examples/synonyms.zok | 15 +-- zokrates_cli/examples/taxation.zok | 14 +-- zokrates_cli/examples/ternary_eq.zok | 9 ++ zokrates_cli/examples/test1.zok | 25 ++--- zokrates_cli/examples/test_lt_max_value.zok | 11 ++- zokrates_cli/examples/tuples/add.zok | 11 ++- .../examples/tuples/constant_in_member.zok | 9 +- zokrates_cli/examples/tuples/generic.zok | 15 +-- .../examples/tuples/nested_access.zok | 7 +- zokrates_cli/examples/tuples/set_member.zok | 18 ++-- zokrates_cli/examples/waldo.zok | 18 ++-- zokrates_cli/examples/wavelets.zok | 37 +++---- 203 files changed, 1499 insertions(+), 1222 deletions(-) delete mode 100644 zokrates_cli/examples/compile_errors/wrongsyntax-error.zok delete mode 100644 zokrates_cli/examples/if_eq.zok create mode 100644 zokrates_cli/examples/simple_conditional.zok delete mode 100644 zokrates_cli/examples/simple_ifelse.zok create mode 100644 zokrates_cli/examples/ternary_eq.zok diff --git a/zokrates_cli/examples/add.zok b/zokrates_cli/examples/add.zok index c7d2b4d6..85585b8a 100644 --- a/zokrates_cli/examples/add.zok +++ b/zokrates_cli/examples/add.zok @@ -1,6 +1,8 @@ // only using add, no need to flatten -def main(field a) -> field: - field b = a + 5 - field c = a + b + a + 4 - field d = a + c + a + b - return b + c + d +def main(field a) -> field { + field b = a + 5; + field c = a + b + a + 4; + field d = a + c + a + b; + return b + c + d; +} + diff --git a/zokrates_cli/examples/alias/basic_aliasing.zok b/zokrates_cli/examples/alias/basic_aliasing.zok index c12362e5..f00533b3 100644 --- a/zokrates_cli/examples/alias/basic_aliasing.zok +++ b/zokrates_cli/examples/alias/basic_aliasing.zok @@ -1,13 +1,15 @@ -type byte = u8 -type uint32 = u32 -type UInt32Array = uint32[N] +type byte = u8; +type uint32 = u32; +type UInt32Array = uint32[N]; -type matrix = field[R][C] +type matrix = field[R][C]; -def fill(field v) -> matrix: - return [[v; C]; R] +def fill(field v) -> matrix { + return [[v; C]; R]; +} -def main(uint32 a, uint32 b) -> (UInt32Array<2>, matrix<2, 4>): - UInt32Array<2> res = [a, b] - matrix<2, 4> m = fill(1) - return res, m \ No newline at end of file +def main(uint32 a, uint32 b) -> (UInt32Array<2>, matrix<2, 4>) { + UInt32Array<2> res = [a, b]; + matrix<2, 4> m = fill(1); + return res, m; +} diff --git a/zokrates_cli/examples/alias/import_alias.zok b/zokrates_cli/examples/alias/import_alias.zok index 6e7e54e4..8ce717ff 100644 --- a/zokrates_cli/examples/alias/import_alias.zok +++ b/zokrates_cli/examples/alias/import_alias.zok @@ -1,14 +1,16 @@ -from "./basic_aliasing.zok" import matrix -from "./struct_aliasing.zok" import Buzz +from "./basic_aliasing.zok" import matrix; +from "./struct_aliasing.zok" import Buzz; -const u32 R = 2 -const u32 C = 4 +const u32 R = 2; +const u32 C = 4; -type matrix_2x4 = matrix +type matrix_2x4 = matrix; -def buzz() -> Buzz: - return Buzz { a: [0; N], b: [0; N] } +def buzz() -> Buzz { + return Buzz { a: [0; N], b: [0; N] }; +} -def main(matrix_2x4 m) -> (Buzz<2>, matrix_2x4): - Buzz<2> b = buzz::<2>() - return b, m \ No newline at end of file +def main(matrix_2x4 m) -> (Buzz<2>, matrix_2x4) { + Buzz<2> b = buzz::<2>(); + return b, m; +} diff --git a/zokrates_cli/examples/alias/struct_aliasing.zok b/zokrates_cli/examples/alias/struct_aliasing.zok index 932587b6..bfa7371f 100644 --- a/zokrates_cli/examples/alias/struct_aliasing.zok +++ b/zokrates_cli/examples/alias/struct_aliasing.zok @@ -1,15 +1,16 @@ -type FieldArray = field[N] +type FieldArray = field[N]; struct Foo { - FieldArray a - FieldArray b + FieldArray a; + FieldArray b; } -type Bar = Foo<2, 2> -type Buzz = Foo +type Bar = Foo<2, 2>; +type Buzz = Foo; -def main(Bar a) -> Buzz<2>: - Bar bar = Bar { a: [1, 2], b: [1, 2] } - Buzz<2> buzz = Buzz { a: [1, 2], b: [1, 2] } - assert(bar == buzz) - return buzz \ No newline at end of file +def main(Bar a) -> Buzz<2> { + Bar bar = Bar { a: [1, 2], b: [1, 2] }; + Buzz<2> buzz = Buzz { a: [1, 2], b: [1, 2] }; + assert(bar == buzz); + return buzz; +} diff --git a/zokrates_cli/examples/argument_reassign.zok b/zokrates_cli/examples/argument_reassign.zok index 209d0daa..ef553589 100644 --- a/zokrates_cli/examples/argument_reassign.zok +++ b/zokrates_cli/examples/argument_reassign.zok @@ -1,6 +1,8 @@ -def sub(field a) -> field: - a = a + 3 - return a +def sub(field a) -> field { + a = a + 3; + return a; +} -def main() -> field: - return sub(4) \ No newline at end of file +def main() -> field { + return sub(4); +} diff --git a/zokrates_cli/examples/array_generic_inference.zok b/zokrates_cli/examples/array_generic_inference.zok index 40da76a0..1d0af717 100644 --- a/zokrates_cli/examples/array_generic_inference.zok +++ b/zokrates_cli/examples/array_generic_inference.zok @@ -1,11 +1,12 @@ -def myFct(u64[N] ignored) -> u64[N2]: - assert(2*N == N2) - return [0; N2] +def myFct(u64[N] ignored) -> u64[N2] { + assert(2*N == N2); + return [0; N2]; +} -const u32 N = 3 +const u32 N = 3; +const u32 N2 = 2 * N; -const u32 N2 = 2*N - -def main(u64[N] arg) -> bool: - u64[N2] someVariable = myFct(arg) - return true \ No newline at end of file +def main(u64[N] arg) -> bool { + u64[N2] someVariable = myFct(arg); + return true; +} diff --git a/zokrates_cli/examples/array_overload.zok b/zokrates_cli/examples/array_overload.zok index 7f380548..f92e0c47 100644 --- a/zokrates_cli/examples/array_overload.zok +++ b/zokrates_cli/examples/array_overload.zok @@ -1,8 +1,11 @@ -def foo(field[2] a) -> bool: - return true +def foo(field[2] a) -> bool { + return true; +} -def foo(field[1] a) -> bool: - return true +def foo(field[1] a) -> bool { + return true; +} -def main() -> bool: - return foo([1]) \ No newline at end of file +def main() -> bool { + return foo([1]); +} diff --git a/zokrates_cli/examples/arrays/array_argument.zok b/zokrates_cli/examples/arrays/array_argument.zok index 539df3f6..ff5d845f 100644 --- a/zokrates_cli/examples/arrays/array_argument.zok +++ b/zokrates_cli/examples/arrays/array_argument.zok @@ -1,2 +1,3 @@ -def main(field[3] a) -> field: - return a[0] + a[1] + a[2] \ No newline at end of file +def main(field[3] a) -> field { + return a[0] + a[1] + a[2]; +} diff --git a/zokrates_cli/examples/arrays/array_loop.zok b/zokrates_cli/examples/arrays/array_loop.zok index 73e4fb45..d0e917a2 100644 --- a/zokrates_cli/examples/arrays/array_loop.zok +++ b/zokrates_cli/examples/arrays/array_loop.zok @@ -1,7 +1,8 @@ -def main() -> u32: - u32[3] a = [1, 2, 3] - u32 c = 0 - for u32 i in 0..3 do - c = c + a[i] - endfor - return c \ No newline at end of file +def main() -> u32 { + u32[3] a = [1, 2, 3]; + u32 c = 0; + for u32 i in 0..3 { + c = c + a[i]; + } + return c; +} diff --git a/zokrates_cli/examples/arrays/array_loop_update.zok b/zokrates_cli/examples/arrays/array_loop_update.zok index d16cc9da..764050fa 100644 --- a/zokrates_cli/examples/arrays/array_loop_update.zok +++ b/zokrates_cli/examples/arrays/array_loop_update.zok @@ -1,7 +1,8 @@ -def main() -> (u32[3]): - u32[3] a = [1, 2, 3] - u32[3] c = [4, 5, 6] - for u32 i in 0..3 do - c[i] = c[i] + a[i] - endfor - return c \ No newline at end of file +def main() -> (u32[3]) { + u32[3] a = [1, 2, 3]; + u32[3] c = [4, 5, 6]; + for u32 i in 0..3 { + c[i] = c[i] + a[i]; + } + return c; +} diff --git a/zokrates_cli/examples/arrays/boolean_array.zok b/zokrates_cli/examples/arrays/boolean_array.zok index 89576f4d..6a0870de 100644 --- a/zokrates_cli/examples/arrays/boolean_array.zok +++ b/zokrates_cli/examples/arrays/boolean_array.zok @@ -1,9 +1,11 @@ -def main(bool[3] a) -> (field[3]): - bool[3] c = [true, true || false, true] - a[1] = true || a[2] - a[2] = a[0] - field[3] result = [0; 3] - for u32 i in 0..3 do - result[i] = if a[i] then 33 else 0 fi - endfor - return result +def main(bool[3] a) -> (field[3]) { + bool[3] c = [true, true || false, true]; + a[1] = true || a[2]; + a[2] = a[0]; + field[3] result = [0; 3]; + for u32 i in 0..3 { + result[i] = a[i] ? 33 : 0; + } + return result; +} + diff --git a/zokrates_cli/examples/arrays/constant_array.zok b/zokrates_cli/examples/arrays/constant_array.zok index 96e5848e..571b1a3a 100644 --- a/zokrates_cli/examples/arrays/constant_array.zok +++ b/zokrates_cli/examples/arrays/constant_array.zok @@ -1,3 +1,4 @@ -def main() -> field: - field[4] a = [1, 2, 42, 55] - return a[2] \ No newline at end of file +def main() -> field { + field[4] a = [1, 2, 42, 55]; + return a[2]; +} diff --git a/zokrates_cli/examples/arrays/cube.zok b/zokrates_cli/examples/arrays/cube.zok index eca27ec6..cdeababb 100644 --- a/zokrates_cli/examples/arrays/cube.zok +++ b/zokrates_cli/examples/arrays/cube.zok @@ -1,12 +1,13 @@ -def main(field[2][2][2] cube) -> field: - field res = 0 +def main(field[2][2][2] cube) -> field { + field res = 0; - for u32 i in 0..2 do - for u32 j in 0..2 do - for u32 k in 0..2 do - res = res + cube[i][j][k] - endfor - endfor - endfor + for u32 i in 0..2 { + for u32 j in 0..2 { + for u32 k in 0..2 { + res = res + cube[i][j][k]; + } + } + } - return res \ No newline at end of file + return res; +} diff --git a/zokrates_cli/examples/arrays/if_eq.zok b/zokrates_cli/examples/arrays/if_eq.zok index 2fc1aca5..13a080b8 100644 --- a/zokrates_cli/examples/arrays/if_eq.zok +++ b/zokrates_cli/examples/arrays/if_eq.zok @@ -1,2 +1,3 @@ -def main(field[2] a, field[2] b, field condition) -> field[2]: - return if condition == 1 then a else b fi \ No newline at end of file +def main(field[2] a, field[2] b, field condition) -> field[2] { + return condition == 1 ? a : b; +} diff --git a/zokrates_cli/examples/arrays/init_with_value.zok b/zokrates_cli/examples/arrays/init_with_value.zok index 07d9fbf9..0c5fcc6a 100644 --- a/zokrates_cli/examples/arrays/init_with_value.zok +++ b/zokrates_cli/examples/arrays/init_with_value.zok @@ -1,2 +1,3 @@ -def main(field value) -> (field[3]): - return [value, value, value] \ No newline at end of file +def main(field value) -> (field[3]) { + return [value, value, value]; +} diff --git a/zokrates_cli/examples/arrays/large_equality.zok b/zokrates_cli/examples/arrays/large_equality.zok index 93c8d834..b4c45b48 100644 --- a/zokrates_cli/examples/arrays/large_equality.zok +++ b/zokrates_cli/examples/arrays/large_equality.zok @@ -1,4 +1,6 @@ -const u32 SIZE = 100 -def main(private field[SIZE][SIZE] a): - assert(a == [[0; SIZE]; SIZE]) - return \ No newline at end of file +const u32 SIZE = 100; + +def main(private field[SIZE][SIZE] a) { + assert(a == [[0; SIZE]; SIZE]); + return; +} diff --git a/zokrates_cli/examples/arrays/lookup.zok b/zokrates_cli/examples/arrays/lookup.zok index 6b25d439..50f61308 100644 --- a/zokrates_cli/examples/arrays/lookup.zok +++ b/zokrates_cli/examples/arrays/lookup.zok @@ -1,2 +1,3 @@ -def main(u32 index, field[5] array) -> field: - return array[index] \ No newline at end of file +def main(u32 index, field[5] array) -> field { + return array[index]; +} diff --git a/zokrates_cli/examples/arrays/multi_init.zok b/zokrates_cli/examples/arrays/multi_init.zok index b6ec0201..ed45a8e5 100644 --- a/zokrates_cli/examples/arrays/multi_init.zok +++ b/zokrates_cli/examples/arrays/multi_init.zok @@ -1,5 +1,7 @@ -def identity(field[N][N] t) -> field[N][N]: - return t +def identity(field[N][N] t) -> field[N][N] { + return t; +} -def main() -> field[1][1]: - return identity([[0]; 1]) \ No newline at end of file +def main() -> field[1][1] { + return identity([[0]; 1]); +} diff --git a/zokrates_cli/examples/arrays/multidim_update.zok b/zokrates_cli/examples/arrays/multidim_update.zok index 358c049a..8c86dd1a 100644 --- a/zokrates_cli/examples/arrays/multidim_update.zok +++ b/zokrates_cli/examples/arrays/multidim_update.zok @@ -1,4 +1,5 @@ -def main(field[10][10][10] a, u32 i, u32 j, u32 k) -> (field[3]): - a[i][j][k] = 42 - field[3][3] b = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] - return b[0] \ No newline at end of file +def main(field[10][10][10] a, u32 i, u32 j, u32 k) -> (field[3]) { + a[i][j][k] = 42; + field[3][3] b = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]; + return b[0]; +} diff --git a/zokrates_cli/examples/arrays/repeat.zok b/zokrates_cli/examples/arrays/repeat.zok index 07ca853e..a96c219f 100644 --- a/zokrates_cli/examples/arrays/repeat.zok +++ b/zokrates_cli/examples/arrays/repeat.zok @@ -1,4 +1,5 @@ -def main(field a) -> field[4]: - u32 SIZE = 4 - field[SIZE] res = [a; SIZE] - return res \ No newline at end of file +def main(field a) -> field[4] { + u32 SIZE = 4; + field[SIZE] res = [a; SIZE]; + return res; +} diff --git a/zokrates_cli/examples/arrays/return_array.zok b/zokrates_cli/examples/arrays/return_array.zok index a5a63499..df987536 100644 --- a/zokrates_cli/examples/arrays/return_array.zok +++ b/zokrates_cli/examples/arrays/return_array.zok @@ -1,5 +1,7 @@ -def foo() -> field[2]: - return [1, 2] +def foo() -> field[2] { + return [1, 2]; +} -def main() -> field[2]: - return foo() \ No newline at end of file +def main() -> field[2] { + return foo(); +} diff --git a/zokrates_cli/examples/arrays/return_variable_array.zok b/zokrates_cli/examples/arrays/return_variable_array.zok index 4532c73f..cc900420 100644 --- a/zokrates_cli/examples/arrays/return_variable_array.zok +++ b/zokrates_cli/examples/arrays/return_variable_array.zok @@ -1,2 +1,3 @@ -def main(field[2] a, field[2] b) -> field[2]: - return [a[0] + b[0], a[1] + b[1]] \ No newline at end of file +def main(field[2] a, field[2] b) -> field[2] { + return [a[0] + b[0], a[1] + b[1]]; +} diff --git a/zokrates_cli/examples/arrays/slicefrom.zok b/zokrates_cli/examples/arrays/slicefrom.zok index 225d4a6f..913eaca5 100644 --- a/zokrates_cli/examples/arrays/slicefrom.zok +++ b/zokrates_cli/examples/arrays/slicefrom.zok @@ -1,11 +1,12 @@ -def slice32from(u32 offset, field[2048] input) -> (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] - for u32 i in 0..32 do - result[i] = input[offset + i] - endfor - return result +def slice32from(u32 offset, field[2048] input) -> (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]; + for u32 i in 0..32 { + result[i] = input[offset + i]; + } + return result; +} -def main() ->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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + return slice32from(67, input); +} diff --git a/zokrates_cli/examples/arrays/update.zok b/zokrates_cli/examples/arrays/update.zok index 58ddc836..4f6e616b 100644 --- a/zokrates_cli/examples/arrays/update.zok +++ b/zokrates_cli/examples/arrays/update.zok @@ -1,9 +1,12 @@ -def foo(field[3] a) -> field: - a[1] = 2 - return a[1] +def foo(field[3] a) -> field { + a[1] = 2; + return a[1]; +} + +def main() -> (field, field) { + field[3] a = [0, 0, 0]; + field res = foo(a); + assert(a[1] == 0); + return res, a[1]; +} -def main() -> (field, field): - field[3] a = [0, 0, 0] - field res = foo(a) - assert(a[1] == 0) - return res, a[1] diff --git a/zokrates_cli/examples/arrays/update_with_call.zok b/zokrates_cli/examples/arrays/update_with_call.zok index d27f3b0d..bf35342e 100644 --- a/zokrates_cli/examples/arrays/update_with_call.zok +++ b/zokrates_cli/examples/arrays/update_with_call.zok @@ -1,9 +1,11 @@ -def foo(field a) -> field: - return 2 +def foo(field a) -> field { + return 2; +} -def main(field a) -> (field, field): - field[2] result = [0, 0] - field r = foo(a) - result[1] = r - assert(result[1] == r) - return result[1], r \ No newline at end of file +def main(field a) -> (field, field) { + field[2] result = [0, 0]; + field r = foo(a); + result[1] = r; + assert(result[1] == r); + return result[1], r; +} diff --git a/zokrates_cli/examples/arrays/value.zok b/zokrates_cli/examples/arrays/value.zok index 41d2f3e4..ef19f129 100644 --- a/zokrates_cli/examples/arrays/value.zok +++ b/zokrates_cli/examples/arrays/value.zok @@ -1,10 +1,11 @@ -def main(): - field[3] a = [1, 2, 3] - bool[3] b = [true, true, false] - field[3][2] c = [[1, 2], [3, 4], [5, 6]] +def main() { + field[3] a = [1, 2, 3]; + bool[3] b = [true, true, false]; + field[3][2] c = [[1, 2], [3, 4], [5, 6]]; - field[3] aa = [...a] - bool[3] bb = [...b] - field[3][2] cc = [...c] + field[3] aa = [...a]; + bool[3] bb = [...b]; + field[3][2] cc = [...c]; - return \ No newline at end of file + return; +} diff --git a/zokrates_cli/examples/arrays/wrap_select.zok b/zokrates_cli/examples/arrays/wrap_select.zok index 03c8b545..da6c34f8 100644 --- a/zokrates_cli/examples/arrays/wrap_select.zok +++ b/zokrates_cli/examples/arrays/wrap_select.zok @@ -1,7 +1,9 @@ -def get(field[32] array, u32 index) -> field: - return array[index] +def get(field[32] array, u32 index) -> field { + return array[index]; +} -def main() -> field: - field[32] array = [0, 0, 0, 0, 0, 0, 7, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - field r = get(array, 7) - return r \ No newline at end of file +def main() -> field { + field[32] array = [0, 0, 0, 0, 0, 0, 7, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + field r = get(array, 7); + return r; +} diff --git a/zokrates_cli/examples/assign_to_element.zok b/zokrates_cli/examples/assign_to_element.zok index 054c3877..70adca98 100644 --- a/zokrates_cli/examples/assign_to_element.zok +++ b/zokrates_cli/examples/assign_to_element.zok @@ -1,11 +1,13 @@ -def foo() -> u32: - return 0 +def foo() -> u32 { + return 0; +} -def bar() -> (u32, u32): - return 0, 0 +def bar() -> (u32, u32) { + return 0, 0; +} - -def main(u32[1] a, u32 b): - a[0] = foo() - a[0], b = bar() - return \ No newline at end of file +def main(u32[1] a, u32 b) { + a[0] = foo(); + a[0], b = bar(); + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/abi.zok b/zokrates_cli/examples/book/abi.zok index 8592fce6..c9c794fa 100644 --- a/zokrates_cli/examples/book/abi.zok +++ b/zokrates_cli/examples/book/abi.zok @@ -1,11 +1,12 @@ struct Bar { - field a + field a; } struct Foo { - u8 a - Bar b + u8 a; + Bar b; } -def main(Foo foo, bool[2] bar, field num) -> field: - return 42 \ No newline at end of file +def main(Foo foo, bool[2] bar, field num) -> field { + return 42; +} diff --git a/zokrates_cli/examples/book/array.zok b/zokrates_cli/examples/book/array.zok index 1e8bcfce..6e921353 100644 --- a/zokrates_cli/examples/book/array.zok +++ b/zokrates_cli/examples/book/array.zok @@ -1,10 +1,11 @@ -def main() -> field: - 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 - u32 SIZE = 3 - field[SIZE] f = [1, 2, 3] // initialize a field array with a size that's a compile-time constant - return a[0] + b[1] + c[2] +def main() -> field { + 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 + u32 SIZE = 3; + field[SIZE] f = [1, 2, 3]; // initialize a field array with a size that's a compile-time constant + return a[0] + b[1] + c[2]; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/assert.zok b/zokrates_cli/examples/book/assert.zok index ccef8009..c7bd7830 100644 --- a/zokrates_cli/examples/book/assert.zok +++ b/zokrates_cli/examples/book/assert.zok @@ -1,3 +1,4 @@ -def main() -> (): - assert(1f + 1f == 2f) - return \ No newline at end of file +def main() -> () { + assert(1f + 1f == 2f); + return; +} diff --git a/zokrates_cli/examples/book/bubblesort.zok b/zokrates_cli/examples/book/bubblesort.zok index 29c037ca..a3892d4e 100644 --- a/zokrates_cli/examples/book/bubblesort.zok +++ b/zokrates_cli/examples/book/bubblesort.zok @@ -1,16 +1,20 @@ -def swap(u32 a, u32 b, bool c) -> (u32, u32): - u32 a_prime = if c then b else a fi - b = if c then a else b fi - return a_prime, b +def swap(u32 a, u32 b, bool c) -> (u32, u32) { + u32 a_prime = c ? b : a; + b = c ? a : b; + return a_prime, b; +} -def bubblesort(u32[N] a) -> u32[N]: - for u32 i in 0..(N-1) do - for u32 j in 0..(N-1-i) do - bool need_swap = a[j + 1] < a[j] - a[j], a[j + 1] = swap(a[j], a[j + 1], need_swap) - endfor - endfor - return a +def bubblesort(u32[N] a) -> u32[N] { + for u32 i in 0..(N-1) { + for u32 j in 0..(N-1-i) { + bool need_swap = a[j + 1] < a[j]; + a[j], a[j + 1] = swap(a[j], a[j + 1], need_swap); + } + } + return a; +} + +def main(u32[10] a) -> u32[10] { + return bubblesort(a); +} -def main(u32[10] a) -> u32[10]: - return bubblesort(a) diff --git a/zokrates_cli/examples/book/comments.zok b/zokrates_cli/examples/book/comments.zok index a8c06de1..125ab98c 100644 --- a/zokrates_cli/examples/book/comments.zok +++ b/zokrates_cli/examples/book/comments.zok @@ -1,4 +1,5 @@ -def main() -> field: - field a = 42 // this is an end of line comment +def main() -> field { + field a = 42; // this is an end of line comment // this is a full line comment - return a \ No newline at end of file + return a; +} diff --git a/zokrates_cli/examples/book/constant_definition.zok b/zokrates_cli/examples/book/constant_definition.zok index 10b31ec7..79cb1cc7 100644 --- a/zokrates_cli/examples/book/constant_definition.zok +++ b/zokrates_cli/examples/book/constant_definition.zok @@ -1,4 +1,5 @@ -const field PRIME = 31 +const field PRIME = 31; -def main() -> field: - return PRIME \ No newline at end of file +def main() -> field { + return PRIME; +} diff --git a/zokrates_cli/examples/book/constant_reference.zok b/zokrates_cli/examples/book/constant_reference.zok index b6850f89..a61cdca7 100644 --- a/zokrates_cli/examples/book/constant_reference.zok +++ b/zokrates_cli/examples/book/constant_reference.zok @@ -1,5 +1,6 @@ -const field ONE = 1 -const field TWO = ONE + ONE +const field ONE = 1; +const field TWO = ONE + ONE; -def main() -> field: - return TWO \ No newline at end of file +def main() -> field { + return TWO; +} diff --git a/zokrates_cli/examples/book/declaration.zok b/zokrates_cli/examples/book/declaration.zok index 4f3fd29f..f4f8c7d7 100644 --- a/zokrates_cli/examples/book/declaration.zok +++ b/zokrates_cli/examples/book/declaration.zok @@ -1,6 +1,7 @@ -def main(): - // declare and define `my_variable` - field my_variable = 2 +def main() { + // declare and define `my_variable` + field my_variable = 2; // redefine `my_variable` - my_variable = 3 - return \ No newline at end of file + my_variable = 3; + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/explicit_generic_parameters.zok b/zokrates_cli/examples/book/explicit_generic_parameters.zok index 9b439d99..d68c9084 100644 --- a/zokrates_cli/examples/book/explicit_generic_parameters.zok +++ b/zokrates_cli/examples/book/explicit_generic_parameters.zok @@ -1,11 +1,13 @@ // a function to sum the N first powers of a field element -def sum_powers(field a) -> field: - field res = 0 - for u32 i in 0..N do - res = res + a ** i - endfor - return res +def sum_powers(field a) -> field { + field res = 0; + for u32 i in 0..N { + res = res + a ** i; + } + return res; +} -def main(field a) -> field: +def main(field a) -> field { // call `sum_powers` providing the explicit generic parameter `N := 5` - return sum_powers::<5>(a) \ No newline at end of file + return sum_powers::<5>(a); +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/factorize.zok b/zokrates_cli/examples/book/factorize.zok index 32defecf..045cb138 100644 --- a/zokrates_cli/examples/book/factorize.zok +++ b/zokrates_cli/examples/book/factorize.zok @@ -1,3 +1,4 @@ -def main(private field a, field b): - assert(a * a == b) - return \ No newline at end of file +def main(private field a, field b) { + assert(a * a == b); + return; +} diff --git a/zokrates_cli/examples/book/field_overflow.zok b/zokrates_cli/examples/book/field_overflow.zok index 0ab907e8..9f5a19b0 100644 --- a/zokrates_cli/examples/book/field_overflow.zok +++ b/zokrates_cli/examples/book/field_overflow.zok @@ -1,4 +1,5 @@ -def main(): - field pMinusOne = 21888242871839275222246405745257275088548364400416034343698204186575808495616 - assert(0 - 1 == pMinusOne) - return \ No newline at end of file +def main() { + field pMinusOne = 21888242871839275222246405745257275088548364400416034343698204186575808495616; + assert(0 - 1 == pMinusOne); + return; +} diff --git a/zokrates_cli/examples/book/for.zok b/zokrates_cli/examples/book/for.zok index b5d8f502..994819f9 100644 --- a/zokrates_cli/examples/book/for.zok +++ b/zokrates_cli/examples/book/for.zok @@ -1,8 +1,9 @@ -def main() -> u32: - u32 res = 0 - for u32 i in 0..4 do - for u32 j in i..5 do - res = res + i - endfor - endfor - return res \ No newline at end of file +def main() -> u32 { + u32 res = 0; + for u32 i in 0..4 { + for u32 j in i..5 { + res = res + i; + } + } + return res; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/for_scope.zok b/zokrates_cli/examples/book/for_scope.zok index 2b92dd1f..92e14bba 100644 --- a/zokrates_cli/examples/book/for_scope.zok +++ b/zokrates_cli/examples/book/for_scope.zok @@ -1,7 +1,8 @@ -def main() -> u32: - u32 a = 0 - for u32 i in 0..5 do - a = a + i - endfor +def main() -> u32 { + u32 a = 0; + for u32 i in 0..5 { + a = a + i; + } // return i <- not allowed - return a \ No newline at end of file + return a; +} diff --git a/zokrates_cli/examples/book/function_declaration.zok b/zokrates_cli/examples/book/function_declaration.zok index 2e0f1bb4..7f566cb6 100644 --- a/zokrates_cli/examples/book/function_declaration.zok +++ b/zokrates_cli/examples/book/function_declaration.zok @@ -1,5 +1,7 @@ -def foo(field a, field b) -> field: - return a + b +def foo(field a, field b) -> field { + return a + b; +} -def main() -> field: - return foo(1, 2) \ No newline at end of file +def main() -> field { + return foo(1, 2); +} diff --git a/zokrates_cli/examples/book/function_scope.zok b/zokrates_cli/examples/book/function_scope.zok index d28717ee..0777e37a 100644 --- a/zokrates_cli/examples/book/function_scope.zok +++ b/zokrates_cli/examples/book/function_scope.zok @@ -1,7 +1,9 @@ -def foo() -> field: - // return myGlobal <- not allowed - return 42 +def foo() -> field { + // return myGlobal <- not allowed + return 42; +} -def main() -> field: - field myGlobal = 42 - return foo() \ No newline at end of file +def main() -> field { + field myGlobal = 42; + return foo(); +} diff --git a/zokrates_cli/examples/book/generic_call.zok b/zokrates_cli/examples/book/generic_call.zok index a26a9f81..4d22d8e7 100644 --- a/zokrates_cli/examples/book/generic_call.zok +++ b/zokrates_cli/examples/book/generic_call.zok @@ -1,7 +1,9 @@ -def foo() -> field[P]: - return [42; P] +def foo() -> field[P] { + return [42; P]; +} -def main() -> field[2]: +def main() -> field[2] { // `P` is inferred from the declaration of `res`, while `N` is provided explicitly - field[2] res = foo::<3, _>() - return res \ No newline at end of file + field[2] res = foo::<3, _>(); + return res; +} diff --git a/zokrates_cli/examples/book/generic_function_declaration.zok b/zokrates_cli/examples/book/generic_function_declaration.zok index 07c77353..32760207 100644 --- a/zokrates_cli/examples/book/generic_function_declaration.zok +++ b/zokrates_cli/examples/book/generic_function_declaration.zok @@ -1,6 +1,8 @@ -def foo() -> field[N]: - return [42; N] +def foo() -> field[N] { + return [42; N]; +} -def main() -> field[2]: - field[2] res = foo() - return res \ No newline at end of file +def main() -> field[2] { + field[2] res = foo(); + return res; +} diff --git a/zokrates_cli/examples/book/generics.zok b/zokrates_cli/examples/book/generics.zok index a9f11321..54f27340 100644 --- a/zokrates_cli/examples/book/generics.zok +++ b/zokrates_cli/examples/book/generics.zok @@ -1,9 +1,11 @@ -def sum(field[N] a) -> field: - field res = 0 - for u32 i in 0..N do - res = res + a[i] - endfor - return res +def sum(field[N] a) -> field { + field res = 0; + for u32 i in 0..N { + res = res + a[i]; + } + return res; +} -def main(field[3] a) -> field: - return sum(a) \ No newline at end of file +def main(field[3] a) -> field { + return sum(a); +} diff --git a/zokrates_cli/examples/book/mpc_tutorial/circuit.zok b/zokrates_cli/examples/book/mpc_tutorial/circuit.zok index a31e2d5a..4df4df5e 100644 --- a/zokrates_cli/examples/book/mpc_tutorial/circuit.zok +++ b/zokrates_cli/examples/book/mpc_tutorial/circuit.zok @@ -1,2 +1,3 @@ -def main(private field a, private field b) -> field: - return a * b \ No newline at end of file +def main(private field a, private field b) -> field { + return a * b; +} diff --git a/zokrates_cli/examples/book/multi_def.zok b/zokrates_cli/examples/book/multi_def.zok index 54838395..0c931f30 100644 --- a/zokrates_cli/examples/book/multi_def.zok +++ b/zokrates_cli/examples/book/multi_def.zok @@ -1,9 +1,11 @@ -def foo() -> (field, field): - return 21, 42 +def foo() -> (field, field) { + return 21, 42; +} -def main(): - // a is declared here - field a = 1 - // b is declared here - a, field b = foo() - return \ No newline at end of file +def main() { + // a is declared here + field a = 1; + // b is declared here + a, field b = foo(); + return; +} diff --git a/zokrates_cli/examples/book/multi_return.zok b/zokrates_cli/examples/book/multi_return.zok index 9feae810..3095998d 100644 --- a/zokrates_cli/examples/book/multi_return.zok +++ b/zokrates_cli/examples/book/multi_return.zok @@ -1,2 +1,3 @@ -def main() -> (field, field[3]): - return 1, [2, 3, 4] \ No newline at end of file +def main() -> (field, field[3]) { + return 1, [2, 3, 4]; +} diff --git a/zokrates_cli/examples/book/multidim_array.zok b/zokrates_cli/examples/book/multidim_array.zok index c05be0cd..83ce562d 100644 --- a/zokrates_cli/examples/book/multidim_array.zok +++ b/zokrates_cli/examples/book/multidim_array.zok @@ -1,9 +1,10 @@ -def main() -> field: - +def main() -> field { // Array of two elements of array of 3 elements - field[2][3] a = [[1, 2, 3],[4, 5, 6]] + field[2][3] a = [[1, 2, 3],[4, 5, 6]]; - field[3] b = a[0] // should be [1, 2, 3] + 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 + return a[1][2]; +} + diff --git a/zokrates_cli/examples/book/multiline_comments.zok b/zokrates_cli/examples/book/multiline_comments.zok index 458eb32a..8c57e2cd 100644 --- a/zokrates_cli/examples/book/multiline_comments.zok +++ b/zokrates_cli/examples/book/multiline_comments.zok @@ -2,5 +2,6 @@ This is a multi-line comment written in more than just one line. */ -def main() -> field: - return 42 \ No newline at end of file +def main() -> field { + return 42; +} diff --git a/zokrates_cli/examples/book/no_shadowing.zok b/zokrates_cli/examples/book/no_shadowing.zok index be221372..ee978a37 100644 --- a/zokrates_cli/examples/book/no_shadowing.zok +++ b/zokrates_cli/examples/book/no_shadowing.zok @@ -1,7 +1,8 @@ -def main() -> field: - field a = 2 +def main() -> field { + field a = 2; // field a = 3 <- not allowed - for u32 i in 0..5 do + for u32 i in 0..5 { // field a = 7 <- not allowed - endfor - return a \ No newline at end of file + } + return a; +} diff --git a/zokrates_cli/examples/book/not_equal.zok b/zokrates_cli/examples/book/not_equal.zok index d00d3203..382e6518 100644 --- a/zokrates_cli/examples/book/not_equal.zok +++ b/zokrates_cli/examples/book/not_equal.zok @@ -1,2 +1,3 @@ -def main(field a, field b) -> (bool): - return !(a == b) \ No newline at end of file +def main(field a, field b) -> (bool) { + return !(a == b); +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/numeric_inference.zok b/zokrates_cli/examples/book/numeric_inference.zok index 068229e0..dc034475 100644 --- a/zokrates_cli/examples/book/numeric_inference.zok +++ b/zokrates_cli/examples/book/numeric_inference.zok @@ -1,9 +1,10 @@ -def main(): +def main() { // `255` is infered to `255f`, and the addition happens between field elements - assert(255 + 1f == 256) + assert(255 + 1f == 256); // `255` is infered to `255u8`, and the addition happens between u8 - // This causes an overflow - assert(255 + 1u8 == 0) - - return \ No newline at end of file + // This causes an overflow + assert(255 + 1u8 == 0); + + return; +} diff --git a/zokrates_cli/examples/book/rng_tutorial/get_hash.zok b/zokrates_cli/examples/book/rng_tutorial/get_hash.zok index 5bfd8e90..d23fc9bd 100644 --- a/zokrates_cli/examples/book/rng_tutorial/get_hash.zok +++ b/zokrates_cli/examples/book/rng_tutorial/get_hash.zok @@ -1,5 +1,6 @@ -import "hashes/sha256/512bit" as sha256 +import "hashes/sha256/512bit" as sha256; -def main(u32[16] hashMe) -> u32[8]: - u32[8] h = sha256(hashMe[0..8], hashMe[8..16]) - return h \ No newline at end of file +def main(u32[16] hashMe) -> u32[8] { + u32[8] h = sha256(hashMe[0..8], hashMe[8..16]); + return h; +} diff --git a/zokrates_cli/examples/book/rng_tutorial/reveal_bit.zok b/zokrates_cli/examples/book/rng_tutorial/reveal_bit.zok index 0b0f8c46..e56a6cc5 100644 --- a/zokrates_cli/examples/book/rng_tutorial/reveal_bit.zok +++ b/zokrates_cli/examples/book/rng_tutorial/reveal_bit.zok @@ -1,20 +1,19 @@ -import "hashes/sha256/512bit" as sha256 -import "utils/casts/u32_to_bits" as u32_to_bits +import "hashes/sha256/512bit" as sha256; +import "utils/casts/u32_to_bits" as u32_to_bits; // Reveal a bit from a 512 bit value, and return it with the corresponding hash // for that value. // // WARNING, once enough bits have been revealed it is possible to brute force // the remaining preimage bits. - -def main(private u32[16] preimage, u32 bitNum) -> (u32[8], bool): - // Convert the preimage to bits - bool[512] preimageBits = [false; 512] - for u32 i in 0..16 do - bool[32] val = u32_to_bits(preimage[i]) - for u32 bit in 0..32 do - preimageBits[i*32+bit] = val[bit] - endfor - endfor - - return sha256(preimage[0..8], preimage[8..16]), preimageBits[bitNum] \ No newline at end of file +def main(private u32[16] preimage, u32 bitNum) -> (u32[8], bool) { + // Convert the preimage to bits + bool[512] preimageBits = [false; 512]; + for u32 i in 0..16 { + bool[32] val = u32_to_bits(preimage[i]); + for u32 bit in 0..32 { + preimageBits[i*32 + bit] = val[bit]; + } + } + return sha256(preimage[0..8], preimage[8..16]), preimageBits[bitNum]; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/sha256_tutorial/hashexample.zok b/zokrates_cli/examples/book/sha256_tutorial/hashexample.zok index a4716a34..8952ec33 100644 --- a/zokrates_cli/examples/book/sha256_tutorial/hashexample.zok +++ b/zokrates_cli/examples/book/sha256_tutorial/hashexample.zok @@ -1,5 +1,6 @@ -import "hashes/sha256/512bitPacked" as sha256packed +import "hashes/sha256/512bitPacked" as sha256packed; -def main(private field a, private field b, private field c, private field d) -> field[2]: - field[2] h = sha256packed([a, b, c, d]) - return h \ No newline at end of file +def main(private field a, private field b, private field c, private field d) -> field[2] { + field[2] h = sha256packed([a, b, c, d]); + return h; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/sha256_tutorial/hashexample_updated.zok b/zokrates_cli/examples/book/sha256_tutorial/hashexample_updated.zok index 51254f4e..6382ad01 100644 --- a/zokrates_cli/examples/book/sha256_tutorial/hashexample_updated.zok +++ b/zokrates_cli/examples/book/sha256_tutorial/hashexample_updated.zok @@ -1,7 +1,8 @@ -import "hashes/sha256/512bitPacked" 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]) - assert(h[0] == 263561599766550617289250058199814760685) - assert(h[1] == 65303172752238645975888084098459749904) - return \ No newline at end of file +def main(private field a, private field b, private field c, private field d) { + field[2] h = sha256packed([a, b, c, d]); + assert(h[0] == 263561599766550617289250058199814760685); + assert(h[1] == 65303172752238645975888084098459749904); + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/book/side_effects.zok b/zokrates_cli/examples/book/side_effects.zok index 6df428f1..8e05190b 100644 --- a/zokrates_cli/examples/book/side_effects.zok +++ b/zokrates_cli/examples/book/side_effects.zok @@ -1,9 +1,11 @@ -def incr(field a) -> field: - a = a + 1 - return a +def incr(field a) -> field { + a = a + 1; + return a; +} -def main(): - field x = 1 - field res = incr(x) - assert(x == 1) // x has not changed - return \ No newline at end of file +def main() { + field x = 1; + field res = incr(x); + assert(x == 1); // x has not changed + return; +} diff --git a/zokrates_cli/examples/book/struct_assign.zok b/zokrates_cli/examples/book/struct_assign.zok index c52794d1..633af8e1 100644 --- a/zokrates_cli/examples/book/struct_assign.zok +++ b/zokrates_cli/examples/book/struct_assign.zok @@ -1,10 +1,11 @@ struct Point { - field x - field y + 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 +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.zok b/zokrates_cli/examples/book/struct_init.zok index 837afc84..4da779da 100644 --- a/zokrates_cli/examples/book/struct_init.zok +++ b/zokrates_cli/examples/book/struct_init.zok @@ -1,8 +1,10 @@ struct Point { - field x - field y + field x; + field y; +} + +def main() -> (Point) { + Point p = Point { x: 1, y: 0 }; + return p; } -def main() -> (Point): - Point p = Point {x: 1, y: 0} - return p diff --git a/zokrates_cli/examples/book/structs.zok b/zokrates_cli/examples/book/structs.zok index 9e2ed2e5..86f6f891 100644 --- a/zokrates_cli/examples/book/structs.zok +++ b/zokrates_cli/examples/book/structs.zok @@ -1,14 +1,16 @@ struct Bar { - field[N] c - bool d + field[N] c; + bool d; } struct Foo

{ - Bar

a - bool b + Bar

a; + bool b; +} + +def main() -> (Foo<2>) { + Foo<2>[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]; } -def main() -> (Foo<2>): - Foo<2>[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_cli/examples/book/tuples.zok b/zokrates_cli/examples/book/tuples.zok index 3a8d270c..560de181 100644 --- a/zokrates_cli/examples/book/tuples.zok +++ b/zokrates_cli/examples/book/tuples.zok @@ -1,4 +1,6 @@ -def main() -> bool: - (field[2], bool) v = ([1, 2], true) - v.0 = [42, 43] - return v.1 +def main() -> bool { + (field[2], bool) v = ([1, 2], true); + v.0 = [42, 43]; + return v.1; +} + diff --git a/zokrates_cli/examples/book/type_aliases.zok b/zokrates_cli/examples/book/type_aliases.zok index fd500a4e..ff4c307b 100644 --- a/zokrates_cli/examples/book/type_aliases.zok +++ b/zokrates_cli/examples/book/type_aliases.zok @@ -1,11 +1,12 @@ -type MyField = field +type MyField = field; -type Rectangle = bool[L][W] +type Rectangle = bool[L][W]; -type Square = Rectangle +type Square = Rectangle; -def main(): - MyField f = 42 - Rectangle<2, 2> r = [[true; 2]; 2] - Square<2> s = r - return \ No newline at end of file +def main() { + MyField f = 42; + Rectangle<2, 2> r = [[true; 2]; 2]; + Square<2> s = r; + return; +} diff --git a/zokrates_cli/examples/book/type_annotations.zok b/zokrates_cli/examples/book/type_annotations.zok index 74600f58..3903c389 100644 --- a/zokrates_cli/examples/book/type_annotations.zok +++ b/zokrates_cli/examples/book/type_annotations.zok @@ -1,9 +1,12 @@ -def foo() -> (field, field[3]): - return 1, [2, 3, 4] +def foo() -> (field, field[3]) { + return 1, [2, 3, 4]; +} -def foo() -> (field, field): - return 1, 2 +def foo() -> (field, field) { + return 1, 2; +} -def main(): - field a, field[3] b = foo() - return \ No newline at end of file +def main() { + field a, field[3] b = foo(); + return; +} diff --git a/zokrates_cli/examples/bool_and.zok b/zokrates_cli/examples/bool_and.zok index e6fa034d..fe4c074a 100644 --- a/zokrates_cli/examples/bool_and.zok +++ b/zokrates_cli/examples/bool_and.zok @@ -1,7 +1,8 @@ -// example using if-then-else-fi with && +// example using ternary with && -def main(field a, field b) -> field: - field y = if a + 2 == 3 && a * 2 == 2 then 1 else 0 fi - field z = if y == 1 && 1-y == 0 then y else 1 fi - assert(b == 1) - return a \ No newline at end of file +def main(field a, field b) -> field { + field y = a + 2 == 3 && a * 2 == 2 ? 1 : 0; + field z = y == 1 && 1 - y == 0 ? y : 1; + assert(b == 1); + return a; +} diff --git a/zokrates_cli/examples/bool_not.zok b/zokrates_cli/examples/bool_not.zok index c43408c1..c1ad3ad6 100644 --- a/zokrates_cli/examples/bool_not.zok +++ b/zokrates_cli/examples/bool_not.zok @@ -1,3 +1,4 @@ -def main(field a) -> field: - field x = if !(!(a < 5) && !(a > 1) || a < 4) then 3 else 4 fi - return x \ No newline at end of file +def main(field a) -> field { + field x = !(!(a < 5) && !(a > 1) || a < 4) ? 3 : 4; + return x; +} \ No newline at end of file diff --git a/zokrates_cli/examples/bool_or.zok b/zokrates_cli/examples/bool_or.zok index 7f313d08..8f1a5686 100644 --- a/zokrates_cli/examples/bool_or.zok +++ b/zokrates_cli/examples/bool_or.zok @@ -1,7 +1,7 @@ // example using if-then-else-fi with || -def main(field a, field b) -> field: - field y = if a + 2 == 4 || b * 2 == 2 then 1 else 0 fi - field z = if y == 1 || y == 0 then y else 1 fi - assert(z == 1) - return z - +def main(field a, field b) -> field { + field y = a + 2 == 4 || b * 2 == 2 ? 1 : 0; + field z = y == 1 || y == 0 ? y : 1; + assert(z == 1); + return z; +} \ No newline at end of file diff --git a/zokrates_cli/examples/boolean_literal.zok b/zokrates_cli/examples/boolean_literal.zok index 0f6861ca..97ee1319 100644 --- a/zokrates_cli/examples/boolean_literal.zok +++ b/zokrates_cli/examples/boolean_literal.zok @@ -1,2 +1,3 @@ -def main(bool a) -> bool: - return (false || true) && false \ No newline at end of file +def main(bool a) -> bool { + return (false || true) && false; +} diff --git a/zokrates_cli/examples/brackets.zok b/zokrates_cli/examples/brackets.zok index fab05b4d..bee50438 100644 --- a/zokrates_cli/examples/brackets.zok +++ b/zokrates_cli/examples/brackets.zok @@ -1,4 +1,5 @@ -def main(field a) -> field: - field b = (a + 5) * 6 - field c = 7 * (b + a) - return b + c +def main(field a) -> field { + field b = (a + 5) * 6; + field c = 7 * (b + a); + return b + c; +} diff --git a/zokrates_cli/examples/call_in_const.zok b/zokrates_cli/examples/call_in_const.zok index d6e73dc3..a2fe1d86 100644 --- a/zokrates_cli/examples/call_in_const.zok +++ b/zokrates_cli/examples/call_in_const.zok @@ -1,10 +1,12 @@ -from "./call_in_const_aux.zok" import A, foo, F +from "./call_in_const_aux.zok" import A, foo, F; -def bar(field[A] x) -> field[A]: - return x - -const field[A] Y = [...bar(foo::(F))[..A - 1], 1] +def bar(field[A] x) -> field[A] { + return x; +} -def main(field[A] X): - assert(X == Y) - return \ No newline at end of file +const field[A] Y = [...bar(foo::(F))[..A - 1], 1]; + +def main(field[A] X) { + assert(X == Y); + return; +} diff --git a/zokrates_cli/examples/call_in_const_aux.zok b/zokrates_cli/examples/call_in_const_aux.zok index 2e3e86b7..b5107e6c 100644 --- a/zokrates_cli/examples/call_in_const_aux.zok +++ b/zokrates_cli/examples/call_in_const_aux.zok @@ -1,9 +1,11 @@ -const field F = 10 -const u32 A = 10 -const u32 B = A +const field F = 10; +const u32 A = 10; +const u32 B = A; -def foo(field X) -> field[N]: - return [X; N] +def foo(field X) -> field[N] { + return [X; N]; +} -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/call_in_constant.zok b/zokrates_cli/examples/call_in_constant.zok index 2d1312b5..807de5bb 100644 --- a/zokrates_cli/examples/call_in_constant.zok +++ b/zokrates_cli/examples/call_in_constant.zok @@ -1,7 +1,9 @@ -def yes() -> bool: - return true +def yes() -> bool { + return true; +} -const bool TRUE = yes() +const bool TRUE = yes(); -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/comments.zok b/zokrates_cli/examples/comments.zok index bad9b6eb..08a0dd4c 100644 --- a/zokrates_cli/examples/comments.zok +++ b/zokrates_cli/examples/comments.zok @@ -1,7 +1,8 @@ // only using add, no need to flatten -def main(field a) -> field: // a needs to be 1 - field b = a + 5 // inline comment - field c = a + b + a + 4 - assert(a == 1) // another inline comment - field d = a + c + a + b - return b + c + d +def main(field a) -> field { // a needs to be 1 + field b = a + 5; // inline comment + field c = a + b + a + 4; + assert(a == 1); // another inline comment + field d = a + c + a + b; + return b + c + d; +} diff --git a/zokrates_cli/examples/comparison_operators.zok b/zokrates_cli/examples/comparison_operators.zok index afad1bb7..cfabff83 100644 --- a/zokrates_cli/examples/comparison_operators.zok +++ b/zokrates_cli/examples/comparison_operators.zok @@ -1,8 +1,9 @@ // comparison operator example -def main(field x) -> field: - field y = if x >= 3 then 1 else 5 fi - field z = if y <= x then x**3 else y**3 fi - y = if x < 3 then 2 else 6 fi - z = if y > z then 1 else 2 fi - x = if x == x then x else y fi - return x + y + z +def main(field x) -> field { + field y = x >= 3 ? 1 : 5; + field z = y <= x ? x**3 : y**3; + y = x < 3 ? 2 : 6; + z = y > z ? 1 : 2; + x = x == x ? x : y; + return x + y + z; +} \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/ambiguous_generic_call.zok b/zokrates_cli/examples/compile_errors/ambiguous_generic_call.zok index 5cb7685e..ff895568 100644 --- a/zokrates_cli/examples/compile_errors/ambiguous_generic_call.zok +++ b/zokrates_cli/examples/compile_errors/ambiguous_generic_call.zok @@ -1,14 +1,17 @@ // this should not compile, as A == B -const u32 A = 1 -const u32 B = 1 +const u32 A = 1; +const u32 B = 1; -def foo(field[A] a) -> bool: - return true +def foo(field[A] a) -> bool { + return true; +} -def foo(field[B] a) -> bool: - return true +def foo(field[B] a) -> bool { + return true; +} -def main(): - assert(foo([1])) - return \ No newline at end of file +def main() { + assert(foo([1])); + return; +} diff --git a/zokrates_cli/examples/compile_errors/ambiguous_generic_call_too_strict.zok b/zokrates_cli/examples/compile_errors/ambiguous_generic_call_too_strict.zok index 5abd8acd..b9c7569a 100644 --- a/zokrates_cli/examples/compile_errors/ambiguous_generic_call_too_strict.zok +++ b/zokrates_cli/examples/compile_errors/ambiguous_generic_call_too_strict.zok @@ -1,14 +1,17 @@ // this should actually compile, as A != B -const u32 A = 2 -const u32 B = 1 +const u32 A = 2; +const u32 B = 1; -def foo(field[A] a) -> bool: - return true +def foo(field[A] a) -> bool { + return true; +} -def foo(field[B] a) -> bool: - return true +def foo(field[B] a) -> bool { + return true; +} -def main(): - assert(foo([1])) - return \ No newline at end of file +def main() { + assert(foo([1])); + return; +} diff --git a/zokrates_cli/examples/compile_errors/assertion.zok b/zokrates_cli/examples/compile_errors/assertion.zok index 046e62f5..c108975e 100644 --- a/zokrates_cli/examples/compile_errors/assertion.zok +++ b/zokrates_cli/examples/compile_errors/assertion.zok @@ -1,3 +1,4 @@ -def main(): - assert(1f == 2f) - return \ No newline at end of file +def main() { + assert(1f == 2f); + return; +} diff --git a/zokrates_cli/examples/compile_errors/assertion_unequal_arrays.zok b/zokrates_cli/examples/compile_errors/assertion_unequal_arrays.zok index dc06d4a5..1f337d11 100644 --- a/zokrates_cli/examples/compile_errors/assertion_unequal_arrays.zok +++ b/zokrates_cli/examples/compile_errors/assertion_unequal_arrays.zok @@ -1,3 +1,4 @@ -def main(): - assert([1f] == [2f]) - return \ No newline at end of file +def main() { + assert([1f] == [2f]); + return; +} diff --git a/zokrates_cli/examples/compile_errors/const_complex_type_mismatch.zok b/zokrates_cli/examples/compile_errors/const_complex_type_mismatch.zok index 97d5c9cc..0e1f661a 100644 --- a/zokrates_cli/examples/compile_errors/const_complex_type_mismatch.zok +++ b/zokrates_cli/examples/compile_errors/const_complex_type_mismatch.zok @@ -1,7 +1,8 @@ -const u32 ONE = 1 -const u32 TWO = 2 -const field[ONE] ONE_FIELD = [1; TWO] // actually set the value to an array of 2 elements +const u32 ONE = 1; +const u32 TWO = 2; +const field[ONE] ONE_FIELD = [1; TWO]; // actually set the value to an array of 2 elements -def main(field[TWO] TWO_FIELDS): - assert(TWO_FIELDS == ONE_FIELD) // use the value as is - return \ No newline at end of file +def main(field[TWO] TWO_FIELDS) { + assert(TWO_FIELDS == ONE_FIELD); // use the value as is + return; +} diff --git a/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_field.zok b/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_field.zok index 8c34a04c..cb9008ec 100644 --- a/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_field.zok +++ b/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_field.zok @@ -1,4 +1,5 @@ -const field SIZE = 2 +const field SIZE = 2; -def main(field[SIZE] n): - return \ No newline at end of file +def main(field[SIZE] n) { + return; +} diff --git a/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_u8.zok b/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_u8.zok index 5a086af7..3aa80bab 100644 --- a/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_u8.zok +++ b/zokrates_cli/examples/compile_errors/constant_array_size_type_mismatch_u8.zok @@ -1,4 +1,5 @@ -const u8 SIZE = 0x02 +const u8 SIZE = 0x02; -def main(field[SIZE] n): - return \ No newline at end of file +def main(field[SIZE] n) { + return; +} diff --git a/zokrates_cli/examples/compile_errors/constant_assignment.zok b/zokrates_cli/examples/compile_errors/constant_assignment.zok index e04da9f6..b58f6922 100644 --- a/zokrates_cli/examples/compile_errors/constant_assignment.zok +++ b/zokrates_cli/examples/compile_errors/constant_assignment.zok @@ -1,5 +1,6 @@ -const field a = 1 +const field a = 1; -def main() -> field: - a = 2 // not allowed - return a \ No newline at end of file +def main() -> field { + a = 2; // not allowed + return a; +} diff --git a/zokrates_cli/examples/compile_errors/constant_reduction_fail.zok b/zokrates_cli/examples/compile_errors/constant_reduction_fail.zok index 1f08bc32..706a4e75 100644 --- a/zokrates_cli/examples/compile_errors/constant_reduction_fail.zok +++ b/zokrates_cli/examples/compile_errors/constant_reduction_fail.zok @@ -1,6 +1,7 @@ -from "EMBED" import bit_array_le +from "EMBED" import bit_array_le; -const bool CONST = bit_array_le([true], [true]) +const bool CONST = bit_array_le([true], [true]); -def main() -> bool: - return CONST \ No newline at end of file +def main() -> bool { + return CONST; +} diff --git a/zokrates_cli/examples/compile_errors/constant_type_error.zok b/zokrates_cli/examples/compile_errors/constant_type_error.zok index feebb7f5..e5bb4e2d 100644 --- a/zokrates_cli/examples/compile_errors/constant_type_error.zok +++ b/zokrates_cli/examples/compile_errors/constant_type_error.zok @@ -1,4 +1,5 @@ -const u32[2] A = [1] +const u32[2] A = [1]; -def main() -> u32[2]: - return A \ No newline at end of file +def main() -> u32[2] { + return A; +} diff --git a/zokrates_cli/examples/compile_errors/declare_non_identifier.zok b/zokrates_cli/examples/compile_errors/declare_non_identifier.zok index f7bac518..aa4bc9fa 100644 --- a/zokrates_cli/examples/compile_errors/declare_non_identifier.zok +++ b/zokrates_cli/examples/compile_errors/declare_non_identifier.zok @@ -1,3 +1,4 @@ -def main(): - field[2] a[2] = [1, 2] // only variables can be declared in such a statement, declaring `a[2]` is invalid - return \ No newline at end of file +def main() { + field[2] a[2] = [1, 2]; // only variables can be declared in such a statement, declaring `a[2]` is invalid + return; +} diff --git a/zokrates_cli/examples/compile_errors/div_by_zero.zok b/zokrates_cli/examples/compile_errors/div_by_zero.zok index 784a9aec..e9c15cdd 100644 --- a/zokrates_cli/examples/compile_errors/div_by_zero.zok +++ b/zokrates_cli/examples/compile_errors/div_by_zero.zok @@ -1,3 +1,4 @@ -def main(field input) -> field: - field divisor = if [input, 0] != [input, 1] then 0 else 1 fi - return input / divisor \ No newline at end of file +def main(field input) -> field { + field divisor = [input, 0] != [input, 1] ? 0 : 1; + return input / divisor; +} diff --git a/zokrates_cli/examples/compile_errors/double_negation.zok b/zokrates_cli/examples/compile_errors/double_negation.zok index 257892a8..4f7fcc30 100644 --- a/zokrates_cli/examples/compile_errors/double_negation.zok +++ b/zokrates_cli/examples/compile_errors/double_negation.zok @@ -1,3 +1,4 @@ -def main(): - field a = - - 1 - return \ No newline at end of file +def main() { + field a = - - 1; + return; +} diff --git a/zokrates_cli/examples/compile_errors/double_power.zok b/zokrates_cli/examples/compile_errors/double_power.zok index 43443699..51028ed1 100644 --- a/zokrates_cli/examples/compile_errors/double_power.zok +++ b/zokrates_cli/examples/compile_errors/double_power.zok @@ -1,3 +1,4 @@ -def main(): - field a = 1**2**3 // parentheses are required here - return \ No newline at end of file +def main() { + field a = 1**2**3; // parentheses are required here + return; +} diff --git a/zokrates_cli/examples/compile_errors/embed_type_mismatch.zok b/zokrates_cli/examples/compile_errors/embed_type_mismatch.zok index 047df566..6b7c8398 100644 --- a/zokrates_cli/examples/compile_errors/embed_type_mismatch.zok +++ b/zokrates_cli/examples/compile_errors/embed_type_mismatch.zok @@ -1,5 +1,6 @@ -import "EMBED/u8_to_bits" as u8_to_bits +import "EMBED/u8_to_bits" as u8_to_bits; -def main(u8 x): - bool[32] b = u8_to_bits(x) // note the incorrect array length on the left - return \ No newline at end of file +def main(u8 x) { + bool[32] b = u8_to_bits(x); // note the incorrect array length on the left + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/assertion.zok b/zokrates_cli/examples/compile_errors/generics/assertion.zok index e235a651..07c2cb9b 100644 --- a/zokrates_cli/examples/compile_errors/generics/assertion.zok +++ b/zokrates_cli/examples/compile_errors/generics/assertion.zok @@ -1,7 +1,10 @@ -def foo(field[N] inputs) -> bool: - assert(N <= 5) - return true +def foo(field[N] inputs) -> bool { + assert(N <= 5); + return true; +} + +def main() { + bool b = foo([1, 2, 3, 4, 5, 6]); + return; +} -def main(): - bool b = foo([1, 2, 3, 4, 5, 6]) - return diff --git a/zokrates_cli/examples/compile_errors/generics/assign_size_mismatch.zok b/zokrates_cli/examples/compile_errors/generics/assign_size_mismatch.zok index 727346f6..f8ccb7ad 100644 --- a/zokrates_cli/examples/compile_errors/generics/assign_size_mismatch.zok +++ b/zokrates_cli/examples/compile_errors/generics/assign_size_mismatch.zok @@ -1,8 +1,9 @@ -def foo(field[N] a) -> bool: - field[3] b = a - return true +def foo(field[N] a) -> bool { + field[3] b = a; + return true; +} - -def main(field[1] a): - assert(foo(a)) - return \ No newline at end of file +def main(field[1] a) { + assert(foo(a)); + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/concrete_length_mismatch.zok b/zokrates_cli/examples/compile_errors/generics/concrete_length_mismatch.zok index 906326a4..defee922 100644 --- a/zokrates_cli/examples/compile_errors/generics/concrete_length_mismatch.zok +++ b/zokrates_cli/examples/compile_errors/generics/concrete_length_mismatch.zok @@ -1,3 +1,4 @@ -def main(): - assert([1] == [1, 2]) - return \ No newline at end of file +def main() { + assert([1] == [1, 2]); + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok b/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok index 6b3baa79..cb28daef 100644 --- a/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok +++ b/zokrates_cli/examples/compile_errors/generics/conflicting_call.zok @@ -1,11 +1,15 @@ -def foo(field[N] a) -> field[P]: - return a +def foo(field[N] a) -> field[P] { + return a; +} -def foo(field[P] a) -> field[N]: - return a +def foo(field[P] a) -> field[N] { + return a; +} -def bar(field[Q] a) -> field[Q]: - return foo(a) +def bar(field[Q] a) -> field[Q] { + return foo(a); +} -def main() -> field[1]: - return bar([1]) \ No newline at end of file +def main() -> field[1] { + return bar([1]); +} diff --git a/zokrates_cli/examples/compile_errors/generics/conflicting_constant.zok b/zokrates_cli/examples/compile_errors/generics/conflicting_constant.zok index dcc9e6dc..2a394d23 100644 --- a/zokrates_cli/examples/compile_errors/generics/conflicting_constant.zok +++ b/zokrates_cli/examples/compile_errors/generics/conflicting_constant.zok @@ -1,7 +1,9 @@ -const u32 N = 42 +const u32 N = 42; -def foo(field[N] a) -> bool: - return true +def foo(field[N] a) -> bool { + return true; +} -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok b/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok index bfdbf6b6..abe03730 100644 --- a/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok +++ b/zokrates_cli/examples/compile_errors/generics/conflicting_functions.zok @@ -1,8 +1,11 @@ -def foo(field[N] a) -> bool: - return true +def foo(field[N] a) -> bool { + return true; +} -def foo

(field[P] a) -> bool: - return true +def foo

(field[P] a) -> bool { + return true; +} -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/duplicate_struct_generic.zok b/zokrates_cli/examples/compile_errors/generics/duplicate_struct_generic.zok index a87dcd16..6f18654b 100644 --- a/zokrates_cli/examples/compile_errors/generics/duplicate_struct_generic.zok +++ b/zokrates_cli/examples/compile_errors/generics/duplicate_struct_generic.zok @@ -1,6 +1,7 @@ struct A { - field[N] a + field[N] a; } -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/generic_in_main.zok b/zokrates_cli/examples/compile_errors/generics/generic_in_main.zok index 025c7452..1ec8d350 100644 --- a/zokrates_cli/examples/compile_errors/generics/generic_in_main.zok +++ b/zokrates_cli/examples/compile_errors/generics/generic_in_main.zok @@ -1,2 +1,3 @@ -def main

(): - return \ No newline at end of file +def main

() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/generic_inference.zok b/zokrates_cli/examples/compile_errors/generics/generic_inference.zok index 82c95f5f..30edf8d1 100644 --- a/zokrates_cli/examples/compile_errors/generics/generic_inference.zok +++ b/zokrates_cli/examples/compile_errors/generics/generic_inference.zok @@ -1,7 +1,8 @@ struct A { - field[N] a + field[N] a; } -def main(): - A<_> a = A { a: [1] } - return \ No newline at end of file +def main() { + A<_> a = A { a: [1] }; + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/generics_in_main.zok b/zokrates_cli/examples/compile_errors/generics/generics_in_main.zok index 137f0b61..adbd9755 100644 --- a/zokrates_cli/examples/compile_errors/generics/generics_in_main.zok +++ b/zokrates_cli/examples/compile_errors/generics/generics_in_main.zok @@ -1,2 +1,3 @@ -def main

(field[P] a): - return \ No newline at end of file +def main

(field[P] a) { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/incompatible.zok b/zokrates_cli/examples/compile_errors/generics/incompatible.zok index bbf114d7..11c6c5a0 100644 --- a/zokrates_cli/examples/compile_errors/generics/incompatible.zok +++ b/zokrates_cli/examples/compile_errors/generics/incompatible.zok @@ -1,5 +1,7 @@ -def foo

(field[P] a, field[P] b) -> field: - return 42 +def foo

(field[P] a, field[P] b) -> field { + return 42; +} -def main() -> field: - return foo([1, 2], [1]) \ No newline at end of file +def main() -> field { + return foo([1, 2], [1]); +} diff --git a/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok b/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok index 19120945..146fdc14 100644 --- a/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok +++ b/zokrates_cli/examples/compile_errors/generics/infer_return_call_generics.zok @@ -1,5 +1,7 @@ -def foo() -> field[N]: - return [42; N] +def foo() -> field[N] { + return [42; N]; +} -def main() -> field[2]: - return foo() // N is currently not infered to 2 here \ No newline at end of file +def main() -> field[2] { + return foo(); // N is currently not infered to 2 here +} diff --git a/zokrates_cli/examples/compile_errors/generics/no_weak_eq.zok b/zokrates_cli/examples/compile_errors/generics/no_weak_eq.zok index 5169eb5b..4fc60da7 100644 --- a/zokrates_cli/examples/compile_errors/generics/no_weak_eq.zok +++ b/zokrates_cli/examples/compile_errors/generics/no_weak_eq.zok @@ -1,3 +1,4 @@ -def main(): - assert([[1]] == [1, 2]) - return \ No newline at end of file +def main() { + assert([[1]] == [1, 2]); + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok b/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok index 5d0b71e0..9adfca9b 100644 --- a/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok +++ b/zokrates_cli/examples/compile_errors/generics/non_conflicting_call.zok @@ -1,14 +1,17 @@ // this should compile but requires looking at the generic parameter values, and they are not known at semantic check time. // It is enough of an edge case to not be worth fixing -def foo(field[N] a) -> field[P]: - return [1; P] +def foo(field[N] a) -> field[P] { + return [1; P]; +} -def foo(field[P] a) -> field[N]: - return [1; N] +def foo(field[P] a) -> field[N] { + return [1; N]; +} -def main() -> field[2]: - u32 X = 1 - u32 Y = 2 - field[2] a = foo::([1]) - return a \ No newline at end of file +def main() -> field[2] { + u32 X = 1; + u32 Y = 2; + field[2] a = foo::([1]); + return a; +} diff --git a/zokrates_cli/examples/compile_errors/generics/numerical_struct_generic.zok b/zokrates_cli/examples/compile_errors/generics/numerical_struct_generic.zok index ccb789e3..2bb949b5 100644 --- a/zokrates_cli/examples/compile_errors/generics/numerical_struct_generic.zok +++ b/zokrates_cli/examples/compile_errors/generics/numerical_struct_generic.zok @@ -1,6 +1,7 @@ struct A<1> { - field[1] a + field[1] a; } -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/struct_generic_mismatch.zok b/zokrates_cli/examples/compile_errors/generics/struct_generic_mismatch.zok index b110cd58..78de256f 100644 --- a/zokrates_cli/examples/compile_errors/generics/struct_generic_mismatch.zok +++ b/zokrates_cli/examples/compile_errors/generics/struct_generic_mismatch.zok @@ -1,6 +1,7 @@ struct A { - field[N] a + field[N] a; } -def main(A<1> a, A<2> b) -> bool: - return a == b \ No newline at end of file +def main(A<1> a, A<2> b) -> bool { + return a == b; +} diff --git a/zokrates_cli/examples/compile_errors/generics/undeclared_struct_generic.zok b/zokrates_cli/examples/compile_errors/generics/undeclared_struct_generic.zok index bd1ac03f..1bda7a3f 100644 --- a/zokrates_cli/examples/compile_errors/generics/undeclared_struct_generic.zok +++ b/zokrates_cli/examples/compile_errors/generics/undeclared_struct_generic.zok @@ -1,6 +1,7 @@ struct A { - field[N] a + field[N] a; } -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/generics/unused_struct_generic.zok b/zokrates_cli/examples/compile_errors/generics/unused_struct_generic.zok index 03f97145..370c66c0 100644 --- a/zokrates_cli/examples/compile_errors/generics/unused_struct_generic.zok +++ b/zokrates_cli/examples/compile_errors/generics/unused_struct_generic.zok @@ -1,4 +1,5 @@ struct A {} -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/keyword_as_identifier.zok b/zokrates_cli/examples/compile_errors/keyword_as_identifier.zok index d0e463d3..517d2444 100644 --- a/zokrates_cli/examples/compile_errors/keyword_as_identifier.zok +++ b/zokrates_cli/examples/compile_errors/keyword_as_identifier.zok @@ -1,5 +1,7 @@ -def assert(): - return +def assert() { + return; +} + def main(): return \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/loop_too_large.zok b/zokrates_cli/examples/compile_errors/loop_too_large.zok index d1779a6b..c6560dc4 100644 --- a/zokrates_cli/examples/compile_errors/loop_too_large.zok +++ b/zokrates_cli/examples/compile_errors/loop_too_large.zok @@ -1,4 +1,4 @@ -def main(): - for u32 i in 0..-1 do - endfor - return \ No newline at end of file +def main() { + for u32 i in 0..-1 {} + return; +} diff --git a/zokrates_cli/examples/compile_errors/no_return.zok b/zokrates_cli/examples/compile_errors/no_return.zok index f506ee53..3e2e0f4f 100644 --- a/zokrates_cli/examples/compile_errors/no_return.zok +++ b/zokrates_cli/examples/compile_errors/no_return.zok @@ -1,4 +1,5 @@ -def foo(): +def foo() {} -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/compile_errors/no_struct_equivalence.zok b/zokrates_cli/examples/compile_errors/no_struct_equivalence.zok index 73f81980..bf2c05fc 100644 --- a/zokrates_cli/examples/compile_errors/no_struct_equivalence.zok +++ b/zokrates_cli/examples/compile_errors/no_struct_equivalence.zok @@ -1,5 +1,6 @@ struct Foo {} struct Bar {} -def main() -> (Foo): - return Bar {} \ No newline at end of file +def main() -> (Foo) { + return Bar {}; +} \ No newline at end of file diff --git a/zokrates_cli/examples/compile_errors/out_of_bounds.zok b/zokrates_cli/examples/compile_errors/out_of_bounds.zok index d0d98e5e..5b65f940 100644 --- a/zokrates_cli/examples/compile_errors/out_of_bounds.zok +++ b/zokrates_cli/examples/compile_errors/out_of_bounds.zok @@ -1,4 +1,5 @@ -def main(field a, field b) -> field: - field[10] arr = [0; 10] - u32 index = if [a, 1] != [b, 0] then 1000 else 0 fi - return arr[index] \ No newline at end of file +def main(field a, field b) -> field { + field[10] arr = [0; 10]; + u32 index = [a, 1] != [b, 0] ? 1000 : 0; + return arr[index]; +} diff --git a/zokrates_cli/examples/compile_errors/out_of_bounds_read.zok b/zokrates_cli/examples/compile_errors/out_of_bounds_read.zok index 7401e1d5..cc72fff2 100644 --- a/zokrates_cli/examples/compile_errors/out_of_bounds_read.zok +++ b/zokrates_cli/examples/compile_errors/out_of_bounds_read.zok @@ -1,7 +1,9 @@ -def foo(field[1] a) -> field[1]: - return a +def foo(field[1] a) -> field[1] { + return a; +} -def main(field a): - field[1] h = foo([a]) - field f = h[1] - return \ No newline at end of file +def main(field a) { + field[1] h = foo([a]); + field f = h[1]; + return; +} diff --git a/zokrates_cli/examples/compile_errors/out_of_bounds_write.zok b/zokrates_cli/examples/compile_errors/out_of_bounds_write.zok index 93904120..ea71edb6 100644 --- a/zokrates_cli/examples/compile_errors/out_of_bounds_write.zok +++ b/zokrates_cli/examples/compile_errors/out_of_bounds_write.zok @@ -1,7 +1,9 @@ -def foo(field[1] a) -> field[1]: - return a +def foo(field[1] a) -> field[1] { + return a; +} -def main(field a): - field[1] h = foo([a]) - h[1] = 1 - return \ No newline at end of file +def main(field a) { + field[1] h = foo([a]); + h[1] = 1; + return; +} diff --git a/zokrates_cli/examples/compile_errors/out_of_for_scope.zok b/zokrates_cli/examples/compile_errors/out_of_for_scope.zok index e1c73da1..d7934a8c 100644 --- a/zokrates_cli/examples/compile_errors/out_of_for_scope.zok +++ b/zokrates_cli/examples/compile_errors/out_of_for_scope.zok @@ -1,4 +1,4 @@ -def main() -> field: - for u32 i in 0..5 do - endfor - return i \ No newline at end of file +def main() -> field { + for u32 i in 0..5 {} + return i; +} diff --git a/zokrates_cli/examples/compile_errors/shadowing.zok b/zokrates_cli/examples/compile_errors/shadowing.zok index 701f4050..bcbaa5fb 100644 --- a/zokrates_cli/examples/compile_errors/shadowing.zok +++ b/zokrates_cli/examples/compile_errors/shadowing.zok @@ -1,7 +1,9 @@ -def foo() -> field: - return 1 +def foo() -> field { + return 1; +} -def main(): - field a = 2 - field a = foo() - return \ No newline at end of file +def main() { + field a = 2; + field a = foo(); + return; +} diff --git a/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_field.zok b/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_field.zok index 15b0c961..4fea2779 100644 --- a/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_field.zok +++ b/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_field.zok @@ -1,17 +1,17 @@ struct Foo { - field[2] values + field[2] values; } struct Bar { - Foo foo - field bar + Foo foo; + field bar; } -def main(): +def main() { Bar s = Bar { foo: Foo { values: [1] }, bar: 0, - } - field b = s.bar - - return \ No newline at end of file + }; + field b = s.bar; + return; +} diff --git a/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_u8.zok b/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_u8.zok index 4672d50a..259df3e2 100644 --- a/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_u8.zok +++ b/zokrates_cli/examples/compile_errors/struct_member_type_mismatch_u8.zok @@ -1,17 +1,17 @@ struct Foo { - u8[2] values + u8[2] values; } struct Bar { - Foo foo - u8 bar + Foo foo; + u8 bar; } -def main(): +def main() { Bar s = Bar { foo: Foo { values: [1] }, // notice the size mismatch here bar: 0, - } - u8 b = s.bar - - return \ No newline at end of file + }; + u8 b = s.bar; + return; +} diff --git a/zokrates_cli/examples/compile_errors/ternary_precedence.zok b/zokrates_cli/examples/compile_errors/ternary_precedence.zok index 180b081e..0e179c32 100644 --- a/zokrates_cli/examples/compile_errors/ternary_precedence.zok +++ b/zokrates_cli/examples/compile_errors/ternary_precedence.zok @@ -1,5 +1,6 @@ -def main(bool a) -> field: +def main(bool a) -> field { // ternary expression should be wrapped in parentheses 1 + (a ? 2 : 3) // otherwise the whole expression is parsed as (1 + a) ? 2 : 3 - field x = 1 + a ? 2 : 3 - return x \ No newline at end of file + field x = 1 + a ? 2 : 3; + return x; +} diff --git a/zokrates_cli/examples/compile_errors/too_many_arguments.zok b/zokrates_cli/examples/compile_errors/too_many_arguments.zok index 3efabfdb..cc35f012 100644 --- a/zokrates_cli/examples/compile_errors/too_many_arguments.zok +++ b/zokrates_cli/examples/compile_errors/too_many_arguments.zok @@ -1,5 +1,7 @@ -def foo() -> field: - return 1 +def foo() -> field { + return 1; +} -def main() -> field: - return foo(42) \ No newline at end of file +def main() -> field { + return foo(42); +} diff --git a/zokrates_cli/examples/compile_errors/too_many_generics.zok b/zokrates_cli/examples/compile_errors/too_many_generics.zok index f34a17f5..0a33a8e6 100644 --- a/zokrates_cli/examples/compile_errors/too_many_generics.zok +++ b/zokrates_cli/examples/compile_errors/too_many_generics.zok @@ -1,5 +1,7 @@ -def foo() -> field: - return 1 +def foo() -> field { + return 1; +} -def main() -> field: - return foo::<42>() \ No newline at end of file +def main() -> field { + return foo::<42>(); +} diff --git a/zokrates_cli/examples/compile_errors/too_many_return.zok b/zokrates_cli/examples/compile_errors/too_many_return.zok index 8b1dec6f..44b5d4fa 100644 --- a/zokrates_cli/examples/compile_errors/too_many_return.zok +++ b/zokrates_cli/examples/compile_errors/too_many_return.zok @@ -1,2 +1,3 @@ -def main(): - return 1 \ No newline at end of file +def main() { + return 1; +} diff --git a/zokrates_cli/examples/compile_errors/two_return.zok b/zokrates_cli/examples/compile_errors/two_return.zok index 596f7234..149bb2d9 100644 --- a/zokrates_cli/examples/compile_errors/two_return.zok +++ b/zokrates_cli/examples/compile_errors/two_return.zok @@ -1,3 +1,4 @@ -def main(): - return - return \ No newline at end of file +def main() { + return; + return; +} diff --git a/zokrates_cli/examples/compile_errors/unassigned.zok b/zokrates_cli/examples/compile_errors/unassigned.zok index b10c994d..2c992f0b 100644 --- a/zokrates_cli/examples/compile_errors/unassigned.zok +++ b/zokrates_cli/examples/compile_errors/unassigned.zok @@ -1,4 +1,5 @@ -def main() -> field: - field a - field b = a + 1 - return b \ No newline at end of file +def main() -> field { + field a; + field b = a + 1; + return b; +} diff --git a/zokrates_cli/examples/compile_errors/unpack_value_too_large.zok b/zokrates_cli/examples/compile_errors/unpack_value_too_large.zok index c592d4a0..ed4264df 100644 --- a/zokrates_cli/examples/compile_errors/unpack_value_too_large.zok +++ b/zokrates_cli/examples/compile_errors/unpack_value_too_large.zok @@ -1,5 +1,6 @@ -from "EMBED" import unpack +from "EMBED" import unpack; -def main(): - bool[2] bits = unpack(4) // we need 3 bits to unpack 4 - return \ No newline at end of file +def main() { + bool[2] bits = unpack(4); // we need 3 bits to unpack 4 + return; +} diff --git a/zokrates_cli/examples/compile_errors/variable_constant_lt.zok b/zokrates_cli/examples/compile_errors/variable_constant_lt.zok index 86c3979c..a8901de8 100644 --- a/zokrates_cli/examples/compile_errors/variable_constant_lt.zok +++ b/zokrates_cli/examples/compile_errors/variable_constant_lt.zok @@ -1,5 +1,6 @@ -from "EMBED" import bit_array_le +from "EMBED" import bit_array_le; // Calling the `bit_array_le` embed on a non-constant second argument should fail at compile-time -def main(bool[1] a, bool[1] b) -> bool: - return bit_array_le(a, b) \ No newline at end of file +def main(bool[1] a, bool[1] b) -> bool { + return bit_array_le(a, b); +} diff --git a/zokrates_cli/examples/compile_errors/variable_shift.zok b/zokrates_cli/examples/compile_errors/variable_shift.zok index ea7db352..5475d7ff 100644 --- a/zokrates_cli/examples/compile_errors/variable_shift.zok +++ b/zokrates_cli/examples/compile_errors/variable_shift.zok @@ -1,2 +1,4 @@ -def main(u32 a, u32 b) -> u32: - return a >> b \ No newline at end of file +def main(u32 a, u32 b) -> u32 { + return a >> b; +} + diff --git a/zokrates_cli/examples/compile_errors/wrong_member_type.zok b/zokrates_cli/examples/compile_errors/wrong_member_type.zok index c7644f98..2e03a57d 100644 --- a/zokrates_cli/examples/compile_errors/wrong_member_type.zok +++ b/zokrates_cli/examples/compile_errors/wrong_member_type.zok @@ -1,15 +1,16 @@ struct B { - field a + field a; } struct A { - B a + B a; } -def main(): +def main() { A a = A { a: B { a: false } - } - return \ No newline at end of file + }; + return; +} diff --git a/zokrates_cli/examples/compile_errors/wrongsyntax-error.zok b/zokrates_cli/examples/compile_errors/wrongsyntax-error.zok deleted file mode 100644 index 92e05f8b..00000000 --- a/zokrates_cli/examples/compile_errors/wrongsyntax-error.zok +++ /dev/null @@ -1,16 +0,0 @@ -//def wrong(a) -//def (a): -//def wrongtoo(a,): -def main(a): - b = a + 5 - //c = if x < 6 then b ele 5 fi + 2 - //c = 5 + 2 * b + 5 b * 8 + a - //c = 5 + 2 * b + 5 \ a - //c = 5 + 2 *+ b + 5 \ a - //c *= 1 - //c = - //c = 7 + a + - /// comment with one / - //return a + b \ - return a + b - return a diff --git a/zokrates_cli/examples/complex_call_in_constant.zok b/zokrates_cli/examples/complex_call_in_constant.zok index f988ac23..e0b3a1c2 100644 --- a/zokrates_cli/examples/complex_call_in_constant.zok +++ b/zokrates_cli/examples/complex_call_in_constant.zok @@ -1,14 +1,16 @@ -def constant() -> u32: - u32 res = 0 - u32 x = 3 - for u32 y in 0..x do - res = res + 1 - endfor - return res +def constant() -> u32 { + u32 res = 0; + u32 x = 3; + for u32 y in 0..x { + res = res + 1; + } + return res; +} -const u32 CONSTANT = 1 + constant() +const u32 CONSTANT = 1 + constant(); -const u32 OTHER_CONSTANT = 42 +const u32 OTHER_CONSTANT = 42; -def main(field[CONSTANT] a) -> u32: - return CONSTANT + OTHER_CONSTANT \ No newline at end of file +def main(field[CONSTANT] a) -> u32 { + return CONSTANT + OTHER_CONSTANT; +} diff --git a/zokrates_cli/examples/conditions.zok b/zokrates_cli/examples/conditions.zok index 74cd9b9a..11e4abf8 100644 --- a/zokrates_cli/examples/conditions.zok +++ b/zokrates_cli/examples/conditions.zok @@ -1,19 +1,21 @@ struct Foo { - field a + field a; } struct Bar { - Foo[1] foo + Foo[1] foo; } -def isEqual(field a, field b) -> bool: - return a == b +def isEqual(field a, field b) -> bool { + return a == b; +} -def main(field a) -> field: - field b = (a + 5) * 6 - assert(2 * b == a * 12 + 60) - field c = 7 * (b + a) - assert(isEqual(c, 7 * b + 7 * a)) - field k = if [1f, 2] == [3f, 4] then 1 else 3 fi - assert([Bar { foo : [Foo { a: 42 }]}] == [Bar { foo : [Foo { a: 42 }]}]) - return b + c \ No newline at end of file +def main(field a) -> field { + field b = (a + 5) * 6; + assert(2 * b == a * 12 + 60); + field c = 7 * (b + a); + assert(isEqual(c, 7 * b + 7 * a)); + field k = [1f, 2] == [3f, 4] ? 1 : 3; + assert([Bar { foo : [Foo { a: 42 }]}] == [Bar { foo : [Foo { a: 42 }]}]); + return b + c; +} diff --git a/zokrates_cli/examples/constant_in_sig.zok b/zokrates_cli/examples/constant_in_sig.zok index eed5f098..5a14ae4d 100644 --- a/zokrates_cli/examples/constant_in_sig.zok +++ b/zokrates_cli/examples/constant_in_sig.zok @@ -1,7 +1,10 @@ -const u32 N = 1 -def foo(bool[N] arr) -> bool: - return true +const u32 N = 1; -def main(bool[N] arr): - assert(foo(arr)) - return \ No newline at end of file +def foo(bool[N] arr) -> bool { + return true; +} + +def main(bool[N] arr) { + assert(foo(arr)); + return; +} diff --git a/zokrates_cli/examples/constant_index_on_spread_inline.zok b/zokrates_cli/examples/constant_index_on_spread_inline.zok index c876e1aa..7313a279 100644 --- a/zokrates_cli/examples/constant_index_on_spread_inline.zok +++ b/zokrates_cli/examples/constant_index_on_spread_inline.zok @@ -1,2 +1,3 @@ -def main(field[3] a) -> field: - return [...a][0] + [a[0]][0] + [a[0]; 1][0] \ No newline at end of file +def main(field[3] a) -> field { + return [...a][0] + [a[0]][0] + [a[0]; 1][0]; +} \ No newline at end of file diff --git a/zokrates_cli/examples/decimal_literal.zok b/zokrates_cli/examples/decimal_literal.zok index 86ddc938..f82c4f4a 100644 --- a/zokrates_cli/examples/decimal_literal.zok +++ b/zokrates_cli/examples/decimal_literal.zok @@ -1,4 +1,5 @@ -def main() -> field: - field a = 1f - field b = 1_f // allow underscore between the literal and the suffix - return a + b \ No newline at end of file +def main() -> field { + field a = 1f; + field b = 1_f; // allow underscore between the literal and the suffix + return a + b; +} \ No newline at end of file diff --git a/zokrates_cli/examples/empty_spread_propagation.zok b/zokrates_cli/examples/empty_spread_propagation.zok index 02556562..935ce27f 100644 --- a/zokrates_cli/examples/empty_spread_propagation.zok +++ b/zokrates_cli/examples/empty_spread_propagation.zok @@ -1,16 +1,17 @@ -def func() -> bool: - for u32 i in 0..N do - endfor +def func() -> bool { + for u32 i in 0..N {} - u64[N] y = [...[0; N-1], 1] // the rhs should *not* be reduced to [1] because the spread is not empty - u64 q = 0 + u64[N] y = [...[0; N-1], 1]; // the rhs should *not* be reduced to [1] because the spread is not empty + u64 q = 0; - for u32 i in 0..N do + for u32 i in 0..N { q = y[i] - endfor + } - return true + return true; +} -def main(): - assert(func::<2>()) - return \ No newline at end of file +def main() { + assert(func::<2>()); + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/explicit_generic.zok b/zokrates_cli/examples/explicit_generic.zok index bcc490be..0137a0c0 100644 --- a/zokrates_cli/examples/explicit_generic.zok +++ b/zokrates_cli/examples/explicit_generic.zok @@ -1,6 +1,8 @@ -def foo() -> field[N]: - return [42; N] +def foo() -> field[N] { + return [42; N]; +} -def main() -> field[2]: - field a = foo::<3>()[0] - return foo::<2>() \ No newline at end of file +def main() -> field[2] { + field a = foo::<3>()[0]; + return foo::<2>(); +} \ No newline at end of file diff --git a/zokrates_cli/examples/factorization.zok b/zokrates_cli/examples/factorization.zok index 55105c49..b4719376 100644 --- a/zokrates_cli/examples/factorization.zok +++ b/zokrates_cli/examples/factorization.zok @@ -1,5 +1,6 @@ // a and b are factorization of c -def main(field c, private field a, private field b): - field d = a * b - assert(c == d) - return +def main(field c, private field a, private field b) { + field d = a * b; + assert(c == d); + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/flatten.zok b/zokrates_cli/examples/flatten.zok index f9245037..57eab98a 100644 --- a/zokrates_cli/examples/flatten.zok +++ b/zokrates_cli/examples/flatten.zok @@ -1,6 +1,8 @@ // this code needs flattening -def main(field a) -> field: - field b = a + 5 + a * a - field c = b + a + a * b * b - field d = a * b + c * c - return b + c + d +def main(field a) -> field { + field b = a + 5 + a * a; + field c = b + a + a * b * b; + field d = a * b + c * c; + return b + c + d; +} + diff --git a/zokrates_cli/examples/for.zok b/zokrates_cli/examples/for.zok index 4b60c68e..19b6a057 100644 --- a/zokrates_cli/examples/for.zok +++ b/zokrates_cli/examples/for.zok @@ -1,11 +1,12 @@ -def bound(field x) -> u32: - return 41 + 1 +def bound(field x) -> u32 { + return 41 + 1; +} -def main(field a) -> field: - field x = 7 - x = x + 1 - for u32 i in 0..bound(x) + bound(x + 1) do - // x = x + a - x = x + a - endfor - return x +def main(field a) -> field { + field x = 7; + x = x + 1; + for u32 i in 0..bound(x) + bound(x + 1) { + x = x + a; + } + return x; +} diff --git a/zokrates_cli/examples/functions/expressions.zok b/zokrates_cli/examples/functions/expressions.zok index f2096d52..f66240b2 100644 --- a/zokrates_cli/examples/functions/expressions.zok +++ b/zokrates_cli/examples/functions/expressions.zok @@ -1,10 +1,13 @@ -def add(field a,field b) -> field: - field v = a + b - return v +def add(field a,field b) -> field { + field v = a + b; + return v; +} // Expected for inputs 1,1: c=4, d=7, e=10 -def main(field a,field b) -> field: - field c = add(a*2+3*b-a,b-1) - field d = add(a*b+2, a*b*c) - field e = add(add(a,d),add(a,b)) - return e +def main(field a,field b) -> field { + field c = add(a*2+3*b-a,b-1); + field d = add(a*b+2, a*b*c); + field e = add(add(a,d),add(a,b)); + return e; +} + diff --git a/zokrates_cli/examples/functions/functions.zok b/zokrates_cli/examples/functions/functions.zok index e5993764..663f90df 100644 --- a/zokrates_cli/examples/functions/functions.zok +++ b/zokrates_cli/examples/functions/functions.zok @@ -1,6 +1,9 @@ -def add(field f,field g) -> field: - return f+g +def add(field f,field g) -> field { + return f + g; +} + +def main(field a, field b) -> field { + field c = add(a, b); + return c; +} -def main(field a, field b) -> field: - field c = add(a,b) - return c diff --git a/zokrates_cli/examples/functions/lt_comparison.zok b/zokrates_cli/examples/functions/lt_comparison.zok index c6542840..e31220f4 100644 --- a/zokrates_cli/examples/functions/lt_comparison.zok +++ b/zokrates_cli/examples/functions/lt_comparison.zok @@ -1,17 +1,23 @@ -def lt(field a,field b) -> bool: - return a < b +def lt(field a,field b) -> bool { + return a < b; +} -def cutoff() -> field: - return 31337 +def cutoff() -> field { + return 31337; +} -def getThing(u32 index) -> field: - field[6] a = [13, 23, 43, 53, 73, 83] - return a[index] +def getThing(u32 index) -> field { + field[6] a = [13, 23, 43, 53, 73, 83]; + return a[index]; +} -def cubeThing(field thing) -> field: - return thing**3 +def cubeThing(field thing) -> field { + return thing**3; +} + +def main(u32 index) -> bool { + field thing = getThing(index); + thing = cubeThing(thing); + return lt(cutoff(), thing); +} -def main(u32 index) -> bool: - field thing = getThing(index) - thing = cubeThing(thing) - return lt(cutoff(), thing) diff --git a/zokrates_cli/examples/functions/multi_functions.zok b/zokrates_cli/examples/functions/multi_functions.zok index 4e3f8388..be0bd1de 100644 --- a/zokrates_cli/examples/functions/multi_functions.zok +++ b/zokrates_cli/examples/functions/multi_functions.zok @@ -1,13 +1,15 @@ -def add(field a, field b) -> field: - field v = a + b - return v + a +def add(field a, field b) -> field { + field v = a + b; + return v + a; +} -def main(field a, field b,field c, field d) -> field: - field g = a + b - field x = add(a,b) - field y = add(c,d) - g = add(x, g) - g = add(x, g) - field f = c + d + a - g = add(g+a, add(x,b)) - return x + y + g + f +def main(field a, field b, field c, field d) -> field { + field g = a + b; + field x = add(a, b); + field y = add(c, d); + g = add(x, g); + g = add(x, g); + field f = c + d + a; + g = add(g + a, add(x, b)); + return x + y + g + f; +} \ No newline at end of file diff --git a/zokrates_cli/examples/functions/multi_shadowing.zok b/zokrates_cli/examples/functions/multi_shadowing.zok index 989477ef..50a14c3e 100644 --- a/zokrates_cli/examples/functions/multi_shadowing.zok +++ b/zokrates_cli/examples/functions/multi_shadowing.zok @@ -1,11 +1,14 @@ -def add(field a,field b) -> field: - field v = a + b - return v +def add(field a,field b) -> field { + field v = a + b; + return v; +} -def sub(field a, field b) -> field: - return a-b +def sub(field a, field b) -> field { + return a - b; +} -def main(field a, field b) -> field: - field c = add(a,b) - field d = sub(a,b) - return 0 +def main(field a, field b) -> field { + field c = add(a, b); + field d = sub(a, b); + return 0; +} diff --git a/zokrates_cli/examples/functions/no_args_multiple.zok b/zokrates_cli/examples/functions/no_args_multiple.zok index c70ad021..f05acef0 100644 --- a/zokrates_cli/examples/functions/no_args_multiple.zok +++ b/zokrates_cli/examples/functions/no_args_multiple.zok @@ -1,10 +1,13 @@ -def constant() -> field: - return 123123 +def constant() -> field { + return 123123; +} -def add(field a, field b) -> field: - a = constant() - return a + b +def add(field a, field b) -> field { + a = constant(); + return a + b; +} -def main(field a, field b) -> field: - field c = add(a, b + constant()) - return constant() +def main(field a, field b) -> field { + field c = add(a, b + constant()); + return constant(); +} diff --git a/zokrates_cli/examples/functions/shadowing.zok b/zokrates_cli/examples/functions/shadowing.zok index c1a3133c..5c80814b 100644 --- a/zokrates_cli/examples/functions/shadowing.zok +++ b/zokrates_cli/examples/functions/shadowing.zok @@ -1,6 +1,9 @@ -def add(field a,field b) -> field: - return a+b +def add(field a,field b) -> field { + return a + b; +} + +def main(field a,field b) -> field { + field c = add(a, b); + return c; +} -def main(field a,field b) -> field: - field c = add(a,b) - return c diff --git a/zokrates_cli/examples/functions_equivalent.zok b/zokrates_cli/examples/functions_equivalent.zok index 6c253c12..e732827e 100644 --- a/zokrates_cli/examples/functions_equivalent.zok +++ b/zokrates_cli/examples/functions_equivalent.zok @@ -1,3 +1,4 @@ -def main(field a,field b) -> field: - field c = a + b - return c +def main(field a, field b) -> field { + field c = a + b; + return c; +} diff --git a/zokrates_cli/examples/if_eq.zok b/zokrates_cli/examples/if_eq.zok deleted file mode 100644 index d45fe1fd..00000000 --- a/zokrates_cli/examples/if_eq.zok +++ /dev/null @@ -1,7 +0,0 @@ -// example using if-then-else-fi with == -// x = 1 -> 1 + 1 + 1 = 3 -// x = 2 -> 2 + 5 + 125 = 132 -def main(field x) -> field: - field y = if x + 2 == 3 then 1 else 5 fi - field z = if y == x then x**3 else y**3 fi - return x + y + z diff --git a/zokrates_cli/examples/imports/bar.zok b/zokrates_cli/examples/imports/bar.zok index 34eb1c5a..54bb073a 100644 --- a/zokrates_cli/examples/imports/bar.zok +++ b/zokrates_cli/examples/imports/bar.zok @@ -1,7 +1,8 @@ struct Bar {} -const field ONE = 1 -const field BAR = 21 * ONE +const field ONE = 1; +const field BAR = 21 * ONE; -def main() -> field: - return BAR \ No newline at end of file +def main() -> field { + return BAR; +} diff --git a/zokrates_cli/examples/imports/baz.zok b/zokrates_cli/examples/imports/baz.zok index 84cc641d..5834f904 100644 --- a/zokrates_cli/examples/imports/baz.zok +++ b/zokrates_cli/examples/imports/baz.zok @@ -1,6 +1,7 @@ struct Baz {} -const field BAZ = 123 +const field BAZ = 123; -def main() -> field: - return BAZ \ No newline at end of file +def main() -> field { + return BAZ; +} diff --git a/zokrates_cli/examples/imports/foo.zok b/zokrates_cli/examples/imports/foo.zok index 8dddfd8b..2160fb2e 100644 --- a/zokrates_cli/examples/imports/foo.zok +++ b/zokrates_cli/examples/imports/foo.zok @@ -1,10 +1,11 @@ -from "./baz" import Baz -from "./baz" import main as my_function -import "./baz" +from "./baz" import Baz; +from "./baz" import main as my_function; +import "./baz"; -const field FOO = 144 +const field FOO = 144; -def main() -> field: - Baz b = Baz {} - assert(baz() == my_function()) - return FOO \ No newline at end of file +def main() -> field { + Baz b = Baz {}; + assert(baz() == my_function()); + return FOO; +} diff --git a/zokrates_cli/examples/imports/import_constants.zok b/zokrates_cli/examples/imports/import_constants.zok index 2abaaea5..3d1b2d54 100644 --- a/zokrates_cli/examples/imports/import_constants.zok +++ b/zokrates_cli/examples/imports/import_constants.zok @@ -1,6 +1,7 @@ -from "./foo" import FOO -from "./bar" import BAR -from "./baz" import BAZ +from "./foo" import FOO; +from "./bar" import BAR; +from "./baz" import BAZ; -def main() -> bool: - return FOO == BAR + BAZ \ No newline at end of file +def main() -> bool { + return FOO == BAR + BAZ; +} diff --git a/zokrates_cli/examples/imports/import_functions.zok b/zokrates_cli/examples/imports/import_functions.zok index 32628eb9..1174c1aa 100644 --- a/zokrates_cli/examples/imports/import_functions.zok +++ b/zokrates_cli/examples/imports/import_functions.zok @@ -1,6 +1,7 @@ -import "./foo" -import "./bar" -import "./baz" +import "./foo"; +import "./bar"; +import "./baz"; -def main() -> bool: - return foo() == bar() + baz() \ No newline at end of file +def main() -> bool { + return foo() == bar() + baz(); +} diff --git a/zokrates_cli/examples/imports/import_multiple.zok b/zokrates_cli/examples/imports/import_multiple.zok index 7f5b1f6a..11154fcc 100644 --- a/zokrates_cli/examples/imports/import_multiple.zok +++ b/zokrates_cli/examples/imports/import_multiple.zok @@ -1,5 +1,6 @@ -from "./bar" import Bar, main as f +from "./bar" import Bar, main as f; -def main() -> field: - Bar bar = Bar {} - return f() \ No newline at end of file +def main() -> field { + Bar bar = Bar {}; + return f(); +} diff --git a/zokrates_cli/examples/imports/import_structs.zok b/zokrates_cli/examples/imports/import_structs.zok index 61c94b02..daaeea2d 100644 --- a/zokrates_cli/examples/imports/import_structs.zok +++ b/zokrates_cli/examples/imports/import_structs.zok @@ -1,8 +1,9 @@ -from "./bar" import Bar as MyBar -from "./bar" import Bar +from "./bar" import Bar as MyBar; +from "./bar" import Bar; -def main(): - MyBar my_bar = MyBar {} - Bar bar = Bar {} - assert(my_bar == bar) - return \ No newline at end of file +def main() { + MyBar my_bar = MyBar {}; + Bar bar = Bar {}; + assert(my_bar == bar); + return; +} diff --git a/zokrates_cli/examples/imports/import_with_alias.zok b/zokrates_cli/examples/imports/import_with_alias.zok index 5e013691..164f0d89 100644 --- a/zokrates_cli/examples/imports/import_with_alias.zok +++ b/zokrates_cli/examples/imports/import_with_alias.zok @@ -1,8 +1,9 @@ -from "./bar" import main as bar -from "./baz" import BAZ as baz -import "./foo" as f +from "./bar" import main as bar; +from "./baz" import BAZ as baz; +import "./foo" as f; -def main() -> field: - field foo = f() - assert(foo == bar() + baz) - return foo \ No newline at end of file +def main() -> field { + field foo = f(); + assert(foo == bar() + baz); + return foo; +} diff --git a/zokrates_cli/examples/imports/inliner_state.zok b/zokrates_cli/examples/imports/inliner_state.zok index 321ee5a0..034c580c 100644 --- a/zokrates_cli/examples/imports/inliner_state.zok +++ b/zokrates_cli/examples/imports/inliner_state.zok @@ -1,12 +1,14 @@ -from "./inliner_state_aux" import main as test +from "./inliner_state_aux" import main as test; // we check that the constant inliner does not get corrupted // notice that the constant generic has the same name as the constant `K` // defined in the `test1.zok` module -def tmp(): - u32 junk = test() + K - return +def tmp() { + u32 junk = test() + K; + return; +} // dummy main -def main(): - return \ No newline at end of file +def main() { + return; +} diff --git a/zokrates_cli/examples/imports/inliner_state_aux.zok b/zokrates_cli/examples/imports/inliner_state_aux.zok index f828089d..a44c8563 100644 --- a/zokrates_cli/examples/imports/inliner_state_aux.zok +++ b/zokrates_cli/examples/imports/inliner_state_aux.zok @@ -1,5 +1,6 @@ // the issue only shows if `K` is an array, renaming this constant to something else works -const u32[1] K = [1] +const u32[1] K = [1]; -def main() -> u32: - return K[0] \ No newline at end of file +def main() -> u32 { + return K[0]; +} diff --git a/zokrates_cli/examples/left_side_call.zok b/zokrates_cli/examples/left_side_call.zok index d01ae619..c0884f1a 100644 --- a/zokrates_cli/examples/left_side_call.zok +++ b/zokrates_cli/examples/left_side_call.zok @@ -1,6 +1,9 @@ -def foo() -> field: - return 1 +def foo() -> field { + return 1; +} + +def main() { + assert(foo() + (1 + 44*3) == 134); + return; +} -def main(): - assert(foo() + (1 + 44*3) == 134) - return diff --git a/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok b/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok index bf1be2e9..a0320bed 100644 --- a/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok +++ b/zokrates_cli/examples/merkleTree/pedersenPathProof3.zok @@ -1,20 +1,20 @@ -import "hashes/pedersen/512bit" as hash -import "hashes/utils/256bitsDirectionHelper" as multiplex +import "hashes/pedersen/512bit" as hash; +import "hashes/utils/256bitsDirectionHelper" as multiplex; -const u32 DEPTH = 3 +const u32 DEPTH = 3; // Merke-Tree inclusion proof for tree depth 4 using SNARK-efficient pedersen hashes // directionSelector => true if current digest is on the rhs of the hash -def main(u32[8] root, private u32[8] leaf, private bool[DEPTH] directionSelector, private u32[DEPTH][8] path) -> bool: +def main(u32[8] root, private u32[8] leaf, private bool[DEPTH] directionSelector, private u32[DEPTH][8] path) -> bool { // Start from the leaf - u32[8] digest = leaf + u32[8] digest = leaf; // Loop up the tree - for u32 i in 0..DEPTH do - u32[16] preimage = multiplex(directionSelector[i], digest, path[i]) - digest = hash(preimage) - endfor - - return digest == root + for u32 i in 0..DEPTH { + u32[16] preimage = multiplex(directionSelector[i], digest, path[i]); + digest = hash(preimage); + } + return digest == root; +} \ No newline at end of file diff --git a/zokrates_cli/examples/merkleTree/sha256PathProof3.zok b/zokrates_cli/examples/merkleTree/sha256PathProof3.zok index c2cd8288..3fb6e225 100644 --- a/zokrates_cli/examples/merkleTree/sha256PathProof3.zok +++ b/zokrates_cli/examples/merkleTree/sha256PathProof3.zok @@ -1,23 +1,26 @@ -import "hashes/sha256/512bit" as hash -import "hashes/utils/256bitsDirectionHelper" as multiplex +import "hashes/sha256/512bit" as hash; +import "hashes/utils/256bitsDirectionHelper" as multiplex; -const u32 DEPTH = 3 +const u32 DEPTH = 3; -def select(bool condition, u32[8] left, u32[8] right) -> (u32[8], u32[8]): - return if condition then right else left fi, if condition then left else right fi +def select(bool condition, u32[8] left, u32[8] right) -> (u32[8], u32[8]) { + return condition ? right : left, condition ? left : right +} // Merke-Tree inclusion proof for tree depth 4 using sha256 // directionSelector => true if current digest is on the rhs of the hash -def main(u32[8] root, private u32[8] leaf, private bool[DEPTH] directionSelector, private u32[DEPTH][8] path) -> bool: +def main(u32[8] root, private u32[8] leaf, private bool[DEPTH] directionSelector, private u32[DEPTH][8] path) -> bool { // Start from the leaf - u32[8] digest = leaf + u32[8] digest = leaf; // Loop up the tree - for u32 i in 0..DEPTH do - u32[8] left, u32[8] right = select(directionSelector[i], digest, path[i]) - digest = hash(left, right) - endfor + for u32 i in 0..DEPTH { + u32[8] left, u32[8] right = select(directionSelector[i], digest, path[i]); + digest = hash(left, right); + } + + return digest == root; +} - return digest == root diff --git a/zokrates_cli/examples/multi_return.zok b/zokrates_cli/examples/multi_return.zok index f689b1a2..ea2067e4 100644 --- a/zokrates_cli/examples/multi_return.zok +++ b/zokrates_cli/examples/multi_return.zok @@ -1,7 +1,9 @@ -def foo(field a) -> (field, field, field, field): - field b = 12*a - return a, 2*a, 5*b, a*b +def foo(field a) -> (field, field, field, field) { + field b = 12 * a; + return a, 2 * a, 5 * b, a * b; +} -def main(field i): - field x, field y, field z, field t = foo(i) - return +def main(field i) { + field x, field y, field z, field t = foo(i); + return; +} diff --git a/zokrates_cli/examples/multi_return_sum.zok b/zokrates_cli/examples/multi_return_sum.zok index 786abf81..da539c55 100644 --- a/zokrates_cli/examples/multi_return_sum.zok +++ b/zokrates_cli/examples/multi_return_sum.zok @@ -1,5 +1,8 @@ -def foo() -> (field, field): - return 1, 2 -def main() -> (field, field): - field a, field b = foo() - return a + b, b - a \ No newline at end of file +def foo() -> (field, field) { + return 1, 2; +} + +def main() -> (field, field) { + field a, field b = foo(); + return a + b, b - a; +} diff --git a/zokrates_cli/examples/multiple_witnesses.zok b/zokrates_cli/examples/multiple_witnesses.zok index 6b34e765..e41d4631 100644 --- a/zokrates_cli/examples/multiple_witnesses.zok +++ b/zokrates_cli/examples/multiple_witnesses.zok @@ -1,4 +1,6 @@ // this code does not need to be flattened -def main(field x, field a, field b) -> field: - assert(a == b * 7) - return x + a + b +def main(field x, field a, field b) -> field { + assert(a == b * 7); + return x + a + b; +} + diff --git a/zokrates_cli/examples/n_choose_k.zok b/zokrates_cli/examples/n_choose_k.zok index b5e820d7..5eddc1a5 100644 --- a/zokrates_cli/examples/n_choose_k.zok +++ b/zokrates_cli/examples/n_choose_k.zok @@ -1,14 +1,16 @@ -import "utils/casts/u32_to_field" as to_field +import "utils/casts/u32_to_field" as to_field; // Binomial Coeffizient, n!/(k!*(n-k)!). -def fac(field x) -> field: - field f = 1 - field counter = 0 - for u32 i in 1..100 do - f = if counter == x then f else f * to_field(i) fi - counter = if counter == x then counter else counter + 1 fi - endfor - return f +def fac(field x) -> field { + field f = 1; + field counter = 0; + for u32 i in 1..100 { + f = counter == x ? f : f * to_field(i); + counter = counter == x ? counter : counter + 1; + } + return f; +} -def main(field n, field k) -> field: - return fac(n)/(fac(k)*fac(n-k)) +def main(field n, field k) -> field { + return fac(n) / (fac(k) * fac(n - k)); +} diff --git a/zokrates_cli/examples/no_flatten.zok b/zokrates_cli/examples/no_flatten.zok index 08f05fb9..c3c93a77 100644 --- a/zokrates_cli/examples/no_flatten.zok +++ b/zokrates_cli/examples/no_flatten.zok @@ -1,6 +1,8 @@ // this code does not need to be flattened -def main(field x, field y, field z) -> field: - field a = x + 3*y - z *2 - x * 12 - assert(3*y - z *2 - x * 12 == a - x) - assert((x + y) - ((z + 3*x) - y) == (x - y) + ((2*x - 4*y) + (4*y - 2*z))) - return x +def main(field x, field y, field z) -> field { + field a = x + 3 * y - z * 2 - x * 12; + assert(3*y - z * 2 - x * 12 == a - x); + assert((x + y) - ((z + 3*x) - y) == (x - y) + ((2*x - 4*y) + (4*y - 2*z))); + return x; +} + diff --git a/zokrates_cli/examples/pow.zok b/zokrates_cli/examples/pow.zok index 4b76748f..09200e24 100644 --- a/zokrates_cli/examples/pow.zok +++ b/zokrates_cli/examples/pow.zok @@ -1,16 +1,17 @@ -def main(): - field x = 2**4 - assert(x == 16) - x = x**2 - assert(x == 256) - field y = 3**3 - assert(y == 27) - field z = y**2 - assert(z == 729) - field a = 5**2 - assert(a == 25) - a = a**2 - assert(a == 625) - a = 5**5 - assert(a == 3125) - return +def main() { + field x = 2**4; + assert(x == 16); + x = x**2; + assert(x == 256); + field y = 3**3; + assert(y == 27); + field z = y**2; + assert(z == 729); + field a = 5**2; + assert(a == 25); + a = a**2; + assert(a == 625); + a = 5**5; + assert(a == 3125); + return; +} diff --git a/zokrates_cli/examples/pragma.zok b/zokrates_cli/examples/pragma.zok index 28f94e2a..bcce00ad 100644 --- a/zokrates_cli/examples/pragma.zok +++ b/zokrates_cli/examples/pragma.zok @@ -1,4 +1,5 @@ #pragma curve bn128 -def main(): - return \ No newline at end of file +def main() { + return; +} \ No newline at end of file diff --git a/zokrates_cli/examples/propagate.zok b/zokrates_cli/examples/propagate.zok index 543ac20c..e5b3e0e7 100644 --- a/zokrates_cli/examples/propagate.zok +++ b/zokrates_cli/examples/propagate.zok @@ -1,9 +1,10 @@ -def main() -> field: - field a = 1 + 2 + 3 - field b = if 1 < a then 3 else a + 3 fi - field c = if b + a == 2 then 1 else b fi - for u32 e in 0..2 do - field g = 4 - c = c + g - endfor - return c * a \ No newline at end of file +def main() -> field { + field a = 1 + 2 + 3; + field b = 1 < a ? 3 : a + 3; + field c = b + a == 2 ? 1 : b; + for u32 e in 0..2 { + field g = 4; + c = c + g; + } + return c * a; +} diff --git a/zokrates_cli/examples/propagate_call.zok b/zokrates_cli/examples/propagate_call.zok index d2dba6f8..41f89f0d 100644 --- a/zokrates_cli/examples/propagate_call.zok +++ b/zokrates_cli/examples/propagate_call.zok @@ -1,7 +1,9 @@ -def foo(field a, field b) -> (field, field): - assert(a == b) - return a, b +def foo(field a, field b) -> (field, field) { + assert(a == b); + return a, b; +} -def main() -> field: - field a, field b = foo(1, 1) - return a + b \ No newline at end of file +def main() -> field { + field a, field b = foo(1, 1); + return a + b; +} diff --git a/zokrates_cli/examples/reassignment.zok b/zokrates_cli/examples/reassignment.zok index 1d48bfad..de4ac976 100644 --- a/zokrates_cli/examples/reassignment.zok +++ b/zokrates_cli/examples/reassignment.zok @@ -1,7 +1,9 @@ -def main(field x) -> field: - field a = x + 5 - field b = a + x - a = 7 - field c = a + b - a = a + 5 - return a + c +def main(field x) -> field { + field a = x + 5; + field b = a + x; + a = 7; + field c = a + b; + a = a + 5; + return a + c; +} + diff --git a/zokrates_cli/examples/reduceable_exponent.zok b/zokrates_cli/examples/reduceable_exponent.zok index b17bb1c0..9bd0da71 100644 --- a/zokrates_cli/examples/reduceable_exponent.zok +++ b/zokrates_cli/examples/reduceable_exponent.zok @@ -1,3 +1,4 @@ -def main() -> field: - u32 a = 2 - return 2**(a * 2 + 2) \ No newline at end of file +def main() -> field { + u32 a = 2; + return 2**(a * 2 + 2); +} diff --git a/zokrates_cli/examples/runtime_errors/div_zero_field.zok b/zokrates_cli/examples/runtime_errors/div_zero_field.zok index dd0668f3..9d9cc2ea 100644 --- a/zokrates_cli/examples/runtime_errors/div_zero_field.zok +++ b/zokrates_cli/examples/runtime_errors/div_zero_field.zok @@ -1,3 +1,4 @@ -def main(field x): - field y = 1 / x - return \ No newline at end of file +def main(field x) { + field y = 1 / x; + return; +} diff --git a/zokrates_cli/examples/runtime_errors/div_zero_uint.zok b/zokrates_cli/examples/runtime_errors/div_zero_uint.zok index b307a5c9..9858b7ff 100644 --- a/zokrates_cli/examples/runtime_errors/div_zero_uint.zok +++ b/zokrates_cli/examples/runtime_errors/div_zero_uint.zok @@ -1,3 +1,4 @@ -def main(u8 x): - u8 y = 0x01 / x - return \ No newline at end of file +def main(u8 x) { + u8 y = 0x01 / x; + return; +} diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok index 4cc497c7..cc64d027 100644 --- a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok +++ b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1.zok @@ -1,11 +1,12 @@ -from "field" import FIELD_SIZE_IN_BITS +from "field" import FIELD_SIZE_IN_BITS; // we can compare numbers whose difference fits in (pbits - 2) bits // It should not work for the maxvalue = 2^(pbits - 2) - 1 augmented by one // /!\ should be called with a = 0 -def main(field a) -> bool: - u32 pbits = FIELD_SIZE_IN_BITS +def main(field a) -> bool { + u32 pbits = FIELD_SIZE_IN_BITS; // we added a = 0 to prevent the condition to be evaluated at compile time - field maxvalue = a + (2**(pbits - 2) - 1) - return a < maxvalue + 1 \ No newline at end of file + field maxvalue = a + (2**(pbits - 2) - 1); + return a < maxvalue + 1; +} diff --git a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1_sym.zok b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1_sym.zok index fb6e71c5..fe3fb431 100644 --- a/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1_sym.zok +++ b/zokrates_cli/examples/runtime_errors/lt_overflow_max_plus_1_sym.zok @@ -1,11 +1,12 @@ -from "field" import FIELD_SIZE_IN_BITS +from "field" import FIELD_SIZE_IN_BITS; // we can compare numbers whose difference fits in (pbits - 2) bits // It should not work for the maxvalue = 2^(pbits - 2) - 1 augmented by one // /!\ should be called with a = 0 -def main(field a) -> bool: - u32 pbits = FIELD_SIZE_IN_BITS +def main(field a) -> bool { + u32 pbits = FIELD_SIZE_IN_BITS; // we added a = 0 to prevent the condition to be evaluated at compile time - field maxvalue = a + (2**(pbits - 2) - 1) - return maxvalue + 1 < a \ No newline at end of file + field maxvalue = a + (2**(pbits - 2) - 1); + return maxvalue + 1 < a; +} diff --git a/zokrates_cli/examples/simple_add.zok b/zokrates_cli/examples/simple_add.zok index 9853b69c..4ee36df2 100644 --- a/zokrates_cli/examples/simple_add.zok +++ b/zokrates_cli/examples/simple_add.zok @@ -1,3 +1,4 @@ // only using add, no need to flatten -def main(field a, field b) -> field: - return a + b +def main(field a, field b) -> field { + return a + b; +} diff --git a/zokrates_cli/examples/simple_conditional.zok b/zokrates_cli/examples/simple_conditional.zok new file mode 100644 index 00000000..ff39a91c --- /dev/null +++ b/zokrates_cli/examples/simple_conditional.zok @@ -0,0 +1,8 @@ +// simple ifelse example +// x = 2 -> 2 + 1 + 2**3 = 11 +// x = 5 -> 5 + 5 + 5**3 = 135 +def main(field x) -> field { + field y = x < 3 ? 1 : 5; + field z = y < x ? x**3 : y**3: + return x + y + z; +} diff --git a/zokrates_cli/examples/simple_ifelse.zok b/zokrates_cli/examples/simple_ifelse.zok deleted file mode 100644 index b478061b..00000000 --- a/zokrates_cli/examples/simple_ifelse.zok +++ /dev/null @@ -1,7 +0,0 @@ -// simple ifelse example -// x = 2 -> 2 + 1 + 2**3 = 11 -// x = 5 -> 5 + 5 + 5**3 = 135 -def main(field x) -> field: - field y = if x < 3 then 1 else 5 fi - field z = if y < x then x**3 else y**3 fi - return x + y + z diff --git a/zokrates_cli/examples/simple_mul.zok b/zokrates_cli/examples/simple_mul.zok index ec81fcef..9da0461d 100644 --- a/zokrates_cli/examples/simple_mul.zok +++ b/zokrates_cli/examples/simple_mul.zok @@ -1,3 +1,3 @@ - -def main(field a, field b, field c) -> field: - return a * b * c +def main(field a, field b, field c) -> field { + return a * b * c; +} diff --git a/zokrates_cli/examples/spaces_tabs_comments.zok b/zokrates_cli/examples/spaces_tabs_comments.zok index 2c3ea970..58467e7c 100644 --- a/zokrates_cli/examples/spaces_tabs_comments.zok +++ b/zokrates_cli/examples/spaces_tabs_comments.zok @@ -2,12 +2,14 @@ // comment -def main(field x) -> field: - // comment - field y = x**3 - field b = x**5 +def main(field x) -> field { + // comment + field y = x**3; + field b = x**5; + + field c = x / 2; + field d = (2 * x + 3 * b) * (x - b); + return y + x + y + c + d; + // comment +} - field c = x / 2 - field d = (2 * x + 3 * b) * (x - b) - return y + x + y + c + d -// comment diff --git a/zokrates_cli/examples/struct_generic_inference.zok b/zokrates_cli/examples/struct_generic_inference.zok index 0e094a2a..95fd56b3 100644 --- a/zokrates_cli/examples/struct_generic_inference.zok +++ b/zokrates_cli/examples/struct_generic_inference.zok @@ -1,15 +1,17 @@ struct SomeStruct { - u64[N] f + u64[N] f; } -def myFct(SomeStruct ignored) -> u32[N2]: - assert(2*N == N2) - return [N3; N2] +def myFct(SomeStruct ignored) -> u32[N2] { + assert(2*N == N2); + return [N3; N2]; +} -const u32 N = 3 +const u32 N = 3; -const u32 N2 = 2*N +const u32 N2 = 2*N; -def main(SomeStruct arg) -> u32: - u32[N2] someVariable = myFct::<_, _, 42>(arg) - return someVariable[0] \ No newline at end of file +def main(SomeStruct arg) -> u32 { + u32[N2] someVariable = myFct::<_, _, 42>(arg); + return someVariable[0]; +} diff --git a/zokrates_cli/examples/structs/add.zok b/zokrates_cli/examples/structs/add.zok index e8e1f839..cda9b7f3 100644 --- a/zokrates_cli/examples/structs/add.zok +++ b/zokrates_cli/examples/structs/add.zok @@ -1,16 +1,18 @@ struct Point { - field x - field y + field x; + field y; } -def main(Point p, Point q) -> Point: +def main(Point p, Point q) -> Point { + field a = 42; + field d = 21; - field a = 42 - field d = 21 - - field dpxpyqxqy = d * p.x * p.y * q.x * q.y + 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) - } + }; +} + + diff --git a/zokrates_cli/examples/structs/constant_in_member.zok b/zokrates_cli/examples/structs/constant_in_member.zok index 95ea5712..1388b51d 100644 --- a/zokrates_cli/examples/structs/constant_in_member.zok +++ b/zokrates_cli/examples/structs/constant_in_member.zok @@ -1,11 +1,12 @@ -const u32 SIZE = 42 +const u32 SIZE = 42; struct Foo { - field[SIZE] foo + field[SIZE] foo; } -def main(): - Foo f = Foo { +def main() { + Foo f = Foo { foo: [42; SIZE] - } - return \ No newline at end of file + }; + return; +} diff --git a/zokrates_cli/examples/structs/generic.zok b/zokrates_cli/examples/structs/generic.zok index 12f6d9c8..cba9b471 100644 --- a/zokrates_cli/examples/structs/generic.zok +++ b/zokrates_cli/examples/structs/generic.zok @@ -1,13 +1,14 @@ struct B

{ - field[P] a + field[P] a; } struct A { - field[N] a - B b + field[N] a; + B b; } -def main(A<2> a) -> bool: - u32 SIZE = 1 + 1 - A b = A { a: [1, 2], b: B { a: [1, 2] } } - return a == b \ No newline at end of file +def main(A<2> a) -> bool { + u32 SIZE = 1 + 1; + A b = A { a: [1, 2], b: B { a: [1, 2] } } ; + return a == b; +} diff --git a/zokrates_cli/examples/structs/nested_access.zok b/zokrates_cli/examples/structs/nested_access.zok index 42f285f5..b9de6081 100644 --- a/zokrates_cli/examples/structs/nested_access.zok +++ b/zokrates_cli/examples/structs/nested_access.zok @@ -1,11 +1,12 @@ struct Foo { - field a + field a; } struct Bar { - Foo foo + Foo foo; } -def main(Bar b): - field a = b.foo.a - return \ No newline at end of file +def main(Bar b) { + field a = b.foo.a; + return; +} diff --git a/zokrates_cli/examples/structs/set_member.zok b/zokrates_cli/examples/structs/set_member.zok index 305b28e5..675c9434 100644 --- a/zokrates_cli/examples/structs/set_member.zok +++ b/zokrates_cli/examples/structs/set_member.zok @@ -1,14 +1,14 @@ struct Bar { - field[2] c - bool d + field[2] c; + bool d; } struct Foo { - Bar a - bool b + Bar a; + bool b; } -def main() -> Foo: +def main() -> Foo { Foo[2] f = [ Foo { a: Bar { @@ -24,6 +24,7 @@ def main() -> Foo: }, b: true } - ] - f[0].a.c = [42, 43] - return f[0] + ]; + f[0].a.c = [42, 43]; + return f[0]; +} diff --git a/zokrates_cli/examples/sub.zok b/zokrates_cli/examples/sub.zok index 4c4b7bbd..653d18f2 100644 --- a/zokrates_cli/examples/sub.zok +++ b/zokrates_cli/examples/sub.zok @@ -1,7 +1,8 @@ // only using sub, no need to flatten -def main(field a) -> field: - field b = a + 100 - field c = b + a + b - field d = b - a - 3 - a - field e = d + 3 - a - return d + c + e +def main(field a) -> field { + field b = a + 100; + field c = b + a + b; + field d = b - a - 3 - a; + field e = d + 3 - a; + return d + c + e; +} diff --git a/zokrates_cli/examples/sudoku/prime_sudoku_checker.zok b/zokrates_cli/examples/sudoku/prime_sudoku_checker.zok index aec77917..19ec2cf6 100644 --- a/zokrates_cli/examples/sudoku/prime_sudoku_checker.zok +++ b/zokrates_cli/examples/sudoku/prime_sudoku_checker.zok @@ -8,8 +8,8 @@ // -------------------------- // | c21 | c22 || d21 | d22 | -type Grid = field[N][N] -const field[4] PRIMES = [2, 3, 5, 7] +type Grid = field[N][N]; +const field[4] PRIMES = [2, 3, 5, 7]; // We encode values in the following way: // 1 -> 2 @@ -19,49 +19,51 @@ const field[4] PRIMES = [2, 3, 5, 7] // returns true if there are no duplicates // assumption: `a, b, c, d` are all in `{ 2, 3, 5, 7 }` -def checkNoDuplicates(field a, field b, field c, field d) -> bool: - // as `{ 2, 3, 5, 7 }` are primes, the set `{ a, b, c, d }` is equal to the set `{ 2, 3, 5, 7}` if and only if the products match - return a * b * c * d == PRIMES[0] * PRIMES[1] * PRIMES[2] * PRIMES[3] +def checkNoDuplicates(field a, field b, field c, field d) -> bool { + // as `{ 2, 3, 5, 7 }` are primes, the set `{ a, b, c, d }` is equal to the set `{ 2, 3, 5, 7}` if and only if the products match + return a * b * c * d == PRIMES[0] * PRIMES[1] * PRIMES[2] * PRIMES[3]; +} // returns true if and only if `x` is one of the `4` primes -def validateInput(field x) -> bool: - field res = 1 +def validateInput(field x) -> bool { + field res = 1; - for u32 i in 0..4 do - res = res * (x - PRIMES[i]) - endfor + for u32 i in 0..4 { + res = res * (x - PRIMES[i]); + } - return res == 0 + return res == 0; +} // variables naming: box'row''column' -def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> bool: +def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> bool { - Grid<4> a = [[a11, a12, b11, b12], [a21, a22, b21, b22], [c11, c12, d11, d12], [c21, c22, d21, d22]] + Grid<4> a = [[a11, a12, b11, b12], [a21, a22, b21, b22], [c11, c12, d11, d12], [c21, c22, d21, d22]]; + bool res = true; - bool res = true + // go through the whole grid and check that all elements are valid + for u32 i in 0..4 { + for u32 j in 0..4 { + res = res && validateInput(a[i][j]); + } + } - // go through the whole grid and check that all elements are valid - for u32 i in 0..4 do - for u32 j in 0..4 do - res = res && validateInput(a[i][j]) - endfor - endfor + // go through the 4 2x2 boxes and check that they do not contain duplicates + for u32 i in 0..1 { + for u32 j in 0..1 { + res = res && checkNoDuplicates(a[2*i][2*i], a[2*i][2*i + 1], a[2*i + 1][2*i], a[2*i + 1][2*i + 1]); + } + } - // go through the 4 2x2 boxes and check that they do not contain duplicates - for u32 i in 0..1 do - for u32 j in 0..1 do - res = res && checkNoDuplicates(a[2*i][2*i], a[2*i][2*i + 1], a[2*i + 1][2*i], a[2*i + 1][2*i + 1]) - endfor - endfor + // go through the 4 rows and check that they do not contain duplicates + for u32 i in 0..4 { + res = res && checkNoDuplicates(a[i][0], a[i][1], a[i][2], a[i][3]); + } - // go through the 4 rows and check that they do not contain duplicates - for u32 i in 0..4 do - res = res && checkNoDuplicates(a[i][0], a[i][1], a[i][2], a[i][3]) - endfor + // go through the 4 columns and check that they do not contain duplicates + for u32 j in 0..4 { + res = res && checkNoDuplicates(a[0][j], a[1][j], a[2][j], a[3][j]); + } - // go through the 4 columns and check that they do not contain duplicates - for u32 j in 0..4 do - res = res && checkNoDuplicates(a[0][j], a[1][j], a[2][j], a[3][j]) - endfor - - return res + return res; +} diff --git a/zokrates_cli/examples/sudoku/sudoku_checker.zok b/zokrates_cli/examples/sudoku/sudoku_checker.zok index 0339e8a8..bece837d 100644 --- a/zokrates_cli/examples/sudoku/sudoku_checker.zok +++ b/zokrates_cli/examples/sudoku/sudoku_checker.zok @@ -10,66 +10,69 @@ // We use a naive encoding of the values as `[1, 2, 3, 4]` and rely on if-else statements to detect duplicates -def countDuplicates(field e11,field e12,field e21,field e22) -> field: - field duplicates = if e11 == e12 then 1 else 0 fi - duplicates = duplicates + if e11 == e21 then 1 else 0 fi - duplicates = duplicates + if e11 == e22 then 1 else 0 fi - duplicates = duplicates + if e12 == e21 then 1 else 0 fi - duplicates = duplicates + if e12 == e21 then 1 else 0 fi - duplicates = duplicates + if e21 == e22 then 1 else 0 fi - return duplicates +def countDuplicates(field e11, field e12, field e21, field e22) -> field { + field duplicates = e11 == e12 ? 1 : 0; + duplicates = duplicates + e11 == e21 ? 1 : 0; + duplicates = duplicates + e11 == e22 ? 1 : 0; + duplicates = duplicates + e12 == e21 ? 1 : 0; + duplicates = duplicates + e12 == e21 ? 1 : 0; + duplicates = duplicates + e21 == e22 ? 1 : 0; + return duplicates; +} // returns 0 for x in (1..4) -def validateInput(field x) -> bool: - return (x-1)*(x-2)*(x-3)*(x-4) == 0 +def validateInput(field x) -> bool { + return (x - 1) * (x - 2) * (x - 3) * (x - 4) == 0; +} // variables naming: box'row''column' -def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> bool: +def main(field a21, field b11, field b22, field c11, field c22, field d21, private field a11, private field a12, private field a22, private field b12, private field b21, private field c12, private field c21, private field d11, private field d12, private field d22) -> bool { - // validate inputs - assert(validateInput(a11)) - assert(validateInput(a12)) - assert(validateInput(a21)) - assert(validateInput(a22)) + // validate inputs + assert(validateInput(a11)); + assert(validateInput(a12)); + assert(validateInput(a21)); + assert(validateInput(a22)); - assert(validateInput(b11)) - assert(validateInput(b12)) - assert(validateInput(b21)) - assert(validateInput(b22)) + assert(validateInput(b11)); + assert(validateInput(b12)); + assert(validateInput(b21)); + assert(validateInput(b22)); - assert(validateInput(c11)) - assert(validateInput(c12)) - assert(validateInput(c21)) - assert(validateInput(c22)) + assert(validateInput(c11)); + assert(validateInput(c12)); + assert(validateInput(c21)); + assert(validateInput(c22)); - assert(validateInput(d11)) - assert(validateInput(d12)) - assert(validateInput(d21)) - assert(validateInput(d22)) + assert(validateInput(d11)); + assert(validateInput(d12)); + assert(validateInput(d21)); + assert(validateInput(d22)); - field duplicates = 0 // globally counts duplicate entries in boxes, rows and columns + field duplicates = 0; // globally counts duplicate entries in boxes, rows and columns - // check box correctness + // check box correctness - // no duplicates - duplicates = duplicates + countDuplicates(a11,a12,a21,a22) - duplicates = duplicates + countDuplicates(b11,b12,b21,b22) - duplicates = duplicates + countDuplicates(c11,c12,c21,c22) - duplicates = duplicates + countDuplicates(d11,d12,d21,d22) + // no duplicates + duplicates = duplicates + countDuplicates(a11, a12, a21, a22); + duplicates = duplicates + countDuplicates(b11, b12, b21, b22); + duplicates = duplicates + countDuplicates(c11, c12, c21, c22); + duplicates = duplicates + countDuplicates(d11, d12, d21, d22); - // check row correctness + // check row correctness - duplicates = duplicates + countDuplicates(a11,a12,b11,b12) - duplicates = duplicates + countDuplicates(a21,a22,b21,b22) - duplicates = duplicates + countDuplicates(c11,c12,d11,d12) - duplicates = duplicates + countDuplicates(c21,c22,d21,d22) + duplicates = duplicates + countDuplicates(a11, a12, b11, b12); + duplicates = duplicates + countDuplicates(a21, a22, b21, b22); + duplicates = duplicates + countDuplicates(c11, c12, d11, d12); + duplicates = duplicates + countDuplicates(c21, c22, d21, d22); - // check column correctness + // check column correctness - duplicates = duplicates + countDuplicates(a11,a21,c11,c21) - duplicates = duplicates + countDuplicates(a12,a22,c12,c22) - duplicates = duplicates + countDuplicates(b11,b21,d11,d21) - duplicates = duplicates + countDuplicates(b12,b22,d12,d22) + duplicates = duplicates + countDuplicates(a11, a21, c11, c21); + duplicates = duplicates + countDuplicates(a12, a22, c12, c22); + duplicates = duplicates + countDuplicates(b11, b21, d11, d21); + duplicates = duplicates + countDuplicates(b12, b22, d12, d22); - // the solution is correct if and only if there are no duplicates - return duplicates == 0 + // the solution is correct if and only if there are no duplicates + return duplicates == 0; +} diff --git a/zokrates_cli/examples/synonyms.zok b/zokrates_cli/examples/synonyms.zok index bb0e6e09..e432e4e2 100644 --- a/zokrates_cli/examples/synonyms.zok +++ b/zokrates_cli/examples/synonyms.zok @@ -1,7 +1,8 @@ -def main() -> field: - field a = 1 - field b = a - field c = b - field d = c - field e = d - return e \ No newline at end of file +def main() -> field { + field a = 1; + field b = a; + field c = b; + field d = c; + field e = d; + return e; +} diff --git a/zokrates_cli/examples/taxation.zok b/zokrates_cli/examples/taxation.zok index 7371fe8f..5f274ace 100644 --- a/zokrates_cli/examples/taxation.zok +++ b/zokrates_cli/examples/taxation.zok @@ -1,7 +1,9 @@ -def wtax(field debt, field wealth) -> field: - field x = if wealth < debt then 0 else (wealth-debt) fi - return x +def wtax(field debt, field wealth) -> field { + field x = wealth < debt ? 0 : (wealth - debt); + return x; +} -def main(private field debt, private field wealth) -> field: - field tax = wtax(debt,wealth) - return tax \ No newline at end of file +def main(private field debt, private field wealth) -> field { + field tax = wtax(debt, wealth); + return tax; +} \ No newline at end of file diff --git a/zokrates_cli/examples/ternary_eq.zok b/zokrates_cli/examples/ternary_eq.zok new file mode 100644 index 00000000..17a6823e --- /dev/null +++ b/zokrates_cli/examples/ternary_eq.zok @@ -0,0 +1,9 @@ +// example using ternary operator with == +// x = 1 -> 1 + 1 + 1 = 3 +// x = 2 -> 2 + 5 + 125 = 132 +def main(field x) -> field { + field y = x + 2 == 3 ? 1 : 5; + field z = y == x ? x**3 : y**3; + return x + y + z; +} + diff --git a/zokrates_cli/examples/test1.zok b/zokrates_cli/examples/test1.zok index c51a29a9..487b3636 100644 --- a/zokrates_cli/examples/test1.zok +++ b/zokrates_cli/examples/test1.zok @@ -1,13 +1,14 @@ // only using sub, no need to flatten -def main(field x) -> field: - field a = 5 - field b = 7 - field c = if a == b then 4 else 3 fi - assert(c == 3) - field d = if a == 5 then 1 else 2 fi - assert(d == 1) - field e = if a < b then 5 else 6 fi - assert(e == 5) - field f = if b < a then 7 else 8 fi - assert(f == 8) - return x +def main(field x) -> field { + field a = 5; + field b = 7; + field c = a == b ? 4 : 3; + assert(c == 3); + field d = a == 5 ? 1 : 2; + assert(d == 1); + field e = a < b ? 5 : 6; + assert(e == 5); + field f = b < a ? 7 : 8; + assert(f == 8); + return x; +} diff --git a/zokrates_cli/examples/test_lt_max_value.zok b/zokrates_cli/examples/test_lt_max_value.zok index 087cf927..35568365 100644 --- a/zokrates_cli/examples/test_lt_max_value.zok +++ b/zokrates_cli/examples/test_lt_max_value.zok @@ -1,9 +1,10 @@ -from "field" import FIELD_SIZE_IN_BITS +from "field" import FIELD_SIZE_IN_BITS; // we can compare numbers up to 2^(pbits - 2) - 1, ie any number which fits in (pbits - 2) bits // lt should work for the maxvalue = 2^(pbits - 2) - 1 -def main(field a) -> bool: - u32 pbits = FIELD_SIZE_IN_BITS - field maxvalue = 2**(pbits - 2) - 1 - return 0 < maxvalue \ No newline at end of file +def main(field a) -> bool { + u32 pbits = FIELD_SIZE_IN_BITS; + field maxvalue = 2**(pbits - 2) - 1; + return 0 < maxvalue; +} diff --git a/zokrates_cli/examples/tuples/add.zok b/zokrates_cli/examples/tuples/add.zok index 13ede25f..168959f4 100644 --- a/zokrates_cli/examples/tuples/add.zok +++ b/zokrates_cli/examples/tuples/add.zok @@ -1,8 +1,9 @@ -def main((field, field) p, (field, field) q) -> ((field, field)): +def main((field, field) p, (field, field) q) -> ((field, field)) { + field a = 42; + field d = 21; - field a = 42 - field d = 21 + field dpxpyqxqy = d * p.0 * p.1 * q.0 * q.1; - field dpxpyqxqy = d * p.0 * p.1 * q.0 * q.1 + return ((p.0 * q.1 + q.0 * p.1) / (1 + dpxpyqxqy), (q.0 * q.1 - a * p.0 * p.1) / (1 - dpxpyqxqy)); +} - return ((p.0 * q.1 + q.0 * p.1) / (1 + dpxpyqxqy), (q.0 * q.1 - a * p.0 * p.1) / (1 - dpxpyqxqy)) diff --git a/zokrates_cli/examples/tuples/constant_in_member.zok b/zokrates_cli/examples/tuples/constant_in_member.zok index dc5e8de7..5cbd853f 100644 --- a/zokrates_cli/examples/tuples/constant_in_member.zok +++ b/zokrates_cli/examples/tuples/constant_in_member.zok @@ -1,5 +1,6 @@ -const u32 SIZE = 42 +const u32 SIZE = 42; -def main(): - (field[SIZE],) f = ([42; SIZE],) - return \ No newline at end of file +def main() { + (field[SIZE],) f = ([42; SIZE],); + return; +} diff --git a/zokrates_cli/examples/tuples/generic.zok b/zokrates_cli/examples/tuples/generic.zok index d42f9bfb..644a7bb9 100644 --- a/zokrates_cli/examples/tuples/generic.zok +++ b/zokrates_cli/examples/tuples/generic.zok @@ -1,13 +1,14 @@ struct B

{ - field[P] a + field[P] a; } struct A { - field[N] a - B b + field[N] a; + B b; } -def main((field[2], (field[2],)) a) -> bool: - u32 SIZE = 1 + 1 - (field[SIZE], (field[SIZE],)) b = ([1, 2], ([1, 2],)) - return a == b \ No newline at end of file +def main((field[2], (field[2],)) a) -> bool { + u32 SIZE = 1 + 1; + (field[SIZE], (field[SIZE],)) b = ([1, 2], ([1, 2],)) ; + return a == b; +} diff --git a/zokrates_cli/examples/tuples/nested_access.zok b/zokrates_cli/examples/tuples/nested_access.zok index dc23a621..9125ba29 100644 --- a/zokrates_cli/examples/tuples/nested_access.zok +++ b/zokrates_cli/examples/tuples/nested_access.zok @@ -1,3 +1,4 @@ -def main(((field,),) b): - field a = b.0.0 - return \ No newline at end of file +def main(((field,),) b) { + field a = b.0.0; + return; +} diff --git a/zokrates_cli/examples/tuples/set_member.zok b/zokrates_cli/examples/tuples/set_member.zok index 8e1f827d..83a37909 100644 --- a/zokrates_cli/examples/tuples/set_member.zok +++ b/zokrates_cli/examples/tuples/set_member.zok @@ -1,17 +1,19 @@ struct Bar { - field[2] c - bool d + field[2] c; + bool d; } struct Foo { - Bar a - bool b + Bar a; + bool b; } -def main() -> (((field[2], bool), bool)): +def main() -> (((field[2], bool), bool)) { ((field[2], bool), bool)[2] f = [ (([0, 0], false), true), (([0, 0], false), true) - ] - f[0].0.0 = [42, 43] - return f[0] + ]; + f[0].0.0 = [42, 43]; + return f[0]; +} + diff --git a/zokrates_cli/examples/waldo.zok b/zokrates_cli/examples/waldo.zok index 436a42b3..d02ec8b0 100644 --- a/zokrates_cli/examples/waldo.zok +++ b/zokrates_cli/examples/waldo.zok @@ -2,14 +2,16 @@ // In this example, the crowd is a series of numbers, ideally* all prime but one, and Waldo is a non-prime number // * we don't enforce only one number being non-prime, so there could be multiple Waldos -def isWaldo(field a, field p, field q) -> bool: - // make sure that p and q are both not one - assert(p != 1 && q != 1) +def isWaldo(field a, field p, field q) -> bool { + // make sure that p and q are both not one + assert(p != 1 && q != 1); - // we know how to factor a - return a == p * q + // we know how to factor a + return a == p * q; +} // define all -def main(field[3] a, private u32 index, private field p, private field q) -> bool: - // prover provides the index of Waldo - return isWaldo(a[index], p, q) \ No newline at end of file +def main(field[3] a, private u32 index, private field p, private field q) -> bool { + // prover provides the index of Waldo + return isWaldo(a[index], p, q); +} diff --git a/zokrates_cli/examples/wavelets.zok b/zokrates_cli/examples/wavelets.zok index f23bfccd..9ea3648b 100644 --- a/zokrates_cli/examples/wavelets.zok +++ b/zokrates_cli/examples/wavelets.zok @@ -1,19 +1,20 @@ +def main(field in1, field in2, field in3, field in4, field in5, field in6, field in7, field in8) -> field { + // first iteration + field a = (in1 + in2) / 2; + field b = (in3 + in4) / 2; + field c = (in5 + in6) / 2; + field d = (in7 + in8) / 2; + field e = (in1 - in2) / 2; + field f = (in3 - in4) / 2; + field g = (in5 - in6) / 2; + field h = (in7 - in8) / 2; + // second iteration + field i = (a + b) / 2; + field j = (c + d) / 2; + field k = (e - f) / 2; + field l = (g - h) / 2; + // third iteration + field out1 = (i + j) / 2; + return (k - l) / 2; +} -def main(field in1, field in2, field in3, field in4, field in5, field in6, field in7, field in8) -> field: - // first iteration - field a = (in1 + in2) / 2 - field b = (in3 + in4) / 2 - field c = (in5 + in6) / 2 - field d = (in7 + in8) / 2 - field e = (in1 - in2) / 2 - field f = (in3 - in4) / 2 - field g = (in5 - in6) / 2 - field h = (in7 - in8) / 2 - // second iteration - field i = (a + b) / 2 - field j = (c + d) / 2 - field k = (e - f) / 2 - field l = (g - h) / 2 - // third iteration - field out1 = (i + j) / 2 - return (k - l) / 2