From ef39f7508da7a445462682bd96339d03dc12be8b Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Fri, 5 Jul 2019 14:55:52 +0800 Subject: [PATCH 1/4] test verify empty_pubkey_and_signature --- py_ecc/bls/constants.py | 7 +++++++ tests/test_bls.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/py_ecc/bls/constants.py b/py_ecc/bls/constants.py index 7f6f18b9..d9fb9f2a 100644 --- a/py_ecc/bls/constants.py +++ b/py_ecc/bls/constants.py @@ -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 @@ -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) diff --git a/tests/test_bls.py b/tests/test_bls.py index 94173736..e444c52a 100644 --- a/tests/test_bls.py +++ b/tests/test_bls.py @@ -44,6 +44,10 @@ normalize, field_modulus as q, ) +from py_ecc.bls.constants import ( + EMPTY_PUBKEY, + EMPTY_SIGNATURE, +) @pytest.mark.parametrize( @@ -78,6 +82,14 @@ 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) + + @pytest.mark.parametrize( 'pt,on_curve,is_infinity', [ From ec62abd75bf01f67c21e5b1ca743aa21762eea49 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Fri, 5 Jul 2019 15:01:35 +0800 Subject: [PATCH 2/4] fix #65, add tests to empty aggregation --- tests/test_bls.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_bls.py b/tests/test_bls.py index e444c52a..cfe5d1fe 100644 --- a/tests/test_bls.py +++ b/tests/test_bls.py @@ -89,6 +89,10 @@ def test_verify_empty_pubkey_and_signature(): """ assert verify(b'\x11' * 32, EMPTY_PUBKEY, EMPTY_SIGNATURE, 1000) +def test_empty_aggregation(): + assert aggregate_pubkeys([]) == EMPTY_PUBKEY + assert aggregate_signatures([]) == EMPTY_SIGNATURE + @pytest.mark.parametrize( 'pt,on_curve,is_infinity', From 87d2e2282a6007f557ec44ba63ad57d199b40a4c Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Mon, 8 Jul 2019 17:50:03 +0800 Subject: [PATCH 3/4] add tests for verify_multiple --- tests/test_bls.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_bls.py b/tests/test_bls.py index cfe5d1fe..ae9c3719 100644 --- a/tests/test_bls.py +++ b/tests/test_bls.py @@ -88,6 +88,13 @@ def test_verify_empty_pubkey_and_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=[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 @@ -229,6 +236,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): From 094dffdafb098427e02c158b09aaa4b030a6af6f Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Mon, 8 Jul 2019 18:42:29 +0800 Subject: [PATCH 4/4] add empty list as pubkeys --- tests/test_bls.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_bls.py b/tests/test_bls.py index ae9c3719..970c4185 100644 --- a/tests/test_bls.py +++ b/tests/test_bls.py @@ -88,6 +88,12 @@ def test_verify_empty_pubkey_and_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],