diff --git a/src/circuit/boolean.rs b/src/circuit/boolean.rs index 1c10ab3..689775e 100644 --- a/src/circuit/boolean.rs +++ b/src/circuit/boolean.rs @@ -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( mut cs: CS, a: &Self, diff --git a/src/circuit/uint32.rs b/src/circuit/uint32.rs index a186cb3..c691855 100644 --- a/src/circuit/uint32.rs +++ b/src/circuit/uint32.rs @@ -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(); }