Skip to content

Commit

Permalink
Use Python's pow() in bls_modular_inverse().
Browse files Browse the repository at this point in the history
  • Loading branch information
asn-d6 committed Jun 22, 2022
1 parent 249b2bf commit 3a86b99
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions specs/eip4844/polynomial-commitments.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,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`
Expand Down

0 comments on commit 3a86b99

Please sign in to comment.