Skip to content

Commit 98bc83b

Browse files
jonathanpwangkilicashWhiteHatBrechtpddavidnevadoc
authored
Performance optimizations (#6)
* 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-ethereum#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-ethereum#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 <[email protected]> * feat: Parallel random blinder poly impl (privacy-ethereum#152) * feat: Parallelize `commit` blinder poly generator method Solves the concerns raised in privacy-ethereum#151 related to the performance of the random poly generator inside of `commit`. Resolves: privacy-ethereum#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 <[email protected]> * remove: legacy comments & code --------- Co-authored-by: Edu <[email protected]> * chore: remove debug_assert on phase to allow non-specialized circuits to pass --------- Co-authored-by: kilic <[email protected]> Co-authored-by: NoCtrlZ <[email protected]> Co-authored-by: Brechtpd <[email protected]> Co-authored-by: David Nevado <[email protected]> Co-authored-by: han0110 <[email protected]> Co-authored-by: Nalin Bhardwaj <[email protected]> Co-authored-by: Jonathan Wang <[email protected]> Co-authored-by: adria0 <nowhere@> Co-authored-by: Carlos Pérez <[email protected]> Co-authored-by: adria0.eth <[email protected]> Co-authored-by: dante <[email protected]> Co-authored-by: pinkiebell <[email protected]> Co-authored-by: Eduard S <[email protected]> Co-authored-by: naure <[email protected]> Co-authored-by: Aurélien Nicolas <[email protected]>
1 parent bc03964 commit 98bc83b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3059
-1894
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI checks
22

3-
on: [push, pull_request]
3+
on: [pull_request, push]
44

55
jobs:
66
test:
@@ -21,89 +21,6 @@ jobs:
2121
command: test
2222
args: --verbose --release --all --all-features
2323

24-
build:
25-
name: Build target ${{ matrix.target }}
26-
runs-on: ubuntu-latest
27-
strategy:
28-
matrix:
29-
target:
30-
- wasm32-unknown-unknown
31-
- wasm32-wasi
32-
33-
steps:
34-
- uses: actions/checkout@v3
35-
- uses: actions-rs/toolchain@v1
36-
with:
37-
override: false
38-
- name: Add target
39-
run: rustup target add ${{ matrix.target }}
40-
- name: cargo build
41-
uses: actions-rs/cargo@v1
42-
with:
43-
command: build
44-
args: --features dev-graph,gadget-traces,unstable --target ${{ matrix.target }}
45-
46-
bitrot:
47-
name: Bitrot check
48-
runs-on: ubuntu-latest
49-
50-
steps:
51-
- uses: actions/checkout@v3
52-
- uses: actions-rs/toolchain@v1
53-
with:
54-
override: false
55-
# Build benchmarks to prevent bitrot
56-
- name: Build benchmarks
57-
uses: actions-rs/cargo@v1
58-
with:
59-
command: build
60-
args: --benches --examples --all-features
61-
62-
codecov:
63-
name: Code coverage
64-
runs-on: ubuntu-latest
65-
66-
steps:
67-
- uses: actions/checkout@v3
68-
# Use stable for this to ensure that cargo-tarpaulin can be built.
69-
- uses: actions-rs/toolchain@v1
70-
with:
71-
override: false
72-
- name: Install cargo-tarpaulin
73-
uses: actions-rs/cargo@v1
74-
with:
75-
command: install
76-
args: cargo-tarpaulin
77-
- name: Generate coverage report
78-
uses: actions-rs/cargo@v1
79-
with:
80-
command: tarpaulin
81-
args: --all-features --timeout 600 --out Xml
82-
- name: Upload coverage to Codecov
83-
uses: codecov/[email protected]
84-
85-
doc-links:
86-
name: Intra-doc links
87-
runs-on: ubuntu-latest
88-
89-
steps:
90-
- uses: actions/checkout@v3
91-
- uses: actions-rs/toolchain@v1
92-
with:
93-
override: false
94-
- name: cargo fetch
95-
uses: actions-rs/cargo@v1
96-
with:
97-
command: fetch
98-
99-
# Ensure intra-documentation links all resolve correctly
100-
# Requires #![deny(intra_doc_link_resolution_failure)] in crates.
101-
- name: Check intra-doc links
102-
uses: actions-rs/cargo@v1
103-
with:
104-
command: doc
105-
args: --all --document-private-items
106-
10724
fmt:
10825
name: Rustfmt
10926
timeout-minutes: 30

.github/workflows/ci_main.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: CI checks main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
test:
9+
name: Test on ${{ matrix.os }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macOS-latest]
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions-rs/toolchain@v1
18+
with:
19+
override: false
20+
- name: Run tests
21+
uses: actions-rs/cargo@v1
22+
with:
23+
command: test
24+
args: --verbose --release --all --all-features
25+
bitrot:
26+
name: Bitrot check
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v3
31+
- uses: actions-rs/toolchain@v1
32+
with:
33+
override: false
34+
# Build benchmarks to prevent bitrot
35+
- name: Build benchmarks
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: build
39+
args: --benches --examples --all-features
40+
41+
codecov:
42+
name: Code coverage
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
# Use stable for this to ensure that cargo-tarpaulin can be built.
48+
- uses: actions-rs/toolchain@v1
49+
with:
50+
override: false
51+
- name: Install cargo-tarpaulin
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: install
55+
args: cargo-tarpaulin
56+
- name: Generate coverage report
57+
uses: actions-rs/cargo@v1
58+
with:
59+
command: tarpaulin
60+
args: --all-features --timeout 600 --out Xml
61+
- name: Upload coverage to Codecov
62+
uses: codecov/[email protected]
63+
64+
doc-links:
65+
name: Intra-doc links
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- uses: actions/checkout@v3
70+
- uses: actions-rs/toolchain@v1
71+
with:
72+
override: false
73+
- name: cargo fetch
74+
uses: actions-rs/cargo@v1
75+
with:
76+
command: fetch
77+
78+
# Ensure intra-documentation links all resolve correctly
79+
# Requires #![deny(intra_doc_link_resolution_failure)] in crates.
80+
- name: Check intra-doc links
81+
uses: actions-rs/cargo@v1
82+
with:
83+
command: doc
84+
args: --all --document-private-items
85+
86+
build:
87+
name: Build target ${{ matrix.target }}
88+
runs-on: ubuntu-latest
89+
strategy:
90+
matrix:
91+
target:
92+
- wasm32-unknown-unknown
93+
- wasm32-wasi
94+
95+
steps:
96+
- uses: actions/checkout@v3
97+
- uses: actions-rs/toolchain@v1
98+
with:
99+
override: false
100+
- name: Add target
101+
run: rustup target add ${{ matrix.target }}
102+
- name: cargo build
103+
uses: actions-rs/cargo@v1
104+
with:
105+
command: build
106+
args: --features dev-graph,gadget-traces,unstable --target ${{ matrix.target }}

arithmetic/curves/src/tests/field.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn random_field_tests<F: Field>(type_name: String) {
4646
}
4747

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

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

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

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

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

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

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

178178
fn random_expansion_tests<F: Field, R: RngCore>(mut rng: R, type_name: String) {
179-
let message = format!("expansion {}", type_name);
179+
let message = format!("expansion {type_name}");
180180
let start = start_timer!(|| message);
181181
for _ in 0..1000000 {
182182
// Compare (a + b)(c + d) and (a*c + b*c + a*d + b*d)
@@ -215,7 +215,7 @@ pub fn random_serialization_test<F: Field + SerdeObject>(type_name: String) {
215215
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
216216
0xe5,
217217
]);
218-
let message = format!("serialization {}", type_name);
218+
let message = format!("serialization {type_name}");
219219
let start = start_timer!(|| message);
220220
for _ in 0..1000000 {
221221
let a = F::random(&mut rng);

halo2_proofs/Cargo.toml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,44 @@ keywords = ["halo", "proofs", "zkp", "zkSNARKs"]
2323
all-features = true
2424
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]
2525

26-
# [[bench]]
27-
# name = "arithmetic"
28-
# harness = false
29-
#
30-
# [[bench]]
31-
# name = "hashtocurve"
32-
# harness = false
33-
#
34-
# [[bench]]
35-
# name = "plonk"
36-
# harness = false
37-
#
38-
# [[bench]]
39-
# name = "dev_lookup"
40-
# harness = false
41-
#
42-
# [[bench]]
43-
# name = "fft"
44-
# harness = false
26+
[[bench]]
27+
name = "arithmetic"
28+
harness = false
29+
30+
[[bench]]
31+
name = "commit_zk"
32+
harness = false
33+
34+
[[bench]]
35+
name = "hashtocurve"
36+
harness = false
37+
38+
[[bench]]
39+
name = "plonk"
40+
harness = false
41+
42+
[[bench]]
43+
name = "dev_lookup"
44+
harness = false
45+
46+
[[bench]]
47+
name = "fft"
48+
harness = false
4549

4650
[dependencies]
4751
backtrace = { version = "0.3", optional = true }
4852
rayon = "1.5.1"
53+
crossbeam = "0.8"
4954
ff = "0.12"
5055
group = "0.12"
5156
halo2curves = { path = "../arithmetic/curves" }
52-
rand_core = { version = "0.6", default-features = false }
57+
rand = "0.8"
58+
rand_core = { version = "0.6", default-features = false}
5359
tracing = "0.1"
5460
blake2b_simd = "1"
5561
rustc-hash = "1.1.0"
62+
sha3 = "0.9.1"
63+
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }
5664

5765
# Developer tooling dependencies
5866
plotters = { version = "0.3.0", optional = true }
@@ -63,7 +71,7 @@ assert_matches = "1.5"
6371
criterion = "0.3"
6472
gumdrop = "0.8"
6573
proptest = "1"
66-
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
74+
rand_core = { version = "0.6", features = ["getrandom"] }
6775

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

7987
[lib]
8088
bench = false

0 commit comments

Comments
 (0)