Skip to content

Commit

Permalink
Use halo2curves v0.4.0 and ff v0.13 (#107)
Browse files Browse the repository at this point in the history
* wip: change import to ff v0.13

* feat: remove `GateInstructions::get_field_element`

halo2curves now has `bn256-table` which creates table of small field
elements at compile time, so we should just use `F::from` always. This
also improves readability.

* chore: fix syntax and imports after update

* chore: add asm feature

* chore: workspace.resolver = 2

* chore: update ethers-core

* chore: add jemallocator feature to zkevm-keccak crate

* test: add bigger test case to keccak prover

* feat: use `configure_with_params`

remove `thread_local!` usage

* chore: bump zkevm-keccak version to 0.1.1

* feat: add `GateThreadBuilder::from_stage` for convenience

* chore: fixes

* fix: removed `lookup_bits` from `GateThreadBuilder::config`

* fix: debug_assert_false should load witness for debugging

* chore: use unreachable to document that Circuit::configure is never used

* chore: fix comment

* feat(keccak): use configure_with_params

* chore: fix halo2-pse errors

* chore: change halo2_proofs to main
  • Loading branch information
jonathanpwang authored Aug 15, 2023
1 parent 2b3dd5d commit 0b16812
Show file tree
Hide file tree
Showing 59 changed files with 947 additions and 956 deletions.
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"halo2-ecc",
"hashes/zkevm-keccak",
]
resolver = "2"

[profile.dev]
opt-level = 3
Expand Down Expand Up @@ -37,9 +38,4 @@ incremental = false
# For performance profiling
[profile.flamegraph]
inherits = "release"
debug = true

# patch so snark-verifier uses this crate's halo2-base
[patch."https://github.com/axiom-crypto/halo2-lib.git"]
halo2-base = { path = "./halo2-base" }
halo2-ecc = { path = "./halo2-ecc" }
debug = true
15 changes: 7 additions & 8 deletions halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
[package]
name = "halo2-base"
version = "0.3.1"
version = "0.3.2"
edition = "2021"

[dependencies]
itertools = "0.10"
itertools = "0.11"
num-bigint = { version = "0.4", features = ["rand"] }
num-integer = "0.1"
num-traits = "0.2"
rand_chacha = "0.3"
rustc-hash = "1.1"
ff = "0.12"
rayon = "1.6.1"
rayon = "1.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
log = "0.4"

# Use Axiom's custom halo2 monorepo for faster proving when feature = "halo2-axiom" is on
halo2_proofs_axiom = { git = "https://github.com/axiom-crypto/halo2.git", branch = "main", package = "halo2_proofs", optional = true }
halo2_proofs_axiom = { git = "https://github.com/axiom-crypto/halo2.git", package = "halo2_proofs", optional = true }
# Use PSE halo2 and halo2curves for compatibility when feature = "halo2-pse" is on
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02", optional = true }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", rev = "f348757", optional = true }

# plotting circuit layout
plotters = { version = "0.3.0", optional = true }
Expand All @@ -34,7 +33,6 @@ rand = "0.8"
pprof = { version = "0.11", features = ["criterion", "flamegraph"] }
criterion = "0.4"
criterion-macro = "0.4"
rayon = "1.6.1"
test-case = "3.1.0"
proptest = "1.1.0"

Expand All @@ -46,8 +44,9 @@ mimalloc = { version = "0.1", default-features = false, optional = true }

