Skip to content

Commit

Permalink
Implement circuit params under feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ed255 committed Apr 18, 2023
1 parent 8c5fa2a commit c6448d4
Show file tree
Hide file tree
Showing 36 changed files with 246 additions and 60 deletions.
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
6 changes: 5 additions & 1 deletion halo2_gadgets/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ where
{
type Config = MyConfig<WIDTH, RATE, L>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Expand All @@ -62,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
6 changes: 5 additions & 1 deletion halo2_gadgets/benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +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
6 changes: 5 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,13 +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
12 changes: 10 additions & 2 deletions halo2_gadgets/src/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +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 @@ -736,6 +740,7 @@ mod tests {
{
type Config = Pow5Config<Fp, WIDTH, RATE>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Expand All @@ -746,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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sha256/table16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sha256/table16/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sha256/table16/message_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sha256/table16/spread_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +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
6 changes: 5 additions & 1 deletion halo2_gadgets/src/utilities/cond_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +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
6 changes: 5 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,7 @@ mod tests {
{
type Config = RunningSumConfig<F, WINDOW_NUM_BITS>;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Expand All @@ -252,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
12 changes: 10 additions & 2 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +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 @@ -507,6 +511,7 @@ 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 {
Expand All @@ -516,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
6 changes: 5 additions & 1 deletion halo2_proofs/benches/dev_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +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
6 changes: 5 additions & 1 deletion halo2_proofs/benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ 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 {
Expand All @@ -192,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

0 comments on commit c6448d4

Please sign in to comment.