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

Fix hyperplonk compilation #286

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
7 changes: 4 additions & 3 deletions examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<univariate::UnivariateKzg<Bn256>>;
type HyperPlonk = backend::hyperplonk::HyperPlonk<GeminiKzg>;
bench_plonkish_backend::<HyperPlonk, Fr>(System::HyperPlonk, 4, &hyperplonk_circuit);
bench_plonkish_backend::<HyperPlonk, Fr>(System::HyperPlonk, k, &hyperplonk_circuit);

// pil boilerplate
use chiquito::pil::backend::powdr_pil::chiquito2Pil;
Expand Down
37 changes: 30 additions & 7 deletions src/plonkish/backend/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ impl<F: Field + From<u64> + Hash> ChiquitoHyperPlonk<F> {
}

impl<F: Field + From<u64> + Hash> ChiquitoHyperPlonkCircuit<F> {
pub fn new(k: usize, circuit: Circuit<F>) -> Self {
let chiquito_hyper_plonk = ChiquitoHyperPlonk::new(k, circuit);
pub fn new(circuit: Circuit<F>) -> 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,
Expand All @@ -165,6 +168,10 @@ impl<F: Field + From<u64> + Hash> ChiquitoHyperPlonkCircuit<F> {
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
Expand All @@ -189,7 +196,6 @@ impl<F: Field + Clone + From<u64> + Hash> PlonkishCircuit<F> 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<Expression<F>> = self
.circuit
Expand Down Expand Up @@ -262,15 +268,24 @@ impl<F: Field + Clone + From<u64> + Hash> PlonkishCircuit<F> for ChiquitoHyperPl
.fixed_uuids
.iter()
.map(|uuid| {
self.circuit
let mut column_fixed_assignments = self
.circuit
.chiquito_ir
.fixed_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_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::<Vec<Vec<F>>>();

Expand All @@ -297,13 +312,21 @@ impl<F: Field + Clone + From<u64> + Hash> PlonkishCircuit<F> 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::<Vec<Vec<F>>>();
Ok(advice_assignments)
Expand Down
2 changes: 1 addition & 1 deletion src/plonkish/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<F> From<CompilationUnit<F>> for Circuit<F> {
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,
}
}
}
Loading