Skip to content

Commit

Permalink
fix: wasm compatible timings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Aug 24, 2024
1 parent db0fbbe commit 8b13a0d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
1 change: 1 addition & 0 deletions halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ rustacuda = { version = "0.1", optional = true }
serde_derive = { version = "1", optional = true}
bincode = { version = "1.3.3", default_features = false }
serde = { version = "1.0.126", features = ["derive"] }
instant = { version = "0.1" }


# Developer tooling dependencies
Expand Down
12 changes: 6 additions & 6 deletions halo2_proofs/examples/simple-lookup-unblinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ fn main() {
println!("k = {K}");
// time it
println!("keygen");
let start = std::time::Instant::now();
let start = instant::Instant::now();
let (params, pk) = keygen(K);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("keygen time: {:?}", end.duration_since(start));

println!("saving proving key 💾");
Expand Down Expand Up @@ -315,14 +315,14 @@ fn main() {

// time it
println!("prover");
let start = std::time::Instant::now();
let start = instant::Instant::now();
let proof = prover(K, &params, &pk);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("prover time: {:?}", end.duration_since(start));
// time it
println!("verifier");
let start = std::time::Instant::now();
let start = instant::Instant::now();
verifier(&params, &vk, &proof);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("verifier time: {:?}", end.duration_since(start));
}
12 changes: 6 additions & 6 deletions halo2_proofs/examples/simple-lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ fn main() {
println!("k = {K}");
// time it
println!("keygen");
let start = std::time::Instant::now();
let start = instant::Instant::now();
let (params, pk) = keygen(K);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("keygen time: {:?}", end.duration_since(start));

println!("saving proving key 💾");
Expand Down Expand Up @@ -315,14 +315,14 @@ fn main() {

// time it
println!("prover");
let start = std::time::Instant::now();
let start = instant::Instant::now();
let proof = prover(K, &params, &pk);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("prover time: {:?}", end.duration_since(start));
// time it
println!("verifier");
let start = std::time::Instant::now();
let start = instant::Instant::now();
verifier(&params, &vk, &proof);
let end = std::time::Instant::now();
let end = instant::Instant::now();
println!("verifier time: {:?}", end.duration_since(start));
}
4 changes: 2 additions & 2 deletions halo2_proofs/examples/vector-mul-unblinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ fn main() {
// of the instance column, so we position it there in our public inputs.
let mut public_inputs = c;

let start = std::time::Instant::now();
let start = instant::Instant::now();
// Given the correct public input, our circuit will verify.
let prover = MockProver::run(k, &circuit, vec![public_inputs.clone()]).unwrap();
assert_eq!(prover.verify(), Ok(()));
println!("positive test took {:?}", start.elapsed());

// If we try some other public input, the proof will fail!
let start = std::time::Instant::now();
let start = instant::Instant::now();
public_inputs[0] += Fp::one();
let prover = MockProver::run(k, &circuit, vec![public_inputs]).unwrap();
assert!(prover.verify().is_err());
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/examples/vector-mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ fn main() {
// of the instance column, so we position it there in our public inputs.
let mut public_inputs = c;

let start = std::time::Instant::now();
let start = instant::Instant::now();
// Given the correct public input, our circuit will verify.
let prover = MockProver::run(k, &circuit, vec![public_inputs.clone()]).unwrap();
assert_eq!(prover.verify(), Ok(()));
println!("positive test took {:?}", start.elapsed());

// If we try some other public input, the proof will fail!
let start = std::time::Instant::now();
let start = instant::Instant::now();
public_inputs[0] += Fp::one();
let prover = MockProver::run(k, &circuit, vec![public_inputs]).unwrap();
assert!(prover.verify().is_err());
Expand Down
17 changes: 8 additions & 9 deletions halo2_proofs/src/plonk/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<C: CurveAffine> Evaluator<C> {
shuffles: &[Vec<shuffle::prover::Committed<C>>],
permutations: &[permutation::prover::Committed<C>],
) -> Polynomial<C::ScalarExt, ExtendedLagrangeCoeff> {
let start = std::time::Instant::now();
let start = instant::Instant::now();
let domain = &pk.vk.domain;
let size = domain.extended_len();
let rot_scale = 1 << (domain.extended_k() - domain.k());
Expand All @@ -395,7 +395,7 @@ impl<C: CurveAffine> Evaluator<C> {
let p = &pk.vk.cs.permutation;
log::trace!(" - Initialization: {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
// Calculate the advice and instance cosets
let advice: Vec<Vec<Polynomial<C::Scalar, ExtendedLagrangeCoeff>>> = advice_polys
.iter()
Expand All @@ -408,7 +408,7 @@ impl<C: CurveAffine> Evaluator<C> {
.collect();
log::trace!(" - Advice cosets: {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
let instance: Vec<Vec<Polynomial<C::Scalar, ExtendedLagrangeCoeff>>> = instance_polys
.iter()
.map(|instance_polys| {
Expand All @@ -424,7 +424,7 @@ impl<C: CurveAffine> Evaluator<C> {

// Core expression evaluations

let start = std::time::Instant::now();
let start = instant::Instant::now();
let num_threads = multicore::current_num_threads();
for ((((advice, instance), lookups), shuffles), permutation) in advice
.iter()
Expand Down Expand Up @@ -465,7 +465,7 @@ impl<C: CurveAffine> Evaluator<C> {
log::trace!(" - Custom gates: {:?}", start.elapsed());

// Permutations
let start = std::time::Instant::now();
let start = instant::Instant::now();
let sets = &permutation.sets;
if !sets.is_empty() {
let blinding_factors = pk.vk.cs.blinding_factors();
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<C: CurveAffine> Evaluator<C> {
}
log::trace!(" - Permutations: {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
// For lookups, compute inputs_inv_sum = ∑ 1 / (f_i(X) + α)
// The outer vector has capacity self.lookups.len()
// The middle vector has capacity domain.extended_len()
Expand Down Expand Up @@ -616,7 +616,7 @@ impl<C: CurveAffine> Evaluator<C> {
log::trace!(" - Lookups inv sum: {:?}", start.elapsed());

#[cfg(feature = "mv-lookup")]
let start = std::time::Instant::now();
let start = instant::Instant::now();
// Lookups
#[cfg(feature = "mv-lookup")]
parallelize(&mut values, |values, start| {
Expand Down Expand Up @@ -764,7 +764,6 @@ impl<C: CurveAffine> Evaluator<C> {
(product_coset, permuted_input_coset, permuted_table_coset)
};

let start = std::time::Instant::now();
// Lookup constraints
parallelize(&mut values, |values, start| {
let lookup_evaluator = &self.lookups[n];
Expand Down Expand Up @@ -827,7 +826,7 @@ impl<C: CurveAffine> Evaluator<C> {
log::trace!(" - Lookups constraints: {:?}", start.elapsed());

// Shuffle constraints
let start = std::time::Instant::now();
let start = instant::Instant::now();
for (n, shuffle) in shuffles.iter().enumerate() {
let product_coset = pk.vk.domain.coeff_to_extended(&shuffle.product_poly);

Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/lookup/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn permute_expression_pair<'params, C: CurveAffine, P: Params<'params, C>, R: Rn
);
}*/
#[cfg(not(target_arch = "wasm32"))]
let start = std::time::Instant::now();
let start = instant::Instant::now();
let res =
permute_expression_pair_par(pk, params, domain, rng, input_expression, table_expression);
#[cfg(not(target_arch = "wasm32"))]
Expand Down
22 changes: 11 additions & 11 deletions halo2_proofs/src/plonk/mv_lookup/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<F: WithSmallOrderMulGroup<3>> Argument<F> {
compressed_expression
};

let start = std::time::Instant::now();
let start = instant::Instant::now();
// Get values of input expressions involved in the lookup and compress them
let compressed_inputs_expressions: Vec<_> = self
.inputs_expressions
Expand All @@ -124,7 +124,7 @@ impl<F: WithSmallOrderMulGroup<3>> Argument<F> {
log::trace!("compressed_inputs_expressions {:?}", start.elapsed());

// Get values of table expressions involved in the lookup and compress them
let start = std::time::Instant::now();
let start = instant::Instant::now();
let compressed_table_expression = compress_expressions(&self.table_expressions);
log::trace!("compressed_table_expression {:?}", start.elapsed());

Expand All @@ -133,7 +133,7 @@ impl<F: WithSmallOrderMulGroup<3>> Argument<F> {
let chunk_size = n - blinding_factors - 1;

// compute m(X)
let start = std::time::Instant::now();
let start = instant::Instant::now();
let table_index_value_mapping: HashMap<Vec<u8>, usize> = compressed_table_expression
.par_iter()
.take(chunk_size)
Expand All @@ -142,7 +142,7 @@ impl<F: WithSmallOrderMulGroup<3>> Argument<F> {
.collect();
log::trace!("table_index_value_mapping {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
let m_values: Vec<F> = {
use std::sync::atomic::{AtomicU64, Ordering};
let m_values: Vec<AtomicU64> = (0..params.n()).map(|_| AtomicU64::new(0)).collect();
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<F: WithSmallOrderMulGroup<3>> Argument<F> {
}

// commit to m(X)
let start = std::time::Instant::now();
let start = instant::Instant::now();
let blind = Blind(C::Scalar::ZERO);
let m_commitment = params.commit_lagrange(&m_values, blind).to_affine();
log::trace!("m_commitment {:?}", start.elapsed());
Expand Down Expand Up @@ -248,7 +248,7 @@ impl<C: CurveAffine> Prepared<C> {
RHS = τ(X) * Π(φ_i(X)) * (∑ 1/(φ_i(X)) - m(X) / τ(X))))
*/

let start = std::time::Instant::now();
let start = instant::Instant::now();
// ∑ 1/(φ_i(X))
let mut inputs_log_derivatives = vec![C::Scalar::ZERO; params.n() as usize];
for compressed_input_expression in self.compressed_inputs_expressions.iter() {
Expand All @@ -275,7 +275,7 @@ impl<C: CurveAffine> Prepared<C> {

log::trace!(" - inputs_log_derivatives {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
// 1 / τ(X)
let mut table_log_derivatives = vec![C::Scalar::ZERO; params.n() as usize];
parallelize(
Expand All @@ -292,14 +292,14 @@ impl<C: CurveAffine> Prepared<C> {

log::trace!(" - table_log_derivatives {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
table_log_derivatives.iter_mut().batch_invert();
log::trace!(
" - table_log_derivatives batch_invert {:?}",
start.elapsed()
);

let start = std::time::Instant::now();
let start = instant::Instant::now();
// (Σ 1/(φ_i(X)) - m(X) / τ(X))
let mut log_derivatives_diff = vec![C::Scalar::ZERO; params.n() as usize];
parallelize(&mut log_derivatives_diff, |log_derivatives_diff, start| {
Expand All @@ -316,7 +316,7 @@ impl<C: CurveAffine> Prepared<C> {

log::trace!(" - log_derivatives_diff {:?}", start.elapsed());

let start = std::time::Instant::now();
let start = instant::Instant::now();
// Compute the evaluations of the lookup grand sum polynomial
// over our domain, starting with phi[0] = 0
let blinding_factors = vk.cs.blinding_factors();
Expand Down Expand Up @@ -397,7 +397,7 @@ impl<C: CurveAffine> Prepared<C> {
}

let grand_sum_blind = Blind(C::Scalar::ZERO);
let start = std::time::Instant::now();
let start = instant::Instant::now();
let phi_commitment = params.commit_lagrange(&phi, grand_sum_blind).to_affine();
log::trace!(" - phi_commitment {:?}", start.elapsed());

Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use ff::{Field, FromUniformBytes, WithSmallOrderMulGroup};
use group::Curve;
use halo2curves::serde::SerdeObject;

use instant::Instant;
use rand_core::RngCore;
use rustc_hash::FxBuildHasher;
use rustc_hash::FxHashMap as HashMap;
use rustc_hash::FxHashSet as HashSet;
use std::collections::BTreeSet;
use std::iter;
use std::ops::RangeTo;
use std::time::Instant;

use super::{
circuit::{
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/poly/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ fn test_coeff_to_extended_part() {
fn bench_coeff_to_extended_parts() {
use halo2curves::pasta::pallas::Scalar;
use rand_core::OsRng;
use std::time::Instant;
use instant::Instant;

let k = 20;
let domain = EvaluationDomain::<Scalar>::new(3, k);
Expand Down Expand Up @@ -935,7 +935,7 @@ fn test_lagrange_vecs_to_extended() {
fn bench_lagrange_vecs_to_extended() {
use halo2curves::pasta::pallas::Scalar;
use rand_core::OsRng;
use std::time::Instant;
use instant::Instant;

let rng = OsRng;
let domain = EvaluationDomain::<Scalar>::new(8, 10);
Expand Down

0 comments on commit 8b13a0d

Please sign in to comment.