From 6f6c808d80d8836a10f86a94c742089821020e7d Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Wed, 15 Mar 2023 19:41:55 -0700 Subject: [PATCH] more efficient divmod --- evm/src/bls381_arithmetic.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/evm/src/bls381_arithmetic.rs b/evm/src/bls381_arithmetic.rs index bf886e1c..f3217639 100644 --- a/evm/src/bls381_arithmetic.rs +++ b/evm/src/bls381_arithmetic.rs @@ -105,10 +105,11 @@ impl Mul for Fp { type Output = Self; fn mul(self, other: Self) -> Self { - let b256: U512 = U512([0, 0, 0, 0, 1, 0, 0, 0]); // x1, y1 are at most (q-1) // 2^256 < 2^125 - let (x1, x0) = self.val.div_mod(b256); - let (y1, y0) = other.val.div_mod(b256); + let x1 = U512(self.val.0[..4].try_into().unwrap()); + let x0 = U512(self.val.0[4..].try_into().unwrap()); + let y1 = U512(other.val.0[..4].try_into().unwrap()); + let y0 = U512(other.val.0[4..].try_into().unwrap()); let z00 = Fp { val: x0.saturating_mul(y0) % BLS_BASE,