Relocate computation of the degree of the constraint system to the ConstraintSystem struct.

This commit is contained in:
Sean Bowe 2021-02-24 10:19:46 -07:00
parent 4e7d4a0f64
commit d92b1c4fb9
No known key found for this signature in database
GPG key ID: 95684257D8F8B031
2 changed files with 33 additions and 25 deletions

View file

@ -753,4 +753,36 @@ impl<F: Field> ConstraintSystem<F> {
self.num_instance_columns += 1;
tmp
}
/// Compute the degree of the constraint system (the maximum degree of all
/// constraints).
pub fn degree(&self) -> usize {
// The permutation argument will serve alongside the gates, so must be
// accounted for.
let mut degree = self
.permutations
.iter()
.map(|p| p.required_degree())
.max()
.unwrap_or(1);
// The lookup argument also serves alongside the gates and must be accounted
// for.
degree = std::cmp::max(
degree,
self.lookups
.iter()
.map(|l| l.required_degree())
.max()
.unwrap_or(1),
);
// Account for each gate to ensure our quotient polynomial is the
// correct degree and that our extended domain is the right size.
for (_, poly) in self.gates.iter() {
degree = std::cmp::max(degree, poly.degree());
}
degree
}
}

View file

@ -25,31 +25,7 @@ where
let mut cs = ConstraintSystem::default();
let config = ConcreteCircuit::configure(&mut cs);
// The permutation argument will serve alongside the gates, so must be
// accounted for.
let mut degree = cs
.permutations
.iter()
.map(|p| p.required_degree())
.max()
.unwrap_or(1);
// The lookup argument also serves alongside the gates and must be accounted
// for.
degree = std::cmp::max(
degree,
cs.lookups
.iter()
.map(|l| l.required_degree())
.max()
.unwrap_or(1),
);
// Account for each gate to ensure our quotient polynomial is the
// correct degree and that our extended domain is the right size.
for (_, poly) in cs.gates.iter() {
degree = std::cmp::max(degree, poly.degree());
}
let degree = cs.degree();
let domain = EvaluationDomain::new(degree as u32, params.k);