Bump milagro_bls_binding to `1.4.0`, handle the exception cases
This commit is contained in:
parent
4613c6b333
commit
4d3ac72473
2
setup.py
2
setup.py
|
@ -537,7 +537,7 @@ setup(
|
||||||
"eth-typing>=2.1.0,<3.0.0",
|
"eth-typing>=2.1.0,<3.0.0",
|
||||||
"pycryptodome==3.9.4",
|
"pycryptodome==3.9.4",
|
||||||
"py_ecc==5.0.0",
|
"py_ecc==5.0.0",
|
||||||
"milagro_bls_binding==1.3.0",
|
"milagro_bls_binding==1.4.0",
|
||||||
"dataclasses==0.6",
|
"dataclasses==0.6",
|
||||||
"remerkleable==0.1.17",
|
"remerkleable==0.1.17",
|
||||||
"ruamel.yaml==0.16.5",
|
"ruamel.yaml==0.16.5",
|
||||||
|
|
|
@ -10,6 +10,7 @@ bls = py_ecc_bls
|
||||||
|
|
||||||
STUB_SIGNATURE = b'\x11' * 96
|
STUB_SIGNATURE = b'\x11' * 96
|
||||||
STUB_PUBKEY = b'\x22' * 48
|
STUB_PUBKEY = b'\x22' * 48
|
||||||
|
Z1_PUBKEY = b'\xc0' + b'\x00' * 47
|
||||||
Z2_SIGNATURE = b'\xc0' + b'\x00' * 95
|
Z2_SIGNATURE = b'\xc0' + b'\x00' * 95
|
||||||
STUB_COORDINATES = _signature_to_G2(Z2_SIGNATURE)
|
STUB_COORDINATES = _signature_to_G2(Z2_SIGNATURE)
|
||||||
|
|
||||||
|
@ -66,6 +67,11 @@ def AggregateVerify(pubkeys, messages, signature):
|
||||||
|
|
||||||
@only_with_bls(alt_return=True)
|
@only_with_bls(alt_return=True)
|
||||||
def FastAggregateVerify(pubkeys, message, signature):
|
def FastAggregateVerify(pubkeys, message, signature):
|
||||||
|
# TODO: remove it when milagro_bls_binding is fixed
|
||||||
|
# https://github.com/ChihChengLiang/milagro_bls_binding/issues/19
|
||||||
|
if Z1_PUBKEY in pubkeys:
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = bls.FastAggregateVerify(list(pubkeys), message, signature)
|
result = bls.FastAggregateVerify(list(pubkeys), message, signature)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -81,6 +87,9 @@ def Aggregate(signatures):
|
||||||
|
|
||||||
@only_with_bls(alt_return=STUB_SIGNATURE)
|
@only_with_bls(alt_return=STUB_SIGNATURE)
|
||||||
def Sign(SK, message):
|
def Sign(SK, message):
|
||||||
|
# TODO: remove it when https://github.com/sigp/milagro_bls/issues/39 is fixed
|
||||||
|
if SK == 0:
|
||||||
|
raise Exception("SK should not be zero")
|
||||||
if bls == py_ecc_bls:
|
if bls == py_ecc_bls:
|
||||||
return bls.Sign(SK, message)
|
return bls.Sign(SK, message)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -83,7 +83,8 @@ def case01_sign():
|
||||||
}
|
}
|
||||||
# Edge case: privkey == 0
|
# Edge case: privkey == 0
|
||||||
expect_exception(bls.Sign, ZERO_PRIVKEY, message)
|
expect_exception(bls.Sign, ZERO_PRIVKEY, message)
|
||||||
# expect_exception(milagro_bls.Sign, ZERO_PRIVKEY_BYTES, message) # TODO: enable it when milagro is ready
|
# TODO enable it when milagro_bls is ready for IETF BLS draft 04
|
||||||
|
# expect_exception(milagro_bls.Sign, ZERO_PRIVKEY_BYTES, message)
|
||||||
yield f'sign_case_zero_privkey', {
|
yield f'sign_case_zero_privkey', {
|
||||||
'input': {
|
'input': {
|
||||||
'privkey': encode_hex(ZERO_PRIVKEY_BYTES),
|
'privkey': encode_hex(ZERO_PRIVKEY_BYTES),
|
||||||
|
@ -147,7 +148,7 @@ def case02_verify():
|
||||||
|
|
||||||
# Invalid pubkey and signature with the point at infinity
|
# Invalid pubkey and signature with the point at infinity
|
||||||
assert not bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE)
|
assert not bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE)
|
||||||
# assert not milagro_bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE) # TODO: enable it when milagro is ready
|
assert not milagro_bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE)
|
||||||
yield f'verify_infinity_pubkey_and_infinity_signature', {
|
yield f'verify_infinity_pubkey_and_infinity_signature', {
|
||||||
'input': {
|
'input': {
|
||||||
'pubkey': encode_hex(Z1_PUBKEY),
|
'pubkey': encode_hex(Z1_PUBKEY),
|
||||||
|
@ -266,7 +267,7 @@ def case04_fast_aggregate_verify():
|
||||||
signatures = [bls.Sign(privkey, SAMPLE_MESSAGE) for privkey in PRIVKEYS]
|
signatures = [bls.Sign(privkey, SAMPLE_MESSAGE) for privkey in PRIVKEYS]
|
||||||
aggregate_signature = bls.Aggregate(signatures)
|
aggregate_signature = bls.Aggregate(signatures)
|
||||||
assert not bls.FastAggregateVerify(pubkeys_with_infinity, SAMPLE_MESSAGE, aggregate_signature)
|
assert not bls.FastAggregateVerify(pubkeys_with_infinity, SAMPLE_MESSAGE, aggregate_signature)
|
||||||
# TODO: enable it when milagro is ready
|
# TODO enable it when milagro_bls is ready for IETF BLS draft 04
|
||||||
# assert not milagro_bls.FastAggregateVerify(pubkeys_with_infinity, SAMPLE_MESSAGE, aggregate_signature)
|
# assert not milagro_bls.FastAggregateVerify(pubkeys_with_infinity, SAMPLE_MESSAGE, aggregate_signature)
|
||||||
yield f'fast_aggregate_verify_infinity_pubkey', {
|
yield f'fast_aggregate_verify_infinity_pubkey', {
|
||||||
'input': {
|
'input': {
|
||||||
|
@ -345,8 +346,7 @@ def case05_aggregate_verify():
|
||||||
pubkeys_with_infinity = pubkeys + [Z1_PUBKEY]
|
pubkeys_with_infinity = pubkeys + [Z1_PUBKEY]
|
||||||
messages_with_sample = messages + [SAMPLE_MESSAGE]
|
messages_with_sample = messages + [SAMPLE_MESSAGE]
|
||||||
assert not bls.AggregateVerify(pubkeys_with_infinity, messages_with_sample, aggregate_signature)
|
assert not bls.AggregateVerify(pubkeys_with_infinity, messages_with_sample, aggregate_signature)
|
||||||
# TODO: enable it when milagro is ready
|
assert not milagro_bls.AggregateVerify(pubkeys_with_infinity, messages_with_sample, aggregate_signature)
|
||||||
# assert not milagro_bls.AggregateVerify(pubkeys_with_infinity, messages_with_sample, aggregate_signature)
|
|
||||||
yield f'aggregate_verify_infinity_pubkey', {
|
yield f'aggregate_verify_infinity_pubkey', {
|
||||||
'input': {
|
'input': {
|
||||||
'pubkeys': [encode_hex(pubkey) for pubkey in pubkeys_with_infinity],
|
'pubkeys': [encode_hex(pubkey) for pubkey in pubkeys_with_infinity],
|
||||||
|
|
Loading…
Reference in New Issue