Skip to content

Commit

Permalink
Expand cases for generating a witness in prepare inputs (#452)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vezenovm authored Nov 9, 2022
1 parent 10ce7a8 commit 1d1b592
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
8 changes: 6 additions & 2 deletions crates/nargo/tests/test_data/scalar_mul/Prover.toml
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 17 additions & 2 deletions crates/nargo/tests/test_data/scalar_mul/src/main.nr
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 4 additions & 5 deletions crates/noirc_evaluator/src/ssa/acir_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion crates/noirc_evaluator/src/ssa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1d1b592

Please sign in to comment.