Simplify implementation of addmany.

This commit is contained in:
Sean Bowe 2018-03-15 11:26:47 -06:00
parent b16f4abc75
commit 8cc319f79e
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
2 changed files with 9 additions and 18 deletions

View File

@ -367,6 +367,13 @@ pub enum Boolean {
}
impl Boolean {
pub fn is_constant(&self) -> bool {
match *self {
Boolean::Constant(_) => true,
_ => false
}
}
pub fn enforce_equal<E, CS>(
mut cs: CS,
a: &Self,

View File

@ -418,25 +418,9 @@ impl UInt32 {
// the linear combination
let mut coeff = E::Fr::one();
for bit in &op.bits {
match bit {
&Boolean::Is(ref bit) => {
all_constants = false;
lc = lc + &bit.lc(CS::one(), coeff);
// Add coeff * bit
lc = lc + (coeff, bit.get_variable());
},
&Boolean::Not(ref bit) => {
all_constants = false;
// Add coeff * (1 - bit) = coeff * ONE - coeff * bit
lc = lc + (coeff, CS::one()) - (coeff, bit.get_variable());
},
&Boolean::Constant(bit) => {
if bit {
lc = lc + (coeff, CS::one());
}
}
}
all_constants &= bit.is_constant();
coeff.double();
}