Refactor "booleanization" of objects.

This commit is contained in:
Sean Bowe
2018-02-20 15:11:29 -07:00
parent 8d633db82b
commit 1df7fbeeff
2 changed files with 75 additions and 36 deletions
+7 -35
View File
@@ -17,8 +17,9 @@ use super::{
};
use super::boolean::{
Boolean,
AllocatedBit
self,
Boolean,
AllocatedBit
};
pub struct AllocatedNum<E: Engine> {
@@ -76,39 +77,10 @@ impl<E: Engine> AllocatedNum<E> {
) -> Result<Vec<Boolean>, SynthesisError>
where CS: ConstraintSystem<E>
{
let bit_values = match self.value {
Some(value) => {
let mut field_char = BitIterator::new(E::Fr::char());
let mut tmp = Vec::with_capacity(E::Fr::NUM_BITS as usize);
let mut found_one = false;
for b in BitIterator::new(value.into_repr()) {
// Skip leading bits
found_one |= field_char.next().unwrap();
if !found_one {
continue;
}
tmp.push(Some(b));
}
assert_eq!(tmp.len(), E::Fr::NUM_BITS as usize);
tmp
},
None => {
vec![None; E::Fr::NUM_BITS as usize]
}
};
let mut bits = vec![];
for (i, b) in bit_values.into_iter().enumerate() {
bits.push(AllocatedBit::alloc(
cs.namespace(|| format!("bit {}", i)),
b
)?);
}
let bits = boolean::field_into_allocated_bits_be(
&mut cs,
self.value
)?;
let mut lc = LinearCombination::zero();
let mut coeff = E::Fr::one();