Browse Source

Change `from_repr` to output `Option<Self>`

master
Pratyush Mishra 4 years ago
parent
commit
75c55f7bee
2 changed files with 1 additions and 30 deletions
  1. +0
    -29
      r1cs-std/src/bits/boolean.rs
  2. +1
    -1
      r1cs-std/src/fields/fp/cmp.rs

+ 0
- 29
r1cs-std/src/bits/boolean.rs

@ -1985,35 +1985,6 @@ mod test {
assert!(cs.is_satisfied()); assert!(cs.is_satisfied());
} }
// for _ in 0..1000 {
// // Sample a random element not in the field
// let r = loop {
// let mut a = Fr::rand(&mut rng).into_repr();
// let b = Fr::rand(&mut rng).into_repr();
// a.add_nocarry(&b);
// // we're shaving off the high bit_gadget later
// a.as_mut()[3] &= 0x7fffffffffffffff;
// if Fr::from_repr(a).is_err() {
// break a;
// }
// };
// let mut cs = TestConstraintSystem::<Fr>::new();
// let mut bits = vec![];
// for (i, b) in BitIterator::new(r).skip(1).enumerate() {
// bits.push(Boolean::from(
// AllocatedBit::alloc(cs.ns(|| format!("bit_gadget {}",
// i)), Some(b)) .unwrap(),
// ));
// }
// Boolean::enforce_in_field::<_, _, Fr>(&mut cs, &bits).unwrap();
// assert!(!cs.is_satisfied());
// }
} }
#[test] #[test]

+ 1
- 1
r1cs-std/src/fields/fp/cmp.rs

@ -222,7 +222,7 @@ mod test {
0x06, 0x54, 0x06, 0x54,
]); ]);
fn rand_in_range<R: Rng>(rng: &mut R) -> Fr { fn rand_in_range<R: Rng>(rng: &mut R) -> Fr {
let pminusonedivtwo = Fr::from_repr(Fr::modulus_minus_one_div_two());
let pminusonedivtwo: Fr = Fr::modulus_minus_one_div_two().into();
let mut r; let mut r;
loop { loop {
r = Fr::rand(rng); r = Fr::rand(rng);

Loading…
Cancel
Save