diff --git a/tests/core/pyspec/eth2spec/test/deneb/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/deneb/unittests/polynomial_commitments/test_polynomial_commitments.py index f42f88393..7d89a9788 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/deneb/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -215,6 +215,29 @@ 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)) + expect_assertion_error(lambda: spec.bls_modular_inverse(spec.BLS_MODULUS)) + expect_assertion_error(lambda: spec.bls_modular_inverse(2 * spec.BLS_MODULUS)) + + # 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