Skip to content

Commit

Permalink
Performance optimizations (#6)
Browse files Browse the repository at this point in the history
* feat: remove `Result` from `assign_advice` return value

* apply `cargo clippy --fix`

* feat: remove `Result` from `assign_advice` return value

* apply `cargo clippy --fix`

* feat: add timers to "profile" feature

* FFT opt

* chore: fix measurement display when "profile" is on only

* feat: parallelize vanishing random poly generation; remove `Result`s and
unwrap instead

* feat: add new parallel implementation for `permute_expression_pair` to
get (A', S') that is fully multi-threaded: this is a different algorithm
than the original `permute_expression_pair_seq`

* revert: go back to `Rng` without `Clone`

* chore: remove rng: Sync requirement for compatibility reasons

* Expose mod `permutation` and re-export `permutation::keygen::Assembly` (privacy-scaling-explorations#149)

* feat: expose mod ule `permutation` and re-export `permutation::keygen::Assembly`

* feat: derive `lone` for `permutation::keygen::Assembly`

* feat: bump MSRV for `inferno`

* feat(MockProver): replace errors by asserts

In MockProver, replace all code that returns an error by an assert that panics instead of returning the error.  This change aims to make it easier to debug circuit code bugs by getting backtraces.

* feat: parallelize vanishing rand poly using `thread_rng()` for now

* MockProver test utililities (privacy-scaling-explorations#153)

* test/unwrap_value: escape Value safety in the dev module

* test/mock-prover-values: MockProver exposes the generated columns to tests

* test/mock-prover-values: doc

* mockprover-util: remove unwrap_value

---------

Co-authored-by: Aurélien Nicolas <info@nau.re>

* feat: Parallel random blinder poly impl (privacy-scaling-explorations#152)

* feat: Parallelize `commit` blinder poly generator method

Solves the concerns raised in privacy-scaling-explorations#151 related to the performance of the
random poly generator inside of `commit`.

Resolves: privacy-scaling-explorations#151

* chore: add `from_evals` for Polynomial

* chore: add benches for commit_zk serial vs par

* fix: Correct thread_seeds iter size

* fix: Clippy

* chore: apply review suggestions

* fix: Inconsisten num of Scalars generated parallely

This fix from @ed255 fixes an error on the code proposal which was
rounding the num of Scalars to be generated and so, was producing
failures.

Co-authored-by: Edu <eduardsanou@posteo.net>

* remove: legacy comments & code

---------

Co-authored-by: Edu <eduardsanou@posteo.net>

* chore: remove debug_assert on phase to allow non-specialized circuits to pass

---------

Co-authored-by: kilic <kiliconu@itu.edu.tr>
Co-authored-by: NoCtrlZ <phantomofrotten@gmail.com>
Co-authored-by: Brechtpd <Brechtp.Devos@gmail.com>
Co-authored-by: David Nevado <david@davidnevado.xyz>
Co-authored-by: han0110 <tinghan0110@gmail.com>
Co-authored-by: Nalin Bhardwaj <nalinbhardwaj@nibnalin.me>
Co-authored-by: Jonathan Wang <jonathanpwang@users.noreply.github.com>
Co-authored-by: adria0 <nowhere@>
Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com>
Co-authored-by: adria0.eth <5526331+adria0@users.noreply.github.com>
Co-authored-by: dante <45801863+alexander-camuto@users.noreply.github.com>
Co-authored-by: pinkiebell <40266861+pinkiebell@users.noreply.github.com>
Co-authored-by: Eduard S <eduardsanou@posteo.net>
Co-authored-by: naure <naure@users.noreply.github.com>
Co-authored-by: Aurélien Nicolas <info@nau.re>
  • Loading branch information
15 people committed Jun 20, 2023
1 parent bc03964 commit 98bc83b
Show file tree
Hide file tree
Showing 45 changed files with 3,059 additions and 1,894 deletions.
85 changes: 1 addition & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI checks

on: [push, pull_request]
on: [pull_request, push]

jobs:
test:
Expand All @@ -21,89 +21,6 @@ jobs:
command: test
args: --verbose --release --all --all-features

build:
name: Build target ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- wasm32-unknown-unknown
- wasm32-wasi

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --features dev-graph,gadget-traces,unstable --target ${{ matrix.target }}

bitrot:
name: Bitrot check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
# Build benchmarks to prevent bitrot
- name: Build benchmarks
uses: actions-rs/cargo@v1
with:
command: build
args: --benches --examples --all-features

codecov:
name: Code coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# Use stable for this to ensure that cargo-tarpaulin can be built.
- uses: actions-rs/toolchain@v1
with:
override: false
- name: Install cargo-tarpaulin
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-tarpaulin
- name: Generate coverage report
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --all-features --timeout 600 --out Xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0

doc-links:
name: Intra-doc links
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- name: cargo fetch
uses: actions-rs/cargo@v1
with:
command: fetch

# Ensure intra-documentation links all resolve correctly
# Requires #![deny(intra_doc_link_resolution_failure)] in crates.
- name: Check intra-doc links
uses: actions-rs/cargo@v1
with:
command: doc
args: --all --document-private-items

fmt:
name: Rustfmt
timeout-minutes: 30
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/ci_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: CI checks main

on:
push:
branches:
- main
jobs:
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --release --all --all-features
bitrot:
name: Bitrot check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
# Build benchmarks to prevent bitrot
- name: Build benchmarks
uses: actions-rs/cargo@v1
with:
command: build
args: --benches --examples --all-features

codecov:
name: Code coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# Use stable for this to ensure that cargo-tarpaulin can be built.
- uses: actions-rs/toolchain@v1
with:
override: false
- name: Install cargo-tarpaulin
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-tarpaulin
- name: Generate coverage report
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --all-features --timeout 600 --out Xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0

doc-links:
name: Intra-doc links
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- name: cargo fetch
uses: actions-rs/cargo@v1
with:
command: fetch

# Ensure intra-documentation links all resolve correctly
# Requires #![deny(intra_doc_link_resolution_failure)] in crates.
- name: Check intra-doc links
uses: actions-rs/cargo@v1
with:
command: doc
args: --all --document-private-items

build:
name: Build target ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- wasm32-unknown-unknown
- wasm32-wasi

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --features dev-graph,gadget-traces,unstable --target ${{ matrix.target }}
18 changes: 9 additions & 9 deletions arithmetic/curves/src/tests/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn random_field_tests<F: Field>(type_name: String) {
}

fn random_multiplication_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("multiplication {}", type_name);
let message = format!("multiplication {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -72,7 +72,7 @@ fn random_multiplication_tests<F: Field, R: RngCore>(mut rng: R, type_name: Stri
}

fn random_addition_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("addition {}", type_name);
let message = format!("addition {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -98,7 +98,7 @@ fn random_addition_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_subtraction_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("subtraction {}", type_name);
let message = format!("subtraction {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -119,7 +119,7 @@ fn random_subtraction_tests<F: Field, R: RngCore>(mut rng: R, type_name: String)
}

fn random_negation_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("negation {}", type_name);
let message = format!("negation {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand All @@ -133,7 +133,7 @@ fn random_negation_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_doubling_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("doubling {}", type_name);
let message = format!("doubling {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -147,7 +147,7 @@ fn random_doubling_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_squaring_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("squaring {}", type_name);
let message = format!("squaring {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -163,7 +163,7 @@ fn random_squaring_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
fn random_inversion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
assert!(bool::from(F::zero().invert().is_none()));

let message = format!("inversion {}", type_name);
let message = format!("inversion {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let mut a = F::random(&mut rng);
Expand All @@ -176,7 +176,7 @@ fn random_inversion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
}

fn random_expansion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
let message = format!("expansion {}", type_name);
let message = format!("expansion {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
// Compare (a + b)(c + d) and (a*c + b*c + a*d + b*d)
Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn random_serialization_test<F: Field + SerdeObject>(type_name: String) {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);
let message = format!("serialization {}", type_name);
let message = format!("serialization {type_name}");
let start = start_timer!(|| message);
for _ in 0..1000000 {
let a = F::random(&mut rng);
Expand Down
54 changes: 31 additions & 23 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,44 @@ keywords = ["halo", "proofs", "zkp", "zkSNARKs"]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]

# [[bench]]
# name = "arithmetic"
# 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 = "arithmetic"
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 }
rayon = "1.5.1"
crossbeam = "0.8"
ff = "0.12"
group = "0.12"
halo2curves = { path = "../arithmetic/curves" }
rand_core = { version = "0.6", default-features = false }
rand = "0.8"
rand_core = { version = "0.6", default-features = false}
tracing = "0.1"
blake2b_simd = "1"
rustc-hash = "1.1.0"
sha3 = "0.9.1"
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

# Developer tooling dependencies
plotters = { version = "0.3.0", optional = true }
Expand All @@ -63,7 +71,7 @@ assert_matches = "1.5"
criterion = "0.3"
gumdrop = "0.8"
proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
rand_core = { version = "0.6", features = ["getrandom"] }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand All @@ -73,8 +81,8 @@ default = ["batch"]
dev-graph = ["plotters", "tabbycat"]
gadget-traces = ["backtrace"]
sanity-checks = []
batch = ["rand_core/getrandom"]
profile = []
batch = ["rand/getrandom"]
profile = ["dep:ark-std"]

[lib]
bench = false
Expand Down
Loading

0 comments on commit 98bc83b

Please sign in to comment.