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 authored Aug 1, 2024
2 parents 3222b43 + a142e84 commit 6a7ca6e
Show file tree
Hide file tree
Showing 31 changed files with 917 additions and 651 deletions.
20 changes: 7 additions & 13 deletions examples/blake2f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use chiquito::{
CircuitContext, StepTypeSetupContext, StepTypeWGHandler,
},
plonkish::{
backend::halo2::{
chiquitoSuperCircuit2Halo2, halo2_verify, ChiquitoHalo2SuperCircuit, DummyRng,
Halo2Prover, PlonkishHalo2,
},
backend::halo2::{halo2_verify, Halo2Provable},
compiler::{
cell_manager::{MaxWidthCellManager, SingleRowCellManager},
config,
Expand All @@ -22,7 +19,6 @@ use chiquito::{
sbpir::query::Queriable,
};
use halo2_proofs::halo2curves::{bn256::Fr, group::ff::PrimeField};
use rand_chacha::rand_core::block::BlockRng;
use std::{fmt::Write, hash::Hash};

pub const IV_LEN: usize = 8;
Expand Down Expand Up @@ -1398,8 +1394,7 @@ fn blake2f_super_circuit<F: PrimeField + Hash>() -> SuperCircuit<F, InputValues>
}

fn main() {
let super_circuit = blake2f_super_circuit::<Fr>();
let compiled = chiquitoSuperCircuit2Halo2(&super_circuit);
let mut super_circuit = blake2f_super_circuit::<Fr>();

// h[0] = hex"48c9bdf267e6096a 3ba7ca8485ae67bb 2bf894fe72f36e3c f1361d5f3af54fa5";
// h[1] = hex"d182e6ad7f520e51 1f6c3e2b8c68059b 6bbd41fbabd9831f 79217e1319cde05b";
Expand Down Expand Up @@ -1482,18 +1477,17 @@ fn main() {
};

let witness = super_circuit.get_mapping().generate(values);
let mut circuit = ChiquitoHalo2SuperCircuit::new(compiled);

let rng = BlockRng::new(DummyRng {});

let halo2_prover = circuit.create_halo2_prover(9, rng);
let params_path = "examples/ptau/hermez-raw-11";
let halo2_prover = super_circuit.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) = halo2_prover.generate_proof(witness);

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_zero(self):
)
assert last_assignments[0] == 0 # i
assert last_assignments[1] == 1 # x
factorial.halo2_mock_prover(factorial_witness)
factorial.halo2_mock_prover(factorial_witness, "examples/ptau/hermez-raw-11")

def test_basic(self):
factorial = Factorial()
Expand All @@ -116,7 +116,7 @@ def test_basic(self):
)
assert last_assignments[0] == 7 # i
assert last_assignments[1] == 5040 # x
factorial.halo2_mock_prover(factorial_witness)
factorial.halo2_mock_prover(factorial_witness, "examples/ptau/hermez-raw-11")


