Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Circuit trait to take parameters in config #168

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions halo2_gadgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bench = false

[features]
dev-graph = ["halo2_proofs/dev-graph", "plotters"]
circuit-params = ["halo2_proofs/circuit-params"]
test-dependencies = ["proptest"]
unstable = []

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ where
{
type Config = MyConfig<WIDTH, RATE, L>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self {
Expand All @@ -61,7 +63,10 @@ where
}
}

fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<Fp>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
let expected = meta.instance_column();
meta.enable_equality(expected);
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
impl Circuit<pallas::Base> for MyCircuit {
type Config = Table16Config;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
Table16Chip::configure(meta)
}

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,17 @@ pub(crate) mod tests {
impl Circuit<pallas::Base> for MyCircuit {
type Config = EccConfig<TestFixedBases>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit { test_errors: false }
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,17 @@ pub mod tests {
impl Circuit<pallas::Base> for MyCircuit {
type Config = EccConfig<TestFixedBases>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
14 changes: 12 additions & 2 deletions halo2_gadgets/src/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,17 @@ mod tests {
{
type Config = Pow5Config<Fp, WIDTH, RATE>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
PermuteCircuit::<S, WIDTH, RATE>(PhantomData)
}

fn configure(meta: &mut ConstraintSystem<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
fn configure(
meta: &mut ConstraintSystem<Fp>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Pow5Config<Fp, WIDTH, RATE> {
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
let partial_sbox = meta.advice_column();

Expand Down Expand Up @@ -735,6 +740,8 @@ mod tests {
{
type Config = Pow5Config<Fp, WIDTH, RATE>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self {
Expand All @@ -744,7 +751,10 @@ mod tests {
}
}

fn configure(meta: &mut ConstraintSystem<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
fn configure(
meta: &mut ConstraintSystem<Fp>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Pow5Config<Fp, WIDTH, RATE> {
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
let partial_sbox = meta.advice_column();

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sha256/table16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,17 @@ mod tests {
impl Circuit<pallas::Base> for MyCircuit {
type Config = Table16Config;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {}
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
Table16Chip::configure(meta)
}

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sha256/table16/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,12 +954,17 @@ mod tests {
impl Circuit<pallas::Base> for MyCircuit {
type Config = Table16Config;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {}
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
Table16Chip::configure(meta)
}

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sha256/table16/message_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,17 @@ mod tests {
impl Circuit<pallas::Base> for MyCircuit {
type Config = Table16Config;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {}
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
Table16Chip::configure(meta)
}

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sha256/table16/spread_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,17 @@ mod tests {
impl<F: PrimeField> Circuit<F> for MyCircuit {
type Config = SpreadTableConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {}
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let input_tag = meta.advice_column();
let input_dense = meta.advice_column();
let input_spread = meta.advice_column();
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,18 @@ pub(crate) mod tests {
SinsemillaConfig<TestHashDomain, TestCommitDomain, TestFixedBases>,
);
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {}
}

#[allow(non_snake_case)]
fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,17 @@ pub mod tests {
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases>,
);
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,17 @@ mod tests {
impl<const RANGE: usize> Circuit<pallas::Base> for MyCircuit<RANGE> {
type Config = Config;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit(self.0)
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let selector = meta.selector();
let advice = meta.advice_column();

Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/utilities/cond_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,17 @@ mod tests {
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
type Config = CondSwapConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/utilities/decompose_running_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ mod tests {
{
type Config = RunningSumConfig<F, WINDOW_NUM_BITS>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self {
Expand All @@ -251,7 +253,10 @@ mod tests {
}
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let z = meta.advice_column();
let q_range_check = meta.selector();
let constants = meta.fixed_column();
Expand Down
14 changes: 12 additions & 2 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,17 @@ mod tests {
impl<F: PrimeFieldBits> Circuit<F> for MyCircuit<F> {
type Config = LookupRangeCheckConfig<F, K>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
*self
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let running_sum = meta.advice_column();
let table_idx = meta.lookup_table_column();
let constants = meta.fixed_column();
Expand Down Expand Up @@ -506,6 +511,8 @@ mod tests {
impl<F: PrimeFieldBits> Circuit<F> for MyCircuit<F> {
type Config = LookupRangeCheckConfig<F, K>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
MyCircuit {
Expand All @@ -514,7 +521,10 @@ mod tests {
}
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> Self::Config {
let running_sum = meta.advice_column();
let table_idx = meta.lookup_table_column();
let constants = meta.fixed_column();
Expand Down
1 change: 1 addition & 0 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ dev-graph = ["plotters", "tabbycat"]
gadget-traces = ["backtrace"]
sanity-checks = []
batch = ["rand_core/getrandom"]
circuit-params = []

[lib]
bench = false
Expand Down
7 changes: 6 additions & 1 deletion halo2_proofs/benches/dev_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ fn criterion_benchmark(c: &mut Criterion) {
impl<F: PrimeField> Circuit<F> for MyCircuit<F> {
type Config = MyConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<F>) -> MyConfig {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> MyConfig {
let config = MyConfig {
selector: meta.complex_selector(),
table: meta.lookup_table_column(),
Expand Down
7 changes: 6 additions & 1 deletion halo2_proofs/benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ fn criterion_benchmark(c: &mut Criterion) {
impl<F: Field> Circuit<F> for MyCircuit<F> {
type Config = PlonkConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self {
Expand All @@ -191,7 +193,10 @@ fn criterion_benchmark(c: &mut Criterion) {
}
}

fn configure(meta: &mut ConstraintSystem<F>) -> PlonkConfig {
fn configure(
meta: &mut ConstraintSystem<F>,
#[cfg(feature = "circuit-params")] _: &(),
) -> PlonkConfig {
meta.set_minimum_degree(5);

let a = meta.advice_column();
Expand Down
Loading