From ef4484f7efca8764af9ecc8c2617ef1fe1214646 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 31 May 2021 19:55:23 +0200 Subject: [PATCH] introduce if-else expression, implement case in propagation when consequence and alternative are equal, adjust tests --- .../tests/panics/conditional_bound_throw.zok | 10 ++++ .../conditional_bound_throw_no_isolation.json | 51 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 zokrates_core_test/tests/tests/panics/conditional_bound_throw.zok create mode 100644 zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json diff --git a/zokrates_core_test/tests/tests/panics/conditional_bound_throw.zok b/zokrates_core_test/tests/tests/panics/conditional_bound_throw.zok new file mode 100644 index 00000000..2258ee9c --- /dev/null +++ b/zokrates_core_test/tests/tests/panics/conditional_bound_throw.zok @@ -0,0 +1,10 @@ +def throwing_bound(u32 x) -> u32: + assert(x == N) + return 1 + +// this compiles: the conditional, even though it can throw, has a constant compile-time value of `1` +// However, the assertions are still checked at runtime, which leads to panics without branch isolation. +def main(u32 x): + for u32 i in 0..if x == 0 then throwing_bound::<0>(x) else throwing_bound::<1>(x) fi do + endfor + return \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json new file mode 100644 index 00000000..9d8548fa --- /dev/null +++ b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json @@ -0,0 +1,51 @@ +{ + "entry_point": "./tests/tests/panics/conditional_bound_throw.zok", + "curves": ["Bn128"], + "tests": [ + { + "input": { + "values": [ + "0" + ] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1" + } + } + } + }, + { + "input": { + "values": [ + "1" + ] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "1", + "right": "0" + } + } + } + }, + { + "input": { + "values": [ + "2" + ] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "2", + "right": "0" + } + } + } + } + ] +}