mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-05 07:13:08 +00:00
remove .scale
This commit is contained in:
parent
3f4d970f15
commit
0650d2636c
@ -69,14 +69,14 @@ pub fn miller_loop(p: Curve, q: TwistedCurve) -> Fp12<BN254> {
|
||||
pub fn tangent(p: Curve, q: TwistedCurve) -> Fp12<BN254> {
|
||||
let cx = -BN254::new(3) * p.x * p.x;
|
||||
let cy = BN254::new(2) * p.y;
|
||||
sparse_embed(p.y * p.y - BN254::new(9), q.x.scale(cx), q.y.scale(cy))
|
||||
sparse_embed(p.y * p.y - BN254::new(9), q.x * cx, q.y * cy)
|
||||
}
|
||||
|
||||
/// The sloped line function for adding two points
|
||||
pub fn cord(p1: Curve, p2: Curve, q: TwistedCurve) -> Fp12<BN254> {
|
||||
let cx = p2.y - p1.y;
|
||||
let cy = p1.x - p2.x;
|
||||
sparse_embed(p1.y * p2.x - p2.y * p1.x, q.x.scale(cx), q.y.scale(cy))
|
||||
sparse_embed(p1.y * p2.x - p2.y * p1.x, q.x * cx, q.y * cy)
|
||||
}
|
||||
|
||||
/// The tangent and cord functions output sparse Fp12 elements.
|
||||
|
||||
@ -6,8 +6,7 @@ use rand::distributions::{Distribution, Standard};
|
||||
use rand::Rng;
|
||||
|
||||
pub trait FieldExt:
|
||||
Sized
|
||||
+ Copy
|
||||
Copy
|
||||
+ std::ops::Add<Output = Self>
|
||||
+ std::ops::Neg<Output = Self>
|
||||
+ std::ops::Sub<Output = Self>
|
||||
@ -317,15 +316,19 @@ impl<T: FieldExt> Mul for Fp2<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FieldExt> Fp2<T> {
|
||||
/// This function scalar multiplies an Fp2 by an BN254
|
||||
pub fn scale(self, x: T) -> Self {
|
||||
/// This function scalar multiplies an Fp2 by an Fp
|
||||
impl<T: FieldExt> Mul<T> for Fp2<T> {
|
||||
type Output = Fp2<T>;
|
||||
|
||||
fn mul(self, other: T) -> Self {
|
||||
Fp2 {
|
||||
re: x * self.re,
|
||||
im: x * self.im,
|
||||
re: other * self.re,
|
||||
im: other * self.im,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FieldExt> Fp2<T> {
|
||||
/// Return the complex conjugate z' of z: Fp2
|
||||
/// This also happens to be the frobenius map
|
||||
/// z -> z^p
|
||||
@ -357,7 +360,7 @@ impl<T: FieldExt> FieldExt for Fp2<T> {
|
||||
/// The inverse of z is given by z'/||z||^2 since ||z||^2 = zz'
|
||||
fn inv(self) -> Fp2<T> {
|
||||
let norm_sq = self.norm_sq();
|
||||
self.conj().scale(norm_sq.inv())
|
||||
self.conj() * norm_sq.inv()
|
||||
}
|
||||
}
|
||||
|
||||
@ -880,17 +883,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fp6<T>
|
||||
/// This function scalar multiplies an Fp6 by an Fp2
|
||||
impl<T> Mul<Fp2<T>> for Fp6<T>
|
||||
where
|
||||
T: FieldExt,
|
||||
Fp2<T>: Adj,
|
||||
{
|
||||
// This function scalar multiplies an Fp6 by an Fp2
|
||||
fn scale(self, x: Fp2<T>) -> Fp6<T> {
|
||||
type Output = Fp6<T>;
|
||||
|
||||
fn mul(self, other: Fp2<T>) -> Self {
|
||||
Fp6 {
|
||||
t0: x * self.t0,
|
||||
t1: x * self.t1,
|
||||
t2: x * self.t2,
|
||||
t0: other * self.t0,
|
||||
t1: other * self.t1,
|
||||
t2: other * self.t2,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -981,9 +986,9 @@ where
|
||||
let prod_13 = self.frob(1) * self.frob(3);
|
||||
let prod_135 = (prod_13 * self.frob(5)).t0;
|
||||
let phi = prod_135.norm_sq();
|
||||
let prod_odds_over_phi = prod_135.scale(phi.inv());
|
||||
let prod_odds_over_phi = prod_135 * phi.inv();
|
||||
let prod_24 = prod_13.frob(1);
|
||||
prod_24.scale(prod_odds_over_phi)
|
||||
prod_24 * prod_odds_over_phi
|
||||
}
|
||||
}
|
||||
|
||||
@ -1044,10 +1049,10 @@ where
|
||||
let prod_1379 = prod_17 * prod_17.frob(2);
|
||||
let prod_odds = (prod_1379 * prod_17.frob(4)).t0;
|
||||
let phi = prod_odds.norm_sq();
|
||||
let prod_odds_over_phi = prod_odds.scale(phi.inv());
|
||||
let prod_odds_over_phi = prod_odds * phi.inv();
|
||||
let prod_evens_except_six = prod_1379.frob(1);
|
||||
let prod_except_six = prod_evens_except_six.scale(prod_odds_over_phi);
|
||||
self.conj().scale(prod_except_six)
|
||||
let prod_except_six = prod_evens_except_six * prod_odds_over_phi;
|
||||
self.conj() * prod_except_six
|
||||
}
|
||||
}
|
||||
|
||||
@ -1126,19 +1131,27 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// This function scalar multiplies an Fp12 by an Fp6
|
||||
impl<T> Mul<Fp6<T>> for Fp12<T>
|
||||
where
|
||||
T: FieldExt,
|
||||
Fp2<T>: Adj,
|
||||
{
|
||||
type Output = Fp12<T>;
|
||||
|
||||
fn mul(self, other: Fp6<T>) -> Self {
|
||||
Fp12 {
|
||||
z0: other * self.z0,
|
||||
z1: other * self.z1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fp12<T>
|
||||
where
|
||||
T: FieldExt,
|
||||
Fp2<T>: Adj,
|
||||
{
|
||||
// This function scalar multiplies an Fp12 by an Fp6
|
||||
fn scale(self, x: Fp6<T>) -> Fp12<T> {
|
||||
Fp12 {
|
||||
z0: x * self.z0,
|
||||
z1: x * self.z1,
|
||||
}
|
||||
}
|
||||
|
||||
fn conj(self) -> Fp12<T> {
|
||||
Fp12 {
|
||||
z0: self.z0,
|
||||
@ -1161,7 +1174,7 @@ where
|
||||
let n = n % 12;
|
||||
Fp12 {
|
||||
z0: self.z0.frob(n),
|
||||
z1: self.z1.frob(n).scale(Fp2::<T>::FROB_Z[n]),
|
||||
z1: self.z1.frob(n) * (Fp2::<T>::FROB_Z[n]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user