forked from privacy-scaling-explorations/halo2
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: public cells to allow for implementations of custom
Layouter
(p…
…rivacy-scaling-explorations#192) * feat: public cells * Update mds.rs * Update mds.rs * Update single_pass.rs Co-authored-by: Han <[email protected]> * bump toolchain to resolve errors * fix clippy errors for CI run * rustfmt post clippy * plz let it be the last lint * patch clippy lints in gadgets * clippy lints for sha256 bench * patch halo2proof benches * Update assigned.rs * Update halo2_gadgets/src/poseidon/primitives/mds.rs Co-authored-by: Han <[email protected]> * Update halo2_gadgets/src/poseidon/primitives/mds.rs Co-authored-by: Han <[email protected]> --------- Co-authored-by: Han <[email protected]>
- Loading branch information
Showing
23 changed files
with
163 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
extern crate criterion; | ||
|
||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use group::ff::Field; | ||
use halo2_proofs::*; | ||
use halo2curves::pasta::pallas::Scalar; | ||
use rand_chacha::rand_core::RngCore; | ||
use rand_chacha::ChaCha20Rng; | ||
use rand_core::SeedableRng; | ||
use rayon::{current_num_threads, prelude::*}; | ||
|
||
fn rand_poly_serial(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> { | ||
// Sample a random polynomial of degree n - 1 | ||
let mut random_poly = vec![Scalar::zero(); 1 << domain]; | ||
for coeff in random_poly.iter_mut() { | ||
*coeff = Scalar::random(&mut rng); | ||
} | ||
|
||
random_poly | ||
} | ||
|
||
fn rand_poly_par(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> { | ||
// Sample a random polynomial of degree n - 1 | ||
let n_threads = current_num_threads(); | ||
let n = 1usize << domain; | ||
let n_chunks = n_threads + usize::from(n % n_threads != 0); | ||
let mut rand_vec = vec![Scalar::zero(); n]; | ||
|
||
let mut thread_seeds: Vec<ChaCha20Rng> = (0..n_chunks) | ||
.map(|_| { | ||
let mut seed = [0u8; 32]; | ||
rng.fill_bytes(&mut seed); | ||
ChaCha20Rng::from_seed(seed) | ||
}) | ||
.collect(); | ||
|
||
thread_seeds | ||
.par_iter_mut() | ||
.zip_eq(rand_vec.par_chunks_mut(n / n_threads)) | ||
.for_each(|(mut rng, chunk)| chunk.iter_mut().for_each(|v| *v = Scalar::random(&mut rng))); | ||
|
||
rand_vec | ||
} | ||
|
||
fn bench_commit(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Blinder_poly"); | ||
let rand = ChaCha20Rng::from_seed([1u8; 32]); | ||
for i in [ | ||
18usize, 19usize, 20usize, 21usize, 22usize, 23usize, 24usize, 25usize, | ||
] | ||
.iter() | ||
{ | ||
group.bench_with_input(BenchmarkId::new("serial", i), i, |b, i| { | ||
b.iter(|| rand_poly_serial(rand.clone(), *i)) | ||
}); | ||
group.bench_with_input(BenchmarkId::new("parallel", i), i, |b, i| { | ||
b.iter(|| rand_poly_par(rand.clone(), *i)) | ||
}); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_commit); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.