diff --git a/CHANGELOG.md b/CHANGELOG.md index b2dd2594..d562acf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Removed +- `halo2::arithmetic::BatchInvert` (use `ff::BatchInvert` instead). ## [0.1.0-beta.1] - 2021-09-24 Initial beta release! diff --git a/src/arithmetic.rs b/src/arithmetic.rs index f3663ea0..8984eb1a 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -3,48 +3,10 @@ use super::multicore; pub use ff::Field; -use group::Group as _; +use group::{ff::BatchInvert, Group as _}; pub use pasta_curves::arithmetic::*; -/// Extension trait for iterators over mutable field elements which allows those -/// field elements to be inverted in a batch. -pub trait BatchInvert { - /// Consume this iterator and invert each field element (when nonzero), - /// returning the inverse of all nonzero field elements. Zero elements - /// are left as zero. - fn batch_invert(self) -> F; -} - -impl<'a, F, I> BatchInvert for I -where - F: FieldExt, - I: IntoIterator, -{ - fn batch_invert(self) -> F { - let mut acc = F::one(); - let iter = self.into_iter(); - let mut tmp = Vec::with_capacity(iter.size_hint().0); - for p in iter { - let q = *p; - tmp.push((acc, p)); - acc = F::conditional_select(&(acc * q), &acc, q.is_zero()); - } - acc = acc.invert().unwrap(); - let allinv = acc; - - for (tmp, p) in tmp.into_iter().rev() { - let skip = p.is_zero(); - - let tmp = tmp * acc; - acc = F::conditional_select(&(acc * *p), &acc, skip); - *p = F::conditional_select(&tmp, p, skip); - } - - allinv - } -} - fn multiexp_serial(coeffs: &[C::Scalar], bases: &[C], acc: &mut C::Curve) { let coeffs: Vec<[u8; 32]> = coeffs.iter().map(|a| a.to_bytes()).collect(); diff --git a/src/plonk/lookup/prover.rs b/src/plonk/lookup/prover.rs index a5b12987..f90f36dd 100644 --- a/src/plonk/lookup/prover.rs +++ b/src/plonk/lookup/prover.rs @@ -4,7 +4,7 @@ use super::super::{ }; use super::Argument; use crate::{ - arithmetic::{eval_polynomial, parallelize, BatchInvert, CurveAffine, FieldExt}, + arithmetic::{eval_polynomial, parallelize, CurveAffine, FieldExt}, poly::{ commitment::{Blind, Params}, multiopen::ProverQuery, @@ -12,8 +12,10 @@ use crate::{ }, transcript::{EncodedChallenge, TranscriptWrite}, }; -use ff::Field; -use group::Curve; +use group::{ + ff::{BatchInvert, Field}, + Curve, +}; use std::{ collections::BTreeMap, iter, diff --git a/src/plonk/permutation/prover.rs b/src/plonk/permutation/prover.rs index ca31aff0..8412f879 100644 --- a/src/plonk/permutation/prover.rs +++ b/src/plonk/permutation/prover.rs @@ -1,11 +1,13 @@ -use ff::Field; -use group::Curve; +use group::{ + ff::{BatchInvert, Field}, + Curve, +}; use std::iter::{self, ExactSizeIterator}; use super::super::{circuit::Any, ChallengeBeta, ChallengeGamma, ChallengeX}; use super::{Argument, ProvingKey}; use crate::{ - arithmetic::{eval_polynomial, parallelize, BatchInvert, CurveAffine, FieldExt}, + arithmetic::{eval_polynomial, parallelize, CurveAffine, FieldExt}, plonk::{self, Error}, poly::{ commitment::{Blind, Params}, diff --git a/src/poly.rs b/src/poly.rs index b5892daa..8c43ee6c 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -3,10 +3,9 @@ //! the committed polynomials at arbitrary points. use crate::arithmetic::parallelize; -use crate::arithmetic::BatchInvert; use crate::plonk::Assigned; -use ff::Field; +use group::ff::{BatchInvert, Field}; use pasta_curves::arithmetic::FieldExt; use std::fmt::Debug; use std::marker::PhantomData; diff --git a/src/poly/commitment/verifier.rs b/src/poly/commitment/verifier.rs index 134df346..a87c6bc0 100644 --- a/src/poly/commitment/verifier.rs +++ b/src/poly/commitment/verifier.rs @@ -1,11 +1,13 @@ -use ff::Field; -use group::Curve; +use group::{ + ff::{BatchInvert, Field}, + Curve, +}; use super::super::Error; use super::{Params, MSM}; use crate::transcript::{EncodedChallenge, TranscriptRead}; -use crate::arithmetic::{best_multiexp, BatchInvert, CurveAffine}; +use crate::arithmetic::{best_multiexp, CurveAffine}; /// A guard returned by the verifier #[derive(Debug, Clone)] diff --git a/src/poly/domain.rs b/src/poly/domain.rs index 257577a2..5f796ca4 100644 --- a/src/poly/domain.rs +++ b/src/poly/domain.rs @@ -2,13 +2,14 @@ //! domain that is of a suitable size for the application. use crate::{ - arithmetic::{best_fft, parallelize, BatchInvert, FieldExt, Group}, + arithmetic::{best_fft, parallelize, FieldExt, Group}, plonk::Assigned, }; use super::{Coeff, ExtendedLagrangeCoeff, LagrangeCoeff, Polynomial, Rotation}; -use ff::{Field, PrimeField}; +use group::ff::{BatchInvert, Field, PrimeField}; + use std::marker::PhantomData; /// This structure contains precomputed constants and other details needed for