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

Commit

Permalink
Restore halo2 frontend compilation test
Browse files Browse the repository at this point in the history
  • Loading branch information
alxkzmn committed Aug 6, 2024
1 parent ec0cd93 commit fc60d66
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
78 changes: 75 additions & 3 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ fn get_block_stmts(stmt: &Statement<BigInt, Identifier>) -> Vec<Statement<BigInt

#[cfg(test)]
mod test {
use crate::plonkish::backend::halo2::Halo2Provable;
use halo2_proofs::halo2curves::bn256::Fr;
use crate::plonkish::backend::{
halo2::Halo2Provable,
halo2_legacy::{chiquito2Halo2, ChiquitoHalo2Circuit},
};
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
use std::collections::HashMap;

use crate::{
Expand Down Expand Up @@ -404,7 +407,76 @@ mod test {
}

#[test]
fn test_run_halo2_prover() {
fn test_run_halo2_mock_prover() {
let code = "
machine fibo(signal n) (signal b: field) {
// n and be are created automatically as shared
// signals
signal a: field, i;
// there is always a state called initial
// input signals get bound to the signal
// in the initial state (first instance)
state initial {
signal c;
i, a, b, c <== 1, 1, 1, 2;
-> middle {
i', a', b', n' <== i + 1, b, c, n;
}
}
state middle {
signal c;
c <== a + b;
if i + 1 == n {
-> final {
i', b', n' <== i + 1, c, n;
}
} else {
-> middle {
i', a', b', n' <== i + 1, b, c, n;
}
}
}
// There is always a state called final.
// Output signals get automatically bound to the signals
// with the same name in the final step (last instance).
// This state can be implicit if there are no constraints in it.
}
";

let chiquito =
compile_legacy::<Fr>(code, Config::default(), &DebugSymRefFactory::new("", code))
.unwrap();

let plonkish = chiquito.plonkish(config(
SingleRowCellManager {},
SimpleStepSelectorBuilder {},
));

let compiled = chiquito2Halo2(plonkish.circuit);

let circuit = ChiquitoHalo2Circuit::new(
compiled,
plonkish
.assignment_generator
.map(|g| g.generate(HashMap::from([("n".to_string(), Fr::from(12))]))),
);

let prover = MockProver::<Fr>::run(10, &circuit, circuit.instance()).unwrap();

let result = prover.verify();

assert!(result.is_ok());
}

#[test]
fn test_run_halo2_middleware_prover() {
let code = "
machine fibo(signal n) (signal b: field) {
// n and be are created automatically as shared
Expand Down
10 changes: 9 additions & 1 deletion src/parser/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ impl PartialEq for DebugSymRef {
}

#[derive(Clone, PartialEq, Eq)]
pub struct Identifier(pub String, pub i32, pub DebugSymRef);
pub struct Identifier(
/// Name
pub String,
/// Rotation
pub i32,
/// Debug symbol reference
pub DebugSymRef,
);
impl Identifier {
pub(crate) fn new<S: AsRef<str>>(value: S, dsym: DebugSymRef) -> Self {
let value_str = value.as_ref();
Expand All @@ -153,6 +160,7 @@ impl Identifier {
self.2.clone()
}

/// Increase the rotation by one
pub(crate) fn next(&self) -> Self {
Self(self.0.clone(), self.1 + 1, self.2.clone())
}
Expand Down
4 changes: 3 additions & 1 deletion src/plonkish/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
Circuit, Column, Poly, PolyExpr, PolyLookup,
},
poly::Expr,
sbpir::{query::Queriable, ExposeOffset, StepType, StepTypeUUID, PIR, SBPIRLegacy as astCircuit},
sbpir::{
query::Queriable, ExposeOffset, SBPIRLegacy as astCircuit, StepType, StepTypeUUID, PIR,
},
wit_gen::{AutoTraceGenerator, FixedAssignment, TraceGenerator},
};
use std::hash::Hash;
Expand Down

0 comments on commit fc60d66

Please sign in to comment.