From ea328d3a4d4fdf2556345c3172afda94dc65036d Mon Sep 17 00:00:00 2001 From: "github-merge-queue[bot]" Date: Sun, 25 Feb 2024 10:24:45 +0000 Subject: [PATCH] deploy: 6089294309d13fa57735bc4c0098393d82b9ff97 --- docs/arecibo/provider/hyperkzg/index.html | 2 +- .../hyperkzg/struct.EvaluationEngine.html | 6 +- docs/arecibo/provider/ipa_pc/index.html | 2 +- .../trait.EvaluationEngineTrait.html | 2 +- docs/src/arecibo/provider/hyperkzg.rs.html | 20 ++++--- docs/src/arecibo/provider/ipa_pc.rs.html | 50 +--------------- docs/src/arecibo/provider/util/mod.rs.html | 44 ++++++++++++++ .../arecibo/spartan/sumcheck/engine.rs.html | 58 +------------------ 8 files changed, 66 insertions(+), 118 deletions(-) diff --git a/docs/arecibo/provider/hyperkzg/index.html b/docs/arecibo/provider/hyperkzg/index.html index bcad04054..9f911c57a 100644 --- a/docs/arecibo/provider/hyperkzg/index.html +++ b/docs/arecibo/provider/hyperkzg/index.html @@ -1,5 +1,5 @@ arecibo::provider::hyperkzg - Rust -

Module arecibo::provider::hyperkzg

source ·
Expand description

This module implements Nova’s evaluation engine using HyperKZG, a KZG-based polynomial commitment for multilinear polynomials +

Module arecibo::provider::hyperkzg

source ·
Expand description

