From 890717f8fe52dc25beb9d9503918172d7342bc81 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Sun, 2 Jun 2024 12:32:38 -0700 Subject: [PATCH] bugfix: opt::mem::obliv recognize scalar variables as tuple-free --- examples/ZoKrates/pf/2024_06_02_chad_bug.zok | 22 ++++++++++++++++++++ scripts/zokrates_test.zsh | 1 + src/ir/opt/mem/obliv.rs | 1 + 3 files changed, 24 insertions(+) create mode 100644 examples/ZoKrates/pf/2024_06_02_chad_bug.zok diff --git a/examples/ZoKrates/pf/2024_06_02_chad_bug.zok b/examples/ZoKrates/pf/2024_06_02_chad_bug.zok new file mode 100644 index 000000000..5130e8356 --- /dev/null +++ b/examples/ZoKrates/pf/2024_06_02_chad_bug.zok @@ -0,0 +1,22 @@ +struct BigNat_init_quotient { + field[Qm1][Lp1] limbs + field last_limb +} + +struct BigNat_init { + field[N][Lp1] limbs +} +struct BigNatModMult_init { + BigNat_init_quotient quotient_init + BigNat_init carry_init +} + +const u32 Qm1 = 7 +const u32 Lp1 = 4 +const u32 ZG = 2 +const u32 CL = 5 + +def main(private BigNatModMult_init[1] intermediate_mod) -> bool: + BigNat_init carry = intermediate_mod[0].carry_init + assert(carry.limbs[0][0] == 1) + return true diff --git a/scripts/zokrates_test.zsh b/scripts/zokrates_test.zsh index 3b0b356a0..5af8f6ddc 100755 --- a/scripts/zokrates_test.zsh +++ b/scripts/zokrates_test.zsh @@ -88,6 +88,7 @@ r1cs_test ./third_party/ZoKrates/zokrates_stdlib/stdlib/utils/casts/bool_128_to_ r1cs_test ./third_party/ZoKrates/zokrates_stdlib/stdlib/ecc/edwardsScalarMult.zok r1cs_test ./third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/mimc7/mimc7R20.zok r1cs_test ./third_party/ZoKrates/zokrates_stdlib/stdlib/hashes/pedersen/512bit.zok +r1cs_test ./examples/ZoKrates/pf/2024_06_02_chad_bug.zok pf_test_only_pf sha_temp1 pf_test_only_pf sha_rot diff --git a/src/ir/opt/mem/obliv.rs b/src/ir/opt/mem/obliv.rs index aa0e54ea2..9514692b4 100644 --- a/src/ir/opt/mem/obliv.rs +++ b/src/ir/opt/mem/obliv.rs @@ -42,6 +42,7 @@ impl OblivRewriter { } fn visit(&mut self, t: &Term) { let (tup_opt, term_opt) = match t.op() { + Op::Var(_, sort) if sort.is_scalar() => (Some(t.clone()), None), Op::Const(v @ Value::Array(_)) => (Some(leaf_term(Op::Const(arr_val_to_tup(v)))), None), Op::Array(_k, _v) => ( Some(term(