Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Automatic plaf instance - Issue #129 #133

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/fibo_with_padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::<Fr>::run(8, &plaf_circuit, plaf_instance).unwrap();
let prover_plaf = MockProver::<Fr>::run(8, &plaf_circuit, plaf_circuit.instance()).unwrap();

let result_plaf = prover_plaf.verify_par();

Expand Down
4 changes: 2 additions & 2 deletions examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -148,7 +148,7 @@ fn main() {
let plaf_circuit = PlafH2Circuit { plaf, wit };

// same as halo2 boilerplate above
let prover_plaf = MockProver::<Fr>::run(8, &plaf_circuit, Vec::new()).unwrap();
let prover_plaf = MockProver::<Fr>::run(8, &plaf_circuit, plaf_circuit.instance()).unwrap();

let result_plaf = prover_plaf.verify_par();

Expand Down
47 changes: 45 additions & 2 deletions src/plonkish/backend/plaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -324,3 +324,46 @@ impl ChiquitoPlafWitGen {
}
}
}

pub trait PlafInstance<F> {
fn instance(&self) -> Vec<Vec<F>>;
}

impl<F: PrimeField> PlafInstance<F> for PlafH2Circuit {
fn instance(&self) -> Vec<Vec<F>> {
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) = &copy.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()
}
}
Loading