group: Rename zero and one to identity and generator
This commit is contained in:
parent
145747c08b
commit
3d1af5bed8
|
@ -218,7 +218,7 @@ impl<G: CurveProjective> Clone for Point<G> {
|
||||||
|
|
||||||
impl<G: CurveProjective> Group<G::Engine> for Point<G> {
|
impl<G: CurveProjective> Group<G::Engine> for Point<G> {
|
||||||
fn group_zero() -> Self {
|
fn group_zero() -> Self {
|
||||||
Point(G::zero())
|
Point(G::identity())
|
||||||
}
|
}
|
||||||
fn group_mul_assign(&mut self, by: &G::Scalar) {
|
fn group_mul_assign(&mut self, by: &G::Scalar) {
|
||||||
self.0.mul_assign(by.to_repr());
|
self.0.mul_assign(by.to_repr());
|
||||||
|
|
|
@ -234,7 +234,7 @@ where
|
||||||
|
|
||||||
let worker = Worker::new();
|
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
|
// Compute powers of tau
|
||||||
{
|
{
|
||||||
|
@ -287,11 +287,11 @@ where
|
||||||
powers_of_tau.ifft(&worker);
|
powers_of_tau.ifft(&worker);
|
||||||
let powers_of_tau = powers_of_tau.into_coeffs();
|
let powers_of_tau = powers_of_tau.into_coeffs();
|
||||||
|
|
||||||
let mut a = vec![E::G1::zero(); assembly.num_inputs + assembly.num_aux];
|
let mut a = vec![E::G1::identity(); assembly.num_inputs + assembly.num_aux];
|
||||||
let mut b_g1 = vec![E::G1::zero(); 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::zero(); 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::zero(); assembly.num_inputs];
|
let mut ic = vec![E::G1::identity(); assembly.num_inputs];
|
||||||
let mut l = vec![E::G1::zero(); assembly.num_aux];
|
let mut l = vec![E::G1::identity(); assembly.num_aux];
|
||||||
|
|
||||||
fn eval<E: Engine>(
|
fn eval<E: Engine>(
|
||||||
// wNAF window tables
|
// wNAF window tables
|
||||||
|
@ -446,7 +446,7 @@ where
|
||||||
// Don't allow any elements be unconstrained, so that
|
// Don't allow any elements be unconstrained, so that
|
||||||
// the L query is always fully dense.
|
// the L query is always fully dense.
|
||||||
for e in l.iter() {
|
for e in l.iter() {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
return Err(SynthesisError::UnconstrainedVariable);
|
return Err(SynthesisError::UnconstrainedVariable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,19 +472,19 @@ where
|
||||||
// Filter points at infinity away from A/B queries
|
// Filter points at infinity away from A/B queries
|
||||||
a: Arc::new(
|
a: Arc::new(
|
||||||
a.into_iter()
|
a.into_iter()
|
||||||
.filter(|e| !e.is_zero())
|
.filter(|e| !e.is_identity())
|
||||||
.map(|e| e.into_affine())
|
.map(|e| e.into_affine())
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
b_g1: Arc::new(
|
b_g1: Arc::new(
|
||||||
b_g1.into_iter()
|
b_g1.into_iter()
|
||||||
.filter(|e| !e.is_zero())
|
.filter(|e| !e.is_identity())
|
||||||
.map(|e| e.into_affine())
|
.map(|e| e.into_affine())
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
b_g2: Arc::new(
|
b_g2: Arc::new(
|
||||||
b_g2.into_iter()
|
b_g2.into_iter()
|
||||||
.filter(|e| !e.is_zero())
|
.filter(|e| !e.is_identity())
|
||||||
.map(|e| e.into_affine())
|
.map(|e| e.into_affine())
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl<E: Engine> Proof<E> {
|
||||||
.into_affine()
|
.into_affine()
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
@ -69,7 +69,7 @@ impl<E: Engine> Proof<E> {
|
||||||
.into_affine()
|
.into_affine()
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
@ -84,7 +84,7 @@ impl<E: Engine> Proof<E> {
|
||||||
.into_affine()
|
.into_affine()
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
@ -198,7 +198,7 @@ impl<E: Engine> VerifyingKey<E> {
|
||||||
.into_affine()
|
.into_affine()
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
@ -303,7 +303,7 @@ impl<E: Engine> Parameters<E> {
|
||||||
}
|
}
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
@ -325,7 +325,7 @@ impl<E: Engine> Parameters<E> {
|
||||||
}
|
}
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||||
.and_then(|e| {
|
.and_then(|e| {
|
||||||
if e.is_zero() {
|
if e.is_identity() {
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
"point at infinity",
|
"point at infinity",
|
||||||
|
|
|
@ -295,7 +295,7 @@ where
|
||||||
);
|
);
|
||||||
let b_g2_aux = multiexp(&worker, b_g2_aux_source, b_aux_density, aux_assignment);
|
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
|
// If this element is zero, someone is trying to perform a
|
||||||
// subversion-CRS attack.
|
// subversion-CRS attack.
|
||||||
return Err(SynthesisError::UnexpectedIdentity);
|
return Err(SynthesisError::UnexpectedIdentity);
|
||||||
|
|
|
@ -362,15 +362,15 @@ impl CurveProjective for Fr {
|
||||||
<Fr as Field>::random(rng)
|
<Fr as Field>::random(rng)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zero() -> Self {
|
fn identity() -> Self {
|
||||||
<Fr as Field>::zero()
|
<Fr as Field>::zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn one() -> Self {
|
fn generator() -> Self {
|
||||||
<Fr as Field>::one()
|
<Fr as Field>::one()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_zero(&self) -> bool {
|
fn is_identity(&self) -> bool {
|
||||||
<Fr as Field>::is_zero(self)
|
<Fr as Field>::is_zero(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,15 +450,15 @@ impl CurveAffine for Fr {
|
||||||
type Scalar = Fr;
|
type Scalar = Fr;
|
||||||
type Engine = DummyEngine;
|
type Engine = DummyEngine;
|
||||||
|
|
||||||
fn zero() -> Self {
|
fn identity() -> Self {
|
||||||
<Fr as Field>::zero()
|
<Fr as Field>::zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn one() -> Self {
|
fn generator() -> Self {
|
||||||
<Fr as Field>::one()
|
<Fr as Field>::one()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_zero(&self) -> bool {
|
fn is_identity(&self) -> bool {
|
||||||
<Fr as Field>::is_zero(self)
|
<Fr as Field>::is_zero(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl<G: CurveAffine> Source<G> for (Arc<Vec<G>>, usize) {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.0[self.1].is_zero() {
|
if self.0[self.1].is_identity() {
|
||||||
return Err(SynthesisError::UnexpectedIdentity);
|
return Err(SynthesisError::UnexpectedIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,13 +173,13 @@ where
|
||||||
|
|
||||||
pool.compute(move || {
|
pool.compute(move || {
|
||||||
// Accumulate the result
|
// Accumulate the result
|
||||||
let mut acc = G::zero();
|
let mut acc = G::identity();
|
||||||
|
|
||||||
// Build a source for the bases
|
// Build a source for the bases
|
||||||
let mut bases = bases.new();
|
let mut bases = bases.new();
|
||||||
|
|
||||||
// Create space for the buckets
|
// 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 = <G::Engine as ScalarEngine>::Fr::one();
|
let one = <G::Engine as ScalarEngine>::Fr::one();
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ where
|
||||||
// e.g. 3a + 2b + 1c = a +
|
// e.g. 3a + 2b + 1c = a +
|
||||||
// (a) + b +
|
// (a) + b +
|
||||||
// ((a) + b) + c
|
// ((a) + b) + c
|
||||||
let mut running_sum = G::zero();
|
let mut running_sum = G::identity();
|
||||||
for exp in buckets.into_iter().rev() {
|
for exp in buckets.into_iter().rev() {
|
||||||
running_sum.add_assign(&exp);
|
running_sum.add_assign(&exp);
|
||||||
acc.add_assign(&running_sum);
|
acc.add_assign(&running_sum);
|
||||||
|
@ -302,7 +302,7 @@ fn test_with_bls12() {
|
||||||
) -> G {
|
) -> G {
|
||||||
assert_eq!(bases.len(), exponents.len());
|
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()) {
|
for (base, exp) in bases.iter().zip(exponents.iter()) {
|
||||||
AddAssign::<&G>::add_assign(&mut acc, &base.mul(exp.to_repr()));
|
AddAssign::<&G>::add_assign(&mut acc, &base.mul(exp.to_repr()));
|
||||||
|
|
Loading…
Reference in New Issue