Account for change in bellman's API for enforcement to use closures.
This commit is contained in:
@@ -16,7 +16,7 @@ features = ["expose-arith"]
|
|||||||
rand = "0.3"
|
rand = "0.3"
|
||||||
blake2 = "0.7"
|
blake2 = "0.7"
|
||||||
digest = "0.7"
|
digest = "0.7"
|
||||||
bellman = "0.0.7"
|
bellman = "0.0.8"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["u128-support"]
|
default = ["u128-support"]
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ impl<Var: Copy> AllocatedBit<Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "boolean constraint",
|
|| "boolean constraint",
|
||||||
LinearCombination::zero() + one - var,
|
|lc| lc + one - var,
|
||||||
LinearCombination::zero() + var,
|
|lc| lc + var,
|
||||||
LinearCombination::zero()
|
|lc| lc
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
@@ -107,9 +107,9 @@ impl<Var: Copy> AllocatedBit<Var> {
|
|||||||
// (a + a) * b = a + b - c
|
// (a + a) * b = a + b - c
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "xor constraint",
|
|| "xor constraint",
|
||||||
LinearCombination::zero() + a.variable + a.variable,
|
|lc| lc + a.variable + a.variable,
|
||||||
LinearCombination::zero() + b.variable,
|
|lc| lc + b.variable,
|
||||||
LinearCombination::zero() + a.variable + b.variable - result_var
|
|lc| lc + a.variable + b.variable - result_var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
@@ -146,9 +146,9 @@ impl<Var: Copy> AllocatedBit<Var> {
|
|||||||
// a AND b are both 1.
|
// a AND b are both 1.
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "and constraint",
|
|| "and constraint",
|
||||||
LinearCombination::zero() + a.variable,
|
|lc| lc + a.variable,
|
||||||
LinearCombination::zero() + b.variable,
|
|lc| lc + b.variable,
|
||||||
LinearCombination::zero() + result_var
|
|lc| lc + result_var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
@@ -185,9 +185,9 @@ impl<Var: Copy> AllocatedBit<Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "and not constraint",
|
|| "and not constraint",
|
||||||
LinearCombination::zero() + a.variable,
|
|lc| lc + a.variable,
|
||||||
LinearCombination::zero() + one - b.variable,
|
|lc| lc + one - b.variable,
|
||||||
LinearCombination::zero() + result_var
|
|lc| lc + result_var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
@@ -224,9 +224,9 @@ impl<Var: Copy> AllocatedBit<Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "nor constraint",
|
|| "nor constraint",
|
||||||
LinearCombination::zero() + one - a.variable,
|
|lc| lc + one - a.variable,
|
||||||
LinearCombination::zero() + one - b.variable,
|
|lc| lc + one - b.variable,
|
||||||
LinearCombination::zero() + result_var
|
|lc| lc + result_var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
@@ -401,9 +401,9 @@ impl<Var: Copy> Boolean<Var> {
|
|||||||
Boolean::Is(ref res) => {
|
Boolean::Is(ref res) => {
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "enforce nand",
|
|| "enforce nand",
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero() + res.get_variable()
|
|lc| lc + res.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -412,9 +412,9 @@ impl<Var: Copy> Boolean<Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "enforce nand",
|
|| "enforce nand",
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero() + one - res.get_variable()
|
|lc| lc + one - res.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ use super::*;
|
|||||||
use super::num::AllocatedNum;
|
use super::num::AllocatedNum;
|
||||||
use super::boolean::Boolean;
|
use super::boolean::Boolean;
|
||||||
use bellman::{
|
use bellman::{
|
||||||
ConstraintSystem,
|
ConstraintSystem
|
||||||
LinearCombination
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Synthesize the constants for each base pattern.
|
// Synthesize the constants for each base pattern.
|
||||||
@@ -89,12 +88,12 @@ pub fn lookup3_xy<E: Engine, CS, Var: Copy>(
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "x-coordinate lookup",
|
|| "x-coordinate lookup",
|
||||||
LinearCombination::<Var, E>::zero() + (x_coeffs[0b001], one)
|
|lc| lc + (x_coeffs[0b001], one)
|
||||||
+ &bits[1].lc::<E>(one, x_coeffs[0b011])
|
+ &bits[1].lc::<E>(one, x_coeffs[0b011])
|
||||||
+ &bits[2].lc::<E>(one, x_coeffs[0b101])
|
+ &bits[2].lc::<E>(one, x_coeffs[0b101])
|
||||||
+ &precomp.lc::<E>(one, x_coeffs[0b111]),
|
+ &precomp.lc::<E>(one, x_coeffs[0b111]),
|
||||||
LinearCombination::<Var, E>::zero() + &bits[0].lc::<E>(one, E::Fr::one()),
|
|lc| lc + &bits[0].lc::<E>(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + res_x.get_variable()
|
|lc| lc + res_x.get_variable()
|
||||||
- (x_coeffs[0b000], one)
|
- (x_coeffs[0b000], one)
|
||||||
- &bits[1].lc::<E>(one, x_coeffs[0b010])
|
- &bits[1].lc::<E>(one, x_coeffs[0b010])
|
||||||
- &bits[2].lc::<E>(one, x_coeffs[0b100])
|
- &bits[2].lc::<E>(one, x_coeffs[0b100])
|
||||||
@@ -103,12 +102,12 @@ pub fn lookup3_xy<E: Engine, CS, Var: Copy>(
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "y-coordinate lookup",
|
|| "y-coordinate lookup",
|
||||||
LinearCombination::<Var, E>::zero() + (y_coeffs[0b001], one)
|
|lc| lc + (y_coeffs[0b001], one)
|
||||||
+ &bits[1].lc::<E>(one, y_coeffs[0b011])
|
+ &bits[1].lc::<E>(one, y_coeffs[0b011])
|
||||||
+ &bits[2].lc::<E>(one, y_coeffs[0b101])
|
+ &bits[2].lc::<E>(one, y_coeffs[0b101])
|
||||||
+ &precomp.lc::<E>(one, y_coeffs[0b111]),
|
+ &precomp.lc::<E>(one, y_coeffs[0b111]),
|
||||||
LinearCombination::<Var, E>::zero() + &bits[0].lc::<E>(one, E::Fr::one()),
|
|lc| lc + &bits[0].lc::<E>(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + res_y.get_variable()
|
|lc| lc + res_y.get_variable()
|
||||||
- (y_coeffs[0b000], one)
|
- (y_coeffs[0b000], one)
|
||||||
- &bits[1].lc::<E>(one, y_coeffs[0b010])
|
- &bits[1].lc::<E>(one, y_coeffs[0b010])
|
||||||
- &bits[2].lc::<E>(one, y_coeffs[0b100])
|
- &bits[2].lc::<E>(one, y_coeffs[0b100])
|
||||||
@@ -172,20 +171,20 @@ pub fn lookup3_xy_with_conditional_negation<E: Engine, CS, Var: Copy>(
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "x-coordinate lookup",
|
|| "x-coordinate lookup",
|
||||||
LinearCombination::<Var, E>::zero() + (x_coeffs[0b01], one)
|
|lc| lc + (x_coeffs[0b01], one)
|
||||||
+ &bits[1].lc::<E>(one, x_coeffs[0b11]),
|
+ &bits[1].lc::<E>(one, x_coeffs[0b11]),
|
||||||
LinearCombination::<Var, E>::zero() + &bits[0].lc::<E>(one, E::Fr::one()),
|
|lc| lc + &bits[0].lc::<E>(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + res_x.get_variable()
|
|lc| lc + res_x.get_variable()
|
||||||
- (x_coeffs[0b00], one)
|
- (x_coeffs[0b00], one)
|
||||||
- &bits[1].lc::<E>(one, x_coeffs[0b10])
|
- &bits[1].lc::<E>(one, x_coeffs[0b10])
|
||||||
);
|
);
|
||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "y-coordinate lookup",
|
|| "y-coordinate lookup",
|
||||||
LinearCombination::<Var, E>::zero() + (y_coeffs[0b01], one)
|
|lc| lc + (y_coeffs[0b01], one)
|
||||||
+ &bits[1].lc::<E>(one, y_coeffs[0b11]),
|
+ &bits[1].lc::<E>(one, y_coeffs[0b11]),
|
||||||
LinearCombination::<Var, E>::zero() + &bits[0].lc::<E>(one, E::Fr::one()),
|
|lc| lc + &bits[0].lc::<E>(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + res_y.get_variable()
|
|lc| lc + res_y.get_variable()
|
||||||
- (y_coeffs[0b00], one)
|
- (y_coeffs[0b00], one)
|
||||||
- &bits[1].lc::<E>(one, y_coeffs[0b10])
|
- &bits[1].lc::<E>(one, y_coeffs[0b10])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ use pairing::{
|
|||||||
|
|
||||||
use bellman::{
|
use bellman::{
|
||||||
SynthesisError,
|
SynthesisError,
|
||||||
ConstraintSystem,
|
ConstraintSystem
|
||||||
LinearCombination
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -122,9 +121,9 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "x' computation",
|
|| "x' computation",
|
||||||
LinearCombination::<Var, E>::zero() + self.x.get_variable(),
|
|lc| lc + self.x.get_variable(),
|
||||||
condition.lc(one, E::Fr::one()),
|
|_| condition.lc(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + x_prime.get_variable()
|
|lc| lc + x_prime.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute y' = self.y if condition, and 1 otherwise
|
// Compute y' = self.y if condition, and 1 otherwise
|
||||||
@@ -141,9 +140,9 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
// if condition is 1, y' must be y
|
// if condition is 1, y' must be y
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "y' computation",
|
|| "y' computation",
|
||||||
LinearCombination::<Var, E>::zero() + self.y.get_variable(),
|
|lc| lc + self.y.get_variable(),
|
||||||
condition.lc(one, E::Fr::one()),
|
|_| condition.lc(one, E::Fr::one()),
|
||||||
LinearCombination::<Var, E>::zero() + y_prime.get_variable()
|
|lc| lc + y_prime.get_variable()
|
||||||
- &condition.not().lc(one, E::Fr::one())
|
- &condition.not().lc(one, E::Fr::one())
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -225,10 +224,10 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "on curve check",
|
|| "on curve check",
|
||||||
LinearCombination::zero() - x2.get_variable()
|
|lc| lc - x2.get_variable()
|
||||||
+ y2.get_variable(),
|
+ y2.get_variable(),
|
||||||
LinearCombination::zero() + one,
|
|lc| lc + one,
|
||||||
LinearCombination::zero() + one
|
|lc| lc + one
|
||||||
+ (*params.edwards_d(), x2y2.get_variable())
|
+ (*params.edwards_d(), x2y2.get_variable())
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -272,11 +271,11 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "U computation",
|
|| "U computation",
|
||||||
LinearCombination::<Var, E>::zero() + self.x.get_variable()
|
|lc| lc + self.x.get_variable()
|
||||||
+ self.y.get_variable(),
|
+ self.y.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + other.x.get_variable()
|
|lc| lc + other.x.get_variable()
|
||||||
+ other.y.get_variable(),
|
+ other.y.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + u.get_variable()
|
|lc| lc + u.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute A = y2 * x1
|
// Compute A = y2 * x1
|
||||||
@@ -296,9 +295,9 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "C computation",
|
|| "C computation",
|
||||||
LinearCombination::<Var, E>::zero() + (*params.edwards_d(), a.get_variable()),
|
|lc| lc + (*params.edwards_d(), a.get_variable()),
|
||||||
LinearCombination::<Var, E>::zero() + b.get_variable(),
|
|lc| lc + b.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + c.get_variable()
|
|lc| lc + c.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute x3 = (A + B) / (1 + C)
|
// Compute x3 = (A + B) / (1 + C)
|
||||||
@@ -324,9 +323,9 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "x3 computation",
|
|| "x3 computation",
|
||||||
LinearCombination::<Var, E>::zero() + one + c.get_variable(),
|
|lc| lc + one + c.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + x3.get_variable(),
|
|lc| lc + x3.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + a.get_variable()
|
|lc| lc + a.get_variable()
|
||||||
+ b.get_variable()
|
+ b.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -353,9 +352,9 @@ impl<E: JubjubEngine, Var: Copy> EdwardsPoint<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "y3 computation",
|
|| "y3 computation",
|
||||||
LinearCombination::<Var, E>::zero() + one - c.get_variable(),
|
|lc| lc + one - c.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + y3.get_variable(),
|
|lc| lc + y3.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + u.get_variable()
|
|lc| lc + u.get_variable()
|
||||||
- a.get_variable()
|
- a.get_variable()
|
||||||
- b.get_variable()
|
- b.get_variable()
|
||||||
);
|
);
|
||||||
@@ -402,9 +401,9 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "u computation",
|
|| "u computation",
|
||||||
LinearCombination::<Var, E>::zero() + self.y.get_variable(),
|
|lc| lc + self.y.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + u.get_variable(),
|
|lc| lc + u.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + (*params.scale(), self.x.get_variable())
|
|lc| lc + (*params.scale(), self.x.get_variable())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute v = (x - 1) / (x + 1)
|
// Compute v = (x - 1) / (x + 1)
|
||||||
@@ -429,10 +428,10 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "v computation",
|
|| "v computation",
|
||||||
LinearCombination::<Var, E>::zero() + self.x.get_variable()
|
|lc| lc + self.x.get_variable()
|
||||||
+ one,
|
+ one,
|
||||||
LinearCombination::<Var, E>::zero() + v.get_variable(),
|
|lc| lc + v.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + self.x.get_variable()
|
|lc| lc + self.x.get_variable()
|
||||||
- one,
|
- one,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -488,12 +487,12 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate lambda",
|
|| "evaluate lambda",
|
||||||
LinearCombination::<Var, E>::zero() + other.x.get_variable()
|
|lc| lc + other.x.get_variable()
|
||||||
- self.x.get_variable(),
|
- self.x.get_variable(),
|
||||||
|
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
|
|
||||||
LinearCombination::<Var, E>::zero() + other.y.get_variable()
|
|lc| lc + other.y.get_variable()
|
||||||
- self.y.get_variable()
|
- self.y.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -512,9 +511,9 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate xprime",
|
|| "evaluate xprime",
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + (*params.montgomery_a(), one)
|
|lc| lc + (*params.montgomery_a(), one)
|
||||||
+ self.x.get_variable()
|
+ self.x.get_variable()
|
||||||
+ other.x.get_variable()
|
+ other.x.get_variable()
|
||||||
+ xprime.get_variable()
|
+ xprime.get_variable()
|
||||||
@@ -534,12 +533,12 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
// y' + y = lambda(x - x')
|
// y' + y = lambda(x - x')
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate yprime",
|
|| "evaluate yprime",
|
||||||
LinearCombination::zero() + self.x.get_variable()
|
|lc| lc + self.x.get_variable()
|
||||||
- xprime.get_variable(),
|
- xprime.get_variable(),
|
||||||
|
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
|
|
||||||
LinearCombination::<Var, E>::zero() + yprime.get_variable()
|
|lc| lc + yprime.get_variable()
|
||||||
+ self.y.get_variable()
|
+ self.y.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -589,12 +588,12 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate lambda",
|
|| "evaluate lambda",
|
||||||
LinearCombination::<Var, E>::zero() + self.y.get_variable()
|
|lc| lc + self.y.get_variable()
|
||||||
+ self.y.get_variable(),
|
+ self.y.get_variable(),
|
||||||
|
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
|
|
||||||
LinearCombination::<Var, E>::zero() + xx.get_variable()
|
|lc| lc + xx.get_variable()
|
||||||
+ xx.get_variable()
|
+ xx.get_variable()
|
||||||
+ xx.get_variable()
|
+ xx.get_variable()
|
||||||
+ (*params.montgomery_2a(), self.x.get_variable())
|
+ (*params.montgomery_2a(), self.x.get_variable())
|
||||||
@@ -615,9 +614,9 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
// (lambda) * (lambda) = (A + 2.x + x')
|
// (lambda) * (lambda) = (A + 2.x + x')
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate xprime",
|
|| "evaluate xprime",
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
LinearCombination::<Var, E>::zero() + (*params.montgomery_a(), one)
|
|lc| lc + (*params.montgomery_a(), one)
|
||||||
+ self.x.get_variable()
|
+ self.x.get_variable()
|
||||||
+ self.x.get_variable()
|
+ self.x.get_variable()
|
||||||
+ xprime.get_variable()
|
+ xprime.get_variable()
|
||||||
@@ -637,12 +636,12 @@ impl<E: JubjubEngine, Var: Copy> MontgomeryPoint<E, Var> {
|
|||||||
// y' + y = lambda(x - x')
|
// y' + y = lambda(x - x')
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "evaluate yprime",
|
|| "evaluate yprime",
|
||||||
LinearCombination::zero() + self.x.get_variable()
|
|lc| lc + self.x.get_variable()
|
||||||
- xprime.get_variable(),
|
- xprime.get_variable(),
|
||||||
|
|
||||||
LinearCombination::zero() + lambda.get_variable(),
|
|lc| lc + lambda.get_variable(),
|
||||||
|
|
||||||
LinearCombination::<Var, E>::zero() + yprime.get_variable()
|
|lc| lc + yprime.get_variable()
|
||||||
+ self.y.get_variable()
|
+ self.y.get_variable()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -122,9 +122,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "unpacking constraint",
|
|| "unpacking constraint",
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
lc
|
|_| lc
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(bits.into_iter().map(|b| Boolean::from(b)).collect())
|
Ok(bits.into_iter().map(|b| Boolean::from(b)).collect())
|
||||||
@@ -191,9 +191,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "packing constraint",
|
|| "packing constraint",
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
lc
|
|_| lc
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(num)
|
Ok(num)
|
||||||
@@ -220,9 +220,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
// Constrain: a * b = ab
|
// Constrain: a * b = ab
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "multiplication constraint",
|
|| "multiplication constraint",
|
||||||
LinearCombination::zero() + self.variable,
|
|lc| lc + self.variable,
|
||||||
LinearCombination::zero() + other.variable,
|
|lc| lc + other.variable,
|
||||||
LinearCombination::zero() + var
|
|lc| lc + var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedNum {
|
Ok(AllocatedNum {
|
||||||
@@ -251,9 +251,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
// Constrain: a * a = aa
|
// Constrain: a * a = aa
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "squaring constraint",
|
|| "squaring constraint",
|
||||||
LinearCombination::zero() + self.variable,
|
|lc| lc + self.variable,
|
||||||
LinearCombination::zero() + self.variable,
|
|lc| lc + self.variable,
|
||||||
LinearCombination::zero() + var
|
|lc| lc + var
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedNum {
|
Ok(AllocatedNum {
|
||||||
@@ -284,9 +284,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "nonzero assertion constraint",
|
|| "nonzero assertion constraint",
|
||||||
LinearCombination::zero() + self.variable,
|
|lc| lc + self.variable,
|
||||||
LinearCombination::zero() + inv,
|
|lc| lc + inv,
|
||||||
LinearCombination::zero() + one
|
|lc| lc + one
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -317,9 +317,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "first conditional reversal",
|
|| "first conditional reversal",
|
||||||
LinearCombination::zero() + a.variable - b.variable,
|
|lc| lc + a.variable - b.variable,
|
||||||
condition.lc(one, E::Fr::one()),
|
|_| condition.lc(one, E::Fr::one()),
|
||||||
LinearCombination::zero() + a.variable - c.variable
|
|lc| lc + a.variable - c.variable
|
||||||
);
|
);
|
||||||
|
|
||||||
let d = Self::alloc(
|
let d = Self::alloc(
|
||||||
@@ -335,9 +335,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "second conditional reversal",
|
|| "second conditional reversal",
|
||||||
LinearCombination::zero() + b.variable - a.variable,
|
|lc| lc + b.variable - a.variable,
|
||||||
condition.lc(one, E::Fr::one()),
|
|_| condition.lc(one, E::Fr::one()),
|
||||||
LinearCombination::zero() + b.variable - d.variable
|
|lc| lc + b.variable - d.variable
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok((c, d))
|
Ok((c, d))
|
||||||
@@ -368,9 +368,9 @@ impl<E: Engine, Var: Copy> AllocatedNum<E, Var> {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "conditional negation",
|
|| "conditional negation",
|
||||||
LinearCombination::zero() + self.variable + self.variable,
|
|lc| lc + self.variable + self.variable,
|
||||||
condition.lc(one, E::Fr::one()),
|
|_| condition.lc(one, E::Fr::one()),
|
||||||
LinearCombination::zero() + self.variable - r.variable
|
|lc| lc + self.variable - r.variable
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(r)
|
Ok(r)
|
||||||
|
|||||||
@@ -168,19 +168,26 @@ impl<E: Engine> ConstraintSystem<E> for TestConstraintSystem<E> {
|
|||||||
Ok(var)
|
Ok(var)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enforce<A, AR>(
|
fn enforce<A, AR, LA, LB, LC>(
|
||||||
&mut self,
|
&mut self,
|
||||||
annotation: A,
|
annotation: A,
|
||||||
a: LinearCombination<Self::Variable, E>,
|
a: LA,
|
||||||
b: LinearCombination<Self::Variable, E>,
|
b: LB,
|
||||||
c: LinearCombination<Self::Variable, E>
|
c: LC
|
||||||
)
|
)
|
||||||
where A: FnOnce() -> AR, AR: Into<String>
|
where A: FnOnce() -> AR, AR: Into<String>,
|
||||||
|
LA: FnOnce(LinearCombination<Self::Variable, E>) -> LinearCombination<Self::Variable, E>,
|
||||||
|
LB: FnOnce(LinearCombination<Self::Variable, E>) -> LinearCombination<Self::Variable, E>,
|
||||||
|
LC: FnOnce(LinearCombination<Self::Variable, E>) -> LinearCombination<Self::Variable, E>
|
||||||
{
|
{
|
||||||
let path = compute_path(&self.current_namespace, annotation().into());
|
let path = compute_path(&self.current_namespace, annotation().into());
|
||||||
let index = self.constraints.len();
|
let index = self.constraints.len();
|
||||||
self.set_named_obj(path.clone(), NamedObject::Constraint(index));
|
self.set_named_obj(path.clone(), NamedObject::Constraint(index));
|
||||||
|
|
||||||
|
let a = a(LinearCombination::zero());
|
||||||
|
let b = b(LinearCombination::zero());
|
||||||
|
let c = c(LinearCombination::zero());
|
||||||
|
|
||||||
self.constraints.push((a, b, c, path));
|
self.constraints.push((a, b, c, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,9 +225,9 @@ fn test_cs() {
|
|||||||
|
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "mult",
|
|| "mult",
|
||||||
LinearCombination::zero() + a,
|
|lc| lc + a,
|
||||||
LinearCombination::zero() + b,
|
|lc| lc + b,
|
||||||
LinearCombination::zero() + c
|
|lc| lc + c
|
||||||
);
|
);
|
||||||
assert!(cs.is_satisfied());
|
assert!(cs.is_satisfied());
|
||||||
assert_eq!(cs.num_constraints(), 1);
|
assert_eq!(cs.num_constraints(), 1);
|
||||||
@@ -230,9 +237,9 @@ fn test_cs() {
|
|||||||
let one = cs.one();
|
let one = cs.one();
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "eq",
|
|| "eq",
|
||||||
LinearCombination::zero() + a,
|
|lc| lc + a,
|
||||||
LinearCombination::zero() + one,
|
|lc| lc + one,
|
||||||
LinearCombination::zero() + b
|
|lc| lc + b
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(!cs.is_satisfied());
|
assert!(!cs.is_satisfied());
|
||||||
|
|||||||
@@ -281,9 +281,9 @@ impl<Var: Copy> UInt32<Var> {
|
|||||||
// Enforce that the linear combination equals zero
|
// Enforce that the linear combination equals zero
|
||||||
cs.enforce(
|
cs.enforce(
|
||||||
|| "modular addition",
|
|| "modular addition",
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
LinearCombination::zero(),
|
|lc| lc,
|
||||||
lc
|
|_| lc
|
||||||
);
|
);
|
||||||
|
|
||||||
// Discard carry bits that we don't care about
|
// Discard carry bits that we don't care about
|
||||||
|
|||||||
Reference in New Issue
Block a user