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

Release 0.4.0 rc0 #151

Closed
wants to merge 111 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
863de11
feat: upgrade overall `halo2-base` API to support future multi-threaded
jonathanpwang Feb 6, 2023
941035a
BUG: `GateInstructions::idx_to_indicator` was missing a constraint to
jonathanpwang Feb 6, 2023
4abc9cd
update: working benches for `mul` and `inner_product`
jonathanpwang Feb 6, 2023
ec80e15
feat: add `test_multithread_gates`
jonathanpwang Feb 7, 2023
987853e
BUG: `get_last_bit` did not do an `assert_bit` check on the answer
jonathanpwang Feb 7, 2023
631a71e
fix: `builder::assign_*` was not handling cases where two gates overlap
jonathanpwang Feb 7, 2023
22195f4
feat: update `gates::range` to working tests and new API
jonathanpwang Feb 7, 2023
eff200f
fix: change `AssignedValue` type to `KeccakAssignedValue` for
jonathanpwang Feb 8, 2023
bd55bf5
Initial version 0.3.0 of halo2-ecc (#12)
jonathanpwang Apr 15, 2023
10d1d9f
Fix: assert uses of size hint in release mode (#13)
jonathanpwang Apr 15, 2023
8ab531c
Fix: bit decomposition edge cases (#14)
jonathanpwang Apr 15, 2023
ac1a926
Initial checkpoint for halo2-ecc v0.3.0 (#15)
jonathanpwang Apr 15, 2023
d3f21dc
Fix: make `GateThreadBuilder` compatible with external usage (#16)
jonathanpwang Apr 15, 2023
514dbda
Fix: under-constrained `idx_to_indicator` (#17)
jonathanpwang Apr 15, 2023
11adaa1
Fix: soundness error in `FpChip::assert_eq` due to typo (#18)
jonathanpwang Apr 16, 2023
61e516d
Remove redundant code and prevent race conditions (#19)
jonathanpwang Apr 16, 2023
fe649ae
chore: use `info!` instead of `println` for params
jonathanpwang Apr 28, 2023
0a2964f
Fix: `inner_product_left_last` size hint (#25)
jonathanpwang Apr 28, 2023
6f0ca51
Add documentation for halo2-base (#27)
jonathanpwang May 3, 2023
06905cc
Smart Range Builder (#29)
jonathanpwang May 6, 2023
f566451
fix: `div_mod_var` when `a_num_bits <= b_num_bits` (#31)
jonathanpwang May 10, 2023
a79db0e
Feat: extend halo2 base test coverage (#35)
PatStiles May 18, 2023
086c62c
fix(ecdsa): allow u1*G == u2*PK case (#36)
jonathanpwang May 19, 2023
55eebd4
fix: `log2_ceil(0)` should return `0` (#37)
jonathanpwang May 19, 2023
0948203
Guard `ScalarField` byte representations to always be little-endian (…
jonathanpwang May 19, 2023
e477c34
fix: get_last_bit two errors (#39)
jonathanpwang May 19, 2023
7e564c8
Add documentation for all debug_asserts (#40)
jonathanpwang May 19, 2023
34f1e7e
fix: `FieldChip::divide` renamed `divide_unsafe` (#41)
jonathanpwang May 19, 2023
0f037e7
Use new types to validate input assumptions (#43)
jonathanpwang May 22, 2023
07f2eba
Better handling of EC point at infinity (#44)
jonathanpwang May 22, 2023
652f9e3
feat: use strict ec ops more often (#45)
jonathanpwang May 22, 2023
f978636
feat: add `parallelize_in` helper function (#46)
jonathanpwang May 22, 2023
e5cbf14
fix: minor code quality fixes (#47)
jonathanpwang May 22, 2023
28d6220
feat: `fixed_base::msm_par` handles identity point (#48)
jonathanpwang May 22, 2023
2c76cc3
chore: add assert for query_cell_at_pos (#50)
jonathanpwang May 23, 2023
0e176f3
feat: add Github CI running tests (#51)
jonathanpwang May 23, 2023
3fce68c
fix: ignore code block for doctest (#52)
jonathanpwang May 23, 2023
4a24493
feat: add docs and assert with non-empty array checks (#53)
jonathanpwang May 23, 2023
53e3ad3
Release 0.3.0 ecdsa tests (#54)
jonathanpwang May 23, 2023
bebfb39
chore: fix CI
jonathanpwang May 23, 2023
71cfc51
fix: `prop_test_is_less_than_safe` (#58)
jonathanpwang May 23, 2023
bce3c82
Add halo2-base readme (#66)
jonathanpwang May 26, 2023
282ee8e
fix: change all `1` to `1u64` to prevent unexpected overflow (#72)
jonathanpwang Jun 3, 2023
8b9bdc2
[Fix] Panic when dealing with identity point (#71)
jonathanpwang Jun 6, 2023
05cfc1c
fix: redundant check in `ec_sub_unequal`
jonathanpwang Jun 7, 2023
0be26d4
Add SafeType (#26)
nyunyunyunyu May 23, 2023
d3ed3a9
feat(CI): switch to larger runner
jonathanpwang Jun 9, 2023
e4b956b
fix(builder): handle empty ctx with only equality constraints
jonathanpwang Jun 9, 2023
5293793
feat: add SafeAddress and SafeUint160 (#85)
PatStiles Jun 14, 2023
f6b22ab
Merge release v0.3.0 into develop (#90)
jonathanpwang Jul 7, 2023
da451da
feat: `FpChip::range_check` now works with `max_bits < n * (k-1)` (#91)
jonathanpwang Jul 7, 2023
08a16ce
Feat: test suite (#92)
jonathanpwang Jul 20, 2023
d1beb92
chore: make `bit_length` const function
jonathanpwang Jul 21, 2023
160f503
feat: add debugging functions (#99)
jonathanpwang Jul 26, 2023
081d475
chore: remove cfg(test) for debug functions
jonathanpwang Jul 26, 2023
2b3dd5d
feat(halo2-base): add `GateChip::pow_var` (#103)
jonathanpwang Aug 6, 2023
0b16812
Use halo2curves v0.4.0 and ff v0.13 (#107)
jonathanpwang Aug 15, 2023
3408b7a
Add `sub_mul` to GateInstructions (#102)
mmagician Aug 8, 2023
a62ae5d
fix(test): `select_from_idx` wasn't calling the right function (#105)
mmagician Aug 9, 2023
7100c23
chore: add back RangeCircuitBuilder::config (#111)
jonathanpwang Aug 17, 2023
49aeedd
fix: `RangeCircuitBuilder::config` remember `lookup_bits`
jonathanpwang Aug 17, 2023
a7b5433
[Feat] Add Poseidon Hasher Chip (#110)
nyunyunyunyu Aug 17, 2023
f724c9b
feat: add VariableByteArray (#88)
PatStiles Aug 18, 2023
3bacff7
chore: reduce CI real prover load
jonathanpwang Aug 18, 2023
cd9b6a4
Rename PoseidonHasherChip to PoseidonHasher (#113)
nyunyunyunyu Aug 18, 2023
25e211a
chore(safe_types): add conversion `SafeType` to/from `FixLenBytes`
jonathanpwang Aug 21, 2023
b58046c
chore(safe_type): add `unsafe_to_safe_type` unsafe conversion fn
jonathanpwang Aug 21, 2023
204a699
feat: add `select_array_by_indicator` to `GateInstructions` (#115)
jonathanpwang Aug 21, 2023
1c33fbc
cleanup: use test-utils for benching (#112)
jonathanpwang Aug 22, 2023
83ca65e
fix(safe_types): `VarLenBytes` should allow `len == MAX_LEN` (#117)
jonathanpwang Aug 22, 2023
7b23747
[feat] Add Poseidon Chip (#114)
nyunyunyunyu Aug 22, 2023
9798c85
[chore] Reorg Folder Structure of hashes/zkevm (#118)
nyunyunyunyu Aug 22, 2023
9fac2a8
[fix] CI for zkevm hashes (#119)
nyunyunyunyu Aug 23, 2023
154cd8c
[chore] Split keccak implementation into multiple files (#120)
nyunyunyunyu Aug 23, 2023
89da366
feat: keccak constant visibility changes (#121)
MonkeyKing-1 Aug 24, 2023
eb4fe65
[feat] Keccak Raw Output (#122)
nyunyunyunyu Aug 27, 2023
15bca77
Virtual region managers and dynamic lookup support (#123)
jonathanpwang Aug 27, 2023
f4c7e2a
Use `raw_assign_{advice,fixed}` in keccak (#125)
jonathanpwang Aug 28, 2023
7831b00
[feat] PoseidonHasher supports multiple inputs in compact format (#127)
nyunyunyunyu Aug 28, 2023
7bdf089
[feat] Expose Keccack Raw Inputs in Bytes instead of Input RLCs (#124)
nyunyunyunyu Aug 29, 2023
d07b0d4
Bump `zkevm-hashes` to v0.1.4
jonathanpwang Aug 29, 2023
6c80289
chore: clippy fix
jonathanpwang Aug 29, 2023
f2cf3e8
Generic vertical gate assignment (#129)
jonathanpwang Aug 29, 2023
be52d1d
Add `deep_clone` to `BaseCircuitBuilder` (#131)
jonathanpwang Sep 1, 2023
edd239f
fix: `SingleCorePhaseManager` should not create thread in constructor
jonathanpwang Sep 2, 2023
f39fef3
chore: make `new_context` public
jonathanpwang Sep 3, 2023
608b8f2
Convenience functions and fixes for multi-phase (#133)
jonathanpwang Sep 4, 2023
2b03c17
chore: add `BaseCircuitBuilder::set_k` fn
jonathanpwang Sep 5, 2023
64c8123
fix: `CopyConstraintManager::clear` was dropping
jonathanpwang Sep 5, 2023
04a40d4
feat: impl `From<SafeByte>` for `AssignedValue`
jonathanpwang Sep 5, 2023
671f0cc
chore(poseidon): add `derive` statements
jonathanpwang Sep 5, 2023
d27e46a
fix(copy_constraints): backend permutation argument depends on order
jonathanpwang Sep 6, 2023
a1fec64
feat: add `left_pad` functions for var length arrays (#137)
jonathanpwang Sep 6, 2023
72b53bf
chore: use `PrimeField` for `OptimizedPoseidonSpec` (#139)
jonathanpwang Sep 8, 2023
0acc05a
chore: add getter functions to Poseidon spec (#140)
jonathanpwang Sep 8, 2023
61fda9d
feat: use `(TypeId, usize)` instead of `usize` for lookup tag (#142)
jonathanpwang Sep 9, 2023
58155d7
chore: add `ContextTag` type alias
jonathanpwang Sep 9, 2023
3a35050
feat(base): add `GateInstructions::inner_product_left` function (#143)
jonathanpwang Sep 9, 2023
9377d90
[feat] Keccak Coprocessor Leaf Circuit (#130)
nyunyunyunyu Sep 9, 2023
54044c9
[feat] App Circuit Utils for Keccak Coprocessor (#141)
nyunyunyunyu Sep 9, 2023
14bec5a
[chore] Fix fmt (#144)
nyunyunyunyu Sep 10, 2023
c2a9341
chore: add misc utility functions (#146)
jonathanpwang Sep 10, 2023
482bed6
feat(keccak): add `ingestion` module for Rust native input formatting…
jonathanpwang Sep 10, 2023
41ea795
chore(keccak): use `snark-verifier` native Poseidon for encoding (#148)
jonathanpwang Sep 10, 2023
1ea4f84
feat: optimize leaf poseidon with `hash_compact_chunk_inputs` (#149)
jonathanpwang Sep 11, 2023
2ccfc43
[chore] cleanup code (#150)
jonathanpwang Sep 11, 2023
18057d3
chore: get halo2-pse working again
jonathanpwang Sep 11, 2023
46c5769
Merge branch 'main' into release-0.4.0-rc0
jonathanpwang Sep 11, 2023
eb5b284
chore: fix fmt
jonathanpwang Sep 11, 2023
92277ce
[Doc] Keccak Doc (#145)
nyunyunyunyu Sep 11, 2023
1bf36b1
chore: pin snark-verifier branch
jonathanpwang Sep 11, 2023
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
65 changes: 40 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,62 @@ on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
branches: ["main", "develop", "community-edition"]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-64core-256ram

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run halo2-base tests
working-directory: "halo2-base"
run: |
cd halo2-base
cargo test -- --test-threads=1
cd ..
- name: Run halo2-ecc tests MockProver
cargo test
- name: Run halo2-ecc tests (mock prover)
working-directory: "halo2-ecc"
run: |
cd halo2-ecc
cargo test -- --test-threads=1 test_fp
cargo test -- test_ecc
cargo test -- test_secp
cargo test -- test_ecdsa
cargo test -- test_ec_add
cargo test -- test_fixed
cargo test -- test_msm
cargo test -- test_fb
cargo test -- test_pairing
cd ..
- name: Run halo2-ecc tests real prover
cargo test --lib -- --skip bench
- name: Run halo2-ecc tests (real prover)
working-directory: "halo2-ecc"
run: |
cd halo2-ecc
cargo test --release -- test_fp_assert_eq
cargo test --release -- --nocapture bench_secp256k1_ecdsa
cargo test --release -- --nocapture bench_ec_add
mv configs/bn254/bench_fixed_msm.t.config configs/bn254/bench_fixed_msm.config
cargo test --release -- --nocapture bench_fixed_base_msm
mv configs/bn254/bench_msm.t.config configs/bn254/bench_msm.config
cargo test --release -- --nocapture bench_msm
mv configs/bn254/bench_pairing.t.config configs/bn254/bench_pairing.config
mv configs/secp256k1/bench_ecdsa.t.config configs/secp256k1/bench_ecdsa.config
cargo test --release -- --nocapture bench_secp256k1_ecdsa
cargo test --release -- --nocapture bench_fixed_base_msm
cargo test --release -- --nocapture bench_msm
cargo test --release -- --nocapture bench_pairing
cd ..
- name: Run zkevm tests
working-directory: "hashes/zkevm"
run: |
cargo test packed_multi_keccak_prover::k_14

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: false
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: Run fmt
run: cargo fmt --all -- --check

- name: Run clippy
run: cargo clippy --all -- -D warnings
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Local IDE configs
.idea/
.vscode/
=======
/target

Expand Down
16 changes: 6 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[workspace]
members = [
"halo2-base",
"halo2-ecc",
"hashes/zkevm-keccak",
]
members = ["halo2-base", "halo2-ecc", "hashes/zkevm"]
resolver = "2"

[profile.dev]
opt-level = 3
debug = 1 # change to 0 or 2 for more or less debug info
debug = 2 # change to 0 or 2 for more or less debug info
overflow-checks = true
incremental = true

Expand All @@ -28,7 +25,7 @@ codegen-units = 16
opt-level = 3
debug = false
debug-assertions = false
lto = "fat"
lto = "fat"
# `codegen-units = 1` can lead to WORSE performance - always bench to find best profile for your machine!
# codegen-units = 1
panic = "unwind"
Expand All @@ -39,7 +36,6 @@ incremental = false
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" }
halo2-base = { path = "../halo2-lib/halo2-base" }
halo2-ecc = { path = "../halo2-lib/halo2-ecc" }
38 changes: 27 additions & 11 deletions halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
[package]
name = "halo2-base"
version = "0.3.0"
version = "0.4.0"
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"
getset = "0.1.2"
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

# 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", rev = "98bc83b", 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 = "7a21656", optional = true }

# This is Scroll's audited poseidon circuit. We only use it for the Native Poseidon spec. We do not use the halo2 circuit at all (and it wouldn't even work because the halo2_proofs tag is not compatbile).
# We forked it to upgrade to ff v0.13 and removed the circuit module
poseidon-rs = { git = "https://github.com/axiom-crypto/poseidon-circuit.git", rev = "1aee4a1" }
# plotting circuit layout
plotters = { version = "0.3.0", optional = true }
tabbycat = { version = "0.1", features = ["attributes"], optional = true }
Expand All @@ -34,9 +38,12 @@ 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"
test-log = "0.2.12"
env_logger = "0.10.0"
proptest = "1.1.0"
# native poseidon for testing
pse-poseidon = { git = "https://github.com/axiom-crypto/pse-poseidon.git" }

# memory allocation
[target.'cfg(not(target_env = "msvc"))'.dependencies]
Expand All @@ -45,13 +52,18 @@ jemallocator = { version = "0.5", optional = true }
mimalloc = { version = "0.1", default-features = false, optional = true }

[features]
default = ["halo2-axiom", "display"]
dev-graph = ["halo2_proofs?/dev-graph", "halo2_proofs_axiom?/dev-graph", "plotters"]
halo2-pse = ["halo2_proofs"]
default = ["halo2-axiom", "display", "test-utils"]
asm = ["halo2_proofs_axiom?/asm"]
dev-graph = [
"halo2_proofs?/dev-graph",
"halo2_proofs_axiom?/dev-graph",
"plotters",
]
halo2-pse = ["halo2_proofs/circuit-params"]
halo2-axiom = ["halo2_proofs_axiom"]
display = []
profile = ["halo2_proofs_axiom?/profile"]
test-utils = ["dep:rand"]
test-utils = ["dep:rand", "ark-std"]

[[bench]]
name = "mul"
Expand All @@ -60,3 +72,7 @@ harness = false
[[bench]]
name = "inner_product"
harness = false

[[example]]
name = "inner_product"
required-features = ["test-utils"]
55 changes: 17 additions & 38 deletions halo2-base/benches/inner_product.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder};
use halo2_base::gates::flex_gate::{FlexGateConfig, GateChip, GateInstructions, GateStrategy};
use halo2_base::gates::circuit::{builder::RangeCircuitBuilder, CircuitBuilderStage};
use halo2_base::gates::flex_gate::{GateChip, GateInstructions};
use halo2_base::halo2_proofs::{
arithmetic::Field,
circuit::*,
dev::MockProver,
halo2curves::bn256::{Bn256, Fr, G1Affine},
halo2curves::bn256::{Bn256, Fr},
plonk::*,
poly::kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::ProverSHPLONK,
},
transcript::{Blake2bWrite, Challenge255, TranscriptWriterBuffer},
poly::kzg::commitment::ParamsKZG,
};
use halo2_base::utils::testing::gen_proof;
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 @@ -47,20 +36,20 @@ fn inner_prod_bench<F: ScalarField>(ctx: &mut Context<F>, a: Vec<F>, b: Vec<F>)
fn bench(c: &mut Criterion) {
let k = 19u32;
// create circuit for keygen
let mut builder = GateThreadBuilder::new(false);
let mut builder =
RangeCircuitBuilder::from_stage(CircuitBuilderStage::Keygen).use_k(k as usize);
inner_prod_bench(builder.main(0), vec![Fr::zero(); 5], vec![Fr::zero(); 5]);
builder.config(k as usize, Some(20));
let circuit = GateCircuitBuilder::mock(builder);
let config_params = builder.calculate_params(Some(20));

// check the circuit is correct just in case
MockProver::run(k, &circuit, vec![]).unwrap().assert_satisfied();
MockProver::run(k, &builder, vec![]).unwrap().assert_satisfied();

let params = ParamsKZG::<Bn256>::setup(k, OsRng);
let vk = keygen_vk(&params, &circuit).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &circuit).expect("pk should not fail");
let vk = keygen_vk(&params, &builder).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &builder).expect("pk should not fail");

let break_points = circuit.break_points.take();
drop(circuit);
let break_points = builder.break_points();
drop(builder);

let mut group = c.benchmark_group("plonk-prover");
group.sample_size(10);
Expand All @@ -69,22 +58,12 @@ fn bench(c: &mut Criterion) {
&(&params, &pk),
|bencher, &(params, pk)| {
bencher.iter(|| {
let mut builder = GateThreadBuilder::new(true);
let mut builder =
RangeCircuitBuilder::prover(config_params.clone(), break_points.clone());
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 = GateCircuitBuilder::prover(builder, break_points.clone());

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
KZGCommitmentScheme<Bn256>,
ProverSHPLONK<'_, Bn256>,
Challenge255<G1Affine>,
_,
Blake2bWrite<Vec<u8>, G1Affine, Challenge255<_>>,
_,
>(params, pk, &[circuit], &[&[]], OsRng, &mut transcript)
.expect("prover should not fail");
gen_proof(params, pk, builder);
})
},
);
Expand Down
40 changes: 14 additions & 26 deletions halo2-base/benches/mul.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use ff::Field;
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder};
use halo2_base::gates::circuit::{builder::RangeCircuitBuilder, CircuitBuilderStage};
use halo2_base::gates::flex_gate::{GateChip, GateInstructions};
use halo2_base::halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
halo2curves::bn256::{Bn256, Fr},
halo2curves::ff::Field,
plonk::*,
poly::kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::ProverGWC,
},
transcript::{Blake2bWrite, Challenge255, TranscriptWriterBuffer},
poly::kzg::commitment::ParamsKZG,
};
use halo2_base::utils::testing::gen_proof;
use halo2_base::utils::ScalarField;
use halo2_base::Context;
use rand::rngs::OsRng;
Expand All @@ -34,16 +31,16 @@ fn mul_bench<F: ScalarField>(ctx: &mut Context<F>, inputs: [F; 2]) {

fn bench(c: &mut Criterion) {
// create circuit for keygen
let mut builder = GateThreadBuilder::new(false);
let mut builder =
RangeCircuitBuilder::from_stage(CircuitBuilderStage::Keygen).use_k(K as usize);
mul_bench(builder.main(0), [Fr::zero(); 2]);
builder.config(K as usize, Some(9));
let circuit = GateCircuitBuilder::keygen(builder);
let config_params = builder.calculate_params(Some(9));

let params = ParamsKZG::<Bn256>::setup(K, OsRng);
let vk = keygen_vk(&params, &circuit).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &circuit).expect("pk should not fail");
let vk = keygen_vk(&params, &builder).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &builder).expect("pk should not fail");

let break_points = circuit.break_points.take();
let break_points = builder.break_points();

let a = Fr::random(OsRng);
let b = Fr::random(OsRng);
Expand All @@ -53,21 +50,12 @@ fn bench(c: &mut Criterion) {
&(&params, &pk, [a, b]),
|bencher, &(params, pk, inputs)| {
bencher.iter(|| {
let mut builder = GateThreadBuilder::new(true);
let mut builder =
RangeCircuitBuilder::prover(config_params.clone(), break_points.clone());
// do the computation
mul_bench(builder.main(0), inputs);
let circuit = GateCircuitBuilder::prover(builder, break_points.clone());

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
KZGCommitmentScheme<Bn256>,
ProverGWC<'_, Bn256>,
Challenge255<G1Affine>,
_,
Blake2bWrite<Vec<u8>, G1Affine, Challenge255<_>>,
_,
>(params, pk, &[circuit], &[&[]], OsRng, &mut transcript)
.unwrap();
gen_proof(params, pk, builder);
})
},
);
Expand Down
Loading
Loading