From 17cfae66550de1bd3ff2620e728d8400f322d8e0 Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Sat, 21 Jan 2023 16:15:27 +0700 Subject: [PATCH] reorg --- evm/src/bn254_pairing.rs | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/evm/src/bn254_pairing.rs b/evm/src/bn254_pairing.rs index 8c0b501a..d368162e 100644 --- a/evm/src/bn254_pairing.rs +++ b/evm/src/bn254_pairing.rs @@ -13,7 +13,8 @@ pub struct Curve { y: Fp, } -/// Standard addition formula for elliptic curves, source: +/// Standard addition formula for elliptic curves, restricted to the cases +/// where neither inputs nor output would ever be the identity O. source: /// https://en.wikipedia.org/wiki/Elliptic_curve#Algebraic_interpretation impl Add for Curve { type Output = Self; @@ -79,6 +80,26 @@ pub fn miller_loop(p: Curve, q: TwistedCurve) -> Fp12 { acc } +pub fn tangent(p: Curve, q: TwistedCurve) -> Fp12 { + let cx = -Fp::new(3) * p.x * p.x; + let cy = Fp::new(2) * p.y; + sparse_embed( + p.y * p.y - Fp::new(9), + mul_fp_fp2(cx, q.x), + mul_fp_fp2(cy, q.y), + ) +} + +pub fn cord(p1: Curve, p2: Curve, q: TwistedCurve) -> Fp12 { + let cx = p2.y - p1.y; + let cy = p1.x - p2.x; + sparse_embed( + p1.y * p2.x - p2.y * p1.x, + mul_fp_fp2(cx, q.x), + mul_fp_fp2(cy, q.y), + ) +} + pub fn power(f: Fp12) -> Fp12 { const EXPS4: [(usize, usize, usize); 64] = [ (1, 1, 0), @@ -268,26 +289,6 @@ pub fn power(f: Fp12) -> Fp12 { y4 * y2 * y0 } -pub fn tangent(p: Curve, q: TwistedCurve) -> Fp12 { - let cx = -Fp::new(3) * p.x * p.x; - let cy = Fp::new(2) * p.y; - sparse_embed( - p.y * p.y - Fp::new(9), - mul_fp_fp2(cx, q.x), - mul_fp_fp2(cy, q.y), - ) -} - -pub fn cord(p1: Curve, p2: Curve, q: TwistedCurve) -> Fp12 { - let cx = p2.y - p1.y; - let cy = p1.x - p2.x; - sparse_embed( - p1.y * p2.x - p2.y * p1.x, - mul_fp_fp2(cx, q.x), - mul_fp_fp2(cy, q.y), - ) -} - // The curve is cyclic with generator (1, 2) pub const CURVE_GENERATOR: Curve = { Curve {