This module implements Nova’s evaluation engine using HyperKZG, a KZG-based polynomial commitment for multilinear polynomials HyperKZG is based on the transformation from univariate PCS to multilinear PCS in the Gemini paper (section 2.4.2 in <https://eprint.iacr.org/2022/420.pdf>). However, there are some key differences: (1) HyperKZG works with multilinear polynomials represented in evaluation form (rather than in coefficient form in Gemini’s transformation). diff --git a/docs/arecibo/provider/hyperkzg/struct.EvaluationEngine.html b/docs/arecibo/provider/hyperkzg/struct.EvaluationEngine.html index cac310c3f..7af325002 100644 --- a/docs/arecibo/provider/hyperkzg/struct.EvaluationEngine.html +++ b/docs/arecibo/provider/hyperkzg/struct.EvaluationEngine.html @@ -18,14 +18,14 @@ W: &[E::G1Affine], transcript: &mut impl TranscriptEngineTrait<NE> ) -> E::Fr

TODO: write doc

-

Trait Implementations§

source§

impl<E: Clone, NE: Clone> Clone for EvaluationEngine<E, NE>

source§

fn clone(&self) -> EvaluationEngine<E, NE>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E: Debug, NE: Debug> Debug for EvaluationEngine<E, NE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E, NE> EvaluationEngineTrait<NE> for EvaluationEngine<E, NE>
where +

Trait Implementations§

source§

impl<E: Clone, NE: Clone> Clone for EvaluationEngine<E, NE>

source§

fn clone(&self) -> EvaluationEngine<E, NE>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E: Debug, NE: Debug> Debug for EvaluationEngine<E, NE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E, NE> EvaluationEngineTrait<NE> for EvaluationEngine<E, NE>
where E: MultiMillerLoop, NE: NovaEngine<GE = E::G1, Scalar = E::Fr, CE = KZGCommitmentEngine<E>>, E::Fr: Serialize + DeserializeOwned + PrimeFieldBits + TranscriptReprTrait<E::G1>, E::G1Affine: Serialize + DeserializeOwned + TranscriptReprTrait<E::G1>, E::G2Affine: Serialize + DeserializeOwned, E::G1: DlogGroup<ScalarExt = E::Fr, AffineExt = E::G1Affine>, - <E::G1 as Group>::Base: TranscriptReprTrait<E::G1>,

source§

fn verify( + <E::G1 as Group>::Base: TranscriptReprTrait<E::G1>,

source§

fn verify( vk: &Self::VerifierKey, transcript: &mut <NE as NovaEngine>::TE, C: &Commitment<NE>, @@ -33,7 +33,7 @@ P_of_x: &E::Fr, pi: &Self::EvaluationArgument ) -> Result<(), NovaError>

A method to verify purported evaluations of a batch of polynomials

-
§

type EvaluationArgument = EvaluationArgument<E>

A type that holds the evaluation argument
§

type ProverKey = KZGProverKey<E>

A type that holds the prover key
§

type VerifierKey = KZGVerifierKey<E>

A type that holds the verifier key
source§

fn setup(ck: Arc<UniversalKZGParam<E>>) -> (Self::ProverKey, Self::VerifierKey)

A method to perform any additional setup needed to produce proofs of evaluations Read more
source§

fn prove( +

§

type EvaluationArgument = EvaluationArgument<E>

A type that holds the evaluation argument
§

type ProverKey = KZGProverKey<E>

A type that holds the prover key
§

type VerifierKey = KZGVerifierKey<E>

A type that holds the verifier key
source§

fn setup(ck: Arc<UniversalKZGParam<E>>) -> (Self::ProverKey, Self::VerifierKey)

A method to perform any additional setup needed to produce proofs of evaluations Read more
source§

fn prove( ck: &UniversalKZGParam<E>, _pk: &Self::ProverKey, transcript: &mut <NE as NovaEngine>::TE, diff --git a/docs/arecibo/provider/ipa_pc/index.html b/docs/arecibo/provider/ipa_pc/index.html index f83fc3546..a0c3b8ace 100644 --- a/docs/arecibo/provider/ipa_pc/index.html +++ b/docs/arecibo/provider/ipa_pc/index.html @@ -1,3 +1,3 @@ arecibo::provider::ipa_pc - Rust -

Module arecibo::provider::ipa_pc

source ·
Expand description

This module implements EvaluationEngine using an IPA-based polynomial commitment scheme

+

Module arecibo::provider::ipa_pc

source ·
Expand description

This module implements EvaluationEngine using an IPA-based polynomial commitment scheme

Structs

\ No newline at end of file diff --git a/docs/arecibo/traits/evaluation/trait.EvaluationEngineTrait.html b/docs/arecibo/traits/evaluation/trait.EvaluationEngineTrait.html index 1d7ff89cf..272dd3ef7 100644 --- a/docs/arecibo/traits/evaluation/trait.EvaluationEngineTrait.html +++ b/docs/arecibo/traits/evaluation/trait.EvaluationEngineTrait.html @@ -54,7 +54,7 @@

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<E> EvaluationEngineTrait<E> for arecibo::provider::ipa_pc::EvaluationEngine<E>
where E: Engine, E::GE: DlogGroup, - <<E as Engine>::CE as CommitmentEngineTrait<E>>::CommitmentKey: CommitmentKeyExtTrait<E>,

source§

impl<E, NE> EvaluationEngineTrait<NE> for arecibo::provider::hyperkzg::EvaluationEngine<E, NE>
where + <<E as Engine>::CE as CommitmentEngineTrait<E>>::CommitmentKey: CommitmentKeyExtTrait<E>,

source§

impl<E, NE> EvaluationEngineTrait<NE> for arecibo::provider::hyperkzg::EvaluationEngine<E, NE>
where E: MultiMillerLoop, NE: NovaEngine<GE = E::G1, Scalar = E::Fr, CE = KZGCommitmentEngine<E>>, E::Fr: Serialize + DeserializeOwned + PrimeFieldBits + TranscriptReprTrait<E::G1>, diff --git a/docs/src/arecibo/provider/hyperkzg.rs.html b/docs/src/arecibo/provider/hyperkzg.rs.html index 343f86441..57eb3724c 100644 --- a/docs/src/arecibo/provider/hyperkzg.rs.html +++ b/docs/src/arecibo/provider/hyperkzg.rs.html @@ -608,6 +608,7 @@ 607 608 609 +610
//! This module implements Nova's evaluation engine using `HyperKZG`, a KZG-based polynomial commitment for multilinear polynomials
 //! HyperKZG is based on the transformation from univariate PCS to multilinear PCS in the Gemini paper (section 2.4.2 in `<https://eprint.iacr.org/2022/420.pdf>`).
 //! However, there are some key differences:
@@ -634,7 +635,7 @@
 };
 use core::marker::PhantomData;
 use ff::{Field, PrimeFieldBits};
-use group::{Curve, Group as _};
+use group::{prime::PrimeCurveAffine as _, Curve, Group as _};
 use itertools::Itertools as _;
 use pairing::{Engine, MillerLoopResult, MultiMillerLoop};
 use rayon::prelude::*;
@@ -851,14 +852,15 @@
 
     // We do not need to commit to the first polynomial as it is already committed.
     // Compute commitments in parallel
-    let comms: Vec<E::G1Affine> = (1..polys.len())
-      .into_par_iter()
-      .map(|i| {
-        <NE::CE as CommitmentEngineTrait<NE>>::commit(ck, &polys[i])
-          .comm
-          .to_affine()
-      })
-      .collect();
+    let comms = {
+      let mut comms = vec![E::G1Affine::identity(); polys.len() - 1];
+      let comms_proj: Vec<E::G1> = (1..polys.len())
+        .into_par_iter()
+        .map(|i| <NE::CE as CommitmentEngineTrait<NE>>::commit(ck, &polys[i]).comm)
+        .collect();
+      Curve::batch_normalize(&comms_proj, &mut comms);
+      comms
+    };
 
     // Phase 2
     // We do not need to add x to the transcript, because in our context x was obtained from the transcript.
diff --git a/docs/src/arecibo/provider/ipa_pc.rs.html b/docs/src/arecibo/provider/ipa_pc.rs.html
index 725480755..991b618b4 100644
--- a/docs/src/arecibo/provider/ipa_pc.rs.html
+++ b/docs/src/arecibo/provider/ipa_pc.rs.html
@@ -389,34 +389,11 @@
 388
 389
 390
-391
-392
-393
-394
-395
-396
-397
-398
-399
-400
-401
-402
-403
-404
-405
-406
-407
-408
-409
-410
-411
-412
-413
 

//! This module implements `EvaluationEngine` using an IPA-based polynomial commitment scheme
 use crate::{
   digest::SimpleDigestible,
   errors::{NovaError, PCSError},
-  provider::{pedersen::CommitmentKeyExtTrait, traits::DlogGroup},
+  provider::{pedersen::CommitmentKeyExtTrait, traits::DlogGroup, util::field::batch_invert},
   spartan::polys::eq::EqPolynomial,
   traits::{
     commitment::{CommitmentEngineTrait, CommitmentTrait},
@@ -718,29 +695,6 @@
 
     let P = U.comm_a_vec + CE::<E>::commit(&ck_c, &[U.c]);
 
-    let batch_invert = |v: &[E::Scalar]| -> Result<Vec<E::Scalar>, NovaError> {
-      let mut products = vec![E::Scalar::ZERO; v.len()];
-      let mut acc = E::Scalar::ONE;
-
-      for i in 0..v.len() {
-        products[i] = acc;
-        acc *= v[i];
-      }
-
-      // return error if acc is zero
-      acc = Option::from(acc.invert()).ok_or(NovaError::InternalError)?;
-
-      // compute the inverse once for all entries
-      let mut inv = vec![E::Scalar::ZERO; v.len()];
-      for i in (0..v.len()).rev() {
-        let tmp = acc * v[i];
-        inv[i] = products[i] * acc;
-        acc = tmp;
-      }
-
-      Ok(inv)
-    };
-
     // compute a vector of public coins using self.L_vec and self.R_vec
     let r = (0..self.L_vec.len())
       .map(|i| {
@@ -755,7 +709,7 @@
       .into_par_iter()
       .map(|i| r[i] * r[i])
       .collect();
-    let r_inverse = batch_invert(&r)?;
+    let r_inverse = batch_invert(r.clone())?;
     let r_inverse_square: Vec<E::Scalar> = (0..self.L_vec.len())
       .into_par_iter()
       .map(|i| r_inverse[i] * r_inverse[i])
diff --git a/docs/src/arecibo/provider/util/mod.rs.html b/docs/src/arecibo/provider/util/mod.rs.html
index 7cd11f521..1e6ed9c7c 100644
--- a/docs/src/arecibo/provider/util/mod.rs.html
+++ b/docs/src/arecibo/provider/util/mod.rs.html
@@ -206,6 +206,28 @@
 205
 206
 207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
 

//! Utilities for provider module.
 pub(in crate::provider) mod fb_msm;
 pub mod msm {
@@ -219,6 +241,28 @@
   }
 }
 
+pub mod field {
+  use crate::errors::NovaError;
+  use ff::{BatchInverter, Field};
+
+  #[inline]
+  pub fn batch_invert<F: Field>(mut v: Vec<F>) -> Result<Vec<F>, NovaError> {
+    // we only allocate the scratch space if every element of v is nonzero
+    let mut scratch_space = v
+      .iter()
+      .map(|x| {
+        if !x.is_zero_vartime() {
+          Ok(*x)
+        } else {
+          Err(NovaError::InternalError)
+        }
+      })
+      .collect::<Result<Vec<_>, _>>()?;
+    let _ = BatchInverter::invert_with_external_scratch(&mut v, &mut scratch_space[..]);
+    Ok(v)
+  }
+}
+
 pub mod iterators {
   use ff::Field;
   use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
diff --git a/docs/src/arecibo/spartan/sumcheck/engine.rs.html b/docs/src/arecibo/spartan/sumcheck/engine.rs.html
index 99ba3982c..c1c1cd4af 100644
--- a/docs/src/arecibo/spartan/sumcheck/engine.rs.html
+++ b/docs/src/arecibo/spartan/sumcheck/engine.rs.html
@@ -616,35 +616,10 @@
 615
 616
 617
-618
-619
-620
-621
-622
-623
-624
-625
-626
-627
-628
-629
-630
-631
-632
-633
-634
-635
-636
-637
-638
-639
-640
-641
-642
-643
 
use ff::Field;
 use rayon::prelude::*;
 
+use crate::provider::util::field::batch_invert;
 use crate::spartan::math::Math;
 use crate::spartan::polys::{
   eq::EqPolynomial, masked_eq::MaskedEqPolynomial, multilinear::MultilinearPolynomial,
@@ -835,33 +810,6 @@
       || hash_func_vec(mem_col, addr_col, L_col),
     );
 
-    let batch_invert = |v: &[E::Scalar]| -> Result<Vec<E::Scalar>, NovaError> {
-      let mut products = vec![E::Scalar::ZERO; v.len()];
-      let mut acc = E::Scalar::ONE;
-
-      for i in 0..v.len() {
-        products[i] = acc;
-        acc *= v[i];
-      }
-
-      // we can compute an inversion only if acc is non-zero
-      if acc == E::Scalar::ZERO {
-        return Err(NovaError::InternalError);
-      }
-
-      // compute the inverse once for all entries
-      acc = acc.invert().unwrap();
-
-      let mut inv = vec![E::Scalar::ZERO; v.len()];
-      for i in 0..v.len() {
-        let tmp = acc * v[v.len() - 1 - i];
-        inv[v.len() - 1 - i] = products[v.len() - 1 - i] * acc;
-        acc = tmp;
-      }
-
-      Ok(inv)
-    };
-
     // compute vectors TS[i]/(T[i] + r) and 1/(W[i] + r)
     let helper = |T: &[E::Scalar],
                   W: &[E::Scalar],
@@ -878,7 +826,7 @@
         || {
           rayon::join(
             || {
-              let inv = batch_invert(&T.par_iter().map(|e| *e + *r).collect::<Vec<_>>())?;
+              let inv = batch_invert(T.par_iter().map(|e| *e + *r).collect::<Vec<_>>())?;
 
               // compute inv[i] * TS[i] in parallel
               Ok(
@@ -886,7 +834,7 @@
                   .collect::<Vec<_>>(),
               )
             },
-            || batch_invert(&W.par_iter().map(|e| *e + *r).collect::<Vec<_>>()),
+            || batch_invert(W.par_iter().map(|e| *e + *r).collect::<Vec<_>>()),
           )
         },
         || {