diff --git a/halo2/src/circuit_builder.rs b/halo2/src/circuit_builder.rs index 0dec277279..bb02185498 100644 --- a/halo2/src/circuit_builder.rs +++ b/halo2/src/circuit_builder.rs @@ -57,17 +57,28 @@ pub(crate) fn analyzed_to_plaf( let query = |column, rotation| Expr::Var(PlonkVar::Query(ColumnQuery { column, rotation })); - let mut cd = CircuitData::from(analyzed, fixed.to_owned()); + let mut cd = CircuitData::from(analyzed, fixed); + + println!("Fixed len: {}", fixed.len()); + + let mut fixed_names = fixed + .iter() + .map(|(name, _)| name.clone()) + .collect::>(); + let mut fixed = fixed + .iter() + .map(|(_, column)| convert_column(column)) + .collect::>(); let num_rows: usize = analyzed.degree() as usize + 1; // Append __enable fixed column - let q_enable = query( - cd.insert_constant( - "__enable", - itertools::repeat_n(T::from(1), num_rows - 1).chain(std::iter::once(T::from(0))), - ), - 0, + let q_enable = query(cd.insert_constant("__enable"), 0); + fixed_names.push("__enable".to_string()); + fixed.push( + itertools::repeat_n(Some(BigUint::from(1u8)), num_rows - 1) + .chain(std::iter::once(Some(BigUint::from(0u8)))) + .collect::>(), ); let mut lookups = vec![]; @@ -84,10 +95,9 @@ pub(crate) fn analyzed_to_plaf( // build Plaf columns ------------------------------------------------- let columns = Columns { - fixed: cd - .fixed - .iter() - .map(|(name, _)| ColumnFixed::new(name.to_string())) + fixed: fixed_names + .into_iter() + .map(|name| ColumnFixed::new(name)) .collect(), witness: wit_columns, public: vec![ColumnPublic::new("public".to_string())], @@ -97,7 +107,7 @@ pub(crate) fn analyzed_to_plaf( let info = Info { p: T::modulus().to_arbitrary_integer(), - num_rows: cd.len(), + num_rows, challenges: vec![], }; @@ -174,12 +184,6 @@ pub(crate) fn analyzed_to_plaf( // build Plaf fixed. ------------------------------------------------------------------------- - let fixed: Vec> = cd - .fixed - .iter() - .map(|(_, column)| convert_column(column)) - .collect(); - Plaf { info, columns, @@ -192,7 +196,7 @@ pub(crate) fn analyzed_to_plaf( } } -fn copy_constraints(pil: &Analyzed, cd: &CircuitData) -> Vec { +fn copy_constraints(pil: &Analyzed, cd: &CircuitData) -> Vec { let mut copies = vec![]; // Enforce publics by copy-constraining to cells in the instance column. @@ -335,7 +339,7 @@ pub(crate) fn analyzed_to_circuit_with_witness( ) } -fn expression_2_expr(cd: &CircuitData, expr: &Expression) -> Expr { +fn expression_2_expr(cd: &CircuitData, expr: &Expression) -> Expr { match expr { Expression::Number(n) => Expr::Const(n.to_arbitrary_integer()), Expression::Reference(polyref) => { diff --git a/halo2/src/circuit_data.rs b/halo2/src/circuit_data.rs index eb59dead64..50a23d879a 100644 --- a/halo2/src/circuit_data.rs +++ b/halo2/src/circuit_data.rs @@ -7,14 +7,14 @@ use polyexen::expr::{Column, ColumnKind}; use powdr_ast::analyzed::Analyzed; use powdr_number::{AbstractNumberType, FieldElement}; -pub(crate) struct CircuitData { - pub(crate) fixed: Vec<(String, Vec)>, +pub(crate) struct CircuitData { pub(crate) public_column: Column, pub columns: HashMap, + fixed_id_counter: usize, } -impl<'a, T: FieldElement> CircuitData { - pub fn from(pil: &Analyzed, fixed: Vec<(String, Vec)>) -> Self { +impl<'a> CircuitData { + pub fn from(pil: &Analyzed, fixed: &[(String, Vec)]) -> Self { let const_cols = fixed.iter().enumerate().map(|(index, (name, _))| { ( name.to_string(), @@ -47,9 +47,9 @@ impl<'a, T: FieldElement> CircuitData { }; Self { - fixed, columns, public_column, + fixed_id_counter: fixed.len(), } } @@ -60,26 +60,12 @@ impl<'a, T: FieldElement> CircuitData { .unwrap_or_else(|| panic!("{name} column not found")) } - pub fn len(&self) -> usize { - self.fixed.get(0).unwrap().1.len() - } - - pub fn insert_constant>( - &mut self, - name: &'a str, - values: IT, - ) -> Column { - let values = values.into_iter().collect::>(); - - if !self.fixed.is_empty() { - assert_eq!(values.len(), self.len()); - } - - self.fixed.push((name.to_string(), values)); + pub fn insert_constant(&mut self, name: &'a str) -> Column { let column = Column { kind: ColumnKind::Fixed, - index: self.fixed.len() - 1, + index: self.fixed_id_counter, }; + self.fixed_id_counter += 1; self.columns.insert(name.to_string(), column); column } diff --git a/halo2/src/mock_prover.rs b/halo2/src/mock_prover.rs index d94c40d2f3..2d8790343b 100644 --- a/halo2/src/mock_prover.rs +++ b/halo2/src/mock_prover.rs @@ -26,7 +26,8 @@ pub fn mock_prove( let expanded_row_count_log = circuit_row_count_log + 1; log::debug!("{}", PlafDisplayBaseTOML(&circuit.plaf)); - println!("Fixed len: {}", circuit.plaf.fixed[0].len()); + println!("X Fixed len: {}", circuit.plaf.fixed.len()); + println!("Fixed[0] len: {}", circuit.plaf.fixed[0].len()); let mock_prover = MockProver::::run(expanded_row_count_log, &circuit, publics).unwrap(); mock_prover.assert_satisfied();