Skip to content

Commit 3b12258

Browse files
phrwlkPratyush
andauthored
fix(vanishing_poly): compute x^2 - h^2 when dim_h == 1 in evaluate_constraints (#186)
* fix(vanishing_poly): compute x^2 - h^2 when dim_h == 1 in evaluate_constraints * Update vanishing_poly.rs --------- Co-authored-by: Pratyush Mishra <[email protected]>
1 parent 338ab12 commit 3b12258

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/poly/domain/vanishing_poly.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::fields::{fp::FpVar, FieldVar};
22
use ark_ff::{Field, PrimeField};
33
use ark_relations::gr1cs::SynthesisError;
4-
use ark_std::ops::Sub;
54

65
/// Struct describing vanishing polynomial for a multiplicative coset H where
76
/// |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> {
3938
/// Caution for use in holographic lincheck: The output has 2 entries in one
4039
/// matrix
4140
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-
4741
let mut cur = x.square()?;
4842
for _ in 1..self.dim_h {
4943
cur.square_in_place()?;
@@ -76,4 +70,18 @@ mod tests {
7670
assert!(cs.is_satisfied().unwrap());
7771
assert_eq!(result_var.value().unwrap(), native);
7872
}
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+
}
7987
}

0 commit comments

Comments
 (0)