From 1d1b592039fa73ce561d6b6886c36b02b36ada53 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 9 Nov 2022 10:23:54 -0500 Subject: [PATCH] Expand cases for generating a witness in prepare inputs (#452) * preliminary debugging and testing * more preliminary debugging for prepare_inputs method * more debugging prints * add wnew witness for gadget inputs that are set based upon instructions * working evaluation when inputs to gadget are from aan if statement * clean up syntax and minor changes from PR review --- .../tests/test_data/scalar_mul/Prover.toml | 8 ++++++-- .../tests/test_data/scalar_mul/src/main.nr | 19 +++++++++++++++++-- crates/noirc_evaluator/src/ssa/acir_gen.rs | 9 ++++----- crates/noirc_evaluator/src/ssa/node.rs | 1 - 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/crates/nargo/tests/test_data/scalar_mul/Prover.toml b/crates/nargo/tests/test_data/scalar_mul/Prover.toml index bab1eefa7bb..69b91cb5f31 100644 --- a/crates/nargo/tests/test_data/scalar_mul/Prover.toml +++ b/crates/nargo/tests/test_data/scalar_mul/Prover.toml @@ -1,3 +1,7 @@ a = "1" -pub_x = "0x0000000000000000000000000000000000000000000000000000000000000001" -pub_y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c" +a_pub_x = "0x0000000000000000000000000000000000000000000000000000000000000001" +a_pub_y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c" + +b = "2" +b_pub_x = "0x06ce1b0827aafa85ddeb49cdaa36306d19a74caa311e13d46d8bc688cdbffffe" +b_pub_y = "0x1c122f81a3a14964909ede0ba2a6855fc93faf6fa1a788bf467be7e7a43f80ac" \ No newline at end of file diff --git a/crates/nargo/tests/test_data/scalar_mul/src/main.nr b/crates/nargo/tests/test_data/scalar_mul/src/main.nr index 21a7ce35f5b..72e022edc8e 100644 --- a/crates/nargo/tests/test_data/scalar_mul/src/main.nr +++ b/crates/nargo/tests/test_data/scalar_mul/src/main.nr @@ -1,7 +1,22 @@ use dep::std; -fn main(a: Field, pub_x: pub Field, pub_y: pub Field) { - let res = std::scalar_mul::fixed_base(a); +fn main( + a: Field, + a_pub_x: pub Field, + a_pub_y: pub Field, + b: Field, + b_pub_x: pub Field, + b_pub_y: pub Field +) { + let mut priv_key = a; + let mut pub_x: Field = a_pub_x; + let mut pub_y: Field = a_pub_y; + if a != 1 { // Change `a` in Prover.toml to test input `b` + priv_key = b; + pub_x = b_pub_x; + pub_y = b_pub_y; + } + let res = std::scalar_mul::fixed_base(priv_key); constrain res[0] == pub_x; constrain res[1] == pub_y; } diff --git a/crates/noirc_evaluator/src/ssa/acir_gen.rs b/crates/noirc_evaluator/src/ssa/acir_gen.rs index 0f5235f4593..e96e5cb6c57 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen.rs @@ -526,11 +526,10 @@ impl Acir { } _ => { if self.arith_cache.contains_key(a) { - if let Some(w) = self.arith_cache[a].clone().witness { - inputs.push(GadgetInput { witness: w, num_bits: l_obj.size_in_bits() }); - } else { - todo!(); - } + let var = self.arith_cache[a].clone(); + let witness = + var.witness.unwrap_or_else(|| generate_witness(&var, evaluator)); + inputs.push(GadgetInput { witness, num_bits: l_obj.size_in_bits() }); } else { dbg!(&l_obj); unreachable!("invalid input") diff --git a/crates/noirc_evaluator/src/ssa/node.rs b/crates/noirc_evaluator/src/ssa/node.rs index 39c5c97e73c..2ffebd0a3e3 100644 --- a/crates/noirc_evaluator/src/ssa/node.rs +++ b/crates/noirc_evaluator/src/ssa/node.rs @@ -736,7 +736,6 @@ impl Binary { let l_is_zero = lhs.map_or(false, |x| x.is_zero()); let r_is_zero = rhs.map_or(false, |x| x.is_zero()); - match &self.operator { BinaryOp::Add | BinaryOp::SafeAdd => { if l_is_zero {