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

Iquerejeta/pruning #17

Merged
merged 20 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ keywords = ["halo", "proofs", "zkp", "zkSNARKs"]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]

#[[bench]]
#name = "commit_zk"
#harness = false
#
#[[bench]]
#name = "hashtocurve"
#harness = false
#
#[[bench]]
#name = "plonk"
#harness = false
#
#[[bench]]
#name = "dev_lookup"
#harness = false
#
#[[bench]]
#name = "fft"
#harness = false
[[bench]]
name = "commit_zk"
harness = false

[[bench]]
name = "hashtocurve"
harness = false

[[bench]]
name = "plonk"
harness = false

[[bench]]
name = "dev_lookup"
harness = false

[[bench]]
name = "fft"
harness = false

[dependencies]
backtrace = { version = "0.3", optional = true }
Expand Down
232 changes: 116 additions & 116 deletions benches/dev_lookup.rs
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
// #[macro_use]
// extern crate criterion;
//
// use ff::{Field, PrimeField};
// use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value};
// use halo2_proofs::dev::MockProver;
// use halo2_proofs::plonk::*;
// use halo2_proofs::poly::Rotation;
// use halo2curves::pasta::pallas;
//
// use std::marker::PhantomData;
//
// use criterion::{BenchmarkId, Criterion};
//
// fn criterion_benchmark(c: &mut Criterion) {
// #[derive(Clone, Default)]
// struct MyCircuit<F: Field> {
// _marker: PhantomData<F>,
// }
//
// #[derive(Clone)]
// struct MyConfig {
// selector: Selector,
// table: TableColumn,
// advice: Column<Advice>,
// }
//
// 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 {
// let config = MyConfig {
// selector: meta.complex_selector(),
// table: meta.lookup_table_column(),
// advice: meta.advice_column(),
// };
//
// meta.lookup("lookup", |meta| {
// let selector = meta.query_selector(config.selector);
// let not_selector = Expression::Constant(F::ONE) - selector.clone();
// let advice = meta.query_advice(config.advice, Rotation::cur());
// vec![(selector * advice + not_selector, config.table)]
// });
//
// config
// }
//
// fn synthesize(
// &self,
// config: MyConfig,
// mut layouter: impl Layouter<F>,
// ) -> Result<(), Error> {
// layouter.assign_table(
// || "8-bit table",
// |mut table| {
// for row in 0u64..(1 << 8) {
// table.assign_cell(
// || format!("row {row}"),
// config.table,
// row as usize,
// || Value::known(F::from(row + 1)),
// )?;
// }
//
// Ok(())
// },
// )?;
//
// layouter.assign_region(
// || "assign values",
// |mut region| {
// for offset in 0u64..(1 << 10) {
// config.selector.enable(&mut region, offset as usize)?;
// region.assign_advice(
// || format!("offset {offset}"),
// config.advice,
// offset as usize,
// || Value::known(F::from((offset % 256) + 1)),
// )?;
// }
//
// Ok(())
// },
// )
// }
// }
//
// fn prover(k: u32) {
// let circuit = MyCircuit::<pallas::Base> {
// _marker: PhantomData,
// };
// let prover = MockProver::run(k, &circuit, vec![]).unwrap();
// assert_eq!(prover.verify(), Ok(()))
// }
//
// let k_range = 14..=18;
//
// let mut prover_group = c.benchmark_group("dev-lookup");
// prover_group.sample_size(10);
// for k in k_range {
// prover_group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &k| {
// b.iter(|| prover(k));
// });
// }
// prover_group.finish();
// }
//
// criterion_group!(benches, criterion_benchmark);
// criterion_main!(benches);
#[macro_use]
extern crate criterion;

use ff::{Field, PrimeField};
use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value};
use halo2_proofs::dev::MockProver;
use halo2_proofs::plonk::*;
use halo2_proofs::poly::Rotation;
use halo2curves::pasta::pallas;

use std::marker::PhantomData;

use criterion::{BenchmarkId, Criterion};

fn criterion_benchmark(c: &mut Criterion) {
#[derive(Clone, Default)]
struct MyCircuit<F: Field> {
_marker: PhantomData<F>,
}

#[derive(Clone)]
struct MyConfig {
selector: Selector,
table: TableColumn,
advice: Column<Advice>,
}

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 {
let config = MyConfig {
selector: meta.complex_selector(),
table: meta.lookup_table_column(),
advice: meta.advice_column(),
};

meta.lookup("lookup", |meta| {
let selector = meta.query_selector(config.selector);
let not_selector = Expression::Constant(F::ONE) - selector.clone();
let advice = meta.query_advice(config.advice, Rotation::cur());
vec![(selector * advice + not_selector, config.table)]
});

config
}

fn synthesize(
&self,
config: MyConfig,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
layouter.assign_table(
|| "8-bit table",
|mut table| {
for row in 0u64..(1 << 8) {
table.assign_cell(
|| format!("row {row}"),
config.table,
row as usize,
|| Value::known(F::from(row + 1)),
)?;
}

Ok(())
},
)?;

layouter.assign_region(
|| "assign values",
|mut region| {
for offset in 0u64..(1 << 10) {
config.selector.enable(&mut region, offset as usize)?;
region.assign_advice(
|| format!("offset {offset}"),
config.advice,
offset as usize,
|| Value::known(F::from((offset % 256) + 1)),
)?;
}

Ok(())
},
)
}
}

fn prover(k: u32) {
let circuit = MyCircuit::<pallas::Base> {
_marker: PhantomData,
};
let prover = MockProver::run(k, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), Ok(()))
}

let k_range = 14..=18;

let mut prover_group = c.benchmark_group("dev-lookup");
prover_group.sample_size(10);
for k in k_range {
prover_group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &k| {
b.iter(|| prover(k));
});
}
prover_group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading