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

Restore halo2 frontend compilation test #285

Merged
merged 2 commits into from
Aug 6, 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
2 changes: 1 addition & 1 deletion src/frontend/dsl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
field::Field,
sbpir::{query::Queriable, ExposeOffset, StepType, StepTypeUUID, PIR, SBPIRLegacy},
sbpir::{query::Queriable, ExposeOffset, SBPIRLegacy, StepType, StepTypeUUID, PIR},
util::{uuid, UUID},
wit_gen::{FixedGenContext, StepInstance, TraceGenerator},
};
Expand Down
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
4 changes: 2 additions & 2 deletions src/plonkish/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use halo2_proofs::plonk::{Advice, Column as Halo2Column};
use crate::{
plonkish::ir::{assignments::Assignments, Circuit, Column, ColumnType, Poly, PolyLookup},
sbpir::{
FixedSignal, ForwardSignal, ImportedHalo2Advice, ImportedHalo2Fixed, SharedSignal,
StepType, StepTypeUUID, SBPIRLegacy as astCircuit,
FixedSignal, ForwardSignal, ImportedHalo2Advice, ImportedHalo2Fixed,
SBPIRLegacy as astCircuit, SharedSignal, StepType, StepTypeUUID,
},
util::{uuid, UUID},
wit_gen::TraceGenerator,
Expand Down
2 changes: 1 addition & 1 deletion src/wit_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
field::Field,
frontend::dsl::StepTypeHandler,
poly::Expr,
sbpir::{query::Queriable, ForwardSignal, InternalSignal, StepTypeUUID, PIR, SBPIRLegacy},
sbpir::{query::Queriable, ForwardSignal, InternalSignal, SBPIRLegacy, StepTypeUUID, PIR},
util::UUID,
};

Expand Down
Loading