mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 08:13:11 +00:00
removed from ProjectivePoint
This commit is contained in:
parent
7da99ad4d4
commit
0f49f6461e
@ -11,19 +11,17 @@ impl<C: Curve> Add<ProjectivePoint<C>> for ProjectivePoint<C> {
|
|||||||
x: x1,
|
x: x1,
|
||||||
y: y1,
|
y: y1,
|
||||||
z: z1,
|
z: z1,
|
||||||
zero: zero1,
|
|
||||||
} = self;
|
} = self;
|
||||||
let ProjectivePoint {
|
let ProjectivePoint {
|
||||||
x: x2,
|
x: x2,
|
||||||
y: y2,
|
y: y2,
|
||||||
z: z2,
|
z: z2,
|
||||||
zero: zero2,
|
|
||||||
} = rhs;
|
} = rhs;
|
||||||
|
|
||||||
if zero1 {
|
if z1 == C::BaseField::ZERO {
|
||||||
return rhs;
|
return rhs;
|
||||||
}
|
}
|
||||||
if zero2 {
|
if z2 == C::BaseField::ZERO {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +64,6 @@ impl<C: Curve> Add<AffinePoint<C>> for ProjectivePoint<C> {
|
|||||||
x: x1,
|
x: x1,
|
||||||
y: y1,
|
y: y1,
|
||||||
z: z1,
|
z: z1,
|
||||||
zero: zero1,
|
|
||||||
} = self;
|
} = self;
|
||||||
let AffinePoint {
|
let AffinePoint {
|
||||||
x: x2,
|
x: x2,
|
||||||
@ -74,7 +71,7 @@ impl<C: Curve> Add<AffinePoint<C>> for ProjectivePoint<C> {
|
|||||||
zero: zero2,
|
zero: zero2,
|
||||||
} = rhs;
|
} = rhs;
|
||||||
|
|
||||||
if zero1 {
|
if z1 == C::BaseField::ZERO {
|
||||||
return rhs.to_projective();
|
return rhs.to_projective();
|
||||||
}
|
}
|
||||||
if zero2 {
|
if zero2 {
|
||||||
|
|||||||
@ -23,7 +23,6 @@ pub trait Curve: 'static + Sync + Sized + Copy + Debug {
|
|||||||
x: Self::GENERATOR_AFFINE.x,
|
x: Self::GENERATOR_AFFINE.x,
|
||||||
y: Self::GENERATOR_AFFINE.y,
|
y: Self::GENERATOR_AFFINE.y,
|
||||||
z: Self::BaseField::ONE,
|
z: Self::BaseField::ONE,
|
||||||
zero: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn convert(x: Self::ScalarField) -> CurveScalar<Self> {
|
fn convert(x: Self::ScalarField) -> CurveScalar<Self> {
|
||||||
@ -89,12 +88,13 @@ impl<C: Curve> AffinePoint<C> {
|
|||||||
|
|
||||||
pub fn to_projective(&self) -> ProjectivePoint<C> {
|
pub fn to_projective(&self) -> ProjectivePoint<C> {
|
||||||
let Self { x, y, zero } = *self;
|
let Self { x, y, zero } = *self;
|
||||||
ProjectivePoint {
|
let z = if zero {
|
||||||
x,
|
C::BaseField::ZERO
|
||||||
y,
|
} else {
|
||||||
z: C::BaseField::ONE,
|
C::BaseField::ONE
|
||||||
zero,
|
};
|
||||||
}
|
|
||||||
|
ProjectivePoint { x, y, z }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn batch_to_projective(affine_points: &[Self]) -> Vec<ProjectivePoint<C>> {
|
pub fn batch_to_projective(affine_points: &[Self]) -> Vec<ProjectivePoint<C>> {
|
||||||
@ -150,7 +150,6 @@ pub struct ProjectivePoint<C: Curve> {
|
|||||||
pub x: C::BaseField,
|
pub x: C::BaseField,
|
||||||
pub y: C::BaseField,
|
pub y: C::BaseField,
|
||||||
pub z: C::BaseField,
|
pub z: C::BaseField,
|
||||||
pub zero: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Curve> ProjectivePoint<C> {
|
impl<C: Curve> ProjectivePoint<C> {
|
||||||
@ -158,16 +157,10 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
x: C::BaseField::ZERO,
|
x: C::BaseField::ZERO,
|
||||||
y: C::BaseField::ZERO,
|
y: C::BaseField::ZERO,
|
||||||
z: C::BaseField::ZERO,
|
z: C::BaseField::ZERO,
|
||||||
zero: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn nonzero(x: C::BaseField, y: C::BaseField, z: C::BaseField) -> Self {
|
pub fn nonzero(x: C::BaseField, y: C::BaseField, z: C::BaseField) -> Self {
|
||||||
let point = Self {
|
let point = Self { x, y, z };
|
||||||
x,
|
|
||||||
y,
|
|
||||||
z,
|
|
||||||
zero: false,
|
|
||||||
};
|
|
||||||
debug_assert!(point.is_valid());
|
debug_assert!(point.is_valid());
|
||||||
point
|
point
|
||||||
}
|
}
|
||||||
@ -177,8 +170,8 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_affine(&self) -> AffinePoint<C> {
|
pub fn to_affine(&self) -> AffinePoint<C> {
|
||||||
let Self { x, y, z, zero } = *self;
|
let Self { x, y, z } = *self;
|
||||||
if zero {
|
if z == C::BaseField::ZERO {
|
||||||
AffinePoint::ZERO
|
AffinePoint::ZERO
|
||||||
} else {
|
} else {
|
||||||
let z_inv = z.inverse();
|
let z_inv = z.inverse();
|
||||||
@ -193,8 +186,8 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
|
|
||||||
let mut result = Vec::with_capacity(n);
|
let mut result = Vec::with_capacity(n);
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
let Self { x, y, z: _, zero } = proj_points[i];
|
let Self { x, y, z } = proj_points[i];
|
||||||
result.push(if zero {
|
result.push(if z == C::BaseField::ZERO {
|
||||||
AffinePoint::ZERO
|
AffinePoint::ZERO
|
||||||
} else {
|
} else {
|
||||||
let z_inv = z_invs[i];
|
let z_inv = z_invs[i];
|
||||||
@ -205,8 +198,8 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn double(&self) -> Self {
|
pub fn double(&self) -> Self {
|
||||||
let Self { x, y, z, zero } = *self;
|
let Self { x, y, z } = *self;
|
||||||
if zero {
|
if z == C::BaseField::ZERO {
|
||||||
return ProjectivePoint::ZERO;
|
return ProjectivePoint::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +221,6 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
x: x3,
|
x: x3,
|
||||||
y: y3,
|
y: y3,
|
||||||
z: z3,
|
z: z3,
|
||||||
zero: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +237,6 @@ impl<C: Curve> ProjectivePoint<C> {
|
|||||||
x: self.x,
|
x: self.x,
|
||||||
y: -self.y,
|
y: -self.y,
|
||||||
z: self.z,
|
z: self.z,
|
||||||
zero: self.zero,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,16 +247,14 @@ impl<C: Curve> PartialEq for ProjectivePoint<C> {
|
|||||||
x: x1,
|
x: x1,
|
||||||
y: y1,
|
y: y1,
|
||||||
z: z1,
|
z: z1,
|
||||||
zero: zero1,
|
|
||||||
} = *self;
|
} = *self;
|
||||||
let ProjectivePoint {
|
let ProjectivePoint {
|
||||||
x: x2,
|
x: x2,
|
||||||
y: y2,
|
y: y2,
|
||||||
z: z2,
|
z: z2,
|
||||||
zero: zero2,
|
|
||||||
} = *other;
|
} = *other;
|
||||||
if zero1 || zero2 {
|
if z1 == C::BaseField::ZERO || z2 == C::BaseField::ZERO {
|
||||||
return zero1 == zero2;
|
return z1 == z2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to compare (x1/z1, y1/z1) == (x2/z2, y2/z2).
|
// We want to compare (x1/z1, y1/z1) == (x2/z2, y2/z2).
|
||||||
@ -289,7 +278,7 @@ impl<C: Curve> Neg for ProjectivePoint<C> {
|
|||||||
type Output = ProjectivePoint<C>;
|
type Output = ProjectivePoint<C>;
|
||||||
|
|
||||||
fn neg(self) -> Self::Output {
|
fn neg(self) -> Self::Output {
|
||||||
let ProjectivePoint { x, y, z, zero } = self;
|
let ProjectivePoint { x, y, z } = self;
|
||||||
ProjectivePoint { x, y: -y, z, zero }
|
ProjectivePoint { x, y: -y, z }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user