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

Commit

Permalink
Merge branch 'chiquito-2024' into rutefig/231-applying-cse-to-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
rutefig committed Aug 22, 2024
2 parents 5b878ea + c07f98d commit 8ed9a5f
Show file tree
Hide file tree
Showing 20 changed files with 1,327 additions and 384 deletions.
16 changes: 11 additions & 5 deletions examples/blake2f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chiquito::{
lb::LookupTable,
super_circuit,
trace::DSLTraceGenerator,
CircuitContext, StepTypeSetupContext, StepTypeWGHandler,
CircuitContextLegacy, StepTypeSetupContext, StepTypeWGHandler,
},
plonkish::{
backend::halo2_legacy::{chiquitoSuperCircuit2Halo2, ChiquitoHalo2SuperCircuit},
Expand Down Expand Up @@ -127,7 +127,10 @@ pub fn split_to_4bits_values<F: PrimeField + Hash>(vec_values: &[u64]) -> Vec<Ve
.collect()
}

fn blake2f_iv_table<F: PrimeField + Hash>(ctx: &mut CircuitContext<F>, _: usize) -> LookupTable {
fn blake2f_iv_table<F: PrimeField + Hash>(
ctx: &mut CircuitContextLegacy<F>,
_: usize,
) -> LookupTable {
let lookup_iv_row: Queriable<F> = ctx.fixed("iv row");
let lookup_iv_value: Queriable<F> = ctx.fixed("iv value");

Expand All @@ -144,7 +147,10 @@ fn blake2f_iv_table<F: PrimeField + Hash>(ctx: &mut CircuitContext<F>, _: usize)
}

// For range checking
fn blake2f_4bits_table<F: PrimeField + Hash>(ctx: &mut CircuitContext<F>, _: usize) -> LookupTable {
fn blake2f_4bits_table<F: PrimeField + Hash>(
ctx: &mut CircuitContextLegacy<F>,
_: usize,
) -> LookupTable {
let lookup_4bits_row: Queriable<F> = ctx.fixed("4bits row");
let lookup_4bits_value: Queriable<F> = ctx.fixed("4bits value");

Expand All @@ -160,7 +166,7 @@ fn blake2f_4bits_table<F: PrimeField + Hash>(ctx: &mut CircuitContext<F>, _: usi
}

fn blake2f_xor_4bits_table<F: PrimeField + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
_: usize,
) -> LookupTable {
let lookup_xor_row: Queriable<F> = ctx.fixed("xor row");
Expand Down Expand Up @@ -526,7 +532,7 @@ fn g_setup<F: PrimeField + Hash>(
}

fn blake2f_circuit<F: PrimeField + Hash>(
ctx: &mut CircuitContext<F, DSLTraceGenerator<F, InputValues>>,
ctx: &mut CircuitContextLegacy<F, DSLTraceGenerator<F, InputValues>>,
params: CircuitParams,
) {
let v_vec: Vec<Queriable<F>> = (0..V_LEN)
Expand Down
7 changes: 4 additions & 3 deletions examples/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::hash::Hash;

use chiquito::{
field::Field,
frontend::dsl::{circuit, trace::DSLTraceGenerator}, /* main function for constructing an AST
* circuit */
frontend::dsl::{circuit_legacy, trace::DSLTraceGenerator}, /* main function for constructing
* an AST
* circuit */
plonkish::{
backend::halo2_legacy::{chiquito2Halo2, ChiquitoHalo2Circuit},
compiler::{
Expand Down Expand Up @@ -42,7 +43,7 @@ fn generate<F: Field + From<u64> + Hash>() -> PlonkishCompilationResult<F, DSLTr

use chiquito::frontend::dsl::cb::*; // functions for constraint building

let factorial_circuit = circuit::<F, u32, _>("factorial", |ctx| {
let factorial_circuit = circuit_legacy::<F, u32, _>("factorial", |ctx| {
let i = ctx.shared("i");
let x = ctx.forward("x");

Expand Down
7 changes: 4 additions & 3 deletions examples/fibo_with_padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::hash::Hash;

use chiquito::{
field::Field,
frontend::dsl::{circuit, trace::DSLTraceGenerator}, /* main function for constructing an AST
* circuit */
frontend::dsl::{circuit_legacy, trace::DSLTraceGenerator}, /* main function for constructing
* an AST
* circuit */
plonkish::{
backend::halo2_legacy::{chiquito2Halo2, ChiquitoHalo2Circuit},
compiler::{
Expand Down Expand Up @@ -37,7 +38,7 @@ fn fibo_circuit<F: Field + From<u64> + Hash>(
sbpir::ExposeOffset::*, // for exposing witnesses
};

let fibo = circuit::<F, u32, _>("fibonacci", |ctx| {
let fibo = circuit_legacy::<F, u32, _>("fibonacci", |ctx| {
// Example table for 7 rounds:
// | step_type | a | b | c | n |
// ---------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::hash::Hash;

use chiquito::{
field::Field,
frontend::dsl::{circuit, trace::DSLTraceGenerator}, /* main function for constructing an AST
* circuit */
frontend::dsl::{circuit_legacy, trace::DSLTraceGenerator}, /* main function for constructing
* an AST
* circuit */
plonkish::{
backend::{
halo2_legacy::{chiquito2Halo2, ChiquitoHalo2Circuit},
Expand Down Expand Up @@ -50,7 +51,7 @@ fn fibo_circuit<F: Field + From<u64> + Hash>() -> FiboReturn<F> {

use chiquito::frontend::dsl::cb::*; // functions for constraint building

let fibo = circuit::<F, (), _>("fibonacci", |ctx| {
let fibo = circuit_legacy::<F, (), _>("fibonacci", |ctx| {
// the following objects (forward signals, steptypes) are defined on the circuit-level

// forward signals can have constraints across different steps
Expand Down
17 changes: 9 additions & 8 deletions examples/keccak.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use chiquito::{
frontend::dsl::{
lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContext, StepTypeWGHandler,
lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContextLegacy,
StepTypeWGHandler,
},
plonkish::{
backend::halo2_legacy::{chiquitoSuperCircuit2Halo2, ChiquitoHalo2SuperCircuit},
Expand Down Expand Up @@ -231,7 +232,7 @@ fn eval_keccak_f_to_bit_vec4<F: PrimeField<Repr = [u8; 32]>>(value1: F, value2:
}

fn keccak_xor_table_batch2<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
lens: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -254,7 +255,7 @@ fn keccak_xor_table_batch2<F: PrimeField + Eq + Hash>(
}

fn keccak_xor_table_batch3<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
lens: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -280,7 +281,7 @@ fn keccak_xor_table_batch3<F: PrimeField + Eq + Hash>(
}

fn keccak_xor_table_batch4<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
lens: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -306,7 +307,7 @@ fn keccak_xor_table_batch4<F: PrimeField + Eq + Hash>(
}

fn keccak_chi_table<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
lens: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -332,7 +333,7 @@ fn keccak_chi_table<F: PrimeField + Eq + Hash>(
}

fn keccak_pack_table<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
_: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand Down Expand Up @@ -362,7 +363,7 @@ fn keccak_pack_table<F: PrimeField + Eq + Hash>(
}

fn keccak_round_constants_table<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
lens: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand Down Expand Up @@ -722,7 +723,7 @@ fn eval_keccak_f_one_round<F: PrimeField<Repr = [u8; 32]> + Eq + Hash>(
}

fn keccak_circuit<F: PrimeField<Repr = [u8; 32]> + Eq + Hash>(
ctx: &mut CircuitContext<F, DSLTraceGenerator<F, KeccakCircuit>>,
ctx: &mut CircuitContextLegacy<F, DSLTraceGenerator<F, KeccakCircuit>>,
param: CircuitParams,
) {
use chiquito::frontend::dsl::cb::*;
Expand Down
8 changes: 5 additions & 3 deletions examples/mimc7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use halo2_proofs::{
};

use chiquito::{
frontend::dsl::{lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContext},
frontend::dsl::{
lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContextLegacy,
},
plonkish::{
backend::halo2_legacy::{chiquitoSuperCircuit2Halo2, ChiquitoHalo2SuperCircuit},
compiler::{
Expand All @@ -23,7 +25,7 @@ use mimc7_constants::ROUND_CONSTANTS;
pub const ROUNDS: usize = 91;

fn mimc7_constants<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F, DSLTraceGenerator<F>>,
ctx: &mut CircuitContextLegacy<F, DSLTraceGenerator<F>>,
_: (),
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -49,7 +51,7 @@ fn mimc7_constants<F: PrimeField + Eq + Hash>(
}

fn mimc7_circuit<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F, DSLTraceGenerator<F, (F, F)>>,
ctx: &mut CircuitContextLegacy<F, DSLTraceGenerator<F, (F, F)>>,
constants: LookupTable,
) {
use chiquito::frontend::dsl::cb::*;
Expand Down
10 changes: 6 additions & 4 deletions examples/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use chiquito::{
frontend::dsl::{lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContext},
frontend::dsl::{
lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContextLegacy,
},
plonkish::{
backend::halo2_legacy::{chiquitoSuperCircuit2Halo2, ChiquitoHalo2SuperCircuit},
compiler::{
Expand Down Expand Up @@ -49,7 +51,7 @@ struct CircuitParams {
}

fn poseidon_constants_table<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
param_t: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -75,7 +77,7 @@ fn poseidon_constants_table<F: PrimeField + Eq + Hash>(
}

fn poseidon_matrix_table<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F>,
ctx: &mut CircuitContextLegacy<F>,
param_t: usize,
) -> LookupTable {
use chiquito::frontend::dsl::cb::*;
Expand All @@ -97,7 +99,7 @@ fn poseidon_matrix_table<F: PrimeField + Eq + Hash>(
}

fn poseidon_circuit<F: PrimeField + Eq + Hash>(
ctx: &mut CircuitContext<F, DSLTraceGenerator<F, ValuesAndLens<F>>>,
ctx: &mut CircuitContextLegacy<F, DSLTraceGenerator<F, ValuesAndLens<F>>>,
param: CircuitParams,
) {
use chiquito::frontend::dsl::cb::*;
Expand Down
Loading

0 comments on commit 8ed9a5f

Please sign in to comment.