diff --git a/examples/fibonacci.rs b/examples/fibonacci.rs index a388425f..7dc16302 100644 --- a/examples/fibonacci.rs +++ b/examples/fibonacci.rs @@ -162,12 +162,13 @@ fn main() { // get assignments let assignments = plonkish.assignment_generator.unwrap().generate(()); // get hyperplonk circuit - let mut hyperplonk_circuit = ChiquitoHyperPlonkCircuit::new(4, plonkish.circuit); + let mut hyperplonk_circuit = ChiquitoHyperPlonkCircuit::new(plonkish.circuit); + let k = hyperplonk_circuit.get_k(); + println!("k: {}", k); hyperplonk_circuit.set_assignment(assignments); - type GeminiKzg = multilinear::Gemini>; type HyperPlonk = backend::hyperplonk::HyperPlonk; - bench_plonkish_backend::(System::HyperPlonk, 4, &hyperplonk_circuit); + bench_plonkish_backend::(System::HyperPlonk, k, &hyperplonk_circuit); // pil boilerplate use chiquito::pil::backend::powdr_pil::chiquito2Pil; diff --git a/src/plonkish/backend/hyperplonk.rs b/src/plonkish/backend/hyperplonk.rs index 00ba9c92..15a43986 100644 --- a/src/plonkish/backend/hyperplonk.rs +++ b/src/plonkish/backend/hyperplonk.rs @@ -152,8 +152,11 @@ impl + Hash> ChiquitoHyperPlonk { } impl + Hash> ChiquitoHyperPlonkCircuit { - pub fn new(k: usize, circuit: Circuit) -> Self { - let chiquito_hyper_plonk = ChiquitoHyperPlonk::new(k, circuit); + pub fn new(circuit: Circuit) -> Self { + let chiquito_hyper_plonk = ChiquitoHyperPlonk::new( + circuit.num_rows.next_power_of_two().ilog2() as usize, + circuit, + ); Self { circuit: chiquito_hyper_plonk, assignments: None, @@ -165,6 +168,10 @@ impl + Hash> ChiquitoHyperPlonkCircuit { self.circuit.set_instance(instances); self.assignments = Some(assignments); } + + pub fn get_k(&self) -> usize { + self.circuit.k + } } // given column uuid and the vector of all column uuids, get the index or position of the uuid @@ -189,7 +196,6 @@ impl + Hash> PlonkishCircuit for ChiquitoHyperPl // number of preprocess is equal to number of fixed columns let preprocess_polys = vec![vec![F::ZERO; 1 << self.circuit.k]; self.circuit.fixed_uuids.len()]; - let advice_idx = self.circuit.advice_idx(); let constraints: Vec> = self .circuit @@ -262,7 +268,8 @@ impl + Hash> PlonkishCircuit for ChiquitoHyperPl .fixed_uuids .iter() .map(|uuid| { - self.circuit + let mut column_fixed_assignments = self + .circuit .chiquito_ir .fixed_assignments .get( @@ -270,7 +277,15 @@ impl + Hash> PlonkishCircuit for ChiquitoHyperPl [column_idx(*uuid, &self.circuit.all_uuids)], ) .unwrap() - .clone() + .clone(); + // Make sure that all the column assignments fill the full height of the + // circuit because the Hyperplonk backend expects all columns + // to have the 2^k height + column_fixed_assignments.extend( + std::iter::repeat(F::ZERO) + .take(2_usize.pow(self.circuit.k as u32) - column_fixed_assignments.len()), + ); + column_fixed_assignments }) .collect::>>(); @@ -297,13 +312,21 @@ impl + Hash> PlonkishCircuit for ChiquitoHyperPl .expect("synthesize: phase not found") .iter() .map(|uuid| { - assignments + let mut column_assignments = assignments .get( &self.circuit.chiquito_ir.columns [column_idx(*uuid, &self.circuit.all_uuids)], ) .unwrap() - .clone() + .clone(); + // Make sure that all the column assignments fill the full height of the + // circuit because the Hyperplonk backend expects all columns + // to have the 2^k height + column_assignments.extend( + std::iter::repeat(F::ZERO) + .take(2_usize.pow(self.circuit.k as u32) - (column_assignments.len())), + ); + column_assignments }) .collect::>>(); Ok(advice_assignments) diff --git a/src/plonkish/compiler/unit.rs b/src/plonkish/compiler/unit.rs index 49f4cae8..81a95081 100644 --- a/src/plonkish/compiler/unit.rs +++ b/src/plonkish/compiler/unit.rs @@ -276,7 +276,7 @@ impl From> for Circuit { fixed_assignments: unit.fixed_assignments, id: unit.uuid, ast_id: unit.ast_id, - num_rows: unit.num_rows, + num_rows: unit.num_rows + unit.additional_rows, } } }