diff --git a/halo2_proofs/Cargo.toml b/halo2_proofs/Cargo.toml index 4e7cb401ee..e9a71c5253 100644 --- a/halo2_proofs/Cargo.toml +++ b/halo2_proofs/Cargo.toml @@ -85,6 +85,7 @@ gumdrop = "0.8" proptest = "1" rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } serde_json = "1" +ark-std = "0.4.0" [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] getrandom = { version = "0.2", features = ["js"] } diff --git a/halo2_proofs/benches/arithmetic.rs b/halo2_proofs/benches/arithmetic.rs index 4ae88af137..19f94f2807 100644 --- a/halo2_proofs/benches/arithmetic.rs +++ b/halo2_proofs/benches/arithmetic.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate criterion; -use crate::arithmetic::small_multiexp; +use crate::arithmetic::best_multiexp_cpu; use crate::halo2curves::pasta::{EqAffine, Fp}; use group::ff::Field; use halo2_proofs::*; @@ -27,7 +27,7 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("double-and-add", |b| { b.iter(|| { for (g_lo, g_hi) in g_lo.iter().zip(g_hi.iter()) { - small_multiexp(&[black_box(coeff_1), black_box(coeff_2)], &[*g_lo, *g_hi]); + best_multiexp_cpu(&[black_box(coeff_1), black_box(coeff_2)], &[*g_lo, *g_hi]); } }) }); diff --git a/halo2_proofs/benches/fft.rs b/halo2_proofs/benches/fft.rs index 0de72a0380..e5875010ff 100644 --- a/halo2_proofs/benches/fft.rs +++ b/halo2_proofs/benches/fft.rs @@ -7,16 +7,24 @@ use halo2_proofs::*; use halo2curves::pasta::Fp; use criterion::{BenchmarkId, Criterion}; +use poly::EvaluationDomain; use rand_core::OsRng; fn criterion_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("fft"); for k in 3..19 { group.bench_function(BenchmarkId::new("k", k), |b| { - let mut a = (0..(1 << k)).map(|_| Fp::random(OsRng)).collect::>(); + let domain = EvaluationDomain::::new(1, k); + let n = domain.get_n() as usize; + + let input = vec![Fp::random(OsRng); n]; + + let mut a = input.clone(); + let l_a = a.len(); + let omega = Fp::random(OsRng); // would be weird if this mattered b.iter(|| { - best_fft(&mut a, omega, k as u32); + best_fft(&mut a, omega, k as u32, domain.get_fft_data(l_a), false); }); }); } diff --git a/halo2_proofs/src/circuit/floor_planner/v1/strategy.rs b/halo2_proofs/src/circuit/floor_planner/v1/strategy.rs index b594cd942e..d9b79ec872 100644 --- a/halo2_proofs/src/circuit/floor_planner/v1/strategy.rs +++ b/halo2_proofs/src/circuit/floor_planner/v1/strategy.rs @@ -217,16 +217,8 @@ pub fn slot_in_biggest_advice_first( // We now use `sort_by_cached_key` with non-unique keys, and rely on `region_shapes` // being sorted by region index (which we also rely on below to return `RegionStart`s // in the correct order). - #[cfg(not(feature = "floor-planner-v1-legacy-pdqsort"))] sorted_regions.sort_by_cached_key(sort_key); - // To preserve compatibility, when the "floor-planner-v1-legacy-pdqsort" feature is enabled, - // we use a copy of the pdqsort implementation from the Rust 1.56.1 standard library, fixed - // to its behaviour on 64-bit platforms. - // https://github.com/rust-lang/rust/blob/1.56.1/library/core/src/slice/mod.rs#L2365-L2402 - #[cfg(feature = "floor-planner-v1-legacy-pdqsort")] - halo2_legacy_pdqsort::sort::quicksort(&mut sorted_regions, |a, b| sort_key(a).lt(&sort_key(b))); - sorted_regions.reverse(); // Lay out the sorted regions. diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index b2ddb764ae..f8c313f432 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -22,9 +22,11 @@ use crate::{ use maybe_rayon::prelude::{ IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, ParallelIterator, - ParallelSliceMut, }; +#[cfg(not(feature = "mv-lookup"))] +use maybe_rayon::prelude::ParallelSliceMut; + pub mod metadata; use metadata::Column as ColumnMetadata; mod util; diff --git a/halo2_proofs/src/plonk.rs b/halo2_proofs/src/plonk.rs index 72305731ee..09c9ef4387 100644 --- a/halo2_proofs/src/plonk.rs +++ b/halo2_proofs/src/plonk.rs @@ -25,7 +25,9 @@ mod circuit; mod error; mod evaluation; mod keygen; +#[cfg(not(feature = "mv-lookup"))] mod lookup; +#[cfg(feature = "mv-lookup")] mod mv_lookup; pub mod permutation; mod shuffle; diff --git a/halo2_proofs/src/plonk/circuit.rs b/halo2_proofs/src/plonk/circuit.rs index dc65fdb6aa..c2d722f903 100644 --- a/halo2_proofs/src/plonk/circuit.rs +++ b/halo2_proofs/src/plonk/circuit.rs @@ -1374,11 +1374,6 @@ impl Product for Expression { } } -/// Represents an index into a vector where each entry corresponds to a distinct -/// point that polynomials are queried at. -#[derive(Copy, Clone, Debug)] -pub(crate) struct PointIndex(pub usize); - /// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset /// within a custom gate. #[derive(Clone, Debug)] @@ -1554,6 +1549,7 @@ impl Gate { /// TODO doc #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct LookupTracker { pub(crate) table: Vec>, pub(crate) inputs: Vec>>, diff --git a/halo2_proofs/src/plonk/evaluation.rs b/halo2_proofs/src/plonk/evaluation.rs index 4ce97a333e..9eb8a061ca 100644 --- a/halo2_proofs/src/plonk/evaluation.rs +++ b/halo2_proofs/src/plonk/evaluation.rs @@ -15,6 +15,7 @@ use crate::{ }; use group::ff::{Field, PrimeField, WithSmallOrderMulGroup}; +#[cfg(feature = "mv-lookup")] use maybe_rayon::iter::IndexedParallelIterator; use maybe_rayon::iter::IntoParallelRefIterator; use maybe_rayon::iter::ParallelIterator; diff --git a/halo2_proofs/src/plonk/lookup/prover.rs b/halo2_proofs/src/plonk/lookup/prover.rs index 60a97a739c..2ba5b955aa 100644 --- a/halo2_proofs/src/plonk/lookup/prover.rs +++ b/halo2_proofs/src/plonk/lookup/prover.rs @@ -45,6 +45,7 @@ pub(in crate::plonk) struct Permuted { } #[derive(Debug)] +#[allow(dead_code)] pub(in crate::plonk) struct Committed { pub(in crate::plonk) permuted_input_poly: Polynomial, permuted_input_blind: Blind, @@ -56,6 +57,7 @@ pub(in crate::plonk) struct Committed { } impl Committed { + #[allow(dead_code)] pub fn write( &self, writer: &mut W, @@ -74,6 +76,7 @@ impl Committed { self.commitment.write(writer, format) } + #[allow(dead_code)] pub fn read(reader: &mut R, format: SerdeFormat) -> std::io::Result where ::ScalarExt: crate::helpers::SerdePrimeField, diff --git a/halo2_proofs/src/plonk/mv_lookup/prover.rs b/halo2_proofs/src/plonk/mv_lookup/prover.rs index 4a7c934fdb..bfba3b89db 100644 --- a/halo2_proofs/src/plonk/mv_lookup/prover.rs +++ b/halo2_proofs/src/plonk/mv_lookup/prover.rs @@ -43,6 +43,7 @@ pub(in crate::plonk) struct Committed { } impl Committed { + #[allow(dead_code)] pub fn write( &self, writer: &mut W, @@ -56,6 +57,7 @@ impl Committed { self.commitment.write(writer, format) } + #[allow(dead_code)] pub fn read(reader: &mut R, format: SerdeFormat) -> std::io::Result where ::ScalarExt: crate::helpers::SerdePrimeField, diff --git a/halo2_proofs/src/plonk/prover.rs b/halo2_proofs/src/plonk/prover.rs index e74ffe74f0..53d4df0d73 100644 --- a/halo2_proofs/src/plonk/prover.rs +++ b/halo2_proofs/src/plonk/prover.rs @@ -1,7 +1,5 @@ use ff::{Field, FromUniformBytes, WithSmallOrderMulGroup}; use group::Curve; -use halo2curves::serde::SerdeObject; - use instant::Instant; use rand_core::RngCore; use rustc_hash::FxBuildHasher; @@ -20,8 +18,8 @@ use super::{ permutation, shuffle, vanishing, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error, ProvingKey, }; -use maybe_rayon::iter::IndexedParallelIterator; -use maybe_rayon::iter::ParallelIterator; +#[cfg(feature = "mv-lookup")] +use maybe_rayon::iter::{IndexedParallelIterator, ParallelIterator}; #[cfg(not(feature = "mv-lookup"))] use super::lookup; @@ -29,9 +27,7 @@ use super::lookup; use super::mv_lookup as lookup; #[cfg(feature = "mv-lookup")] -use maybe_rayon::iter::{ - IntoParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, -}; +use maybe_rayon::iter::{IntoParallelIterator, IntoParallelRefIterator}; use crate::{ arithmetic::{eval_polynomial, CurveAffine}, @@ -69,8 +65,7 @@ pub fn create_proof< transcript: &mut T, ) -> Result<(), Error> where - Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64> + SerdeObject, - Scheme::Curve: SerdeObject, + Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>, Scheme::ParamsProver: Send + Sync, { #[cfg(feature = "counter")] @@ -498,11 +493,13 @@ where .collect::, _>>()?; #[cfg(feature = "mv-lookup")] - lookups.iter().for_each(|lookups| { - lookups.iter().for_each(|lookup| { - transcript.write_point(lookup.commitment); - }); - }); + { + for lookups_ in &lookups { + for lookup in lookups_.iter() { + transcript.write_point(lookup.commitment)?; + } + } + } #[cfg(not(feature = "mv-lookup"))] let lookups: Vec>> = instance @@ -603,11 +600,13 @@ where let lookups = commit_lookups()?; #[cfg(feature = "mv-lookup")] - lookups.iter().for_each(|lookups| { - lookups.iter().for_each(|lookup| { - transcript.write_point(lookup.commitment); - }); - }); + { + for lookups_ in &lookups { + for lookup in lookups_.iter() { + transcript.write_point(lookup.commitment)?; + } + } + } log::trace!("Lookup commitment: {:?}", start.elapsed()); diff --git a/halo2_proofs/src/poly/commitment.rs b/halo2_proofs/src/poly/commitment.rs index 9398750611..4f95d044cd 100644 --- a/halo2_proofs/src/poly/commitment.rs +++ b/halo2_proofs/src/poly/commitment.rs @@ -199,7 +199,8 @@ impl Default for Blind { } impl Blind { - /// Writes polynomial to buffer using `SerdePrimeField::write`. + /// Writes blind to buffer using `SerdePrimeField::write`. + #[allow(dead_code)] pub(crate) fn write( &self, writer: &mut W, @@ -209,7 +210,8 @@ impl Blind { Ok(()) } - /// Reads polynomial from buffer using `SerdePrimeField::read`. + /// Reads blind from buffer using `SerdePrimeField::read`. + #[allow(dead_code)] pub(crate) fn read( reader: &mut R, format: crate::SerdeFormat, diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index feb660b41d..16e18b3cdd 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -27,6 +27,7 @@ fn plonk_api() { /// This represents an advice column at a certain row in the ConstraintSystem #[derive(Copy, Clone, Debug)] + #[allow(dead_code)] pub struct Variable(Column, usize); #[derive(Clone)] @@ -459,7 +460,7 @@ fn plonk_api() { Scheme: CommitmentScheme, P: Prover<'params, Scheme>, E: EncodedChallenge, - R: RngCore, + R: RngCore + Send + Sync, T: TranscriptWriterBuffer, Scheme::Curve, E>, >( rng: R, @@ -468,6 +469,8 @@ fn plonk_api() { ) -> Vec where Scheme::Scalar: Ord + WithSmallOrderMulGroup<3> + FromUniformBytes<64>, + Scheme::Curve: Send + Sync, + Scheme::ParamsProver: Send + Sync, { let (a, instance, lookup_table) = common!(Scheme); diff --git a/rust-toolchain b/rust-toolchain index a6d32a878c..99e26d383c 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1,3 @@ -nightly-2024-07-18 +[toolchain] +channel = "nightly-2024-07-18" +components = ["rustfmt", "clippy"] \ No newline at end of file