Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 committed Dec 6, 2024
1 parent 7efa421 commit 29e2af9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
21 changes: 20 additions & 1 deletion expander_compiler/src/frontend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use builder::RootBuilder;

use crate::circuit::layered::NormalInputType;
use crate::circuit::layered::{CrossLayerInputType, NormalInputType};
use crate::circuit::{ir, layered};

mod api;
Expand Down Expand Up @@ -55,6 +55,11 @@ pub struct CompileResult<C: Config> {
pub layered_circuit: layered::Circuit<C, NormalInputType>,
}

pub struct CompileResultCrossLayer<C: Config> {
pub witness_solver: WitnessSolver<C>,
pub layered_circuit: layered::Circuit<C, CrossLayerInputType>,
}

pub fn compile<C: Config, Cir: internal::DumpLoadTwoVariables<Variable> + Define<C> + Clone>(
circuit: &Cir,
) -> Result<CompileResult<C>, Error> {
Expand All @@ -65,3 +70,17 @@ pub fn compile<C: Config, Cir: internal::DumpLoadTwoVariables<Variable> + Define
layered_circuit: lc,
})
}

pub fn compile_cross_layer<
C: Config,
Cir: internal::DumpLoadTwoVariables<Variable> + Define<C> + Clone,
>(
circuit: &Cir,
) -> Result<CompileResultCrossLayer<C>, Error> {
let root = build(circuit);
let (irw, lc) = crate::compile::compile::<C, _>(&root)?;
Ok(CompileResultCrossLayer {
witness_solver: WitnessSolver { circuit: irw },
layered_circuit: lc,
})
}
34 changes: 25 additions & 9 deletions expander_compiler/tests/keccak_gf2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use expander_compiler::frontend::*;
use expander_compiler::{circuit::layered::InputType, frontend::*};
use internal::Serde;
use rand::{thread_rng, Rng};
use tiny_keccak::Hasher;
Expand Down Expand Up @@ -224,14 +224,10 @@ impl Define<GF2Config> for Keccak256Circuit<Variable> {
}
}

#[test]
fn keccak_gf2_main() {
let compile_result = compile(&Keccak256Circuit::default()).unwrap();
let CompileResult {
witness_solver,
layered_circuit,
} = compile_result;

fn keccak_gf2_test<I: InputType>(
witness_solver: WitnessSolver<GF2Config>,
layered_circuit: expander_compiler::circuit::layered::Circuit<GF2Config, I>,
) {
let mut assignment = Keccak256Circuit::<GF2>::default();
for k in 0..N_HASHES {
let mut data = vec![0u8; 64];
Expand Down Expand Up @@ -302,3 +298,23 @@ fn keccak_gf2_main() {

println!("dumped to files");
}

#[test]
fn keccak_gf2_main() {
let compile_result = compile(&Keccak256Circuit::default()).unwrap();
let CompileResult {
witness_solver,
layered_circuit,
} = compile_result;
keccak_gf2_test(witness_solver, layered_circuit);
}

#[test]
fn keccak_gf2_main_cross_layer() {
let compile_result = compile_cross_layer(&Keccak256Circuit::default()).unwrap();
let CompileResultCrossLayer {
witness_solver,
layered_circuit,
} = compile_result;
keccak_gf2_test(witness_solver, layered_circuit);
}

0 comments on commit 29e2af9

Please sign in to comment.