|
1 | 1 | use crate::fields::{fp::FpVar, FieldVar}; |
2 | 2 | use ark_ff::{Field, PrimeField}; |
3 | 3 | use ark_relations::gr1cs::SynthesisError; |
4 | | -use ark_std::ops::Sub; |
5 | 4 |
|
6 | 5 | /// Struct describing vanishing polynomial for a multiplicative coset H where |
7 | 6 | /// |H| is a power of 2. As H is a coset, every element can be described as |
@@ -39,11 +38,6 @@ impl<F: PrimeField> VanishingPolynomial<F> { |
39 | 38 | /// Caution for use in holographic lincheck: The output has 2 entries in one |
40 | 39 | /// matrix |
41 | 40 | pub fn evaluate_constraints(&self, x: &FpVar<F>) -> Result<FpVar<F>, SynthesisError> { |
42 | | - if self.dim_h == 1 { |
43 | | - let result = x.sub(x); |
44 | | - return Ok(result); |
45 | | - } |
46 | | - |
47 | 41 | let mut cur = x.square()?; |
48 | 42 | for _ in 1..self.dim_h { |
49 | 43 | cur.square_in_place()?; |
@@ -76,4 +70,18 @@ mod tests { |
76 | 70 | assert!(cs.is_satisfied().unwrap()); |
77 | 71 | assert_eq!(result_var.value().unwrap(), native); |
78 | 72 | } |
| 73 | + |
| 74 | + #[test] |
| 75 | + fn constraints_test_dim1() { |
| 76 | + let mut rng = test_rng(); |
| 77 | + let offset = Fr::rand(&mut rng); |
| 78 | + let cs = ConstraintSystem::new_ref(); |
| 79 | + let x = Fr::rand(&mut rng); |
| 80 | + let x_var = FpVar::new_witness(ns!(cs, "x_var"), || Ok(x)).unwrap(); |
| 81 | + let vp = VanishingPolynomial::new(offset, 1); |
| 82 | + let native = vp.evaluate(&x); |
| 83 | + let result_var = vp.evaluate_constraints(&x_var).unwrap(); |
| 84 | + assert!(cs.is_satisfied().unwrap()); |
| 85 | + assert_eq!(result_var.value().unwrap(), native); |
| 86 | + } |
79 | 87 | } |
0 commit comments