diff --git a/tooling/nargo_cli/tests/execution_success/conditional_3_regression/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_3_regression/src/main.nr deleted file mode 100644 index cc3e2b2c5ba..00000000000 --- a/tooling/nargo_cli/tests/execution_success/conditional_3_regression/src/main.nr +++ /dev/null @@ -1,155 +0,0 @@ -use dep::std; - - - -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); - assert(digest == result); -} - -fn test4() -> [u32; 4] { - let b: [u32; 4] = [1,2,3,4]; - b -} - -fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ - // Regression test for issue #547 - // Warning: it must be kept at the start of main - let arr: [u8; 2] = [1, 2]; - if arr[0] != arr[1] { - for i in 0..1 { - assert(i != 2); - } - } - - //Issue reported in #421 - if a == c[0] { - assert(c[0] == 0); - } else { - if a == c[1] { - assert(c[1] == 0); - } else { - if a == c[2] { - assert(c[2] == 0); - } - } - } - - //Regression for to_le_bits() constant evaluation - // binary array representation of u8 1 - let as_bits_hardcode_1 = [1, 0]; - let mut c1 = 0; - for i in 0..2 { - let mut as_bits = (arr[i] as Field).to_le_bits(2); - c1 = c1 + as_bits[0] as Field; - - if i == 0 { - assert(arr[i] == 1);// 1 - for k in 0..2 { - assert(as_bits_hardcode_1[k] == as_bits[k]); - } - } - if i == 1 { - assert(arr[i] == 2);//2 - for k in 0..2 { - assert(as_bits_hardcode_1[k] != as_bits[k]); - } - } - } - assert(c1 == 1); - - //Regression for Issue #579 - let result1_true = test(true); - assert(result1_true.array_param[0] == 1); - let result1_false = test(false); - assert(result1_false.array_param[0] == 0); - - //regression for short-circuit2 - if 35 == a { - assert(false); - } - bar(a as Field); - - if a == 3 { - c = test4(); - } - assert(c[1] != 2); - call_intrinsic(x, result); - - - // Regression for issue #661: - let mut c_661 :[u32;1]=[0]; - if a > 5 { - c_661 = issue_661_foo(issue_661_bar(c), a); - } else { - c_661 = issue_661_foo(issue_661_bar(c), a + 2); - } - assert(c_661[0] < 20000); - - // Regression for predicate simplification - safe_inverse(0); -} - -fn test5(a : u32) { - if a > 1 { - let q = a / 2; - assert(q == 2); - } -} - - - -fn foo() { - let mut x = 1; - x /= 0; -} - -fn bar(x:Field) { - if x == 15 { - foo(); - } -} - - -struct MyStruct579 { - array_param: [u32; 2] -} - -impl MyStruct579 { - fn new(array_param: [u32; 2]) -> MyStruct579 { - MyStruct579 { - array_param: array_param - } - } -} - -fn test(flag: bool) -> MyStruct579 { - let mut my_struct = MyStruct579::new([0; 2]); - - if flag == true { - my_struct= MyStruct579::new([1; 2]); - } - my_struct -} - -fn issue_661_foo(array: [u32;4], b:u32) ->[u32;1] { - [array[0]+b] -} - -fn issue_661_bar(a : [u32;4]) ->[u32;4] { - let mut b:[u32;4] = [0;4]; - b[0]=a[0]+1; - b -} - -fn safe_inverse(n: Field) -> Field -{ - if n == 0 { - 0 - } - else { - 1 / n - } -} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_3_regression/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/Nargo.toml similarity index 68% rename from tooling/nargo_cli/tests/execution_success/conditional_3_regression/Nargo.toml rename to tooling/nargo_cli/tests/execution_success/conditional_regression_421/Nargo.toml index 868208a4fe2..9fddef0e86f 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_3_regression/Nargo.toml +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "conditional_3_regression" +name = "conditional_regression_421" type = "bin" authors = [""] compiler_version = "0.1" diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_421/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/Prover.toml new file mode 100644 index 00000000000..73fa4a5e31a --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/Prover.toml @@ -0,0 +1,2 @@ +c=[2, 4, 3, 0, ] +a=0 diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr new file mode 100644 index 00000000000..b31cf761be8 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr @@ -0,0 +1,14 @@ +fn main(a: u32, mut c: [u32; 4]){ + //Issue reported in #421 + if a == c[0] { + assert(c[0] == 0); + } else { + if a == c[1] { + assert(c[1] == 0); + } else { + if a == c[2] { + assert(c[2] == 0); + } + } + } +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_547/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/Nargo.toml new file mode 100644 index 00000000000..2729aca911c --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "conditional_regression_547" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_547/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr new file mode 100644 index 00000000000..e5df4cbf8da --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr @@ -0,0 +1,23 @@ +fn main() -> pub Field { + // Regression test for issue #547 + // Warning: it must be kept at the start of main + let arr: [u8; 2] = [1, 2]; + if arr[0] != arr[1] { + for i in 0..1 { + assert(i != 2); + } + } + + // Regression for predicate simplification + safe_inverse(0) +} + +fn safe_inverse(n: Field) -> Field +{ + if n == 0 { + 0 + } + else { + 1 / n + } +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_579/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/Nargo.toml new file mode 100644 index 00000000000..fab92005fba --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "conditional_regression_579" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_579/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr new file mode 100644 index 00000000000..ae1d11eef77 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr @@ -0,0 +1,28 @@ +fn main(){ + //Regression for Issue #579 + let result1_true = test(true); + assert(result1_true.array_param[0] == 1); + let result1_false = test(false); + assert(result1_false.array_param[0] == 0); +} + +struct MyStruct579 { + array_param: [u32; 2] +} + +impl MyStruct579 { + fn new(array_param: [u32; 2]) -> MyStruct579 { + MyStruct579 { + array_param: array_param + } + } +} + +fn test(flag: bool) -> MyStruct579 { + let mut my_struct = MyStruct579::new([0; 2]); + + if flag == true { + my_struct= MyStruct579::new([1; 2]); + } + my_struct +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_661/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/Nargo.toml new file mode 100644 index 00000000000..902408f5d56 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "conditional_regression_661" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_3_regression/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/Prover.toml similarity index 100% rename from tooling/nargo_cli/tests/execution_success/conditional_3_regression/Prover.toml rename to tooling/nargo_cli/tests/execution_success/conditional_regression_661/Prover.toml diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr new file mode 100644 index 00000000000..a4765ecfc00 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr @@ -0,0 +1,29 @@ +fn main(a: u32, mut c: [u32; 4]){ + // Regression for issue #661: + let mut c_661 :[u32;1]=[0]; + if a > 5 { + c_661 = issue_661_foo(issue_661_bar(c), a); + } else { + c_661 = issue_661_foo(issue_661_bar(c), a + 2); + } + assert(c_661[0] < 20000); +} + +fn test5(a : u32) { + if a > 1 { + let q = a / 2; + assert(q == 2); + } +} + + +fn issue_661_foo(array: [u32;4], b:u32) ->[u32;1] { + [array[0]+b] +} + +fn issue_661_bar(a : [u32;4]) ->[u32;4] { + let mut b:[u32;4] = [0;4]; + b[0]=a[0]+1; + b +} + diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Nargo.toml new file mode 100644 index 00000000000..24c16982cc4 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "conditional_regression_short_circuit" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Prover.toml new file mode 100644 index 00000000000..baad8be126a --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/Prover.toml @@ -0,0 +1,38 @@ +c=[2, 4, 3, 0, ] +a=0 +x = [104, 101, 108, 108, 111] + +result = [ + 0x2c, + 0xf2, + 0x4d, + 0xba, + 0x5f, + 0xb0, + 0xa3, + 0x0e, + 0x26, + 0xe8, + 0x3b, + 0x2a, + 0xc5, + 0xb9, + 0xe2, + 0x9e, + 0x1b, + 0x16, + 0x1e, + 0x5c, + 0x1f, + 0xa7, + 0x42, + 0x5e, + 0x73, + 0x04, + 0x33, + 0x62, + 0x93, + 0x8b, + 0x98, + 0x24, +] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr new file mode 100644 index 00000000000..4fb4c37a1ab --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr @@ -0,0 +1,41 @@ +use dep::std; + +fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ + //regression for short-circuit2 + if 35 == a { + assert(false); + } + bar(a as Field); + + if a == 3 { + c = test4(); + } + assert(c[1] != 2); + call_intrinsic(x, result); +} + + + +fn foo() { + let mut x = 1; + x /= 0; +} + +fn bar(x:Field) { + if x == 15 { + foo(); + } +} + + +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); + assert(digest == result); +} + +fn test4() -> [u32; 4] { + let b: [u32; 4] = [1,2,3,4]; + b +} \ No newline at end of file diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/Nargo.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/Nargo.toml new file mode 100644 index 00000000000..aa1bbaaf89c --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "cconditional_regression_to_bits" +type = "bin" +authors = [""] +compiler_version = "0.1" + +[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/Prover.toml b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr new file mode 100644 index 00000000000..8c612ca0eb2 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr @@ -0,0 +1,32 @@ +use dep::std; + + +fn main() { + + //Regression for to_le_bits() constant evaluation + // binary array representation of u8 1 + let arr: [u8; 2] = [1, 2]; + let as_bits_hardcode_1 = [1, 0]; + let mut c1 = 0; + for i in 0..2 { + let mut as_bits = (arr[i] as Field).to_le_bits(2); + c1 = c1 + as_bits[0] as Field; + + if i == 0 { + assert(arr[i] == 1);// 1 + for k in 0..2 { + assert(as_bits_hardcode_1[k] == as_bits[k]); + } + } + if i == 1 { + assert(arr[i] == 2);//2 + for k in 0..2 { + assert(as_bits_hardcode_1[k] != as_bits[k]); + } + } + } + assert(c1 == 1); + + +} +