diff --git a/src/domain.rs b/src/domain.rs index be97c20..bafa596 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -218,7 +218,7 @@ impl Clone for Point { impl Group for Point { fn group_zero() -> Self { - Point(G::zero()) + Point(G::identity()) } fn group_mul_assign(&mut self, by: &G::Scalar) { self.0.mul_assign(by.to_repr()); diff --git a/src/groth16/generator.rs b/src/groth16/generator.rs index 02efc21..264d3ab 100644 --- a/src/groth16/generator.rs +++ b/src/groth16/generator.rs @@ -234,7 +234,7 @@ where let worker = Worker::new(); - let mut h = vec![E::G1::zero(); powers_of_tau.as_ref().len() - 1]; + let mut h = vec![E::G1::identity(); powers_of_tau.as_ref().len() - 1]; { // Compute powers of tau { @@ -287,11 +287,11 @@ where powers_of_tau.ifft(&worker); let powers_of_tau = powers_of_tau.into_coeffs(); - let mut a = vec![E::G1::zero(); assembly.num_inputs + assembly.num_aux]; - let mut b_g1 = vec![E::G1::zero(); assembly.num_inputs + assembly.num_aux]; - let mut b_g2 = vec![E::G2::zero(); assembly.num_inputs + assembly.num_aux]; - let mut ic = vec![E::G1::zero(); assembly.num_inputs]; - let mut l = vec![E::G1::zero(); assembly.num_aux]; + let mut a = vec![E::G1::identity(); assembly.num_inputs + assembly.num_aux]; + let mut b_g1 = vec![E::G1::identity(); assembly.num_inputs + assembly.num_aux]; + let mut b_g2 = vec![E::G2::identity(); assembly.num_inputs + assembly.num_aux]; + let mut ic = vec![E::G1::identity(); assembly.num_inputs]; + let mut l = vec![E::G1::identity(); assembly.num_aux]; fn eval( // wNAF window tables @@ -446,7 +446,7 @@ where // Don't allow any elements be unconstrained, so that // the L query is always fully dense. for e in l.iter() { - if e.is_zero() { + if e.is_identity() { return Err(SynthesisError::UnconstrainedVariable); } } @@ -472,19 +472,19 @@ where // Filter points at infinity away from A/B queries a: Arc::new( a.into_iter() - .filter(|e| !e.is_zero()) + .filter(|e| !e.is_identity()) .map(|e| e.into_affine()) .collect(), ), b_g1: Arc::new( b_g1.into_iter() - .filter(|e| !e.is_zero()) + .filter(|e| !e.is_identity()) .map(|e| e.into_affine()) .collect(), ), b_g2: Arc::new( b_g2.into_iter() - .filter(|e| !e.is_zero()) + .filter(|e| !e.is_identity()) .map(|e| e.into_affine()) .collect(), ), diff --git a/src/groth16/mod.rs b/src/groth16/mod.rs index 6f5af85..b338b0c 100644 --- a/src/groth16/mod.rs +++ b/src/groth16/mod.rs @@ -54,7 +54,7 @@ impl Proof { .into_affine() .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", @@ -69,7 +69,7 @@ impl Proof { .into_affine() .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", @@ -84,7 +84,7 @@ impl Proof { .into_affine() .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", @@ -198,7 +198,7 @@ impl VerifyingKey { .into_affine() .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", @@ -303,7 +303,7 @@ impl Parameters { } .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", @@ -325,7 +325,7 @@ impl Parameters { } .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .and_then(|e| { - if e.is_zero() { + if e.is_identity() { Err(io::Error::new( io::ErrorKind::InvalidData, "point at infinity", diff --git a/src/groth16/prover.rs b/src/groth16/prover.rs index 34abbb4..97707fb 100644 --- a/src/groth16/prover.rs +++ b/src/groth16/prover.rs @@ -295,7 +295,7 @@ where ); let b_g2_aux = multiexp(&worker, b_g2_aux_source, b_aux_density, aux_assignment); - if vk.delta_g1.is_zero() || vk.delta_g2.is_zero() { + if vk.delta_g1.is_identity() || vk.delta_g2.is_identity() { // If this element is zero, someone is trying to perform a // subversion-CRS attack. return Err(SynthesisError::UnexpectedIdentity); diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index c1bf516..c95a751 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -362,15 +362,15 @@ impl CurveProjective for Fr { ::random(rng) } - fn zero() -> Self { + fn identity() -> Self { ::zero() } - fn one() -> Self { + fn generator() -> Self { ::one() } - fn is_zero(&self) -> bool { + fn is_identity(&self) -> bool { ::is_zero(self) } @@ -450,15 +450,15 @@ impl CurveAffine for Fr { type Scalar = Fr; type Engine = DummyEngine; - fn zero() -> Self { + fn identity() -> Self { ::zero() } - fn one() -> Self { + fn generator() -> Self { ::one() } - fn is_zero(&self) -> bool { + fn is_identity(&self) -> bool { ::is_zero(self) } diff --git a/src/multiexp.rs b/src/multiexp.rs index deed9fa..948086b 100644 --- a/src/multiexp.rs +++ b/src/multiexp.rs @@ -55,7 +55,7 @@ impl Source for (Arc>, usize) { .into()); } - if self.0[self.1].is_zero() { + if self.0[self.1].is_identity() { return Err(SynthesisError::UnexpectedIdentity); } @@ -173,13 +173,13 @@ where pool.compute(move || { // Accumulate the result - let mut acc = G::zero(); + let mut acc = G::identity(); // Build a source for the bases let mut bases = bases.new(); // Create space for the buckets - let mut buckets = vec![G::zero(); (1 << c) - 1]; + let mut buckets = vec![G::identity(); (1 << c) - 1]; let one = ::Fr::one(); @@ -222,7 +222,7 @@ where // e.g. 3a + 2b + 1c = a + // (a) + b + // ((a) + b) + c - let mut running_sum = G::zero(); + let mut running_sum = G::identity(); for exp in buckets.into_iter().rev() { running_sum.add_assign(&exp); acc.add_assign(&running_sum); @@ -302,7 +302,7 @@ fn test_with_bls12() { ) -> G { assert_eq!(bases.len(), exponents.len()); - let mut acc = G::zero(); + let mut acc = G::identity(); for (base, exp) in bases.iter().zip(exponents.iter()) { AddAssign::<&G>::add_assign(&mut acc, &base.mul(exp.to_repr()));