Merge pull request #1300 from ethereum/new_py_ecc_domain

[hotfix] bump `py_ecc==1.7.1`
This commit is contained in:
Danny Ryan 2019-07-16 12:22:11 -06:00 committed by GitHub
commit 7bc4fb6e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 30 deletions

View File

@ -5,7 +5,9 @@ BLS test vectors generator
from typing import Tuple from typing import Tuple
from eth_utils import ( from eth_utils import (
to_tuple, int_to_big_endian encode_hex,
int_to_big_endian,
to_tuple,
) )
from gen_base import gen_runner, gen_suite, gen_typing from gen_base import gen_runner, gen_suite, gen_typing
@ -20,7 +22,7 @@ def int_to_hex(n: int, byte_length: int=None) -> str:
byte_value = int_to_big_endian(n) byte_value = int_to_big_endian(n)
if byte_length: if byte_length:
byte_value = byte_value.rjust(byte_length, b'\x00') byte_value = byte_value.rjust(byte_length, b'\x00')
return '0x' + byte_value.hex() return encode_hex(byte_value)
def hex_to_int(x: str) -> int: def hex_to_int(x: str) -> int:
@ -28,11 +30,9 @@ def hex_to_int(x: str) -> int:
DOMAINS = [ DOMAINS = [
0, b'\x00\x00\x00\x00\x00\x00\x00\x00',
1, b'\x00\x00\x00\x00\x00\x00\x00\x01',
1234, b'\xff\xff\xff\xff\xff\xff\xff\xff'
2**32-1,
2**64-1
] ]
MESSAGES = [ MESSAGES = [
@ -51,12 +51,12 @@ PRIVKEYS = [
def hash_message(msg: bytes, def hash_message(msg: bytes,
domain: int) ->Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]]: domain: bytes) ->Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]]:
""" """
Hash message Hash message
Input: Input:
- Message as bytes - Message as bytes32
- domain as uint64 - domain as bytes8
Output: Output:
- Message hash as a G2 point - Message hash as a G2 point
""" """
@ -69,12 +69,12 @@ def hash_message(msg: bytes,
] ]
def hash_message_compressed(msg: bytes, domain: int) -> Tuple[str, str]: def hash_message_compressed(msg: bytes, domain: bytes) -> Tuple[str, str]:
""" """
Hash message Hash message
Input: Input:
- Message as bytes - Message as bytes32
- domain as uint64 - domain as bytes8
Output: Output:
- Message hash as a compressed G2 point - Message hash as a compressed G2 point
""" """
@ -88,8 +88,8 @@ def case01_message_hash_G2_uncompressed():
for domain in DOMAINS: for domain in DOMAINS:
yield { yield {
'input': { 'input': {
'message': '0x' + msg.hex(), 'message': encode_hex(msg),
'domain': int_to_hex(domain, byte_length=8) 'domain': encode_hex(domain),
}, },
'output': hash_message(msg, domain) 'output': hash_message(msg, domain)
} }
@ -100,8 +100,8 @@ def case02_message_hash_G2_compressed():
for domain in DOMAINS: for domain in DOMAINS:
yield { yield {
'input': { 'input': {
'message': '0x' + msg.hex(), 'message': encode_hex(msg),
'domain': int_to_hex(domain, byte_length=8) 'domain': encode_hex(domain),
}, },
'output': hash_message_compressed(msg, domain) 'output': hash_message_compressed(msg, domain)
} }
@ -125,10 +125,10 @@ def case04_sign_messages():
yield { yield {
'input': { 'input': {
'privkey': int_to_hex(privkey), 'privkey': int_to_hex(privkey),
'message': '0x' + message.hex(), 'message': encode_hex(message),
'domain': int_to_hex(domain, byte_length=8) 'domain': encode_hex(domain),
}, },
'output': '0x' + sig.hex() 'output': encode_hex(sig)
} }
# TODO: case05_verify_messages: Verify messages signed in case04 # TODO: case05_verify_messages: Verify messages signed in case04
@ -141,17 +141,17 @@ def case06_aggregate_sigs():
for message in MESSAGES: for message in MESSAGES:
sigs = [bls.sign(message, privkey, domain) for privkey in PRIVKEYS] sigs = [bls.sign(message, privkey, domain) for privkey in PRIVKEYS]
yield { yield {
'input': ['0x' + sig.hex() for sig in sigs], 'input': [encode_hex(sig) for sig in sigs],
'output': '0x' + bls.aggregate_signatures(sigs).hex(), 'output': encode_hex(bls.aggregate_signatures(sigs)),
} }
@to_tuple @to_tuple
def case07_aggregate_pubkeys(): def case07_aggregate_pubkeys():
pubkeys = [bls.privtopub(privkey) for privkey in PRIVKEYS] pubkeys = [bls.privtopub(privkey) for privkey in PRIVKEYS]
pubkeys_serial = ['0x' + pubkey.hex() for pubkey in pubkeys] pubkeys_serial = [encode_hex(pubkey) for pubkey in pubkeys]
yield { yield {
'input': pubkeys_serial, 'input': pubkeys_serial,
'output': '0x' + bls.aggregate_pubkeys(pubkeys).hex(), 'output': encode_hex(bls.aggregate_pubkeys(pubkeys)),
} }

