From 9c8f11666f8d694d2a039a4943ae12125cccaaf6 Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Wed, 25 Jan 2023 14:15:46 +0700 Subject: [PATCH] ocd --- evm/src/bn254_arithmetic.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/evm/src/bn254_arithmetic.rs b/evm/src/bn254_arithmetic.rs index 26445f06..72f006a1 100644 --- a/evm/src/bn254_arithmetic.rs +++ b/evm/src/bn254_arithmetic.rs @@ -194,8 +194,8 @@ impl Fp2 { /// The inverse of z is given by z'/||z||^2 since ||z||^2 = zz' pub fn inv(self) -> Fp2 { - let norm = self.re * self.re + self.im * self.im; - self.conj().scale(norm.inv()) + let norm_sq = self.norm_sq(); + self.conj().scale(norm_sq.inv()) } } @@ -278,6 +278,7 @@ impl Mul for Fp6 { } impl Fp6 { + // This function scalar multiplies an Fp6 by an Fp2 fn scale(self, x: Fp2) -> Fp6 { Fp6 { t0: x * self.t0, @@ -386,13 +387,7 @@ impl Mul for Fp12 { } impl Fp12 { - fn conj(self) -> Fp12 { - Fp12 { - z0: self.z0, - z1: -self.z1, - } - } - + // This function scalar multiplies an Fp12 by an Fp6 fn scale(self, x: Fp6) -> Fp12 { Fp12 { z0: x * self.z0, @@ -400,6 +395,13 @@ impl Fp12 { } } + fn conj(self) -> Fp12 { + Fp12 { + z0: self.z0, + z1: -self.z1, + } + } + /// The nth frobenius endomorphism of a p^q field is given by mapping /// x to x^(p^n) /// which sends a + bz: Fp12 to