Perform the y-coordinate conditional negation and lookup simultaneously.
This commit is contained in:
parent
6f66fd3f9d
commit
1610bcfbcf
|
@ -154,10 +154,15 @@ pub fn lookup3_xy_with_conditional_negation<E: Engine, CS>(
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Allocate the y-coordinate resulting from the lookup
|
// Allocate the y-coordinate resulting from the lookup
|
||||||
|
// and conditional negation
|
||||||
let res_y = AllocatedNum::alloc(
|
let res_y = AllocatedNum::alloc(
|
||||||
cs.namespace(|| "y"),
|
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<E: Engine, CS>(
|
||||||
|lc| lc + res_x.get_variable()
|
|lc| lc + res_x.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let y_lc = precomp.lc::<E>(one, y_coeffs[0b11]) +
|
||||||
|
&bits[1].lc::<E>(one, y_coeffs[0b10]) +
|
||||||
|
&bits[0].lc::<E>(one, y_coeffs[0b01]) +
|
||||||
|
(y_coeffs[0b00], one);
|
||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "y-coordinate lookup",
|
|| "y-coordinate lookup",
|
||||||
|lc| lc + (y_coeffs[0b00], one)
|
|lc| lc + &y_lc + &y_lc,
|
||||||
+ &bits[0].lc::<E>(one, y_coeffs[0b01])
|
|lc| lc + &bits[2].lc::<E>(one, E::Fr::one()),
|
||||||
+ &bits[1].lc::<E>(one, y_coeffs[0b10])
|
|lc| lc + &y_lc - res_y.get_variable()
|
||||||
+ &precomp.lc::<E>(one, y_coeffs[0b11]),
|
|
||||||
|lc| lc + one,
|
|
||||||
|lc| lc + res_y.get_variable()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let final_y = res_y.conditionally_negate(&mut cs, &bits[2])?;
|
Ok((res_x, res_y))
|
||||||
|
|
||||||
Ok((res_x, final_y))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -155,7 +155,7 @@ mod test {
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
assert!(cs.is_satisfied());
|
assert!(cs.is_satisfied());
|
||||||
assert_eq!(cs.num_constraints(), 1721);
|
assert_eq!(cs.num_constraints(), 1549);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue