|
|
@ -1,4 +1,4 @@ |
|
|
|
use ark_ff::{BitIteratorBE, Field, FpParameters, PrimeField};
|
|
|
|
use ark_ff::{BitIteratorBE, Field, PrimeField};
|
|
|
|
|
|
|
|
use crate::{fields::fp::FpVar, prelude::*, Assignment, ToConstraintFieldGadget, Vec};
|
|
|
|
use ark_relations::r1cs::{
|
|
|
@ -396,7 +396,7 @@ impl Boolean { |
|
|
|
// a XOR (NOT b) = NOT(a XOR b)
|
|
|
|
(is @ &Is(_), not @ &Not(_)) | (not @ &Not(_), is @ &Is(_)) => {
|
|
|
|
Ok(is.xor(¬.not())?.not())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// a XOR b = (NOT a) XOR (NOT b)
|
|
|
|
(&Is(ref a), &Is(ref b)) | (&Not(ref a), &Not(ref b)) => Ok(Is(a.xor(b)?)),
|
|
|
|
}
|
|
|
@ -438,7 +438,7 @@ impl Boolean { |
|
|
|
// a OR b = NOT ((NOT a) AND (NOT b))
|
|
|
|
(a @ &Is(_), b @ &Not(_)) | (b @ &Not(_), a @ &Is(_)) | (b @ &Not(_), a @ &Not(_)) => {
|
|
|
|
Ok(a.not().and(&b.not())?.not())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(&Is(ref a), &Is(ref b)) => a.or(b).map(From::from),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -604,7 +604,7 @@ impl Boolean { |
|
|
|
Is(_) | Not(_) => {
|
|
|
|
r.cs()
|
|
|
|
.enforce_constraint(r.lc(), lc!() + Variable::One, lc!() + Variable::One)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -651,7 +651,7 @@ impl Boolean { |
|
|
|
// If the number of bits is less than the size of the field,
|
|
|
|
// then we do not need to enforce that the element is less than
|
|
|
|
// the modulus.
|
|
|
|
if bits.len() >= F::Params::MODULUS_BITS as usize {
|
|
|
|
if bits.len() >= F::MODULUS_BIT_SIZE as usize {
|
|
|
|
Self::enforce_in_field_le(bits)?;
|
|
|
|
}
|
|
|
|
Ok(crate::fields::fp::AllocatedFp::new(value, variable, cs.clone()).into())
|
|
|
@ -946,7 +946,7 @@ impl CondSelectGadget for Boolean { |
|
|
|
)?;
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1247,30 +1247,30 @@ mod test { |
|
|
|
(OpType::AllocatedTrue, OpType::False, Boolean::Is(_)) => (),
|
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::True, Boolean::Not(_)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::False, Boolean::Is(_)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::AllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
@ -1278,18 +1278,18 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::True, Boolean::Is(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::False, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
@ -1297,7 +1297,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
@ -1305,14 +1305,14 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::True, Boolean::Is(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::False, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::AllocatedFalse,
|
|
|
@ -1320,7 +1320,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
@ -1328,7 +1328,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
@ -1336,7 +1336,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
@ -1409,85 +1409,85 @@ mod test { |
|
|
|
(OpType::AllocatedTrue, OpType::False, Boolean::Is(_)) => (),
|
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::AllocatedFalse, OpType::True, Boolean::Constant(true)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::False, Boolean::Is(_)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::AllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::True, Boolean::Constant(true)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::False, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::True, Boolean::Constant(true)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::False, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Not(ref v)) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::AllocatedFalse,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
Boolean::Not(ref v),
|
|
|
|
) => {
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => panic!(
|
|
|
|
"this should never be encountered, in case: (a = {:?}, b = {:?}, c = {:?})",
|
|
|
@ -1531,49 +1531,49 @@ mod test { |
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::AllocatedFalse, OpType::True, Boolean::Is(_)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::False, Boolean::Constant(false)) => (),
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::AllocatedFalse, OpType::NegatedAllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::True, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::False, Boolean::Constant(false)) => (),
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
@ -1581,7 +1581,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
@ -1589,18 +1589,18 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::True, Boolean::Not(_)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::False, Boolean::Constant(false)) => (),
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(OpType::NegatedAllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedTrue,
|
|
|
@ -1608,7 +1608,7 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero());
|
|
|
|
assert_eq!(v.value(), Ok(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
|
OpType::NegatedAllocatedFalse,
|
|
|
@ -1616,14 +1616,14 @@ mod test { |
|
|
|
) => {
|
|
|
|
assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one());
|
|
|
|
assert_eq!(v.value(), Ok(true));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
panic!(
|
|
|
|
"unexpected behavior at {:?} AND {:?}",
|
|
|
|
first_operand, second_operand
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1642,9 +1642,9 @@ mod test { |
|
|
|
|
|
|
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
|
|
|
|
|
|
|
let native_bits: Vec<_> = BitIteratorLE::new(r.into_repr()).collect();
|
|
|
|
let native_bits: Vec<_> = BitIteratorLE::new(r.into_bigint()).collect();
|
|
|
|
let bits = Vec::new_witness(cs.clone(), || Ok(native_bits))?;
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_repr())?;
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_bigint())?;
|
|
|
|
|
|
|
|
assert!(cs.is_satisfied().unwrap());
|
|
|
|
}
|
|
|
@ -1658,11 +1658,11 @@ mod test { |
|
|
|
let s2 = r.double();
|
|
|
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
|
|
|
|
|
|
|
let native_bits: Vec<_> = BitIteratorLE::new(r.into_repr()).collect();
|
|
|
|
let native_bits: Vec<_> = BitIteratorLE::new(r.into_bigint()).collect();
|
|
|
|
let bits = Vec::new_witness(cs.clone(), || Ok(native_bits))?;
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_repr())?;
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_bigint())?;
|
|
|
|
if r < s2 {
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s2.into_repr())?;
|
|
|
|
Boolean::enforce_smaller_or_equal_than_le(&bits, s2.into_bigint())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(cs.is_satisfied().unwrap());
|
|
|
@ -1693,7 +1693,7 @@ mod test { |
|
|
|
let cs = ConstraintSystem::<Fr>::new_ref();
|
|
|
|
|
|
|
|
let mut bits = vec![];
|
|
|
|
for b in BitIteratorBE::new(r.into_repr()).skip(1) {
|
|
|
|
for b in BitIteratorBE::new(r.into_bigint()).skip(1) {
|
|
|
|
bits.push(Boolean::new_witness(cs.clone(), || Ok(b))?);
|
|
|
|
}
|
|
|
|
bits.reverse();
|
|
|
@ -1796,7 +1796,7 @@ mod test { |
|
|
|
for &mode in modes.iter() {
|
|
|
|
for _ in 0..1000 {
|
|
|
|
let f = Fr::rand(rng);
|
|
|
|
let bits = BitIteratorLE::new(f.into_repr()).collect::<Vec<_>>();
|
|
|
|
let bits = BitIteratorLE::new(f.into_bigint()).collect::<Vec<_>>();
|
|
|
|
let bits: Vec<_> =
|
|
|
|
AllocVar::new_variable(cs.clone(), || Ok(bits.as_slice()), mode)?;
|
|
|
|
let f = AllocVar::new_variable(cs.clone(), || Ok(f), mode)?;
|
|
|
@ -1806,7 +1806,7 @@ mod test { |
|
|
|
|
|
|
|
for _ in 0..1000 {
|
|
|
|
let f = Fr::from(u64::rand(rng));
|
|
|
|
let bits = BitIteratorLE::new(f.into_repr()).collect::<Vec<_>>();
|
|
|
|
let bits = BitIteratorLE::new(f.into_bigint()).collect::<Vec<_>>();
|
|
|
|
let bits: Vec<_> =
|
|
|
|
AllocVar::new_variable(cs.clone(), || Ok(bits.as_slice()), mode)?;
|
|
|
|
let f = AllocVar::new_variable(cs.clone(), || Ok(f), mode)?;
|
|
|
|