From 2c50b39812243d4eaf80315d2ed3ea9d0abe40ca Mon Sep 17 00:00:00 2001 From: Eduard S Date: Tue, 16 Jan 2024 13:51:24 +0000 Subject: [PATCH] Simplify Backend gate type --- halo2_proofs/src/plonk/circuit.rs | 40 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/halo2_proofs/src/plonk/circuit.rs b/halo2_proofs/src/plonk/circuit.rs index b6de88d7..7e57e2f6 100644 --- a/halo2_proofs/src/plonk/circuit.rs +++ b/halo2_proofs/src/plonk/circuit.rs @@ -1623,12 +1623,11 @@ impl>, Iter: IntoIterator> IntoIterato } } -/// GateV2Backend +/// A Gate contains a single polynomial identity with a name as metadata. #[derive(Clone, Debug)] pub struct GateV2Backend { name: String, - constraint_names: Vec, - polys: Vec>, + poly: ExpressionMid, } impl GateV2Backend { @@ -1637,14 +1636,9 @@ impl GateV2Backend { self.name.as_str() } - /// Returns the name of the constraint at index `constraint_index`. - pub fn constraint_name(&self, constraint_index: usize) -> &str { - self.constraint_names[constraint_index].as_str() - } - - /// Returns constraints of this gate - pub fn polynomials(&self) -> &[ExpressionMid] { - &self.polys + /// Returns the polynomial identity of this gate + pub fn polynomial(&self) -> &ExpressionMid { + &self.poly } } @@ -1988,11 +1982,19 @@ pub fn compile_circuit>( gates: cs .gates .iter() - .map(|g| GateV2Backend { - name: g.name.clone(), - constraint_names: g.constraint_names.clone(), - polys: g.polys.clone().into_iter().map(|e| e.into()).collect(), + .map(|g| { + g.polys.clone().into_iter().enumerate().map(|(i, e)| { + let name = match g.constraint_name(i) { + "" => g.name.clone(), + constraint_name => format!("{}:{}", g.name, constraint_name), + }; + GateV2Backend { + name, + poly: e.into(), + } + }) }) + .flatten() .collect(), permutation: cs.permutation.clone(), lookups: cs @@ -2073,12 +2075,8 @@ impl ConstraintSystemV2Backend { .iter() .map(|gate| Gate { name: gate.name.clone(), - constraint_names: gate.constraint_names.clone(), - polys: gate - .polynomials() - .iter() - .map(|e| queries.as_expression(e)) - .collect(), + constraint_names: Vec::new(), + polys: vec![queries.as_expression(gate.polynomial())], queried_selectors: Vec::new(), // Unused? queried_cells: Vec::new(), // Unused? })