diff --git a/examples/fibo_with_padding.rs b/examples/fibo_with_padding.rs index 7a6240b2..473cfeca 100644 --- a/examples/fibo_with_padding.rs +++ b/examples/fibo_with_padding.rs @@ -217,7 +217,7 @@ fn main() { } // plaf boilerplate - use chiquito::plonkish::backend::plaf::chiquito2Plaf; + use chiquito::plonkish::backend::plaf::{chiquito2Plaf, PlafInstance}; use polyexen::plaf::{backends::halo2::PlafH2Circuit, WitnessDisplayCSV}; // get Chiquito ir @@ -234,9 +234,8 @@ fn main() { // this is unnecessary because Chiquito has a halo2 backend already let plaf_circuit = PlafH2Circuit { plaf, wit }; - let plaf_instance = vec![vec![34.field(), 7.field()]]; // same as halo2 boilerplate above - let prover_plaf = MockProver::::run(8, &plaf_circuit, plaf_instance).unwrap(); + let prover_plaf = MockProver::::run(8, &plaf_circuit, plaf_circuit.instance()).unwrap(); let result_plaf = prover_plaf.verify_par(); diff --git a/examples/fibonacci.rs b/examples/fibonacci.rs index d36e3fc1..8e79133b 100644 --- a/examples/fibonacci.rs +++ b/examples/fibonacci.rs @@ -130,7 +130,7 @@ fn main() { } // plaf boilerplate - use chiquito::plonkish::backend::plaf::chiquito2Plaf; + use chiquito::plonkish::backend::plaf::{chiquito2Plaf, PlafInstance}; use polyexen::plaf::{backends::halo2::PlafH2Circuit, WitnessDisplayCSV}; // get Chiquito ir @@ -148,7 +148,7 @@ fn main() { let plaf_circuit = PlafH2Circuit { plaf, wit }; // same as halo2 boilerplate above - let prover_plaf = MockProver::::run(8, &plaf_circuit, Vec::new()).unwrap(); + let prover_plaf = MockProver::::run(8, &plaf_circuit, plaf_circuit.instance()).unwrap(); let result_plaf = prover_plaf.verify_par(); diff --git a/src/plonkish/backend/plaf.rs b/src/plonkish/backend/plaf.rs index c4948c2c..215c71a8 100644 --- a/src/plonkish/backend/plaf.rs +++ b/src/plonkish/backend/plaf.rs @@ -16,8 +16,8 @@ use num_bigint::BigUint; use polyexen::{ expr::{get_field_p, Column as pColumn, ColumnKind, ColumnQuery, Expr as pExpr, PlonkVar}, plaf::{ - ColumnFixed, ColumnPublic, ColumnWitness, CopyC as pCopyC, Lookup as pLookup, Plaf, - Poly as pPoly, Witness as pWitness, + backends::halo2::PlafH2Circuit, ColumnFixed, ColumnPublic, ColumnWitness, CopyC as pCopyC, + Lookup as pLookup, Plaf, Poly as pPoly, Witness as pWitness, }, }; @@ -324,3 +324,46 @@ impl ChiquitoPlafWitGen { } } } + +pub trait PlafInstance { + fn instance(&self) -> Vec>; +} + +impl PlafInstance for PlafH2Circuit { + fn instance(&self) -> Vec> { + if !self.plaf.columns.public.is_empty() { + let mut instance_with_offsets = Vec::new(); + for copy in &self.plaf.copys { + let (left_col, right_col) = ©.columns; + + let (witness_col, offsets) = match (left_col.kind, right_col.kind) { + (ColumnKind::Witness, ColumnKind::Public) => (left_col, copy.offsets.clone()), + (ColumnKind::Public, ColumnKind::Witness) => ( + right_col, + copy.offsets.iter().map(|(l, r)| (*r, *l)).collect(), + ), + _ => continue, + }; + + for (witness_offset, public_offset) in offsets { + instance_with_offsets.push(( + self.wit.witness[witness_col.index][witness_offset] + .as_ref() + .unwrap() + .to_u64_digits()[0], + public_offset, + )); + } + } + instance_with_offsets.sort_by_key(|&(_, offset)| offset); + let instance_values = instance_with_offsets + .iter() + .map(|&(val, _)| F::from(val)) + .collect(); + + return vec![instance_values]; + } + + Vec::new() + } +}