diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 918b7c7..a86b0d8 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -753,4 +753,36 @@ impl ConstraintSystem { 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 + } } diff --git a/src/plonk/keygen.rs b/src/plonk/keygen.rs index dfe0fe2..d903e1f 100644 --- a/src/plonk/keygen.rs +++ b/src/plonk/keygen.rs @@ -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);