Skip to content

Commit

Permalink
Feat: test suite (#92)
Browse files Browse the repository at this point in the history
* feat: stop using env var to pass around FLEX_GATE_CONFIG_PARAMS and

LOOKUP_BITS. Bad for testing (multi-threaded issues). Now we use
thread_local to have a global static for these config params that can be
passed around.

* chore: make utils folder and move some files

* Fix halo2 base tests naming (#76)

* feat: `BaseConfig` to switch between `FlexGateConfig` and `RangeConfig`

- `RangeCircuitBuilder` now uses `BaseConfig` to auto-decide whether to
  create lookup table or not.
    - In the future this should be renamed `BaseCircuitBuilder` or just
      `CircuitBuilder`, but for backwards compatibility we leave the name for now.
- `GateCircuitBuilder` no longer implements `Circuit` because we want to
  switch to having everyone just use `RangeCircuitBuilder`.
- Tests won't compile now because we still need to refactor

* feat: refactored halo2-base tests to use new test suite

* feat: remove use of env var in halo2-ecc

CI now can just run `cargo test`

* feat: remove use of env var from zkevm-keccak

* Add zkevm-keccak test to CI

* chore: fix CI

* chore: add lint to CI

* chore: make Baseconfig fns public

* fix(test): zkevm-keccak test should have `first_pass = SKIP_FIRST_PASS`

Currently with `first_pass = true`, it skips the first pass, but when
feature "halo2-axiom" is used, there is only one pass of `synthesize` so
the whole thing gets skipped. Mea culpa!

---------

Co-authored-by: Xinding Wei <[email protected]>
  • Loading branch information
jonathanpwang and nyunyunyunyu authored Jul 20, 2023
1 parent da451da commit 08a16ce
Show file tree
Hide file tree
Showing 42 changed files with 979 additions and 926 deletions.
59 changes: 37 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,48 @@ jobs:
- 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 --test-threads=2
- name: Run halo2-ecc tests (real prover)
working-directory: "halo2-ecc"
run: |
cd halo2-ecc
cargo test --release -- test_fp_assert_eq
mv configs/bn254/bench_fixed_msm.t.config configs/bn254/bench_fixed_msm.config
mv configs/bn254/bench_msm.t.config configs/bn254/bench_msm.config
mv configs/bn254/bench_pairing.t.config configs/bn254/bench_pairing.config
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
cargo test --release -- --nocapture bench_pairing
cd ..
- name: Run zkevm-keccak tests
working-directory: "hashes/zkevm-keccak"
run: |
cargo test
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
2 changes: 1 addition & 1 deletion halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "halo2-base"
version = "0.3.0"
version = "0.3.1"
edition = "2021"

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions halo2-base/benches/inner_product.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder};
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{FlexGateConfig, GateChip, GateInstructions, GateStrategy};
use halo2_base::halo2_proofs::{
arithmetic::Field,
Expand Down Expand Up @@ -50,7 +50,7 @@ fn bench(c: &mut Criterion) {
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 = GateCircuitBuilder::mock(builder);
let circuit = RangeCircuitBuilder::mock(builder);

// check the circuit is correct just in case
MockProver::run(k, &circuit, vec![]).unwrap().assert_satisfied();
Expand All @@ -59,7 +59,7 @@ fn bench(c: &mut Criterion) {
let vk = keygen_vk(&params, &circuit).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &circuit).expect("pk should not fail");

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

let mut group = c.benchmark_group("plonk-prover");
Expand All @@ -73,7 +73,7 @@ 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 = GateCircuitBuilder::prover(builder, break_points.clone());
let circuit = RangeCircuitBuilder::prover(builder, break_points.clone());

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
Expand Down
8 changes: 4 additions & 4 deletions halo2-base/benches/mul.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ff::Field;
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder};
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},
Expand Down Expand Up @@ -37,13 +37,13 @@ fn bench(c: &mut Criterion) {
let mut builder = GateThreadBuilder::new(false);
mul_bench(builder.main(0), [Fr::zero(); 2]);
builder.config(K as usize, Some(9));
let circuit = GateCircuitBuilder::keygen(builder);
let circuit = RangeCircuitBuilder::keygen(builder);

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 break_points = circuit.break_points.take();
let break_points = circuit.0.break_points.take();

let a = Fr::random(OsRng);
let b = Fr::random(OsRng);
Expand All @@ -56,7 +56,7 @@ fn bench(c: &mut Criterion) {
let mut builder = GateThreadBuilder::new(true);
// do the computation
mul_bench(builder.main(0), inputs);
let circuit = GateCircuitBuilder::prover(builder, break_points.clone());
let circuit = RangeCircuitBuilder::prover(builder, break_points.clone());

let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]);
create_proof::<
Expand Down
8 changes: 4 additions & 4 deletions halo2-base/examples/inner_product.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
use halo2_base::gates::builder::{GateCircuitBuilder, GateThreadBuilder};
use halo2_base::gates::builder::{GateThreadBuilder, RangeCircuitBuilder};
use halo2_base::gates::flex_gate::{FlexGateConfig, GateChip, GateInstructions, GateStrategy};
use halo2_base::halo2_proofs::{
arithmetic::Field,
Expand Down Expand Up @@ -53,7 +53,7 @@ fn main() {
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 = GateCircuitBuilder::mock(builder);
let circuit = RangeCircuitBuilder::mock(builder);

// check the circuit is correct just in case
MockProver::run(k, &circuit, vec![]).unwrap().assert_satisfied();
Expand All @@ -62,13 +62,13 @@ fn main() {
let vk = keygen_vk(&params, &circuit).expect("vk should not fail");
let pk = keygen_pk(&params, vk, &circuit).expect("pk should not fail");

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

let mut builder = GateThreadBuilder::new(true);
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);
let circuit = RangeCircuitBuilder::prover(builder, break_points);

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

0 comments on commit 08a16ce

Please sign in to comment.