From 752d2f97a80ec40fb31a136df4e662dfab61e8be Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 2 May 2023 13:26:17 +0100 Subject: [PATCH 1/2] chore: fix clippy warning (#1270) --- crates/noirc_evaluator/src/ssa_refactor/ir/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/noirc_evaluator/src/ssa_refactor/ir/map.rs b/crates/noirc_evaluator/src/ssa_refactor/ir/map.rs index a99ff06c5fb..14ea521359d 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/ir/map.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/ir/map.rs @@ -123,7 +123,7 @@ impl DenseMap { /// /// The id-element pairs are ordered by the numeric values of the ids. pub(crate) fn iter(&self) -> impl ExactSizeIterator, &T)> { - let ids_iter = (0..self.storage.len()).into_iter().map(|idx| Id::new(idx)); + let ids_iter = (0..self.storage.len()).map(|idx| Id::new(idx)); ids_iter.zip(self.storage.iter()) } } From 562c185af5a97b755f5a554a32da518562f88be1 Mon Sep 17 00:00:00 2001 From: joss-aztec <94053499+joss-aztec@users.noreply.github.com> Date: Tue, 2 May 2023 15:55:15 +0100 Subject: [PATCH 2/2] chore(noir): constrain expr; -> assert(expr); (#1276) * chore(noir): constrain expr; -> assert(expr); * chore(noir): replace remaining `constrain` with `assert(expr)` --------- Co-authored-by: Tom French --- crates/nargo_cli/src/cli/new_cmd.rs | 2 +- .../tests/compile_tests_data/pass/basic.nr | 2 +- .../compile_tests_data/pass/basic_import.nr | 2 +- .../target_tests_data/pass/basic/src/main.nr | 2 +- .../target_tests_data/pass/import/src/main.nr | 2 +- .../tests/test_data/1_mul/src/main.nr | 2 +- .../tests/test_data/2_div/src/main.nr | 4 +- .../tests/test_data/3_add/src/main.nr | 4 +- .../tests/test_data/4_sub/src/main.nr | 2 +- .../tests/test_data/5_over/src/main.nr | 4 +- .../nargo_cli/tests/test_data/6/src/main.nr | 4 +- .../tests/test_data/6_array/src/main.nr | 24 +-- .../nargo_cli/tests/test_data/7/src/main.nr | 2 +- .../tests/test_data/7_function/src/main.nr | 32 ++-- .../tests/test_data/8_integration/src/main.nr | 24 +-- .../tests/test_data/9_conditional/src/main.nr | 62 +++--- .../tests/test_data/array_len/src/main.nr | 14 +- .../tests/test_data/array_neq/src/main.nr | 2 +- .../tests/test_data/assign_ex/src/main.nr | 4 +- .../tests/test_data/bit_and/src/main.nr | 6 +- .../tests/test_data/bool_not/src/main.nr | 2 +- .../tests/test_data/bool_or/src/main.nr | 4 +- .../tests/test_data/cast_bool/src/main.nr | 2 +- .../comptime_array_access/src/main.nr | 6 +- .../tests/test_data/comptime_fail/src/main.nr | 6 +- .../comptime_recursion_regression/src/main.nr | 2 +- .../tests/test_data/contracts/src/main.nr | 2 +- .../test_data/ec_baby_jubjub/src/main.nr | 179 ++++++++++-------- .../tests/test_data/generics/src/main.nr | 12 +- .../tests/test_data/global_consts/src/baz.nr | 2 +- .../tests/test_data/global_consts/src/foo.nr | 2 +- .../tests/test_data/global_consts/src/main.nr | 30 +-- .../higher-order-functions/src/main.nr | 22 +-- .../tests/test_data/if_else_chain/src/main.nr | 10 +- .../tests/test_data/main_bool_arg/src/main.nr | 6 +- .../tests/test_data/merkle_insert/src/main.nr | 8 +- .../tests/test_data/modules/src/main.nr | 2 +- .../tests/test_data/modules_more/src/main.nr | 2 +- .../tests/test_data/modulus/src/main.nr | 10 +- .../test_data/numeric_generics/src/main.nr | 10 +- .../test_data/pedersen_check/src/main.nr | 6 +- .../test_data/poseidon_bn254_hash/src/main.nr | 4 +- .../poseidonsponge_x5_254/src/main.nr | 2 +- .../tests/test_data/pred_eq/src/main.nr | 2 +- .../tests/test_data/regression/src/main.nr | 14 +- .../tests/test_data/scalar_mul/src/main.nr | 4 +- .../tests/test_data/schnorr/src/main.nr | 2 +- .../tests/test_data/sha256/src/main.nr | 2 +- .../tests/test_data/sha2_blocks/src/main.nr | 8 +- .../tests/test_data/sha2_byte/src/main.nr | 4 +- .../tests/test_data/simple_shield/src/main.nr | 2 +- .../tests/test_data/strings/src/main.nr | 12 +- .../tests/test_data/struct/src/main.nr | 16 +- .../tests/test_data/struct_inputs/src/main.nr | 16 +- .../tests/test_data/submodules/src/main.nr | 2 +- .../tests/test_data/to_be_bytes/src/main.nr | 6 +- .../to_bytes_integration/src/main.nr | 8 +- .../tests/test_data/tuples/src/main.nr | 12 +- .../nargo_cli/tests/test_data/xor/src/main.nr | 2 +- .../src/hir/resolution/resolver.rs | 8 +- examples_failing/ecdsa_secp256k1/src/main.nr | 2 +- examples_failing/pow_const/src/main.nr | 2 +- noir_stdlib/src/ec/montcurve.nr | 18 +- noir_stdlib/src/ec/swcurve.nr | 10 +- noir_stdlib/src/ec/tecurve.nr | 8 +- noir_stdlib/src/hash/poseidon.nr | 10 +- noir_stdlib/src/hash/poseidon/bn254.nr | 8 +- 67 files changed, 362 insertions(+), 347 deletions(-) diff --git a/crates/nargo_cli/src/cli/new_cmd.rs b/crates/nargo_cli/src/cli/new_cmd.rs index 9d39f8d1d83..36146028454 100644 --- a/crates/nargo_cli/src/cli/new_cmd.rs +++ b/crates/nargo_cli/src/cli/new_cmd.rs @@ -27,7 +27,7 @@ compiler_version = "{CARGO_PKG_VERSION}" ); const EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) { - constrain x != y; + assert(x != y); } #[test] diff --git a/crates/nargo_cli/tests/compile_tests_data/pass/basic.nr b/crates/nargo_cli/tests/compile_tests_data/pass/basic.nr index 6a678f93fe7..90c0d7ffd3e 100644 --- a/crates/nargo_cli/tests/compile_tests_data/pass/basic.nr +++ b/crates/nargo_cli/tests/compile_tests_data/pass/basic.nr @@ -1,4 +1,4 @@ fn main(x : Field, y : Field) { - constrain x != y; + assert(x != y); } \ No newline at end of file diff --git a/crates/nargo_cli/tests/compile_tests_data/pass/basic_import.nr b/crates/nargo_cli/tests/compile_tests_data/pass/basic_import.nr index 212d0f13590..bb61c0f1edc 100644 --- a/crates/nargo_cli/tests/compile_tests_data/pass/basic_import.nr +++ b/crates/nargo_cli/tests/compile_tests_data/pass/basic_import.nr @@ -7,5 +7,5 @@ fn main(x : Field, y : Field) { let _k = std::hash::pedersen([x]); let _l = hello(x); - constrain x != import::hello(y); + assert(x != import::hello(y)); } diff --git a/crates/nargo_cli/tests/target_tests_data/pass/basic/src/main.nr b/crates/nargo_cli/tests/target_tests_data/pass/basic/src/main.nr index 6a678f93fe7..90c0d7ffd3e 100644 --- a/crates/nargo_cli/tests/target_tests_data/pass/basic/src/main.nr +++ b/crates/nargo_cli/tests/target_tests_data/pass/basic/src/main.nr @@ -1,4 +1,4 @@ fn main(x : Field, y : Field) { - constrain x != y; + assert(x != y); } \ No newline at end of file diff --git a/crates/nargo_cli/tests/target_tests_data/pass/import/src/main.nr b/crates/nargo_cli/tests/target_tests_data/pass/import/src/main.nr index 58fb0c3f3f2..cb6476480d8 100644 --- a/crates/nargo_cli/tests/target_tests_data/pass/import/src/main.nr +++ b/crates/nargo_cli/tests/target_tests_data/pass/import/src/main.nr @@ -5,5 +5,5 @@ fn main(x : Field, y : Field) { let _k = dep::std::hash::pedersen([x]); let _l = hello(x); - constrain x != import::hello(y); + assert(x != import::hello(y)); } diff --git a/crates/nargo_cli/tests/test_data/1_mul/src/main.nr b/crates/nargo_cli/tests/test_data/1_mul/src/main.nr index e423eb65667..4587b4b5947 100644 --- a/crates/nargo_cli/tests/test_data/1_mul/src/main.nr +++ b/crates/nargo_cli/tests/test_data/1_mul/src/main.nr @@ -5,5 +5,5 @@ fn main(mut x: u32, y: u32, z: u32) { x *= x; //144 x *= x; //20736 x *= x; //429 981 696 - constrain x == z; + assert(x == z); } diff --git a/crates/nargo_cli/tests/test_data/2_div/src/main.nr b/crates/nargo_cli/tests/test_data/2_div/src/main.nr index 6df75492553..00608cb697d 100644 --- a/crates/nargo_cli/tests/test_data/2_div/src/main.nr +++ b/crates/nargo_cli/tests/test_data/2_div/src/main.nr @@ -1,6 +1,6 @@ // Testing integer division: 7/3 = 2 fn main(mut x: u32, y: u32, z: u32) { let a = x % y; - constrain x / y == z; - constrain a == x - z*y; + assert(x / y == z); + assert(a == x - z*y); } diff --git a/crates/nargo_cli/tests/test_data/3_add/src/main.nr b/crates/nargo_cli/tests/test_data/3_add/src/main.nr index 73ed46a8e5d..2884415b81a 100644 --- a/crates/nargo_cli/tests/test_data/3_add/src/main.nr +++ b/crates/nargo_cli/tests/test_data/3_add/src/main.nr @@ -1,8 +1,8 @@ // Test integer addition: 3 + 4 = 7 fn main(mut x: u32, y: u32, z: u32) { x += y; - constrain x == z; + assert(x == z); x *= 8; - constrain x>9; + assert(x>9); } diff --git a/crates/nargo_cli/tests/test_data/4_sub/src/main.nr b/crates/nargo_cli/tests/test_data/4_sub/src/main.nr index 242be90970f..80fc0177e41 100644 --- a/crates/nargo_cli/tests/test_data/4_sub/src/main.nr +++ b/crates/nargo_cli/tests/test_data/4_sub/src/main.nr @@ -1,5 +1,5 @@ // Test unsafe integer subtraction with underflow: 12 - 2418266113 = 1876701195 modulo 2^32 fn main(mut x: u32, y: u32, z: u32) { x -= y; - constrain x == z; + assert(x == z); } diff --git a/crates/nargo_cli/tests/test_data/5_over/src/main.nr b/crates/nargo_cli/tests/test_data/5_over/src/main.nr index 8701c1e6320..4fdff16c5c0 100644 --- a/crates/nargo_cli/tests/test_data/5_over/src/main.nr +++ b/crates/nargo_cli/tests/test_data/5_over/src/main.nr @@ -2,8 +2,8 @@ // Test odd bits integer fn main(mut x: u32, y: u32) { x = x * x; - constrain y == x; + assert(y == x); let c:u3 = 2; - constrain c > x as u3; + assert(c > x as u3); } diff --git a/crates/nargo_cli/tests/test_data/6/src/main.nr b/crates/nargo_cli/tests/test_data/6/src/main.nr index 61be34e6d88..8b350de16c1 100644 --- a/crates/nargo_cli/tests/test_data/6/src/main.nr +++ b/crates/nargo_cli/tests/test_data/6/src/main.nr @@ -12,9 +12,9 @@ fn main(x: [u8; 5], result: pub [u8; 32]) { let mut digest = std::hash::sha256(x); digest[0] = 5 as u8; digest = std::hash::sha256(x); - constrain digest == result; + assert(digest == result); let y = [12,45,78,41]; let h = std::hash::mimc_bn254(y); - constrain h == 18226366069841799622585958305961373004333097209608110160936134895615261821931; + assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931); } diff --git a/crates/nargo_cli/tests/test_data/6_array/src/main.nr b/crates/nargo_cli/tests/test_data/6_array/src/main.nr index 3537740f1e5..30d3ab5a22f 100644 --- a/crates/nargo_cli/tests/test_data/6_array/src/main.nr +++ b/crates/nargo_cli/tests/test_data/6_array/src/main.nr @@ -8,7 +8,7 @@ fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { c = z*z*y[i]; z -= c; } - constrain (z==0); //y[4]=0, so c and z are always 0 + assert(z==0); //y[4]=0, so c and z are always 0 //Test 2: c = 2301 as u32; @@ -17,7 +17,7 @@ fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { c = z*z*x[i]; z += x[i]*y[i] - c; } - constrain (z==3814912846); + assert(z==3814912846); //Test 3: c = 2300001 as u32; @@ -29,7 +29,7 @@ fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { z *= c; } } - constrain (z==41472); + assert(z==41472); //Test 4: z = y[4]; @@ -39,16 +39,16 @@ fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { z += x[i+j] - y[i+j]; } } - constrain (z ==11539); + assert(z ==11539); //Test 5: let cc = if z < 1 { x } else { y }; - constrain cc[0] == y[0]; + assert(cc[0] == y[0]); // Test 6: for-each loops for y_elem in y { for x_elem in x { - constrain x_elem != y_elem; + assert(x_elem != y_elem); } } @@ -57,15 +57,15 @@ fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { } // fn dyn_array(mut x: [u32; 5], y: Field, z: Field) { -// constrain x[y] == 111; -// constrain x[z] == 101; +// assert(x[y] == 111); +// assert(x[z] == 101); // x[z] = 0; -// constrain x[y] == 111; -// constrain x[1] == 0; +// assert(x[y] == 111); +// assert(x[1] == 0); // if y as u32 < 10 { // x[y] = x[y] - 2; // } else { // x[y] = 0; // } -// constrain x[4] == 109; -// } \ No newline at end of file +// assert(x[4] == 109); +// } diff --git a/crates/nargo_cli/tests/test_data/7/src/main.nr b/crates/nargo_cli/tests/test_data/7/src/main.nr index ec01ea7c4be..a6bba978644 100644 --- a/crates/nargo_cli/tests/test_data/7/src/main.nr +++ b/crates/nargo_cli/tests/test_data/7/src/main.nr @@ -6,5 +6,5 @@ use dep::std; fn main(x: [u8; 5], result: [u8; 32]) { let digest = std::hash::blake2s(x); - constrain digest == result; + assert(digest == result); } diff --git a/crates/nargo_cli/tests/test_data/7_function/src/main.nr b/crates/nargo_cli/tests/test_data/7_function/src/main.nr index 96ca9759a8f..5a23b493871 100644 --- a/crates/nargo_cli/tests/test_data/7_function/src/main.nr +++ b/crates/nargo_cli/tests/test_data/7_function/src/main.nr @@ -15,20 +15,20 @@ fn f2(mut x: Field) -> Field{ // Simple example fn test0(mut a: Field) { a = f2(a); - constrain a == 3; + assert(a == 3); } // Nested call fn test1(mut a: Field) { a = f1(a); - constrain a == 4; + assert(a == 4); } fn test2(z: Field, t: u32 ) { let a = z + t as Field; - constrain a == 64; + assert(a == 64); let e = pow(z, t as Field); - constrain e == 714924299; + assert(e == 714924299); } fn pow(base: Field, exponent: Field) -> Field { @@ -46,7 +46,7 @@ fn test3(x: [u8; 3]) -> [u8; 3] { for i in 0..3 { buffer[i] = x[i]; } - constrain buffer == x; + assert(buffer == x); buffer } @@ -59,7 +59,7 @@ fn test_multiple2() -> my_struct { } fn test_multiple3(x: u32, y: u32) { - constrain x == y; + assert(x == y); } struct my_struct { @@ -73,18 +73,18 @@ struct my2 { } fn test_multiple4(s: my_struct) { - constrain s.a == s.b+2; + assert(s.a == s.b+2); } fn test_multiple5(a: (u32, u32)) { - constrain a.0 == a.1+2; + assert(a.0 == a.1+2); } fn test_multiple6(a: my2, b: my_struct, c: (my2, my_struct)) { test_multiple4(a.aa); test_multiple5((b.a, b.b)); - constrain c.0.aa.a == c.1.a; + assert(c.0.aa.a == c.1.a); } @@ -110,28 +110,28 @@ fn main(x: u32 , y: u32 , a: Field, arr1: [u32; 9], arr2: [u32; 9]) { ab = ab + a; (x,ab) }; - constrain my_block.1 == 4; + assert(my_block.1 == 4); test0(a); test1(a); test2(x as Field, y); - constrain bar()[0] == 0; + assert(bar()[0] == 0); let mut b = [0 as u8, 5 as u8, 2 as u8]; let c = test3(b); - constrain b == c; + assert(b == c); b[0] = 1 as u8; let cc = test3(b); - constrain c != cc; + assert(c != cc); let e = test_multiple(x, y); - constrain e.1 == e.0 + 54 as u32; + assert(e.1 == e.0 + 54 as u32); let d = test_multiple2(); - constrain d.b == d.a + 2 as u32; + assert(d.b == d.a + 2 as u32); test_multiple3(y, y); //Regression test for issue #628: let result = first(arr_to_field(arr1), arr_to_field(arr2)); - constrain result[0] == arr1[0] as Field; + assert(result[0] == arr1[0] as Field); } diff --git a/crates/nargo_cli/tests/test_data/8_integration/src/main.nr b/crates/nargo_cli/tests/test_data/8_integration/src/main.nr index 57dca4e2ac0..56b02650c27 100644 --- a/crates/nargo_cli/tests/test_data/8_integration/src/main.nr +++ b/crates/nargo_cli/tests/test_data/8_integration/src/main.nr @@ -57,7 +57,7 @@ fn iterate1(mut a0: u32) -> u32{ } fn array_noteq(a: [u32; 4], b: [u32; 4]) { - constrain a != b; + assert(a != b); } fn test3(mut b: [Field; 4]) -> [Field; 4] { @@ -105,7 +105,7 @@ fn iterate3( mut hash: [u32; 8]) -> [u32; 8] { g = f; a = t1+t2; } - constrain a == 2470696267; + assert(a == 2470696267); hash[0] = hash[0] + a; hash[1] = hash[1] + b; hash[2] = hash[2] + c; @@ -126,7 +126,7 @@ fn test5() { sha_hash = iterate2(sha_hash); - constrain sha_hash[0] == 9; + assert(sha_hash[0] == 9); } @@ -244,31 +244,31 @@ fn sig1(x: u32) -> u32 { fn main(a: [u32; 100], b: [u32; 100], c: [u32; 4], mut d: [u32; 4], m: [u8; 32]) { let e = matrix_mul_10(a,b); - constrain e[6] == 1866842232; + assert(e[6] == 1866842232); let f = matrix_mul_2(c,d); - constrain f[3] == 2082554100; + assert(f[3] == 2082554100); let mut a = [1 as u32, 2, 3, 4]; a = test4(a); - constrain a[3] == 20; + assert(a[3] == 20); a = test4(c); - constrain a[3] == c[1] * 10; + assert(a[3] == c[1] * 10); d[0] += c[0]; d[0] += c[1]; - constrain d[0] == 2739986880; + assert(d[0] == 2739986880); let h = iterate1(1); - constrain h == 4; + assert(h == 4); let x = d; array_noteq(x, [d[0], d[1], d[2], 0]); let mut h5 = [d[0] as Field, d[1] as Field, d[2] as Field, d[3] as Field]; let t5 = test3(h5); - constrain t5[3] == 3; + assert(t5[3] == 3); h5 = test3(h5); - constrain h5[3] == 3; + assert(h5[3] == 3); test5(); @@ -279,5 +279,5 @@ fn main(a: [u32; 100], b: [u32; 100], c: [u32; 4], mut d: [u32; 4], m: [u8; 32]) sha_hash = iterate3(sha_hash); let h6 = test6(m); - constrain h6[0]== 523008072; //31.. 3800709683; + assert(h6[0]== 523008072); //31.. 3800709683 } diff --git a/crates/nargo_cli/tests/test_data/9_conditional/src/main.nr b/crates/nargo_cli/tests/test_data/9_conditional/src/main.nr index 0f37f3e92f4..48ac639ecf0 100644 --- a/crates/nargo_cli/tests/test_data/9_conditional/src/main.nr +++ b/crates/nargo_cli/tests/test_data/9_conditional/src/main.nr @@ -17,11 +17,11 @@ fn call_intrinsic(x: [u8; 5], result: [u8; 32]) { let mut digest = std::hash::sha256(x); digest[0] = 5 as u8; digest = std::hash::sha256(x); - constrain digest == result; + assert(digest == result); } fn must_be_zero(x: u8) { - constrain x == 0; + assert(x == 0); } fn test3 (x: u8) { @@ -41,19 +41,19 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ let arr: [u8; 2] = [1, 2]; if arr[0] != arr[1] { for i in 0..1 { - constrain i != 2; + assert(i != 2); } } //Issue reported in #421 if a == c[0] { - constrain c[0] == 0; + assert(c[0] == 0); } else { if a == c[1] { - constrain c[1] == 0; + assert(c[1] == 0); } else { if a == c[2] { - constrain c[2] == 0; + assert(c[2] == 0); } } } @@ -67,25 +67,25 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ c1 = c1 + as_bits[0] as Field; if i == 0 { - constrain arr[i] == 1;// 1 + assert(arr[i] == 1);// 1 for k in 0..2 { - constrain as_bits_hardcode_1[k] == as_bits[k]; + assert(as_bits_hardcode_1[k] == as_bits[k]); } } if i == 1 { - constrain arr[i] == 2;//2 + assert(arr[i] == 2);//2 for k in 0..2 { - constrain as_bits_hardcode_1[k] != as_bits[k]; + assert(as_bits_hardcode_1[k] != as_bits[k]); } } } - constrain c1==1; + assert(c1==1); //Regression for Issue #579 let result1_true = test(true); - constrain result1_true.array_param[0] == 1; + assert(result1_true.array_param[0] == 1); let result1_false = test(false); - constrain result1_false.array_param[0] == 0; + assert(result1_false.array_param[0] == 0); //Test case for short-circuit let mut data = [0 as u32; 32]; @@ -104,23 +104,23 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ } } } - constrain data[31] == 0; - constrain ba != 13; + assert(data[31] == 0); + assert(ba != 13); //regression for short-circuit2 if 35 == a { - constrain false; + assert(false); } bar(a as Field); if a == 3 { c = test4(); } - constrain c[1] != 2; + assert(c[1] != 2); call_intrinsic(x, result); //Test case for conditional with arrays from function parameters let b = sort([1,2,3,4]); - constrain b[0] == 1; + assert(b[0] == 1); if a == 0 { must_be_zero(0); @@ -130,9 +130,9 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ c[0] = 1; c[1] = c[2] / a + 11 % a; let f1 = a as Field; - constrain 10/f1 != 0; + assert(10/f1 != 0); } - constrain c[0] == 3; + assert(c[0] == 3); let mut y = 0; if a == 0 { @@ -141,9 +141,9 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ } else { y = 5; } - constrain y == result[0]; + assert(y == result[0]); c = sort(c); - constrain c[0]==0; + assert(c[0]==0); //test 1 let mut x: u32 = 0; @@ -153,16 +153,16 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ x = 6; } else { x = 2; - constrain x == 2; + assert(x == 2); } } else { x = 5; - constrain x == 5; + assert(x == 5); } if c[0] == 0 { x = 3; } - constrain x == 2; + assert(x == 2); //test2: loops! x = 0; @@ -172,19 +172,19 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ x = i as u32 +2; } } - constrain x == 0; + assert(x == 0); test3(1); if a == 0 { c = test4(); } else { - constrain c[1] != 2; + assert(c[1] != 2); } if false { c[1] = 5; } - constrain c[1] == 2; + assert(c[1] == 2); test5(4); @@ -195,7 +195,7 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ } else { c_661 = issue_661_foo(issue_661_bar(c), x); } - constrain c_661[0] < 20000; + assert(c_661[0] < 20000); // Test case for function synchronisation let mut c_sync = 0; @@ -204,7 +204,7 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ } else { c_sync = foo2() + foo2(); } - constrain c_sync == 6; + assert(c_sync == 6); // Regression for predicate simplification safe_inverse(0); @@ -213,7 +213,7 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ fn test5(a : u32) { if a > 1 { let q = a / 2; - constrain q == 2; + assert(q == 2); } } diff --git a/crates/nargo_cli/tests/test_data/array_len/src/main.nr b/crates/nargo_cli/tests/test_data/array_len/src/main.nr index 7ed9ebfd1c9..29ee44ce928 100644 --- a/crates/nargo_cli/tests/test_data/array_len/src/main.nr +++ b/crates/nargo_cli/tests/test_data/array_len/src/main.nr @@ -13,19 +13,19 @@ fn nested_call(b: [Field]) -> Field { } fn main(len3: [u8; 3], len4: [Field; 4]) { - constrain len_plus_1(len3) == 4; - constrain len_plus_1(len4) == 5; - constrain add_lens(len3, len4) == 7; - constrain nested_call(len4) == 5; + assert(len_plus_1(len3) == 4); + assert(len_plus_1(len4) == 5); + assert(add_lens(len3, len4) == 7); + assert(nested_call(len4) == 5); // std::array::len returns a comptime value - constrain len4[len3.len()] == 4; + assert(len4[len3.len()] == 4); // test for std::array::sort let mut unsorted = len3; unsorted[0] = len3[1]; unsorted[1] = len3[0]; - constrain unsorted[0] > unsorted[1]; + assert(unsorted[0] > unsorted[1]); let sorted = unsorted.sort(); - constrain sorted[0] < sorted[1]; + assert(sorted[0] < sorted[1]); } diff --git a/crates/nargo_cli/tests/test_data/array_neq/src/main.nr b/crates/nargo_cli/tests/test_data/array_neq/src/main.nr index 1fc5d9579c7..be734dea368 100644 --- a/crates/nargo_cli/tests/test_data/array_neq/src/main.nr +++ b/crates/nargo_cli/tests/test_data/array_neq/src/main.nr @@ -1,4 +1,4 @@ // Simple example of checking where two arrays are different fn main(a: [Field; 32], b: [Field; 32]) { - constrain a != b; + assert(a != b); } diff --git a/crates/nargo_cli/tests/test_data/assign_ex/src/main.nr b/crates/nargo_cli/tests/test_data/assign_ex/src/main.nr index 158da959352..b0626d63c8e 100644 --- a/crates/nargo_cli/tests/test_data/assign_ex/src/main.nr +++ b/crates/nargo_cli/tests/test_data/assign_ex/src/main.nr @@ -1,6 +1,6 @@ fn main(x: Field, y: Field) { let mut z = x + y; - constrain z == 3; + assert(z == 3); z = x * y; - constrain z == 2; + assert(z == 2); } diff --git a/crates/nargo_cli/tests/test_data/bit_and/src/main.nr b/crates/nargo_cli/tests/test_data/bit_and/src/main.nr index 14b865d1a38..f4805960a33 100644 --- a/crates/nargo_cli/tests/test_data/bit_and/src/main.nr +++ b/crates/nargo_cli/tests/test_data/bit_and/src/main.nr @@ -4,15 +4,15 @@ fn main(x : Field, y : Field) { let x_as_u8 = x as u8; let y_as_u8 = y as u8; - constrain (x_as_u8 & y_as_u8) == x_as_u8; + assert((x_as_u8 & y_as_u8) == x_as_u8); //bitwise and with 1 bit: let flag = (x == 0) & (y == 16); - constrain flag; + assert(flag); //bitwise and with odd bits: let x_as_u11 = x as u11; let y_as_u11 = y as u11; - constrain (x_as_u11 & y_as_u11) == x_as_u11; + assert((x_as_u11 & y_as_u11) == x_as_u11); } diff --git a/crates/nargo_cli/tests/test_data/bool_not/src/main.nr b/crates/nargo_cli/tests/test_data/bool_not/src/main.nr index 035c0630874..d6b4d7a9fad 100644 --- a/crates/nargo_cli/tests/test_data/bool_not/src/main.nr +++ b/crates/nargo_cli/tests/test_data/bool_not/src/main.nr @@ -1,5 +1,5 @@ use dep::std; fn main(x: u1) { - constrain !x == 0; + assert(!x == 0); } diff --git a/crates/nargo_cli/tests/test_data/bool_or/src/main.nr b/crates/nargo_cli/tests/test_data/bool_or/src/main.nr index 147cc23a922..4a74027e4aa 100644 --- a/crates/nargo_cli/tests/test_data/bool_or/src/main.nr +++ b/crates/nargo_cli/tests/test_data/bool_or/src/main.nr @@ -1,7 +1,7 @@ use dep::std; fn main(x: u1, y: u1) { - constrain x | y == 1; + assert(x | y == 1); - constrain x | y | x == 1; + assert(x | y | x == 1); } diff --git a/crates/nargo_cli/tests/test_data/cast_bool/src/main.nr b/crates/nargo_cli/tests/test_data/cast_bool/src/main.nr index e62f4b80ddd..57af8120b33 100644 --- a/crates/nargo_cli/tests/test_data/cast_bool/src/main.nr +++ b/crates/nargo_cli/tests/test_data/cast_bool/src/main.nr @@ -1,6 +1,6 @@ fn main(x: Field, y: Field) { let z = x == y; let t = z as u8; - constrain t == 1; + assert(t == 1); } diff --git a/crates/nargo_cli/tests/test_data/comptime_array_access/src/main.nr b/crates/nargo_cli/tests/test_data/comptime_array_access/src/main.nr index 0c8242bca4b..04f08bb70c5 100644 --- a/crates/nargo_cli/tests/test_data/comptime_array_access/src/main.nr +++ b/crates/nargo_cli/tests/test_data/comptime_array_access/src/main.nr @@ -7,11 +7,11 @@ fn main(a: [Field; 3]) { // Nor should using it in an expression with a non-comptime variable. let two = i + ii; - constrain i == ii; + assert(i == ii); let elem2 = a[i]; - constrain elem1 == elem2; - constrain two == 2; + assert(elem1 == elem2); + assert(two == 2); } fn foo(x: Field) -> Field { x } diff --git a/crates/nargo_cli/tests/test_data/comptime_fail/src/main.nr b/crates/nargo_cli/tests/test_data/comptime_fail/src/main.nr index 9e861b5dc57..ad9ecc2f689 100644 --- a/crates/nargo_cli/tests/test_data/comptime_fail/src/main.nr +++ b/crates/nargo_cli/tests/test_data/comptime_fail/src/main.nr @@ -4,12 +4,12 @@ fn main(x: Field) { // Error here: let foo = my_const + x; - constrain array[foo] == x; + assert(array[foo] == x); let my_const2 = 3; - constrain array[my_const2] == 3; + assert(array[my_const2] == 3); // Using a comptime variable where a non-comptime variable is expected should be fine main(my_const2); - constrain x != 0; + assert(x != 0); } diff --git a/crates/nargo_cli/tests/test_data/comptime_recursion_regression/src/main.nr b/crates/nargo_cli/tests/test_data/comptime_recursion_regression/src/main.nr index 31d7d10975c..0461fd9c4cb 100644 --- a/crates/nargo_cli/tests/test_data/comptime_recursion_regression/src/main.nr +++ b/crates/nargo_cli/tests/test_data/comptime_recursion_regression/src/main.nr @@ -1,4 +1,4 @@ fn main(x: Field, y: Field) { let flag = (x == 1) | (y == 2); - constrain flag | false == flag; + assert(flag | false == flag); } diff --git a/crates/nargo_cli/tests/test_data/contracts/src/main.nr b/crates/nargo_cli/tests/test_data/contracts/src/main.nr index f236186d426..53e094eb4cc 100644 --- a/crates/nargo_cli/tests/test_data/contracts/src/main.nr +++ b/crates/nargo_cli/tests/test_data/contracts/src/main.nr @@ -1,5 +1,5 @@ fn main(x : Field, y : pub Field) { - constrain x * 2 == y * 3; + assert(x * 2 == y * 3); } contract Foo { diff --git a/crates/nargo_cli/tests/test_data/ec_baby_jubjub/src/main.nr b/crates/nargo_cli/tests/test_data/ec_baby_jubjub/src/main.nr index ee9e2e2eeee..3372e969d4b 100644 --- a/crates/nargo_cli/tests/test_data/ec_baby_jubjub/src/main.nr +++ b/crates/nargo_cli/tests/test_data/ec_baby_jubjub/src/main.nr @@ -23,26 +23,36 @@ fn main() { let p2_affine = Gaffine::new(16540640123574156134436876038791482806971768689494387082833631921987005038935, 20819045374670962167435360035096875258406992893633759881276124905556507972311); let p3_affine = bjj_affine.add(p1_affine, p2_affine); - constrain p3_affine.eq(Gaffine::new(7916061937171219682591368294088513039687205273691143098332585753343424131937, - 14035240266687799601661095864649209771790948434046947201833777492504781204499)); + assert( + p3_affine.eq(Gaffine::new( + 7916061937171219682591368294088513039687205273691143098332585753343424131937, + 14035240266687799601661095864649209771790948434046947201833777492504781204499 + )) + ); // Test scalar multiplication let p4_affine = bjj_affine.mul(2, p1_affine); - constrain p4_affine.eq(Gaffine::new(6890855772600357754907169075114257697580319025794532037257385534741338397365, - 4338620300185947561074059802482547481416142213883829469920100239455078257889)); - constrain p4_affine.eq(bjj_affine.bit_mul([0,1], p1_affine)); + assert( + p4_affine.eq(Gaffine::new( + 6890855772600357754907169075114257697580319025794532037257385534741338397365, + 4338620300185947561074059802482547481416142213883829469920100239455078257889 + )) + ); + assert(p4_affine.eq(bjj_affine.bit_mul([0,1], p1_affine))); // Test subtraction let p5_affine = bjj_affine.subtract(p3_affine, p3_affine); - constrain p5_affine.eq(Gaffine::zero()); + assert(p5_affine.eq(Gaffine::zero())); // Check that these points are on the curve - constrain bjj_affine.contains(bjj_affine.gen) - & bjj_affine.contains(p1_affine) - & bjj_affine.contains(p2_affine) - & bjj_affine.contains(p3_affine) - & bjj_affine.contains(p4_affine) - & bjj_affine.contains(p5_affine); + assert( + bjj_affine.contains(bjj_affine.gen) & + bjj_affine.contains(p1_affine) & + bjj_affine.contains(p2_affine) & + bjj_affine.contains(p3_affine) & + bjj_affine.contains(p4_affine) & + bjj_affine.contains(p5_affine) + ); // Test CurveGroup equivalents let bjj = bjj_affine.into_group(); // Baby Jubjub @@ -54,23 +64,25 @@ fn main() { let p5 = p5_affine.into_group(); // Test addition - constrain p3.eq(bjj.add(p1, p2)); + assert(p3.eq(bjj.add(p1, p2))); // Test scalar multiplication - constrain p4.eq(bjj.mul(2, p1)); - constrain p4.eq(bjj.bit_mul([0,1], p1)); + assert(p4.eq(bjj.mul(2, p1))); + assert(p4.eq(bjj.bit_mul([0,1], p1))); // Test subtraction - constrain G::zero().eq(bjj.subtract(p3, p3)); - constrain p5.eq(G::zero()); + assert(G::zero().eq(bjj.subtract(p3, p3))); + assert(p5.eq(G::zero())); // Check that these points are on the curve - constrain bjj.contains(bjj.gen) - & bjj.contains(p1) - & bjj.contains(p2) - & bjj.contains(p3) - & bjj.contains(p4) - & bjj.contains(p5); + assert( + bjj.contains(bjj.gen) & + bjj.contains(p1) & + bjj.contains(p2) & + bjj.contains(p3) & + bjj.contains(p4) & + bjj.contains(p5) + ); // Test SWCurve equivalents of the above // First the affine representation @@ -83,26 +95,32 @@ fn main() { let p5_swcurve_affine = bjj_affine.map_into_swcurve(p5_affine); // Addition - constrain p3_swcurve_affine.eq( - bjj_swcurve_affine.add( - p1_swcurve_affine, - p2_swcurve_affine)); + assert( + p3_swcurve_affine.eq( + bjj_swcurve_affine.add( + p1_swcurve_affine, + p2_swcurve_affine + ) + ) + ); // Doubling - constrain p4_swcurve_affine.eq(bjj_swcurve_affine.mul(2, p1_swcurve_affine)); - constrain p4_swcurve_affine.eq(bjj_swcurve_affine.bit_mul([0,1], p1_swcurve_affine)); + assert(p4_swcurve_affine.eq(bjj_swcurve_affine.mul(2, p1_swcurve_affine))); + assert(p4_swcurve_affine.eq(bjj_swcurve_affine.bit_mul([0,1], p1_swcurve_affine))); // Subtraction - constrain SWGaffine::zero().eq(bjj_swcurve_affine.subtract(p3_swcurve_affine, p3_swcurve_affine)); - constrain p5_swcurve_affine.eq(SWGaffine::zero()); + assert(SWGaffine::zero().eq(bjj_swcurve_affine.subtract(p3_swcurve_affine, p3_swcurve_affine))); + assert(p5_swcurve_affine.eq(SWGaffine::zero())); // Check that these points are on the curve - constrain bjj_swcurve_affine.contains(bjj_swcurve_affine.gen) - & bjj_swcurve_affine.contains(p1_swcurve_affine) - & bjj_swcurve_affine.contains(p2_swcurve_affine) - & bjj_swcurve_affine.contains(p3_swcurve_affine) - & bjj_swcurve_affine.contains(p4_swcurve_affine) - & bjj_swcurve_affine.contains(p5_swcurve_affine); + assert( + bjj_swcurve_affine.contains(bjj_swcurve_affine.gen) & + bjj_swcurve_affine.contains(p1_swcurve_affine) & + bjj_swcurve_affine.contains(p2_swcurve_affine) & + bjj_swcurve_affine.contains(p3_swcurve_affine) & + bjj_swcurve_affine.contains(p4_swcurve_affine) & + bjj_swcurve_affine.contains(p5_swcurve_affine) + ); // Then the CurveGroup representation let bjj_swcurve = bjj.into_swcurve(); @@ -114,26 +132,25 @@ fn main() { let p5_swcurve = bjj.map_into_swcurve(p5); // Addition - constrain p3_swcurve.eq( - bjj_swcurve.add( - p1_swcurve, - p2_swcurve)); + assert(p3_swcurve.eq(bjj_swcurve.add(p1_swcurve,p2_swcurve))); // Doubling - constrain p4_swcurve.eq(bjj_swcurve.mul(2, p1_swcurve)); - constrain p4_swcurve.eq(bjj_swcurve.bit_mul([0,1], p1_swcurve)); + assert(p4_swcurve.eq(bjj_swcurve.mul(2, p1_swcurve))); + assert(p4_swcurve.eq(bjj_swcurve.bit_mul([0,1], p1_swcurve))); // Subtraction - constrain SWG::zero().eq(bjj_swcurve.subtract(p3_swcurve, p3_swcurve)); - constrain p5_swcurve.eq(SWG::zero()); + assert(SWG::zero().eq(bjj_swcurve.subtract(p3_swcurve, p3_swcurve))); + assert(p5_swcurve.eq(SWG::zero())); // Check that these points are on the curve - constrain bjj_swcurve.contains(bjj_swcurve.gen) - & bjj_swcurve.contains(p1_swcurve) - & bjj_swcurve.contains(p2_swcurve) - & bjj_swcurve.contains(p3_swcurve) - & bjj_swcurve.contains(p4_swcurve) - & bjj_swcurve.contains(p5_swcurve); + assert( + bjj_swcurve.contains(bjj_swcurve.gen) & + bjj_swcurve.contains(p1_swcurve) & + bjj_swcurve.contains(p2_swcurve) & + bjj_swcurve.contains(p3_swcurve) & + bjj_swcurve.contains(p4_swcurve) & + bjj_swcurve.contains(p5_swcurve) + ); // Test MontCurve conversions // First the affine representation @@ -146,26 +163,25 @@ fn main() { let p5_montcurve_affine = p5_affine.into_montcurve(); // Addition - constrain p3_montcurve_affine.eq( - bjj_montcurve_affine.add( - p1_montcurve_affine, - p2_montcurve_affine)); + assert(p3_montcurve_affine.eq(bjj_montcurve_affine.add(p1_montcurve_affine, p2_montcurve_affine))); // Doubling - constrain p4_montcurve_affine.eq(bjj_montcurve_affine.mul(2, p1_montcurve_affine)); - constrain p4_montcurve_affine.eq(bjj_montcurve_affine.bit_mul([0,1], p1_montcurve_affine)); + assert(p4_montcurve_affine.eq(bjj_montcurve_affine.mul(2, p1_montcurve_affine))); + assert(p4_montcurve_affine.eq(bjj_montcurve_affine.bit_mul([0,1], p1_montcurve_affine))); // Subtraction - constrain MGaffine::zero().eq(bjj_montcurve_affine.subtract(p3_montcurve_affine, p3_montcurve_affine)); - constrain p5_montcurve_affine.eq(MGaffine::zero()); + assert(MGaffine::zero().eq(bjj_montcurve_affine.subtract(p3_montcurve_affine, p3_montcurve_affine))); + assert(p5_montcurve_affine.eq(MGaffine::zero())); // Check that these points are on the curve - constrain bjj_montcurve_affine.contains(bjj_montcurve_affine.gen) - & bjj_montcurve_affine.contains(p1_montcurve_affine) - & bjj_montcurve_affine.contains(p2_montcurve_affine) - & bjj_montcurve_affine.contains(p3_montcurve_affine) - & bjj_montcurve_affine.contains(p4_montcurve_affine) - & bjj_montcurve_affine.contains(p5_montcurve_affine); + assert( + bjj_montcurve_affine.contains(bjj_montcurve_affine.gen) & + bjj_montcurve_affine.contains(p1_montcurve_affine) & + bjj_montcurve_affine.contains(p2_montcurve_affine) & + bjj_montcurve_affine.contains(p3_montcurve_affine) & + bjj_montcurve_affine.contains(p4_montcurve_affine) & + bjj_montcurve_affine.contains(p5_montcurve_affine) + ); // Then the CurveGroup representation let bjj_montcurve = bjj.into_montcurve(); @@ -177,35 +193,34 @@ fn main() { let p5_montcurve = p5_montcurve_affine.into_group(); // Addition - constrain p3_montcurve.eq( - bjj_montcurve.add( - p1_montcurve, - p2_montcurve)); - + assert(p3_montcurve.eq(bjj_montcurve.add(p1_montcurve, p2_montcurve))); + // Doubling - constrain p4_montcurve.eq(bjj_montcurve.mul(2, p1_montcurve)); - constrain p4_montcurve.eq(bjj_montcurve.bit_mul([0,1], p1_montcurve)); + assert(p4_montcurve.eq(bjj_montcurve.mul(2, p1_montcurve))); + assert(p4_montcurve.eq(bjj_montcurve.bit_mul([0,1], p1_montcurve))); // Subtraction - constrain MG::zero().eq(bjj_montcurve.subtract(p3_montcurve, p3_montcurve)); - constrain p5_montcurve.eq(MG::zero()); + assert(MG::zero().eq(bjj_montcurve.subtract(p3_montcurve, p3_montcurve))); + assert(p5_montcurve.eq(MG::zero())); // Check that these points are on the curve - constrain bjj_montcurve.contains(bjj_montcurve.gen) - & bjj_montcurve.contains(p1_montcurve) - & bjj_montcurve.contains(p2_montcurve) - & bjj_montcurve.contains(p3_montcurve) - & bjj_montcurve.contains(p4_montcurve) - & bjj_montcurve.contains(p5_montcurve); + assert( + bjj_montcurve.contains(bjj_montcurve.gen) & + bjj_montcurve.contains(p1_montcurve) & + bjj_montcurve.contains(p2_montcurve) & + bjj_montcurve.contains(p3_montcurve) & + bjj_montcurve.contains(p4_montcurve) & + bjj_montcurve.contains(p5_montcurve) + ); // Elligator 2 map-to-curve let ell2_pt_map = bjj_affine.elligator2_map(27); - constrain ell2_pt_map.eq(MGaffine::new(7972459279704486422145701269802978968072470631857513331988813812334797879121, 8142420778878030219043334189293412482212146646099536952861607542822144507872).into_tecurve()); + assert(ell2_pt_map.eq(MGaffine::new(7972459279704486422145701269802978968072470631857513331988813812334797879121, 8142420778878030219043334189293412482212146646099536952861607542822144507872).into_tecurve())); // SWU map-to-curve let swu_pt_map = bjj_affine.swu_map(5,27); - constrain swu_pt_map.eq(bjj_affine.map_from_swcurve(SWGaffine::new(2162719247815120009132293839392097468339661471129795280520343931405114293888, 5341392251743377373758788728206293080122949448990104760111875914082289313973))); + assert(swu_pt_map.eq(bjj_affine.map_from_swcurve(SWGaffine::new(2162719247815120009132293839392097468339661471129795280520343931405114293888, 5341392251743377373758788728206293080122949448990104760111875914082289313973)))); } } diff --git a/crates/nargo_cli/tests/test_data/generics/src/main.nr b/crates/nargo_cli/tests/test_data/generics/src/main.nr index 56078a304e0..c506995adc3 100644 --- a/crates/nargo_cli/tests/test_data/generics/src/main.nr +++ b/crates/nargo_cli/tests/test_data/generics/src/main.nr @@ -5,7 +5,7 @@ struct Bar { } fn foo(bar: Bar) { - constrain bar.one == bar.two; + assert(bar.one == bar.two); } struct BigInt { @@ -15,12 +15,12 @@ struct BigInt { impl BigInt { // `N` is in scope of all methods in the impl fn first(first: BigInt, second: BigInt) -> Self { - constrain first.limbs != second.limbs; + assert(first.limbs != second.limbs); first } fn second(first: BigInt, second: Self) -> Self { - constrain first.limbs != second.limbs; + assert(first.limbs != second.limbs); second } } @@ -42,11 +42,11 @@ fn main(x: Field, y: Field) { let int1 = BigInt { limbs: [1] }; let int2 = BigInt { limbs: [2] }; let BigInt { limbs } = int1.second(int2).first(int1); - constrain limbs == int2.limbs; + assert(limbs == int2.limbs); // Test impl exclusively for Bar - constrain bar1.get_other() == bar1.other; + assert(bar1.get_other() == bar1.other); // Expected type error - // constrain bar2.get_other() == bar2.other; + // assert(bar2.get_other() == bar2.other); } diff --git a/crates/nargo_cli/tests/test_data/global_consts/src/baz.nr b/crates/nargo_cli/tests/test_data/global_consts/src/baz.nr index 3471da43105..e52efc52eae 100644 --- a/crates/nargo_cli/tests/test_data/global_consts/src/baz.nr +++ b/crates/nargo_cli/tests/test_data/global_consts/src/baz.nr @@ -1,5 +1,5 @@ fn from_baz(x : [Field; crate::foo::MAGIC_NUMBER]) { for i in 0..crate::foo::MAGIC_NUMBER { - constrain x[i] == crate::foo::MAGIC_NUMBER; + assert(x[i] == crate::foo::MAGIC_NUMBER); }; } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/global_consts/src/foo.nr b/crates/nargo_cli/tests/test_data/global_consts/src/foo.nr index c54a85ae120..2db74fb1ff7 100644 --- a/crates/nargo_cli/tests/test_data/global_consts/src/foo.nr +++ b/crates/nargo_cli/tests/test_data/global_consts/src/foo.nr @@ -6,6 +6,6 @@ global TYPE_INFERRED = 42; fn from_foo(x : [Field; bar::N]) { for i in 0..bar::N { - constrain x[i] == bar::N; + assert(x[i] == bar::N); }; } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/global_consts/src/main.nr b/crates/nargo_cli/tests/test_data/global_consts/src/main.nr index fb48eb2b798..9bcca2b8071 100644 --- a/crates/nargo_cli/tests/test_data/global_consts/src/main.nr +++ b/crates/nargo_cli/tests/test_data/global_consts/src/main.nr @@ -16,14 +16,14 @@ fn main(a: [Field; M + N - N], b: [Field; 30 + N / 2], c : pub [Field; foo::MAGI let test_struct = Dummy { x: d, y: c }; for i in 0..foo::MAGIC_NUMBER { - constrain c[i] == foo::MAGIC_NUMBER; - constrain test_struct.y[i] == foo::MAGIC_NUMBER; + assert(c[i] == foo::MAGIC_NUMBER); + assert(test_struct.y[i] == foo::MAGIC_NUMBER); } - constrain N != M; + assert(N != M); let expected: u32 = 42; - constrain foo::TYPE_INFERRED == expected; + assert(foo::TYPE_INFERRED == expected); let mut y = 5; let mut x = M; @@ -33,30 +33,30 @@ fn main(a: [Field; M + N - N], b: [Field; 30 + N / 2], c : pub [Field; foo::MAGI y = i; } - constrain y == 24; - constrain x == 10; + assert(y == 24); + assert(x == 10); let q = multiplyByM(3); - constrain q == 96; + assert(q == 96); arrays_neq(a, b); let t: [Field; T_LEN] = [N, M]; - constrain t[1] == 32; + assert(t[1] == 32); - constrain 15 == mysubmodule::my_helper(); + assert(15 == mysubmodule::my_helper()); let add_submodules_N = mysubmodule::N + foo::bar::N; - constrain 15 == add_submodules_N; + assert(15 == add_submodules_N); let add_from_bar_N = mysubmodule::N + foo::bar::from_bar(1); - constrain 15 == add_from_bar_N; + assert(15 == add_from_bar_N); // Example showing an array filled with (mysubmodule::N + 2) 0's let sugared = [0; mysubmodule::N + 2]; - constrain sugared[mysubmodule::N + 1] == 0; + assert(sugared[mysubmodule::N + 1] == 0); let arr: [Field; mysubmodule::N] = [N; 10]; - constrain (arr[0] == 5) & (arr[9] == 5); + assert((arr[0] == 5) & (arr[9] == 5)); foo::from_foo(d); baz::from_baz(c); @@ -67,7 +67,7 @@ fn multiplyByM(x: Field) -> Field { } fn arrays_neq(a: [Field; M], b: [Field; M]) { - constrain a != b; + assert(a != b); } mod mysubmodule { @@ -77,7 +77,7 @@ mod mysubmodule { global L: Field = 50; fn my_bool_or(x: u1, y: u1) { - constrain x | y == 1; + assert(x | y == 1); } fn my_helper() -> comptime Field { diff --git a/crates/nargo_cli/tests/test_data/higher-order-functions/src/main.nr b/crates/nargo_cli/tests/test_data/higher-order-functions/src/main.nr index 70b281951a8..572e6603cc5 100644 --- a/crates/nargo_cli/tests/test_data/higher-order-functions/src/main.nr +++ b/crates/nargo_cli/tests/test_data/higher-order-functions/src/main.nr @@ -2,16 +2,16 @@ use dep::std; fn main() -> pub Field { let f = if 3 * 7 > 200 { foo } else { bar }; - constrain f()[1] == 2; + assert(f()[1] == 2); // Lambdas: - constrain twice(|x| x * 2, 5) == 20; - constrain (|x, y| x + y + 1)(2, 3) == 6; + assert(twice(|x| x * 2, 5) == 20); + assert((|x, y| x + y + 1)(2, 3) == 6); // Closures: let a = 42; let g = || a; - constrain g() == 42; + assert(g() == 42); // Mutable variables cannot be captured, but you can // copy them into immutable variables and capture those: @@ -22,7 +22,7 @@ fn main() -> pub Field { // Add extra mutations to ensure we can mutate x without the // captured z changing. x = x + 1; - constrain (|y| y + z)(1) == 4; + assert((|y| y + z)(1) == 4); x = x + 1; let ret = twice(add1, 3); @@ -34,18 +34,18 @@ fn main() -> pub Field { /// Test the array functions in std::array fn test_array_functions() { let myarray: [i32; 3] = [1, 2, 3]; - constrain myarray.any(|n| n > 2); + assert(myarray.any(|n| n > 2)); let evens: [i32; 3] = [2, 4, 6]; - constrain evens.all(|n| n > 1); + assert(evens.all(|n| n > 1)); - constrain evens.fold(0, |a, b| a + b) == 12; - constrain evens.reduce(|a, b| a + b) == 12; + assert(evens.fold(0, |a, b| a + b) == 12); + assert(evens.reduce(|a, b| a + b) == 12); let descending = myarray.sort_via(|a, b| a > b); - constrain descending == [3, 2, 1]; + assert(descending == [3, 2, 1]); - constrain evens.map(|n| n / 2) == myarray; + assert(evens.map(|n| n / 2) == myarray); } fn foo() -> [u32; 2] { diff --git a/crates/nargo_cli/tests/test_data/if_else_chain/src/main.nr b/crates/nargo_cli/tests/test_data/if_else_chain/src/main.nr index af04fc7bdf8..5105c18c7de 100644 --- a/crates/nargo_cli/tests/test_data/if_else_chain/src/main.nr +++ b/crates/nargo_cli/tests/test_data/if_else_chain/src/main.nr @@ -1,16 +1,16 @@ fn main(a: u32, mut c: [u32; 4]){ if a == c[0] { - constrain c[0] == 0; + assert(c[0] == 0); } else if a == c[1] { - constrain c[1] == 0; + assert(c[1] == 0); } else if a == c[2] { - constrain c[2] == 0; + assert(c[2] == 0); } else if a == c[3] { // expect to match this case - constrain c[3] == 0; + assert(c[3] == 0); } else { - constrain c[0] == 10; + assert(c[0] == 10); } } diff --git a/crates/nargo_cli/tests/test_data/main_bool_arg/src/main.nr b/crates/nargo_cli/tests/test_data/main_bool_arg/src/main.nr index 91a8db03ff3..0615a7dbca4 100644 --- a/crates/nargo_cli/tests/test_data/main_bool_arg/src/main.nr +++ b/crates/nargo_cli/tests/test_data/main_bool_arg/src/main.nr @@ -1,8 +1,8 @@ fn main(x : bool, y: [bool;2]) { if x { - constrain 1 != 2; + assert(1 != 2); } - constrain x; - constrain y[0] != y[1]; + assert(x); + assert(y[0] != y[1]); } diff --git a/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr b/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr index 3ab4efb64c0..53d876272ac 100644 --- a/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr +++ b/crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr @@ -10,13 +10,13 @@ fn main( mimc_input: [Field; 4], ) { let old_leaf_exists = std::merkle::check_membership(old_root, old_leaf, index, old_hash_path); - constrain old_leaf_exists == 1; - constrain old_root == std::merkle::compute_root_from_leaf(old_leaf, index, old_hash_path); + assert(old_leaf_exists == 1); + assert(old_root == std::merkle::compute_root_from_leaf(old_leaf, index, old_hash_path)); let calculated_root = std::merkle::compute_merkle_root(leaf, index, old_hash_path); - constrain new_root == calculated_root; + assert(new_root == calculated_root); let h = std::hash::mimc_bn254(mimc_input); // Regression test for PR #891 std::println(h); - constrain h == 18226366069841799622585958305961373004333097209608110160936134895615261821931; + assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931); } diff --git a/crates/nargo_cli/tests/test_data/modules/src/main.nr b/crates/nargo_cli/tests/test_data/modules/src/main.nr index 4a773c9ed6b..167f7e671a0 100644 --- a/crates/nargo_cli/tests/test_data/modules/src/main.nr +++ b/crates/nargo_cli/tests/test_data/modules/src/main.nr @@ -10,5 +10,5 @@ mod foo; // // To verify that proof, type `cargo run verify {proof_name}` fn main(x: Field, y: pub Field) { - constrain x != foo::hello(y); + assert(x != foo::hello(y)); } diff --git a/crates/nargo_cli/tests/test_data/modules_more/src/main.nr b/crates/nargo_cli/tests/test_data/modules_more/src/main.nr index 73f3a0a6d8b..8862e5a8650 100644 --- a/crates/nargo_cli/tests/test_data/modules_more/src/main.nr +++ b/crates/nargo_cli/tests/test_data/modules_more/src/main.nr @@ -2,5 +2,5 @@ mod foo; // An example of the module system fn main(x: Field, y: Field) { - constrain x != foo::bar::from_bar(y); + assert(x != foo::bar::from_bar(y)); } diff --git a/crates/nargo_cli/tests/test_data/modulus/src/main.nr b/crates/nargo_cli/tests/test_data/modulus/src/main.nr index 070d934976d..4a13a6e06ba 100644 --- a/crates/nargo_cli/tests/test_data/modulus/src/main.nr +++ b/crates/nargo_cli/tests/test_data/modulus/src/main.nr @@ -3,24 +3,24 @@ use dep::std; fn main(bn254_modulus_be_bytes : [u8; 32], bn254_modulus_be_bits : [u1; 254]) -> pub Field { let modulus_size = std::field::modulus_num_bits(); // NOTE: The constraints used in this circuit will only work when testing nargo with the plonk bn254 backend - constrain modulus_size == 254; + assert(modulus_size == 254); let modulus_be_byte_array = std::field::modulus_be_bytes(); for i in 0..32 { - constrain modulus_be_byte_array[i] == bn254_modulus_be_bytes[i]; + assert(modulus_be_byte_array[i] == bn254_modulus_be_bytes[i]); } let modulus_le_byte_array = std::field::modulus_le_bytes(); for i in 0..32 { - constrain modulus_le_byte_array[i] == bn254_modulus_be_bytes[31-i]; + assert(modulus_le_byte_array[i] == bn254_modulus_be_bytes[31-i]); } let modulus_be_bits = std::field::modulus_be_bits(); for i in 0..254 { - constrain modulus_be_bits[i] == bn254_modulus_be_bits[i]; + assert(modulus_be_bits[i] == bn254_modulus_be_bits[i]); } let modulus_le_bits = std::field::modulus_le_bits(); for i in 0..254 { - constrain modulus_le_bits[i] == bn254_modulus_be_bits[253-i]; + assert(modulus_le_bits[i] == bn254_modulus_be_bits[253-i]); } modulus_size diff --git a/crates/nargo_cli/tests/test_data/numeric_generics/src/main.nr b/crates/nargo_cli/tests/test_data/numeric_generics/src/main.nr index ebe50c4d0d9..f1efafc19fd 100644 --- a/crates/nargo_cli/tests/test_data/numeric_generics/src/main.nr +++ b/crates/nargo_cli/tests/test_data/numeric_generics/src/main.nr @@ -3,15 +3,15 @@ fn main() { let b = id([1, 2, 3]); let itWorks1 = MyStruct { data: a }; - constrain itWorks1.data[1] == 2; + assert(itWorks1.data[1] == 2); let itWorks2 = MyStruct { data: b }; - constrain itWorks2.data[1] == 2; + assert(itWorks2.data[1] == 2); let c = [1, 2]; let itAlsoWorks = MyStruct { data: c }; - constrain itAlsoWorks.data[1] == 2; + assert(itAlsoWorks.data[1] == 2); - constrain foo(itWorks2).data[0] == itWorks2.data[0] + 1; + assert(foo(itWorks2).data[0] == itWorks2.data[0] + 1); } fn id(x: [Field; I]) -> [Field; I] { @@ -25,7 +25,7 @@ struct MyStruct { impl MyStruct { fn insert(mut self: Self, index: comptime Field, elem: Field) -> Self { // Regression test for numeric generics on impls - constrain index as u64 < S as u64; + assert(index as u64 < S as u64); self.data[index] = elem; self diff --git a/crates/nargo_cli/tests/test_data/pedersen_check/src/main.nr b/crates/nargo_cli/tests/test_data/pedersen_check/src/main.nr index b727112ce55..37fc3f61188 100644 --- a/crates/nargo_cli/tests/test_data/pedersen_check/src/main.nr +++ b/crates/nargo_cli/tests/test_data/pedersen_check/src/main.nr @@ -2,8 +2,8 @@ use dep::std; fn main(x: Field, y: Field, salt: Field, out_x: Field, out_y: Field ) { let res = std::hash::pedersen([x, y]); - constrain res[0] == out_x; - constrain res[1] == out_y; + assert(res[0] == out_x); + assert(res[1] == out_y); let raw_data = [x,y]; let mut state = 0; @@ -12,6 +12,6 @@ fn main(x: Field, y: Field, salt: Field, out_x: Field, out_y: Field ) { } state += salt; let hash = std::hash::pedersen([state]); - constrain std::hash::pedersen([43])[0] == hash[0]; + assert(std::hash::pedersen([43])[0] == hash[0]); } diff --git a/crates/nargo_cli/tests/test_data/poseidon_bn254_hash/src/main.nr b/crates/nargo_cli/tests/test_data/poseidon_bn254_hash/src/main.nr index f2f1af7ab7d..37621c732a8 100644 --- a/crates/nargo_cli/tests/test_data/poseidon_bn254_hash/src/main.nr +++ b/crates/nargo_cli/tests/test_data/poseidon_bn254_hash/src/main.nr @@ -3,8 +3,8 @@ use dep::std::hash::poseidon; fn main(x1: [Field; 2], y1: pub Field, x2: [Field; 4], y2: pub Field) { let hash1 = poseidon::bn254::hash_2(x1); - constrain hash1 == y1; + assert(hash1 == y1); let hash2 = poseidon::bn254::hash_4(x2); - constrain hash2 == y2; + assert(hash2 == y2); } diff --git a/crates/nargo_cli/tests/test_data/poseidonsponge_x5_254/src/main.nr b/crates/nargo_cli/tests/test_data/poseidonsponge_x5_254/src/main.nr index f5135897f19..3addc1cec97 100644 --- a/crates/nargo_cli/tests/test_data/poseidonsponge_x5_254/src/main.nr +++ b/crates/nargo_cli/tests/test_data/poseidonsponge_x5_254/src/main.nr @@ -5,5 +5,5 @@ fn main(x: [Field; 7]) // Test optimised sponge let result = poseidon::bn254::sponge(x); - constrain result == 0x080ae1669d62f0197190573d4a325bfb8d8fc201ce3127cbac0c47a7ac81ac48; + assert(result == 0x080ae1669d62f0197190573d4a325bfb8d8fc201ce3127cbac0c47a7ac81ac48); } diff --git a/crates/nargo_cli/tests/test_data/pred_eq/src/main.nr b/crates/nargo_cli/tests/test_data/pred_eq/src/main.nr index c9c43b56c07..c7986cb7af3 100644 --- a/crates/nargo_cli/tests/test_data/pred_eq/src/main.nr +++ b/crates/nargo_cli/tests/test_data/pred_eq/src/main.nr @@ -2,5 +2,5 @@ use dep::std; fn main(x: Field, y: Field) { let p = x == y; - constrain p == true; + assert(p == true); } diff --git a/crates/nargo_cli/tests/test_data/regression/src/main.nr b/crates/nargo_cli/tests/test_data/regression/src/main.nr index 2fcf41c8d7f..06e35827d1e 100644 --- a/crates/nargo_cli/tests/test_data/regression/src/main.nr +++ b/crates/nargo_cli/tests/test_data/regression/src/main.nr @@ -2,8 +2,8 @@ global NIBBLE_LENGTH: comptime Field = 16; fn compact_decode(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Field) { - constrain 2*input.len() as u64 <= NIBBLE_LENGTH as u64; - constrain length as u64 <= input.len() as u64; + assert(2*input.len() as u64 <= NIBBLE_LENGTH as u64); + assert(length as u64 <= input.len() as u64); let mut nibble = [0 as u4; NIBBLE_LENGTH]; @@ -43,7 +43,7 @@ fn compact_decode(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Fie fn enc(value: [u8; N], value_length: Field) -> ([u8; 32], Field) { - constrain value.len() as u8 >= value_length as u8; + assert(value.len() as u8 >= value_length as u8); let mut out_value = [0; 32]; if value_length == 0 { @@ -75,8 +75,8 @@ fn main(x: [u8; 5], z: Field) { //Issue 1144 let (nib, len) = compact_decode(x,z); - constrain len == 5; - constrain [nib[0], nib[1], nib[2], nib[3], nib[4]] == [15, 1, 12, 11, 8]; + assert(len == 5); + assert([nib[0], nib[1], nib[2], nib[3], nib[4]] == [15, 1, 12, 11, 8]); } @@ -96,6 +96,6 @@ fn enc_test() let enc_val1 = enc(val1,val1_length); - constrain enc_val1.0 == [0x94,0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]; - constrain enc_val1.1 == 21; + assert(enc_val1.0 == [0x94,0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]); + assert(enc_val1.1 == 21); } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/scalar_mul/src/main.nr b/crates/nargo_cli/tests/test_data/scalar_mul/src/main.nr index 72e022edc8e..d9d267f1dcd 100644 --- a/crates/nargo_cli/tests/test_data/scalar_mul/src/main.nr +++ b/crates/nargo_cli/tests/test_data/scalar_mul/src/main.nr @@ -17,6 +17,6 @@ fn main( pub_y = b_pub_y; } let res = std::scalar_mul::fixed_base(priv_key); - constrain res[0] == pub_x; - constrain res[1] == pub_y; + assert(res[0] == pub_x); + assert(res[1] == pub_y); } diff --git a/crates/nargo_cli/tests/test_data/schnorr/src/main.nr b/crates/nargo_cli/tests/test_data/schnorr/src/main.nr index 39676ca7389..ec4f819858a 100644 --- a/crates/nargo_cli/tests/test_data/schnorr/src/main.nr +++ b/crates/nargo_cli/tests/test_data/schnorr/src/main.nr @@ -6,5 +6,5 @@ fn main(message: [u8; 10], pub_key_x: Field, pub_key_y: Field, signature: [u8; 6 // Is there ever a situation where someone would want // to ensure that a signature was invalid? let x = std::schnorr::verify_signature(pub_key_x,pub_key_y,signature, message); - constrain x == 1; + assert(x == 1); } diff --git a/crates/nargo_cli/tests/test_data/sha256/src/main.nr b/crates/nargo_cli/tests/test_data/sha256/src/main.nr index bf2249c4faf..fd5340e2384 100644 --- a/crates/nargo_cli/tests/test_data/sha256/src/main.nr +++ b/crates/nargo_cli/tests/test_data/sha256/src/main.nr @@ -15,5 +15,5 @@ fn main(x: Field, result: [u8; 32]) { // We use the `as` keyword here to denote the fact that we want to take just the first byte from the x Field // The padding is taken care of by the program let digest = std::hash::sha256([x as u8]); - constrain digest == result; + assert(digest == result); } diff --git a/crates/nargo_cli/tests/test_data/sha2_blocks/src/main.nr b/crates/nargo_cli/tests/test_data/sha2_blocks/src/main.nr index 7e687cd179b..fcdcdb8684f 100644 --- a/crates/nargo_cli/tests/test_data/sha2_blocks/src/main.nr +++ b/crates/nargo_cli/tests/test_data/sha2_blocks/src/main.nr @@ -5,18 +5,18 @@ fn main(x: [u8; 3], result256: [u8; 32], result512: [u8; 64]) { // One-block tests. let mut digest256 = std::sha256::digest(x); - constrain digest256 == result256; + assert(digest256 == result256); let mut digest512 = std::sha512::digest(x); - constrain digest512 == result512; + assert(digest512 == result512); // Two-block SHA256 test. Taken from https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA256.pdf let y: [u8; 56] = [97,98,99,100,98,99,100,101,99,100,101,102,100,101,102,103,101,102,103,104,102,103,104,105,103,104,105,106,104,105,106,107,105,106,107,108,106,107,108,109,107,108,109,110,108,109,110,111,109,110,111,112,110,111,112,113]; // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" digest256 = std::sha256::digest(y); - constrain digest256 == [36,141,106,97,210,6,56,184,229,192,38,147,12,62,96,57,163,60,228,89,100,255,33,103,246,236,237,212,25,219,6,193]; + assert(digest256 == [36,141,106,97,210,6,56,184,229,192,38,147,12,62,96,57,163,60,228,89,100,255,33,103,246,236,237,212,25,219,6,193]); // Two-block SHA256 test. Taken from https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf let z: [u8; 112] = [97,98,99,100,101,102,103,104,98,99,100,101,102,103,104,105,99,100,101,102,103,104,105,106,100,101,102,103,104,105,106,107,101,102,103,104,105,106,107,108,102,103,104,105,106,107,108,109,103,104,105,106,107,108,109,110,104,105,106,107,108,109,110,111,105,106,107,108,109,110,111,112,106,107,108,109,110,111,112,113,107,108,109,110,111,112,113,114,108,109,110,111,112,113,114,115,109,110,111,112,113,114,115,116,110,111,112,113,114,115,116,117]; // "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" digest512 = std::sha512::digest(z); - constrain digest512 == [142,149,155,117,218,227,19,218,140,244,247,40,20,252,20,63,143,119,121,198,235,159,127,161,114,153,174,173,182,136,144,24,80,29,40,158,73,0,247,228,51,27,153,222,196,181,67,58,199,211,41,238,182,221,38,84,94,150,229,91,135,75,233,9]; + assert(digest512 == [142,149,155,117,218,227,19,218,140,244,247,40,20,252,20,63,143,119,121,198,235,159,127,161,114,153,174,173,182,136,144,24,80,29,40,158,73,0,247,228,51,27,153,222,196,181,67,58,199,211,41,238,182,221,38,84,94,150,229,91,135,75,233,9]); } diff --git a/crates/nargo_cli/tests/test_data/sha2_byte/src/main.nr b/crates/nargo_cli/tests/test_data/sha2_byte/src/main.nr index 3458862b646..a7cc9daebb9 100644 --- a/crates/nargo_cli/tests/test_data/sha2_byte/src/main.nr +++ b/crates/nargo_cli/tests/test_data/sha2_byte/src/main.nr @@ -4,8 +4,8 @@ use dep::std; fn main(x: Field, result256: [u8; 32], result512: [u8; 64]) { let digest256 = std::sha256::digest([x as u8]); - constrain digest256 == result256; + assert(digest256 == result256); let digest512 = std::sha512::digest([x as u8]); - constrain digest512 == result512; + assert(digest512 == result512); } diff --git a/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr b/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr index 20d41481c7e..65d0ec954ac 100644 --- a/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr +++ b/crates/nargo_cli/tests/test_data/simple_shield/src/main.nr @@ -30,7 +30,7 @@ fn main( // Check that the input note nullifier is in the root let is_member = std::merkle::check_membership(note_root, note_commitment[0], index, note_hash_path); - constrain is_member == 1; + assert(is_member == 1); [nullifier[0], receiver_note_commitment[0]] } diff --git a/crates/nargo_cli/tests/test_data/strings/src/main.nr b/crates/nargo_cli/tests/test_data/strings/src/main.nr index ca0d1691f86..bee2370201c 100644 --- a/crates/nargo_cli/tests/test_data/strings/src/main.nr +++ b/crates/nargo_cli/tests/test_data/strings/src/main.nr @@ -3,7 +3,7 @@ use dep::std; fn main(message : pub str<11>, y : Field, hex_as_string : str<4>, hex_as_field : Field) { let mut bad_message = "hello world"; - constrain message == "hello world"; + assert(message == "hello world"); bad_message = "helld world"; let x = 10; let z = x * 5; @@ -13,18 +13,18 @@ fn main(message : pub str<11>, y : Field, hex_as_string : str<4>, hex_as_field : std::println(x); let array = [1, 2, 3, 5, 8]; - constrain y == 5; // Change to y != 5 to see how the later print statements are not called + assert(y == 5); // Change to y != 5 to see how the later print statements are not called std::println(array); std::println(bad_message); - constrain message != bad_message; + assert(message != bad_message); let hash = std::hash::pedersen([x]); std::println(hash); - constrain hex_as_string == "0x41"; - // constrain hex_as_string != 0x41; This will fail with a type mismatch between str[4] and Field - constrain hex_as_field == 0x41; + assert(hex_as_string == "0x41"); + // assert(hex_as_string != 0x41); This will fail with a type mismatch between str[4] and Field + assert(hex_as_field == 0x41); } #[test] diff --git a/crates/nargo_cli/tests/test_data/struct/src/main.nr b/crates/nargo_cli/tests/test_data/struct/src/main.nr index b426339c1e4..6d61393920d 100644 --- a/crates/nargo_cli/tests/test_data/struct/src/main.nr +++ b/crates/nargo_cli/tests/test_data/struct/src/main.nr @@ -58,20 +58,20 @@ fn main(x: Field, y: Field) { let first = Foo::default(x,y); let p = Pair { first, second: 1 }; - constrain p.bar() == x; - constrain p.second == y; - constrain p.first.array[0] != p.first.array[1]; + assert(p.bar() == x); + assert(p.second == y); + assert(p.first.array[0] != p.first.array[1]); // Nested structs let (struct_from_tuple, a_bool) = test_struct_in_tuple(true,x,y); - constrain struct_from_tuple.my_bool == true; - constrain a_bool == true; - constrain struct_from_tuple.my_int == 5; - constrain struct_from_tuple.my_nest.a == 0; + assert(struct_from_tuple.my_bool == true); + assert(a_bool == true); + assert(struct_from_tuple.my_int == 5); + assert(struct_from_tuple.my_nest.a == 0); // Regression test for issue #670 let Animal { legs, eyes } = get_dog(); let six = legs + eyes as Field; - constrain six == 6; + assert(six == 6); } diff --git a/crates/nargo_cli/tests/test_data/struct_inputs/src/main.nr b/crates/nargo_cli/tests/test_data/struct_inputs/src/main.nr index e022f26947c..fe77ed6eee6 100644 --- a/crates/nargo_cli/tests/test_data/struct_inputs/src/main.nr +++ b/crates/nargo_cli/tests/test_data/struct_inputs/src/main.nr @@ -14,23 +14,23 @@ fn main(x : Field, y : pub myStruct, z: pub foo::bar::barStruct, a: pub foo::foo check_inner_struct(a, z); for i in 0 .. struct_from_bar.array.len() { - constrain struct_from_bar.array[i] == z.array[i]; + assert(struct_from_bar.array[i] == z.array[i]); } - constrain z.val == struct_from_bar.val; + assert(z.val == struct_from_bar.val); - constrain (struct_from_bar.val * x) == x; + assert((struct_from_bar.val * x) == x); - constrain x != y.bar; + assert(x != y.bar); - constrain y.message == "hello"; - constrain a.bar_struct.message == struct_from_bar.message; + assert(y.message == "hello"); + assert(a.bar_struct.message == struct_from_bar.message); a.bar_struct.array[1] } fn check_inner_struct(a: foo::fooStruct, z: foo::bar::barStruct) { - constrain a.bar_struct.val == z.val; + assert(a.bar_struct.val == z.val); for i in 0.. a.bar_struct.array.len() { - constrain a.bar_struct.array[i] == z.array[i]; + assert(a.bar_struct.array[i] == z.array[i]); } } diff --git a/crates/nargo_cli/tests/test_data/submodules/src/main.nr b/crates/nargo_cli/tests/test_data/submodules/src/main.nr index 90c778db111..9bfe382663f 100644 --- a/crates/nargo_cli/tests/test_data/submodules/src/main.nr +++ b/crates/nargo_cli/tests/test_data/submodules/src/main.nr @@ -9,7 +9,7 @@ mod mysubmodule { use dep::std; fn my_bool_or(x: u1, y: u1) { - constrain x | y == 1; + assert(x | y == 1); } fn my_helper() {} diff --git a/crates/nargo_cli/tests/test_data/to_be_bytes/src/main.nr b/crates/nargo_cli/tests/test_data/to_be_bytes/src/main.nr index 1253656217d..f5831e8c524 100644 --- a/crates/nargo_cli/tests/test_data/to_be_bytes/src/main.nr +++ b/crates/nargo_cli/tests/test_data/to_be_bytes/src/main.nr @@ -7,8 +7,8 @@ fn main(x : Field) -> pub [u8; 31] { for i in 0..31 { bytes[i] = byte_array[i]; } - constrain bytes[30] == 60; - constrain bytes[29] == 33; - constrain bytes[28] == 31; + assert(bytes[30] == 60); + assert(bytes[29] == 33); + assert(bytes[28] == 31); bytes } diff --git a/crates/nargo_cli/tests/test_data/to_bytes_integration/src/main.nr b/crates/nargo_cli/tests/test_data/to_bytes_integration/src/main.nr index 6f57b407da7..1932b7556a8 100644 --- a/crates/nargo_cli/tests/test_data/to_bytes_integration/src/main.nr +++ b/crates/nargo_cli/tests/test_data/to_bytes_integration/src/main.nr @@ -7,8 +7,8 @@ fn main(x : Field) { // The result of this byte array will be little-endian let le_byte_array = x.to_le_bytes(31); - constrain le_byte_array[0] == 60; - constrain le_byte_array[0] == be_byte_array[30]; - constrain le_byte_array[1] == be_byte_array[29]; - constrain le_byte_array[2] == be_byte_array[28]; + assert(le_byte_array[0] == 60); + assert(le_byte_array[0] == be_byte_array[30]); + assert(le_byte_array[1] == be_byte_array[29]); + assert(le_byte_array[2] == be_byte_array[28]); } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/tuples/src/main.nr b/crates/nargo_cli/tests/test_data/tuples/src/main.nr index ce25b9171cd..4a003dc5a42 100644 --- a/crates/nargo_cli/tests/test_data/tuples/src/main.nr +++ b/crates/nargo_cli/tests/test_data/tuples/src/main.nr @@ -2,18 +2,18 @@ use dep::std; fn main(x: Field, y: Field) { let pair = (x, y); - constrain pair.0 == 1; - constrain pair.1 == 0; + assert(pair.0 == 1); + assert(pair.1 == 0); let (a, b) = if true { (0, 1) } else { (2, 3) }; - constrain a == 0; - constrain b == 1; + assert(a == 0); + assert(b == 1); let (u,v) = if x as u32 <1 { (x,x+1) } else { (x+1,x) }; - constrain u==x+1; - constrain v==x; + assert(u==x+1); + assert(v==x); } diff --git a/crates/nargo_cli/tests/test_data/xor/src/main.nr b/crates/nargo_cli/tests/test_data/xor/src/main.nr index cc7caf17fad..e893c938fc3 100644 --- a/crates/nargo_cli/tests/test_data/xor/src/main.nr +++ b/crates/nargo_cli/tests/test_data/xor/src/main.nr @@ -1,5 +1,5 @@ fn main(x : u32, y : pub u32) { let m = x ^ y; - constrain m != 10; + assert(m != 10); } \ No newline at end of file diff --git a/crates/noirc_frontend/src/hir/resolution/resolver.rs b/crates/noirc_frontend/src/hir/resolution/resolver.rs index 98cf5993edf..f03bcefeb2d 100644 --- a/crates/noirc_frontend/src/hir/resolution/resolver.rs +++ b/crates/noirc_frontend/src/hir/resolution/resolver.rs @@ -1357,7 +1357,7 @@ mod test { let src = r#" fn main(x : Field) { let y = x + x; - constrain y == x; + assert(y == x); } "#; @@ -1369,7 +1369,7 @@ mod test { let src = r#" fn main(x : Field) { let y = x + x; - constrain x == x; + assert(x == x); } "#; @@ -1392,7 +1392,7 @@ mod test { let src = r#" fn main(x : Field) { let y = x + x; - constrain y == z; + assert(y == z); } "#; @@ -1428,7 +1428,7 @@ mod test { let src = r#" fn main(x : Field) { let y = 5; - constrain y == x; + assert(y == x); } "#; diff --git a/examples_failing/ecdsa_secp256k1/src/main.nr b/examples_failing/ecdsa_secp256k1/src/main.nr index 6ee7a98a89d..43a4f78e634 100644 --- a/examples_failing/ecdsa_secp256k1/src/main.nr +++ b/examples_failing/ecdsa_secp256k1/src/main.nr @@ -13,5 +13,5 @@ fn main(hashed_message : [32]u8, pub_key_x : [32]u8, pub_key_y : [32]u8, signatu // Is there ever a situation where someone would want // to ensure that a signature was invalid? let x = std::ecdsa_secp256k1::verify_signature(pub_key_x,pub_key_y,signature, hashed_message); - constrain x == 1; + assert(x == 1); } diff --git a/examples_failing/pow_const/src/main.nr b/examples_failing/pow_const/src/main.nr index 4355935d2ad..9b742417e15 100644 --- a/examples_failing/pow_const/src/main.nr +++ b/examples_failing/pow_const/src/main.nr @@ -1,6 +1,6 @@ use dep::std; fn main(_x : Field) { - constrain std::pow_const(2,3) == _x; + assert(std::pow_const(2,3) == _x); } diff --git a/noir_stdlib/src/ec/montcurve.nr b/noir_stdlib/src/ec/montcurve.nr index fad5e5e0a97..e917661f0f1 100644 --- a/noir_stdlib/src/ec/montcurve.nr +++ b/noir_stdlib/src/ec/montcurve.nr @@ -82,13 +82,13 @@ mod affine { // Curve constructor fn new(j: Field, k: Field, gen: Point) -> Self { // Check curve coefficients - constrain k != 0; - constrain j*j != 4; + assert(k != 0); + assert(j*j != 4); let curve = Self {j, k, gen}; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } @@ -180,10 +180,10 @@ mod affine { let z = ZETA; // Non-square Field element required for map // Check whether curve is admissible - constrain j != 0; + assert(j != 0); let l = (j*j - 4)/(k*k); - constrain l != 0; - constrain is_square(l) == false; + assert(l != 0); + assert(is_square(l) == false); let x1 = safe_inverse(1+z*u*u)*(0 - (j/k)); @@ -284,13 +284,13 @@ mod curvegroup { // Curve constructor fn new(j: Field, k: Field, gen: Point) -> Self { // Check curve coefficients - constrain k != 0; - constrain j*j != 4; + assert(k != 0); + assert(j*j != 4); let curve = Self {j, k, gen}; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } diff --git a/noir_stdlib/src/ec/swcurve.nr b/noir_stdlib/src/ec/swcurve.nr index 8e2a996e927..eae4f375e43 100644 --- a/noir_stdlib/src/ec/swcurve.nr +++ b/noir_stdlib/src/ec/swcurve.nr @@ -71,12 +71,12 @@ mod affine { // Curve constructor fn new(a: Field, b: Field, gen: Point) -> Curve { // Check curve coefficients - constrain 4*a*a*a + 27*b*b != 0; + assert(4*a*a*a + 27*b*b != 0); let curve = Curve { a, b, gen }; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } @@ -164,7 +164,7 @@ mod affine { // where g(x) = x^3 + a*x + b. swu_map(c,z,.) then maps a Field element to a point on curve c. fn swu_map(self, z: Field, u: Field) -> Point { // Check whether curve is admissible - constrain self.a*self.b != 0; + assert(self.a*self.b != 0); let Curve {a, b, gen: _gen} = self; @@ -248,12 +248,12 @@ mod curvegroup { // Curve constructor fn new(a: Field, b: Field, gen: Point) -> Curve { // Check curve coefficients - constrain 4*a*a*a + 27*b*b != 0; + assert(4*a*a*a + 27*b*b != 0); let curve = Curve { a, b, gen }; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } diff --git a/noir_stdlib/src/ec/tecurve.nr b/noir_stdlib/src/ec/tecurve.nr index 43c9f5d2017..8611e4270c3 100644 --- a/noir_stdlib/src/ec/tecurve.nr +++ b/noir_stdlib/src/ec/tecurve.nr @@ -81,12 +81,12 @@ mod affine { // Curve constructor fn new(a: Field, d: Field, gen: Point) -> Curve { // Check curve coefficients - constrain a*d*(a-d) != 0; + assert(a*d*(a-d) != 0); let curve = Curve {a, d, gen}; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } @@ -286,12 +286,12 @@ mod curvegroup { // Curve constructor fn new(a: Field, d: Field, gen: Point) -> Curve { // Check curve coefficients - constrain a*d*(a-d) != 0; + assert(a*d*(a-d) != 0); let curve = Curve { a, d, gen }; // gen should be on the curve - constrain curve.contains(curve.gen); + assert(curve.contains(curve.gen)); curve } diff --git a/noir_stdlib/src/hash/poseidon.nr b/noir_stdlib/src/hash/poseidon.nr index 7ac365c4995..416f740bbdf 100644 --- a/noir_stdlib/src/hash/poseidon.nr +++ b/noir_stdlib/src/hash/poseidon.nr @@ -20,9 +20,9 @@ fn config( mds: [Field; N]) -> PoseidonConfig { // Input checks - constrain t as u8 * (rf + rp) == ark.len() as u8; - constrain t * t == mds.len(); - constrain alpha != 0; + assert(t as u8 * (rf + rp) == ark.len() as u8); + assert(t * t == mds.len()); + assert(alpha != 0); PoseidonConfig {t, rf, rp, alpha, ark, mds} } @@ -34,7 +34,7 @@ fn permute( -> [Field; O] { let PoseidonConfig {t, rf, rp, alpha, ark, mds} = pos_conf; - constrain t == state.len(); + assert(t == state.len()); let mut count = 0; @@ -68,7 +68,7 @@ fn absorb( capacity: comptime Field, // Capacity; usually 1 msg: [Field; P]) // Arbitrary length message -> [Field; O] { - constrain pos_conf.t == rate + capacity; + assert(pos_conf.t == rate + capacity); let mut i = 0; diff --git a/noir_stdlib/src/hash/poseidon/bn254.nr b/noir_stdlib/src/hash/poseidon/bn254.nr index 355e7d13a5f..9ba26dbd878 100644 --- a/noir_stdlib/src/hash/poseidon/bn254.nr +++ b/noir_stdlib/src/hash/poseidon/bn254.nr @@ -15,9 +15,9 @@ fn permute( let rf = 8; let rp = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68][state.len() - 2]; - constrain t == state.len(); - constrain rf == config_rf as Field; - constrain rp == config_rp as Field; + assert(t == state.len()); + assert(rf == config_rf as Field); + assert(rp == config_rp as Field); let mut count = 0; @@ -73,7 +73,7 @@ fn absorb( msg: [Field; P] // Arbitrary length message ) -> [Field; O] { - constrain pos_conf.t == rate + capacity; + assert(pos_conf.t == rate + capacity); let mut i = 0;