From e7e520791d27dad6c82d63611d89b8ddcf3b6aac Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Wed, 22 Jun 2022 15:19:24 +0300 Subject: [PATCH] Use Python's pow() in bls_modular_inverse(). --- specs/eip4844/polynomial-commitments.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/specs/eip4844/polynomial-commitments.md b/specs/eip4844/polynomial-commitments.md index df5aad146..9558641c6 100644 --- a/specs/eip4844/polynomial-commitments.md +++ b/specs/eip4844/polynomial-commitments.md @@ -66,19 +66,10 @@ but reusing the `mainnet` settings in public networks is a critical security req ```python def bls_modular_inverse(x: BLSFieldElement) -> BLSFieldElement: """ - Compute the modular inverse of x using the eGCD algorithm + Compute the modular inverse of x i.e. return y such that x * y % BLS_MODULUS == 1 and return 0 for x == 0 """ - if x == 0: - return 0 - - lm, hm = 1, 0 - low, high = x % BLS_MODULUS, BLS_MODULUS - while low > 1: - r = high // low - nm, new = hm - lm * r, high - low * r - lm, low, hm, high = nm, new, lm, low - return lm % BLS_MODULUS + return pow(x, -1, BLS_MODULUS) if x != 0 else 0 ``` #### `div`