if __name__ == "__main__":
Expand Down
21 changes: 11 additions & 10 deletions examples/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use chiquito::{
frontend::dsl::{circuit, trace::DSLTraceGenerator}, /* main function for constructing an AST
* circuit */
plonkish::{
backend::halo2::{halo2_verify, DummyRng, Halo2Prover, PlonkishHalo2},
backend::halo2::{halo2_verify, Halo2Provable},
compiler::{
cell_manager::SingleRowCellManager, // input for constructing the compiler
compile, // input for constructing the compiler
Expand All @@ -23,7 +23,6 @@ use chiquito::{
poly::ToField,
};
use halo2_proofs::halo2curves::bn256::Fr;
use rand_chacha::rand_core::block::BlockRng;

const MAX_FACTORIAL: usize = 10;

Expand Down Expand Up @@ -136,17 +135,18 @@ fn generate<F: Field + From<u64> + Hash>() -> PlonkishCompilationResult<F, DSLTr
// standard main function for a Halo2 circuit
fn main() {
let mut plonkish = generate::<Fr>();
let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let halo2_prover = plonkish.create_halo2_prover(10, rng);
let halo2_prover = plonkish.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) =
halo2_prover.generate_proof(plonkish.assignment_generator.unwrap().generate(0));

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand All @@ -157,17 +157,18 @@ fn main() {
}

let mut plonkish = generate::<Fr>();
let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let halo2_prover = plonkish.create_halo2_prover(8, rng);
let halo2_prover = plonkish.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) =
halo2_prover.generate_proof(plonkish.assignment_generator.unwrap().generate(7));

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
12 changes: 6 additions & 6 deletions examples/fibo_with_padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use chiquito::{
frontend::dsl::{circuit, trace::DSLTraceGenerator}, /* main function for constructing an AST
* circuit */
plonkish::{
backend::halo2::{halo2_verify, DummyRng, Halo2Prover, PlonkishHalo2},
backend::halo2::{halo2_verify, Halo2Provable},
compiler::{
cell_manager::SingleRowCellManager, // input for constructing the compiler
compile, // input for constructing the compiler
Expand All @@ -23,7 +23,6 @@ use chiquito::{
poly::ToField,
};
use halo2_proofs::halo2curves::bn256::Fr;
use rand_chacha::rand_core::block::BlockRng;

// This example file extends the rust example file 'fibonacci.rs',
// describing usage of multiple steptypes, padding, and exposing signals.
Expand Down Expand Up @@ -206,17 +205,18 @@ fn fibo_circuit<F: Field + From<u64> + Hash>(
// standard main function for a Halo2 circuit
fn main() {
let mut plonkish = fibo_circuit::<Fr>();
let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let halo2_prover = plonkish.create_halo2_prover(7, rng);
let halo2_prover = plonkish.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) =
halo2_prover.generate_proof(plonkish.assignment_generator.unwrap().generate(7));

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def trace(self, n):
fibo = Fibonacci()
fibo_witness = fibo.gen_witness(7)
fibo.halo2_mock_prover(
fibo_witness, k=7
fibo_witness, "examples/ptau/hermez-raw-11"
) # 2^k specifies the number of PLONKish table rows in Halo2
another_fibo_witness = fibo.gen_witness(4)
fibo.halo2_mock_prover(another_fibo_witness, k=7)
fibo.halo2_mock_prover(another_fibo_witness, "examples/ptau/hermez-raw-11")

fibo.to_pil(fibo_witness, "FiboCircuit")
12 changes: 6 additions & 6 deletions examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use chiquito::{
* circuit */
plonkish::{
backend::{
halo2::{halo2_verify, DummyRng, Halo2Prover, PlonkishHalo2},
halo2::{halo2_verify, Halo2Provable},
hyperplonk::ChiquitoHyperPlonkCircuit,
},
compiler::{
Expand All @@ -27,7 +27,6 @@ use chiquito::{
sbpir::SBPIR,
};
use halo2_proofs::halo2curves::bn256::Fr;
use rand_chacha::rand_core::block::BlockRng;

// the main circuit function: returns the compiled IR of a Chiquito circuit
// Generic types F, (), (u64, 64) stand for:
Expand Down Expand Up @@ -134,17 +133,18 @@ fn fibo_circuit<F: Field + From<u64> + Hash>() -> FiboReturn<F> {
fn main() {
let (mut chiquito, _) = fibo_circuit::<Fr>();

let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let halo2_prover = chiquito.create_halo2_prover(7, rng);
let halo2_prover = chiquito.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) =
halo2_prover.generate_proof(chiquito.assignment_generator.unwrap().generate(()));

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
21 changes: 7 additions & 14 deletions examples/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use chiquito::{
lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContext, StepTypeWGHandler,
},
plonkish::{
backend::halo2::{
chiquitoSuperCircuit2Halo2, halo2_verify, ChiquitoHalo2SuperCircuit, DummyRng,
Halo2Prover, PlonkishHalo2,
},
backend::halo2::{halo2_verify, Halo2Provable},
compiler::{
cell_manager::{MaxWidthCellManager, SingleRowCellManager},
config,
Expand All @@ -17,7 +14,6 @@ use chiquito::{
poly::ToExpr,
sbpir::query::Queriable,
};
use rand_chacha::rand_core::block::BlockRng;
use std::{hash::Hash, ops::Neg};

use halo2_proofs::halo2curves::{bn256::Fr, group::ff::PrimeField};
Expand Down Expand Up @@ -2255,24 +2251,21 @@ fn main() {
bytes: vec![0, 1, 2, 3, 4, 5, 6, 7],
};

let super_circuit = keccak_super_circuit::<Fr>(circuit_param.bytes.len());

let compiled = chiquitoSuperCircuit2Halo2(&super_circuit);

let mut circuit = ChiquitoHalo2SuperCircuit::new(compiled);
let mut super_circuit = keccak_super_circuit::<Fr>(circuit_param.bytes.len());

let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let witness = super_circuit.get_mapping().generate(circuit_param);

let halo2_prover = circuit.create_halo2_prover(9, rng);
let halo2_prover = super_circuit.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) = halo2_prover.generate_proof(witness);

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/mimc7.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ def mapping(self, x_in_value, k_value):
mimc7_super_witness = mimc7.gen_witness(F(1), F(2))
# for key, value in mimc7_super_witness.items():
# print(f"{key}: {str(value)}")
mimc7.halo2_mock_prover(mimc7_super_witness, k=10)
mimc7.halo2_mock_prover(mimc7_super_witness, "examples/ptau/hermez-raw-11")
20 changes: 7 additions & 13 deletions examples/mimc7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use halo2_proofs::halo2curves::{bn256::Fr, group::ff::PrimeField};
use chiquito::{
frontend::dsl::{lb::LookupTable, super_circuit, trace::DSLTraceGenerator, CircuitContext},
plonkish::{
backend::halo2::{
chiquitoSuperCircuit2Halo2, halo2_verify, ChiquitoHalo2SuperCircuit, DummyRng,
Halo2Prover, PlonkishHalo2,
},
backend::halo2::{halo2_verify, Halo2Provable},
compiler::{
cell_manager::SingleRowCellManager, config, step_selector::SimpleStepSelectorBuilder,
},
Expand All @@ -18,7 +15,6 @@ use chiquito::{
};

use mimc7_constants::ROUND_CONSTANTS;
use rand_chacha::rand_core::block::BlockRng;

// MiMC7 always has 91 rounds
pub const ROUNDS: usize = 91;
Expand Down Expand Up @@ -202,23 +198,21 @@ fn main() {
let x_in_value = Fr::from_str_vartime("1").expect("expected a number");
let k_value = Fr::from_str_vartime("2").expect("expected a number");

let super_circuit = mimc7_super_circuit::<Fr>();
let compiled = chiquitoSuperCircuit2Halo2(&super_circuit);

let mut circuit = ChiquitoHalo2SuperCircuit::new(compiled);
let mut super_circuit = mimc7_super_circuit::<Fr>();

let rng = BlockRng::new(DummyRng {});
let params_path = "examples/ptau/hermez-raw-11";

let witness = super_circuit.get_mapping().generate((x_in_value, k_value));

let halo2_prover = circuit.create_halo2_prover(10, rng);
let halo2_prover = super_circuit.create_halo2_prover(params_path);
println!("k={}", halo2_prover.get_k());

let (proof, instance) = halo2_prover.generate_proof(witness);

let result = halo2_verify(
proof,
&halo2_prover.setup.params,
&halo2_prover.setup.vk,
halo2_prover.get_params(),
halo2_prover.get_vk(),
instance,
);

Expand Down
Loading

0 comments on commit 6a7ca6e

Please sign in to comment.