::zero()),
(true, false) => point1.to_owned(),
(false, true) => point2.to_owned(),
@@ -201,7 +202,7 @@ where
// create new point with the same (x, y) coordinates
self.create_point_variable(selected)?
};
- let wire_vars_x = [b0, b1, 0, 0, selected_point.0];
+ let wire_vars_x = [b0.into(), b1.into(), 0, 0, selected_point.0];
self.insert_gate(
&wire_vars_x,
Box::new(QuaternaryPointSelectXGate {
@@ -210,7 +211,7 @@ where
x3: point3.0,
}),
)?;
- let wire_vars_y = [b0, b1, 0, 0, selected_point.1];
+ let wire_vars_y = [b0.into(), b1.into(), 0, 0, selected_point.1];
self.insert_gate(
&wire_vars_y,
Box::new(QuaternaryPointSelectYGate {
@@ -229,14 +230,13 @@ where
/// Return error if invalid input parameters are provided.
fn binary_point_vars_select(
&mut self,
- b: Variable,
+ b: BoolVar,
point0: &PointVariable,
point1: &PointVariable,
) -> Result (&mut self, point_var: &PointVariable) -> Result (&mut self, point_var: &PointVariable) -> Result ::zero()) {
- self.create_variable(F::one())?
+ self.create_boolean_variable(true)?
} else {
- self.create_variable(F::zero())?
+ self.create_boolean_variable(false)?
}
};
@@ -497,12 +497,11 @@ where
/// Currently only supports GroupAffine:: .
pub fn variable_base_binary_scalar_mul (&p1)?;
let p2_check = circuit.is_neutral_point:: (&p2)?;
- assert_eq!(circuit.witness(p1_check)?, F::one());
- assert_eq!(circuit.witness(p2_check)?, F::zero());
+ assert_eq!(circuit.witness(p1_check.into())?, F::one());
+ assert_eq!(circuit.witness(p2_check.into())?, F::zero());
assert!(circuit.check_circuit_satisfiability(&[]).is_ok());
*circuit.witness_mut(p1.0) = F::one();
assert!(circuit.check_circuit_satisfiability(&[]).is_err());
@@ -852,10 +851,12 @@ mod test {
let p3 = GroupAffine:: ::rand(&mut rng);
let mut circuit: PlonkCircuit (
- circuit.zero(),
- circuit.zero(),
+ false_var,
+ false_var,
&Point::from(p1),
&Point::from(p2),
&Point::from(p3),
@@ -865,24 +866,24 @@ mod test {
Point(circuit.witness(select_p0.0)?, circuit.witness(select_p0.1)?)
);
let select_p1 = circuit.quaternary_point_select:: (
- circuit.one(),
- circuit.zero(),
+ true_var,
+ false_var,
&Point::from(p1),
&Point::from(p2),
&Point::from(p3),
)?;
assert_eq!(Point::from(p1), circuit.point_witness(&select_p1)?);
let select_p2 = circuit.quaternary_point_select:: (
- circuit.zero(),
- circuit.one(),
+ false_var,
+ true_var,
&Point::from(p1),
&Point::from(p2),
&Point::from(p3),
)?;
assert_eq!(Point::from(p2), circuit.point_witness(&select_p2)?);
let select_p3 = circuit.quaternary_point_select:: (
- circuit.one(),
- circuit.one(),
+ true_var,
+ true_var,
&Point::from(p1),
&Point::from(p2),
&Point::from(p3),
@@ -891,55 +892,24 @@ mod test {
assert!(circuit.check_circuit_satisfiability(&[]).is_ok());
- // non binary b0, b1 should fail
- let two = circuit.create_variable(F::from(2u32))?;
- assert!(circuit
- .quaternary_point_select:: (
- two,
- 1,
- &Point::from(p1),
- &Point::from(p2),
- &Point::from(p3)
- )
- .is_err());
- assert!(circuit
- .quaternary_point_select:: (
- 0,
- two,
- &Point::from(p1),
- &Point::from(p2),
- &Point::from(p3)
- )
- .is_err());
-
*circuit.witness_mut(select_p3.0) = p2.x;
*circuit.witness_mut(select_p3.1) = p2.y;
assert!(circuit.check_circuit_satisfiability(&[]).is_err());
- // Check variable out of bound error.
- assert!(circuit
- .quaternary_point_select:: (
- 0,
- circuit.num_vars(),
- &Point::from(p1),
- &Point::from(p2),
- &Point::from(p3)
- )
- .is_err());
- let circuit_1 = build_quaternary_select_gate:: ::rand(&mut rng);
@@ -1032,8 +1002,8 @@ mod test {
let p1_p2_eq = circuit.check_equal_point(&p1_var, &p2_var)?;
let p1_p3_eq = circuit.check_equal_point(&p1_var, &p3_var)?;
- assert_eq!(circuit.witness(p1_p2_eq)?, F::one());
- assert_eq!(circuit.witness(p1_p3_eq)?, F::zero());
+ assert_eq!(circuit.witness(p1_p2_eq.into())?, F::one());
+ assert_eq!(circuit.witness(p1_p3_eq.into())?, F::zero());
assert!(circuit.check_circuit_satisfiability(&[]).is_ok());
*circuit.witness_mut(p2_var.0) = F::zero();
assert!(circuit.check_circuit_satisfiability(&[]).is_err());
@@ -1198,43 +1168,30 @@ mod test {
let mut circuit: PlonkCircuit ::rand(&mut rng);
- let base_var = circuit.create_point_variable(Point::from(base))?;
- // Binary scalar variables out of bound
- assert!(circuit
- .variable_base_binary_scalar_mul:: (&[circuit.one(), circuit.num_vars()], &base_var)
- .is_err());
- // Base point out of bound
- assert!(circuit
- .variable_base_binary_scalar_mul:: (
- &[circuit.zero(), circuit.one()],
- &PointVariable(circuit.num_vars(), circuit.num_vars())
- )
- .is_err());
- // Non-binary scalar variables
- assert!(circuit
- .variable_base_binary_scalar_mul:: (&[circuit.one(), non_bit_var], &base_var)
- .is_err());
-
- Ok(())
- }
-
fn build_variable_base_scalar_mul_circuit )
@@ -111,7 +111,7 @@ where
vk: &VerKeyVar,
msg: &[Variable],
sig: &SignatureVar,
- ) -> Result