diff --git a/src/circuit/lookup.rs b/src/circuit/lookup.rs index e002609..d1123fb 100644 --- a/src/circuit/lookup.rs +++ b/src/circuit/lookup.rs @@ -154,10 +154,15 @@ pub fn lookup3_xy_with_conditional_negation( )?; // Allocate the y-coordinate resulting from the lookup + // and conditional negation let res_y = AllocatedNum::alloc( cs.namespace(|| "y"), || { - Ok(coords[*i.get()?].1) + let mut tmp = coords[*i.get()?].1; + if *bits[2].get_value().get()? { + tmp.negate(); + } + Ok(tmp) } )?; @@ -181,19 +186,19 @@ pub fn lookup3_xy_with_conditional_negation( |lc| lc + res_x.get_variable() ); + let y_lc = precomp.lc::(one, y_coeffs[0b11]) + + &bits[1].lc::(one, y_coeffs[0b10]) + + &bits[0].lc::(one, y_coeffs[0b01]) + + (y_coeffs[0b00], one); + cs.enforce( || "y-coordinate lookup", - |lc| lc + (y_coeffs[0b00], one) - + &bits[0].lc::(one, y_coeffs[0b01]) - + &bits[1].lc::(one, y_coeffs[0b10]) - + &precomp.lc::(one, y_coeffs[0b11]), - |lc| lc + one, - |lc| lc + res_y.get_variable() + |lc| lc + &y_lc + &y_lc, + |lc| lc + &bits[2].lc::(one, E::Fr::one()), + |lc| lc + &y_lc - res_y.get_variable() ); - let final_y = res_y.conditionally_negate(&mut cs, &bits[2])?; - - Ok((res_x, final_y)) + Ok((res_x, res_y)) } #[cfg(test)] diff --git a/src/circuit/pedersen_hash.rs b/src/circuit/pedersen_hash.rs index 68aab98..19e56b8 100644 --- a/src/circuit/pedersen_hash.rs +++ b/src/circuit/pedersen_hash.rs @@ -155,7 +155,7 @@ mod test { ).unwrap(); assert!(cs.is_satisfied()); - assert_eq!(cs.num_constraints(), 1721); + assert_eq!(cs.num_constraints(), 1549); } #[test]