Skip to content

Commit

Permalink
Add some basic bls_modular_inverse() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asn-d6 committed Mar 17, 2023
1 parent 0e0403d commit 77443a2
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,27 @@ def test_verify_blob_kzg_proof_incorrect_proof(spec):
assert not spec.verify_blob_kzg_proof(blob, commitment, proof)


@with_deneb_and_later
@spec_test
@single_phase
def test_bls_modular_inverse(spec):
"""
Verify computation of multiplicative inverse
"""
rng = random.Random(5566)

# Should fail for x == 0
expect_assertion_error(lambda: spec.bls_modular_inverse(0))

# Test a trivial inversion
assert 1 = int(spec.bls_modular_inverse(1))

# Test a random inversion
r = rng.randint(0, spec.BLS_MODULUS - 1)
r_inv = int(spec.bls_modular_inverse(r))
assert r * r_inv % BLS_MODULUS == 1


@with_deneb_and_later
@spec_test
@single_phase
Expand Down

0 comments on commit 77443a2

Please sign in to comment.