Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for behaviors #75

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions py_ecc/bls/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from py_ecc.optimized_bls12_381 import (
field_modulus as q,
)
from eth_typing import (
BLSPubkey,
BLSSignature,
)

G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109 # noqa: E501
FQ2_order = q ** 2 - 1
Expand All @@ -15,3 +19,6 @@
POW_2_381 = 2**381
POW_2_382 = 2**382
POW_2_383 = 2**383

EMPTY_SIGNATURE = BLSSignature(b'\xc0' + b'\x00' * 95)
EMPTY_PUBKEY = BLSPubkey(b'\xc0' + b'\x00' * 47)
31 changes: 31 additions & 0 deletions tests/test_bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
normalize,
field_modulus as q,
)
from py_ecc.bls.constants import (
EMPTY_PUBKEY,
EMPTY_SIGNATURE,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -78,6 +82,31 @@ def test_decompress_G2_with_no_modular_square_root_found():
signature_to_G2(b'\x11' * 96)


def test_verify_empty_pubkey_and_signature():
"""
`verify` returns True for an empty public key and an empty signature.
The behavior is accepted for now and should be revisited in the future.
"""
assert verify(b'\x11' * 32, EMPTY_PUBKEY, EMPTY_SIGNATURE, 1000)
assert verify_multiple(
pubkeys=[],
message_hashes=[],
signature=EMPTY_SIGNATURE,
domain=1000,
)
assert verify_multiple(
pubkeys=[EMPTY_PUBKEY, EMPTY_PUBKEY],
message_hashes=[b'\x11' * 32, b'\x12' * 32],
signature=EMPTY_SIGNATURE,
domain=1000,
)


def test_empty_aggregation():
assert aggregate_pubkeys([]) == EMPTY_PUBKEY
assert aggregate_signatures([]) == EMPTY_SIGNATURE


@pytest.mark.parametrize(
'pt,on_curve,is_infinity',
[
Expand Down Expand Up @@ -213,6 +242,8 @@ def test_signature_aggregation(msg, privkeys):
(tuple(range(10)), tuple(range(10))),
((0, 1, 2, 3), (4, 5, 6, 7)),
((0, 1, 2, 3), (2, 3, 4, 5)),
(tuple(), (2, 3, 4, 5)),
((0, 1, 2, 3), tuple()),
]
)
def test_multi_aggregation(msg_1, msg_2, privkeys_1, privkeys_2):
Expand Down