From 6e73df06929a8911a541dff952d389576189ba16 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 16 Jan 2020 11:09:58 -0700 Subject: [PATCH 1/6] fix broken bls generators --- tests/generators/bls/main.py | 86 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/tests/generators/bls/main.py b/tests/generators/bls/main.py index 587b3adc0..e8503c2e5 100644 --- a/tests/generators/bls/main.py +++ b/tests/generators/bls/main.py @@ -20,6 +20,7 @@ def hash(x): F2Q_COEFF_LEN = 48 G2_COMPRESSED_Z_LEN = 48 +DST = b'BLS_SIG_BLS12381G2-SHA256-SSWU-RO_POP_' def int_to_hex(n: int, byte_length: int = None) -> str: @@ -29,6 +30,13 @@ def int_to_hex(n: int, byte_length: int = None) -> str: return encode_hex(byte_value) +def int_to_bytes(n: int, byte_length: int = None) -> bytes: + byte_value = int_to_big_endian(n) + if byte_length: + byte_value = byte_value.rjust(byte_length, b'\x00') + return byte_value + + def hex_to_int(x: str) -> int: return int(x, 16) @@ -57,13 +65,11 @@ PRIVKEYS = [ ] -def hash_message(msg: bytes, - domain: bytes) -> Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]]: +def hash_message(msg: bytes) -> Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]]: """ Hash message Input: - Message as bytes32 - - domain as bytes8 Output: - Message hash as a G2 point """ @@ -72,49 +78,44 @@ def hash_message(msg: bytes, int_to_hex(fq2.coeffs[0], F2Q_COEFF_LEN), int_to_hex(fq2.coeffs[1], F2Q_COEFF_LEN), ] - for fq2 in bls.utils.hash_to_G2(msg, domain) + for fq2 in bls.hash_to_curve.hash_to_G2(msg, DST) ] -def hash_message_compressed(msg: bytes, domain: bytes) -> Tuple[str, str]: +def hash_message_compressed(msg: bytes) -> Tuple[str, str]: """ Hash message Input: - Message as bytes32 - - domain as bytes8 Output: - Message hash as a compressed G2 point """ - z1, z2 = bls.utils.compress_G2(bls.utils.hash_to_G2(msg, domain)) + z1, z2 = bls.point_compression.compress_G2(bls.hash_to_curve.hash_to_G2(msg, DST)) return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)] def case01_message_hash_G2_uncompressed(): for msg in MESSAGES: - for domain in DOMAINS: - yield f'uncom_g2_hash_{encode_hex(msg)}_{encode_hex(domain)}', { - 'input': { - 'message': encode_hex(msg), - 'domain': encode_hex(domain), - }, - 'output': hash_message(msg, domain) - } + yield f'uncom_g2_hash_{encode_hex(msg)}', { + 'input': { + 'message': encode_hex(msg), + }, + 'output': hash_message(msg) + } def case02_message_hash_G2_compressed(): for msg in MESSAGES: - for domain in DOMAINS: - yield f'com_g2_hash_{encode_hex(msg)}_{encode_hex(domain)}', { - 'input': { - 'message': encode_hex(msg), - 'domain': encode_hex(domain), - }, - 'output': hash_message_compressed(msg, domain) - } + yield f'com_g2_hash_{encode_hex(msg)}', { + 'input': { + 'message': encode_hex(msg), + }, + 'output': hash_message_compressed(msg) + } def case03_private_to_public_key(): - pubkeys = [bls.privtopub(privkey) for privkey in PRIVKEYS] + pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in PRIVKEYS] pubkeys_serial = ['0x' + pubkey.hex() for pubkey in pubkeys] for privkey, pubkey_serial in zip(PRIVKEYS, pubkeys_serial): yield f'priv_to_pub_{int_to_hex(privkey)}', { @@ -126,17 +127,15 @@ def case03_private_to_public_key(): def case04_sign_messages(): for privkey in PRIVKEYS: for message in MESSAGES: - for domain in DOMAINS: - sig = bls.sign(message, privkey, domain) - full_name = f'{int_to_hex(privkey)}_{encode_hex(message)}_{encode_hex(domain)}' - yield f'sign_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { - 'input': { - 'privkey': int_to_hex(privkey), - 'message': encode_hex(message), - 'domain': encode_hex(domain), - }, - 'output': encode_hex(sig) - } + sig = bls.G2ProofOfPossession.Sign(privkey, message) + full_name = f'{int_to_hex(privkey)}_{encode_hex(message)}' + yield f'sign_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'privkey': int_to_hex(privkey), + 'message': encode_hex(message), + }, + 'output': encode_hex(sig) + } # TODO: case05_verify_messages: Verify messages signed in case04 @@ -144,21 +143,20 @@ def case04_sign_messages(): def case06_aggregate_sigs(): - for domain in DOMAINS: - for message in MESSAGES: - sigs = [bls.sign(message, privkey, domain) for privkey in PRIVKEYS] - yield f'agg_sigs_{encode_hex(message)}_{encode_hex(domain)}', { - 'input': [encode_hex(sig) for sig in sigs], - 'output': encode_hex(bls.aggregate_signatures(sigs)), - } + for message in MESSAGES: + sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in PRIVKEYS] + yield f'agg_sigs_{encode_hex(message)}', { + 'input': [encode_hex(sig) for sig in sigs], + 'output': encode_hex(bls.G2ProofOfPossession.Aggregate(sigs)), + } def case07_aggregate_pubkeys(): - pubkeys = [bls.privtopub(privkey) for privkey in PRIVKEYS] + pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in PRIVKEYS] pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys] yield f'agg_pub_keys', { 'input': pubkeys_serial, - 'output': encode_hex(bls.aggregate_pubkeys(pubkeys)), + 'output': encode_hex(bls.G2ProofOfPossession._AggregatePKs(pubkeys)), } From 2a0f68076995fe9915f8df8b58bc5f6273bc9942 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 16 Jan 2020 11:15:44 -0700 Subject: [PATCH 2/6] fix ssz_generic test generator --- tests/generators/ssz_generic/ssz_container.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/generators/ssz_generic/ssz_container.py b/tests/generators/ssz_generic/ssz_container.py index 7dbd5e111..ecb2d8c34 100644 --- a/tests/generators/ssz_generic/ssz_container.py +++ b/tests/generators/ssz_generic/ssz_container.py @@ -1,6 +1,6 @@ from ssz_test_case import invalid_test_case, valid_test_case from eth2spec.utils.ssz.ssz_typing import SSZType, Container, byte, uint8, uint16, \ - uint32, uint64, List, Bytes, Vector, Bitvector, Bitlist + uint32, uint64, List, ByteList, Vector, Bitvector, Bitlist from eth2spec.utils.ssz.ssz_impl import serialize from random import Random from typing import Dict, Tuple, Sequence, Callable @@ -32,7 +32,7 @@ class ComplexTestStruct(Container): A: uint16 B: List[uint16, 128] C: uint8 - D: Bytes[256] + D: ByteList[256] E: VarTestStruct F: Vector[FixedTestStruct, 4] G: Vector[VarTestStruct, 2] From f012844493a83f21d8f9c0dbf7b73761fd1b1d19 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 21 Jan 2020 10:28:31 -0700 Subject: [PATCH 3/6] Add additional bls tests for IETF standards to bls gens --- tests/generators/bls/main.py | 127 +++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/tests/generators/bls/main.py b/tests/generators/bls/main.py index e8503c2e5..e6513e89f 100644 --- a/tests/generators/bls/main.py +++ b/tests/generators/bls/main.py @@ -20,7 +20,7 @@ def hash(x): F2Q_COEFF_LEN = 48 G2_COMPRESSED_Z_LEN = 48 -DST = b'BLS_SIG_BLS12381G2-SHA256-SSWU-RO_POP_' +DST = bls.G2ProofOfPossession.DST def int_to_hex(n: int, byte_length: int = None) -> str: @@ -124,7 +124,7 @@ def case03_private_to_public_key(): } -def case04_sign_messages(): +def case04_sign_message(): for privkey in PRIVKEYS: for message in MESSAGES: sig = bls.G2ProofOfPossession.Sign(privkey, message) @@ -138,8 +138,45 @@ def case04_sign_messages(): } -# TODO: case05_verify_messages: Verify messages signed in case04 -# It takes too long, empty for now +def case05_verify_message(): + for i, privkey in enumerate(PRIVKEYS): + for message in MESSAGES: + # Valid signature + signature = bls.G2ProofOfPossession.Sign(privkey, message) + pubkey = bls.G2Basic.PrivToPub(privkey) + full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_valid' + yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkey': encode_hex(pubkey), + 'message': encode_hex(message), + 'signature': encode_hex(signature), + }, + 'output': True, + } + + # Invalid signatures -- wrong pubkey + wrong_pubkey = bls.G2Basic.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)]) + full_name = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}_wrong_pubkey' + yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkey': encode_hex(wrong_pubkey), + 'message': encode_hex(message), + 'signature': encode_hex(signature), + }, + 'output': False, + } + + # Invalid signature -- tampered with signature + tampered_signature = signature[:-4] + b'\xFF\xFF\xFF\xFF' + full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_tampered_signature' + yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkey': encode_hex(pubkey), + 'message': encode_hex(message), + 'signature': encode_hex(tampered_signature), + }, + 'output': False, + } def case06_aggregate_sigs(): @@ -160,8 +197,81 @@ def case07_aggregate_pubkeys(): } -# TODO -# Aggregate verify +def case08_fast_aggregate_verify(): + for i, message in enumerate(MESSAGES): + privkeys = PRIVKEYS[:i + 1] + sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in privkeys] + aggregate_signature = bls.G2ProofOfPossession.Aggregate(sigs) + pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in privkeys] + pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys] + + # Valid signature + full_name = f'{pubkeys_serial}_{encode_hex(message)}_valid' + yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkeys': pubkeys_serial, + 'message': encode_hex(message), + 'signature': encode_hex(aggregate_signature), + }, + 'output': True, + } + + # Invalid signature -- extra pubkey + pubkeys_extra = pubkeys + [bls.G2Basic.PrivToPub(PRIVKEYS[-1])] + pubkeys_extra_serial = [encode_hex(pubkey) for pubkey in pubkeys] + full_name = f'{pubkeys_extra_serial}_{encode_hex(message)}_extra_pubkey' + yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkeys': pubkeys_extra_serial, + 'message': encode_hex(message), + 'signature': encode_hex(aggregate_signature), + }, + 'output': False, + } + + # Invalid signature -- tampered with signature + tampered_signature = aggregate_signature[:-4] + b'\xff\xff\xff\xff' + full_name = f'{pubkeys_serial}_{encode_hex(message)}_tampered_signature' + yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + 'input': { + 'pubkeys': pubkeys_serial, + 'message': encode_hex(message), + 'signature': encode_hex(tampered_signature), + }, + 'output': False, + } + + +def case09_aggregate_verify(): + pairs = [] + sigs = [] + for privkey, message in zip(PRIVKEYS, MESSAGES): + sig = bls.G2ProofOfPossession.Sign(privkey, message) + pubkey = bls.G2Basic.PrivToPub(privkey) + pairs.append({ + 'pubkey': encode_hex(pubkey), + 'message': encode_hex(message), + }) + sigs.append(sig) + + aggregate_signature = bls.G2ProofOfPossession.Aggregate(sigs) + yield f'fast_aggregate_verify_valid', { + 'input': { + 'pairs': pairs, + 'signature': encode_hex(aggregate_signature), + }, + 'output': True, + } + + tampered_signature = aggregate_signature[:4] + b'\xff\xff\xff\xff' + yield f'fast_aggregate_verify_tampered_signature', { + 'input': { + 'pairs': pairs, + 'signature': encode_hex(tampered_signature), + }, + 'output': False, + } + # TODO # Proof-of-possession @@ -196,7 +306,10 @@ if __name__ == "__main__": create_provider('msg_hash_uncompressed', case01_message_hash_G2_uncompressed), create_provider('msg_hash_compressed', case02_message_hash_G2_compressed), create_provider('priv_to_pub', case03_private_to_public_key), - create_provider('sign_msg', case04_sign_messages), + create_provider('sign_msg', case04_sign_message), + create_provider('verify_msg', case05_verify_message), create_provider('aggregate_sigs', case06_aggregate_sigs), create_provider('aggregate_pubkeys', case07_aggregate_pubkeys), + create_provider('fast_aggregate_verify', case08_fast_aggregate_verify), + create_provider('aggregate_verify', case09_aggregate_verify), ]) From dd9325d9fa3750d50d9a52c3da8657799f09ff09 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 22 Jan 2020 11:32:25 -0700 Subject: [PATCH 4/6] G2Basic to G2ProofOfPossession for private_to_public_key bls test generator Co-Authored-By: Carl Beekhuizen --- tests/generators/bls/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generators/bls/main.py b/tests/generators/bls/main.py index e6513e89f..6959fa746 100644 --- a/tests/generators/bls/main.py +++ b/tests/generators/bls/main.py @@ -115,7 +115,7 @@ def case02_message_hash_G2_compressed(): def case03_private_to_public_key(): - pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in PRIVKEYS] + pubkeys = [bls. G2ProofOfPossession.PrivToPub(privkey) for privkey in PRIVKEYS] pubkeys_serial = ['0x' + pubkey.hex() for pubkey in pubkeys] for privkey, pubkey_serial in zip(PRIVKEYS, pubkeys_serial): yield f'priv_to_pub_{int_to_hex(privkey)}', { From 3b80e12fc3ab3fbc22d00166bb803a9a40af530c Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 22 Jan 2020 17:56:50 -0700 Subject: [PATCH 5/6] only expose BLS tests for the used APIs --- tests/generators/bls/main.py | 77 +++++++----------------------------- 1 file changed, 15 insertions(+), 62 deletions(-) diff --git a/tests/generators/bls/main.py b/tests/generators/bls/main.py index 6959fa746..14a9f474d 100644 --- a/tests/generators/bls/main.py +++ b/tests/generators/bls/main.py @@ -94,42 +94,12 @@ def hash_message_compressed(msg: bytes) -> Tuple[str, str]: return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)] -def case01_message_hash_G2_uncompressed(): - for msg in MESSAGES: - yield f'uncom_g2_hash_{encode_hex(msg)}', { - 'input': { - 'message': encode_hex(msg), - }, - 'output': hash_message(msg) - } - - -def case02_message_hash_G2_compressed(): - for msg in MESSAGES: - yield f'com_g2_hash_{encode_hex(msg)}', { - 'input': { - 'message': encode_hex(msg), - }, - 'output': hash_message_compressed(msg) - } - - -def case03_private_to_public_key(): - pubkeys = [bls. G2ProofOfPossession.PrivToPub(privkey) for privkey in PRIVKEYS] - pubkeys_serial = ['0x' + pubkey.hex() for pubkey in pubkeys] - for privkey, pubkey_serial in zip(PRIVKEYS, pubkeys_serial): - yield f'priv_to_pub_{int_to_hex(privkey)}', { - 'input': int_to_hex(privkey), - 'output': pubkey_serial, - } - - -def case04_sign_message(): +def case01_sign(): for privkey in PRIVKEYS: for message in MESSAGES: sig = bls.G2ProofOfPossession.Sign(privkey, message) full_name = f'{int_to_hex(privkey)}_{encode_hex(message)}' - yield f'sign_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + yield f'sign_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { 'privkey': int_to_hex(privkey), 'message': encode_hex(message), @@ -138,14 +108,14 @@ def case04_sign_message(): } -def case05_verify_message(): +def case02_verify(): for i, privkey in enumerate(PRIVKEYS): for message in MESSAGES: # Valid signature signature = bls.G2ProofOfPossession.Sign(privkey, message) pubkey = bls.G2Basic.PrivToPub(privkey) full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_valid' - yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { 'pubkey': encode_hex(pubkey), 'message': encode_hex(message), @@ -157,7 +127,7 @@ def case05_verify_message(): # Invalid signatures -- wrong pubkey wrong_pubkey = bls.G2Basic.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)]) full_name = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}_wrong_pubkey' - yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { 'pubkey': encode_hex(wrong_pubkey), 'message': encode_hex(message), @@ -169,7 +139,7 @@ def case05_verify_message(): # Invalid signature -- tampered with signature tampered_signature = signature[:-4] + b'\xFF\xFF\xFF\xFF' full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_tampered_signature' - yield f'verify_msg_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { + yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { 'pubkey': encode_hex(pubkey), 'message': encode_hex(message), @@ -179,25 +149,16 @@ def case05_verify_message(): } -def case06_aggregate_sigs(): +def case03_aggregate(): for message in MESSAGES: sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in PRIVKEYS] - yield f'agg_sigs_{encode_hex(message)}', { + yield f'aggregate_{encode_hex(message)}', { 'input': [encode_hex(sig) for sig in sigs], 'output': encode_hex(bls.G2ProofOfPossession.Aggregate(sigs)), } -def case07_aggregate_pubkeys(): - pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in PRIVKEYS] - pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys] - yield f'agg_pub_keys', { - 'input': pubkeys_serial, - 'output': encode_hex(bls.G2ProofOfPossession._AggregatePKs(pubkeys)), - } - - -def case08_fast_aggregate_verify(): +def case04_fast_aggregate_verify(): for i, message in enumerate(MESSAGES): privkeys = PRIVKEYS[:i + 1] sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in privkeys] @@ -242,7 +203,7 @@ def case08_fast_aggregate_verify(): } -def case09_aggregate_verify(): +def case05_aggregate_verify(): pairs = [] sigs = [] for privkey, message in zip(PRIVKEYS, MESSAGES): @@ -273,10 +234,6 @@ def case09_aggregate_verify(): } -# TODO -# Proof-of-possession - - def create_provider(handler_name: str, test_case_fn: Callable[[], Iterable[Tuple[str, Dict[str, Any]]]]) -> gen_typing.TestProvider: @@ -303,13 +260,9 @@ def create_provider(handler_name: str, if __name__ == "__main__": gen_runner.run_generator("bls", [ - create_provider('msg_hash_uncompressed', case01_message_hash_G2_uncompressed), - create_provider('msg_hash_compressed', case02_message_hash_G2_compressed), - create_provider('priv_to_pub', case03_private_to_public_key), - create_provider('sign_msg', case04_sign_message), - create_provider('verify_msg', case05_verify_message), - create_provider('aggregate_sigs', case06_aggregate_sigs), - create_provider('aggregate_pubkeys', case07_aggregate_pubkeys), - create_provider('fast_aggregate_verify', case08_fast_aggregate_verify), - create_provider('aggregate_verify', case09_aggregate_verify), + create_provider('sign', case01_sign), + create_provider('verify', case02_verify), + create_provider('aggregate', case03_aggregate), + create_provider('fast_aggregate_verify', case04_fast_aggregate_verify), + create_provider('aggregate_verify', case05_aggregate_verify), ]) From 67763ae0e08803f95a337b7a9edcfb0376d94a3b Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 23 Jan 2020 10:32:12 -0700 Subject: [PATCH 6/6] PR feedback --- tests/generators/bls/main.py | 39 +++++------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/tests/generators/bls/main.py b/tests/generators/bls/main.py index 14a9f474d..a1f5835be 100644 --- a/tests/generators/bls/main.py +++ b/tests/generators/bls/main.py @@ -65,35 +65,6 @@ PRIVKEYS = [ ] -def hash_message(msg: bytes) -> Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]]: - """ - Hash message - Input: - - Message as bytes32 - Output: - - Message hash as a G2 point - """ - return [ - [ - int_to_hex(fq2.coeffs[0], F2Q_COEFF_LEN), - int_to_hex(fq2.coeffs[1], F2Q_COEFF_LEN), - ] - for fq2 in bls.hash_to_curve.hash_to_G2(msg, DST) - ] - - -def hash_message_compressed(msg: bytes) -> Tuple[str, str]: - """ - Hash message - Input: - - Message as bytes32 - Output: - - Message hash as a compressed G2 point - """ - z1, z2 = bls.point_compression.compress_G2(bls.hash_to_curve.hash_to_G2(msg, DST)) - return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)] - - def case01_sign(): for privkey in PRIVKEYS: for message in MESSAGES: @@ -113,7 +84,7 @@ def case02_verify(): for message in MESSAGES: # Valid signature signature = bls.G2ProofOfPossession.Sign(privkey, message) - pubkey = bls.G2Basic.PrivToPub(privkey) + pubkey = bls.G2ProofOfPossession.PrivToPub(privkey) full_name = f'{encode_hex(pubkey)}_{encode_hex(message)}_valid' yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { @@ -125,7 +96,7 @@ def case02_verify(): } # Invalid signatures -- wrong pubkey - wrong_pubkey = bls.G2Basic.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)]) + wrong_pubkey = bls.G2ProofOfPossession.PrivToPub(PRIVKEYS[(i + 1) % len(PRIVKEYS)]) full_name = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}_wrong_pubkey' yield f'verify_case_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { 'input': { @@ -163,7 +134,7 @@ def case04_fast_aggregate_verify(): privkeys = PRIVKEYS[:i + 1] sigs = [bls.G2ProofOfPossession.Sign(privkey, message) for privkey in privkeys] aggregate_signature = bls.G2ProofOfPossession.Aggregate(sigs) - pubkeys = [bls.G2Basic.PrivToPub(privkey) for privkey in privkeys] + pubkeys = [bls.G2ProofOfPossession.PrivToPub(privkey) for privkey in privkeys] pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys] # Valid signature @@ -178,7 +149,7 @@ def case04_fast_aggregate_verify(): } # Invalid signature -- extra pubkey - pubkeys_extra = pubkeys + [bls.G2Basic.PrivToPub(PRIVKEYS[-1])] + pubkeys_extra = pubkeys + [bls.G2ProofOfPossession.PrivToPub(PRIVKEYS[-1])] pubkeys_extra_serial = [encode_hex(pubkey) for pubkey in pubkeys] full_name = f'{pubkeys_extra_serial}_{encode_hex(message)}_extra_pubkey' yield f'fast_aggregate_verify_{(hash(bytes(full_name, "utf-8"))[:8]).hex()}', { @@ -208,7 +179,7 @@ def case05_aggregate_verify(): sigs = [] for privkey, message in zip(PRIVKEYS, MESSAGES): sig = bls.G2ProofOfPossession.Sign(privkey, message) - pubkey = bls.G2Basic.PrivToPub(privkey) + pubkey = bls.G2ProofOfPossession.PrivToPub(privkey) pairs.append({ 'pubkey': encode_hex(pubkey), 'message': encode_hex(message),