[features]
default = ["halo2-axiom", "display"]
asm = ["halo2_proofs_axiom?/asm"]
dev-graph = ["halo2_proofs?/dev-graph", "halo2_proofs_axiom?/dev-graph", "plotters"]
halo2-pse = ["halo2_proofs"]
halo2-pse = ["halo2_proofs/circuit-params"]
halo2-axiom = ["halo2_proofs_axiom"]
display = []
profile = ["halo2_proofs_axiom?/profile"]
Expand Down
24 changes: 10 additions & 14 deletions halo2-base/benches/inner_product.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{FlexGateConfig, GateChip, GateInstructions, GateStrategy};
use halo2_base::gates::builder::{GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{GateChip, GateInstructions};
use halo2_base::halo2_proofs::{
arithmetic::Field,
circuit::*,
dev::MockProver,
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::*,
Expand All @@ -15,14 +12,9 @@ use halo2_base::halo2_proofs::{
transcript::{Blake2bWrite, Challenge255, TranscriptWriterBuffer},
};
use halo2_base::utils::ScalarField;
use halo2_base::{
Context,
QuantumCell::{Existing, Witness},
SKIP_FIRST_PASS,
};
use halo2_base::{Context, QuantumCell::Existing};
use itertools::Itertools;
use rand::rngs::OsRng;
use std::marker::PhantomData;

use criterion::{criterion_group, criterion_main};
use criterion::{BenchmarkId, Criterion};
Expand All @@ -49,8 +41,8 @@ fn bench(c: &mut Criterion) {
// create circuit for keygen
let mut builder = GateThreadBuilder::new(false);
inner_prod_bench(builder.main(0), vec![Fr::zero(); 5], vec![Fr::zero(); 5]);
builder.config(k as usize, Some(20));
let circuit = RangeCircuitBuilder::mock(builder);
let config_params = builder.config(k as usize, Some(20));
let circuit = RangeCircuitBuilder::mock(builder, config_params.clone());

// check the circuit is correct just in case
MockProver::run(k, &circuit, vec![]).unwrap().assert_satisfied();
Expand All @@ -73,7 +65,11 @@ fn bench(c: &mut Criterion) {
let a = (0..5).map(|_| Fr::random(OsRng)).collect_vec();
let b = (0..5).map(|_| Fr::random(OsRng)).collect_vec();
inner_prod_bench(builder.main(0), a, b);
let circuit = RangeCircuitBuilder::prover(builder, break_points.clone());
let circuit = RangeCircuitBuilder::prover(
builder,
config_params.clone(),
break_points.clone(),
);

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
Expand Down
12 changes: 8 additions & 4 deletions halo2-base/benches/mul.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ff::Field;
use halo2_base::gates::builder::{GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{GateChip, GateInstructions};
use halo2_base::halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
halo2curves::ff::Field,
plonk::*,
poly::kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
Expand Down Expand Up @@ -36,8 +36,8 @@ fn bench(c: &mut Criterion) {
// create circuit for keygen
let mut builder = GateThreadBuilder::new(false);
mul_bench(builder.main(0), [Fr::zero(); 2]);
builder.config(K as usize, Some(9));
let circuit = RangeCircuitBuilder::keygen(builder);
let config_params = builder.config(K as usize, Some(9));
let circuit = RangeCircuitBuilder::keygen(builder, config_params.clone());

let params = ParamsKZG::<Bn256>::setup(K, OsRng);
let vk = keygen_vk(&params, &circuit).expect("vk should not fail");
Expand All @@ -56,7 +56,11 @@ fn bench(c: &mut Criterion) {
let mut builder = GateThreadBuilder::new(true);
// do the computation
mul_bench(builder.main(0), inputs);
let circuit = RangeCircuitBuilder::prover(builder, break_points.clone());
let circuit = RangeCircuitBuilder::prover(
builder,
config_params.clone(),
break_points.clone(),
);

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
Expand Down
25 changes: 5 additions & 20 deletions halo2-base/examples/inner_product.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use halo2_base::gates::builder::{GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{FlexGateConfig, GateChip, GateInstructions, GateStrategy};
use halo2_base::gates::flex_gate::{GateChip, GateInstructions};
use halo2_base::halo2_proofs::{
arithmetic::Field,
circuit::*,
dev::MockProver,
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::*,
Expand All @@ -18,21 +15,9 @@ use halo2_base::halo2_proofs::{
transcript::{Blake2bWrite, Challenge255, TranscriptWriterBuffer},
};
use halo2_base::utils::ScalarField;
use halo2_base::{
Context,
QuantumCell::{Existing, Witness},
SKIP_FIRST_PASS,
};
use halo2_base::{Context, QuantumCell::Existing};
use itertools::Itertools;
use rand::rngs::OsRng;
use std::marker::PhantomData;

use criterion::{criterion_group, criterion_main};
use criterion::{BenchmarkId, Criterion};

use pprof::criterion::{Output, PProfProfiler};
// Thanks to the example provided by @jebbow in his article
// https://www.jibbow.com/posts/criterion-flamegraphs/

const K: u32 = 19;

Expand All @@ -52,8 +37,8 @@ fn main() {
// create circuit for keygen
let mut builder = GateThreadBuilder::new(false);
inner_prod_bench(builder.main(0), vec![Fr::zero(); 5], vec![Fr::zero(); 5]);
builder.config(k as usize, Some(20));
let circuit = RangeCircuitBuilder::mock(builder);
let config_params = builder.config(k as usize, Some(20));
let circuit = RangeCircuitBuilder::mock(builder, config_params.clone());

// check the circuit is correct just in case
MockProver::run(k, &circuit, vec![]).unwrap().assert_satisfied();
Expand All @@ -68,7 +53,7 @@ fn main() {
let a = (0..5).map(|_| Fr::random(OsRng)).collect_vec();
let b = (0..5).map(|_| Fr::random(OsRng)).collect_vec();
inner_prod_bench(builder.main(0), a, b);
let circuit = RangeCircuitBuilder::prover(builder, break_points);
let circuit = RangeCircuitBuilder::prover(builder, config_params, break_points);

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
Expand Down
Loading

0 comments on commit 0b16812

Please sign in to comment.