View File

@ -1,3 +1,3 @@
py-ecc==1.7.0 py_ecc==1.7.1
eth-utils==1.6.0 eth-utils==1.6.0
../../test_libs/gen_helpers ../../test_libs/gen_helpers

View File

@ -24,13 +24,13 @@ def only_with_bls(alt_return=None):
@only_with_bls(alt_return=True) @only_with_bls(alt_return=True)
def bls_verify(pubkey, message_hash, signature, domain): def bls_verify(pubkey, message_hash, signature, domain):
return bls.verify(message_hash=message_hash, pubkey=pubkey, return bls.verify(message_hash=message_hash, pubkey=pubkey,
signature=signature, domain=int.from_bytes(domain, byteorder='little')) signature=signature, domain=domain)
@only_with_bls(alt_return=True) @only_with_bls(alt_return=True)
def bls_verify_multiple(pubkeys, message_hashes, signature, domain): def bls_verify_multiple(pubkeys, message_hashes, signature, domain):
return bls.verify_multiple(pubkeys=pubkeys, message_hashes=message_hashes, return bls.verify_multiple(pubkeys=pubkeys, message_hashes=message_hashes,
signature=signature, domain=int.from_bytes(domain, byteorder='little')) signature=signature, domain=domain)
@only_with_bls(alt_return=STUB_PUBKEY) @only_with_bls(alt_return=STUB_PUBKEY)
@ -46,4 +46,4 @@ def bls_aggregate_signatures(signatures):
@only_with_bls(alt_return=STUB_SIGNATURE) @only_with_bls(alt_return=STUB_SIGNATURE)
def bls_sign(message_hash, privkey, domain): def bls_sign(message_hash, privkey, domain):
return bls.sign(message_hash=message_hash, privkey=privkey, return bls.sign(message_hash=message_hash, privkey=privkey,
domain=int.from_bytes(domain, byteorder='little')) domain=domain)

View File

@ -1,6 +1,6 @@
eth-utils>=1.3.0,<2 eth-utils>=1.3.0,<2
eth-typing>=2.1.0,<3.0.0 eth-typing>=2.1.0,<3.0.0
pycryptodome==3.7.3 pycryptodome==3.7.3
py_ecc>=1.6.0 py_ecc==1.7.1
dataclasses==0.6 dataclasses==0.6
ssz==0.1.0a10 ssz==0.1.0a10

View File

@ -8,7 +8,7 @@ setup(
"eth-utils>=1.3.0,<2", "eth-utils>=1.3.0,<2",
"eth-typing>=2.1.0,<3.0.0", "eth-typing>=2.1.0,<3.0.0",
"pycryptodome==3.7.3", "pycryptodome==3.7.3",
"py_ecc>=1.6.0", "py_ecc==1.7.1",
"ssz==0.1.0a10", "ssz==0.1.0a10",
"dataclasses==0.6", "dataclasses==0.6",
] ]