py_ecc 2.0.0 baby!

This commit is contained in:
Carl Beekhuizen
2020-01-07 20:52:20 +01:00
parent 8948393e76
commit 12ea891ce5
5 changed files with 15 additions and 14 deletions

View File

@@ -590,6 +590,7 @@ Eth2 makes use of BLS signatures as specified in the [IETF draft BLS specificati
- `def Verify(PK: BLSPubkey, message: Bytes, signature: BLSSignature) -> bool`
- `def Aggregate(signatures: Sequence[BLSSignature]) -> BLSSignature`
- `def FastAggregateVerify(PKs: Sequence[BLSSignature], message: Bytes, signature: BLSSignature) -> bool`
- `def AggregateVerify(pairs: Sequence[PK: BLSSignature, message: Bytes], signature: BLSSignature) -> bool`
Within these specifications, BLS signatures are treated as a module for notational clarity, thus to verify a signature `bls.Verify(...)` is used.

View File

@@ -483,7 +483,7 @@ def process_early_derived_secret_reveal(state: BeaconState, reveal: EarlyDerived
domain = get_domain(state, DOMAIN_RANDAO, reveal.epoch)
signing_roots = [compute_signing_root(root, domain) for root in [hash_tree_root(reveal.epoch), reveal.mask]]
assert bls.AggregateVerify(pubkeys, signing_roots, reveal.reveal)
assert bls.AggregateVerify(zip(pubkeys, signing_roots), reveal.reveal)
if reveal.epoch >= get_current_epoch(state) + CUSTODY_PERIOD_TO_RANDAO_PADDING:
# Full slashing when the secret was revealed so early it may be a valid custody

View File

@@ -1,6 +1,6 @@
from py_ecc import bls
from py_ecc.bls import G2ProofOfPossession as bls
from eth2spec.phase0 import spec
privkeys = [i + 1 for i in range(spec.SLOTS_PER_EPOCH * 16)]
pubkeys = [bls.privtopub(privkey) for privkey in privkeys]
pubkeys = [bls.PrivToPub(privkey) for privkey in privkeys]
pubkey_to_privkey = {pubkey: privkey for privkey, pubkey in zip(privkeys, pubkeys)}

View File

@@ -1,11 +1,12 @@
from py_ecc import bls
from py_ecc.bls import G2ProofOfPossession as bls
from py_ecc.bls.g2_primatives import signature_to_G2 as _signature_to_G2
# Flag to make BLS active or not. Used for testing, do not ignore BLS in production unless you know what you are doing.
bls_active = True
STUB_SIGNATURE = b'\x11' * 96
STUB_PUBKEY = b'\x22' * 48
STUB_COORDINATES = bls.api.signature_to_G2(bls.sign(b"", 0, b"\0" * 8))
STUB_COORDINATES = _signature_to_G2(bls.Sign(0, b""))
def only_with_bls(alt_return=None):
@@ -24,30 +25,29 @@ def only_with_bls(alt_return=None):
@only_with_bls(alt_return=True)
def Verify(PK, message, signature):
return bls.verify(message_hash=message, pubkey=PK, signature=signature, domain=b'')
return bls.Verify(PK, message, signature)
@only_with_bls(alt_return=True)
def AggregateVerify(PKs, messages, signature):
return bls.verify_multiple(pubkeys=PKs, message_hashes=messages, signature=signature, domain=b'')
def AggregateVerify(pairs, signature):
return bls.AggregateVerify(pairs, signature)
@only_with_bls(alt_return=True)
def FastAggregateVerify(PKs, message, signature):
aggregate_pubkey = bls.aggregate_pubkeys(PKs)
return bls.verify(pubkey=aggregate_pubkey, message_hash=message, signature=signature, domain=b'')
return bls.FastAggregateVerify(PKs, message, signature)
@only_with_bls(alt_return=STUB_SIGNATURE)
def Aggregate(signatures):
return bls.aggregate_signatures(signatures)
return bls.Aggregate(signatures)
@only_with_bls(alt_return=STUB_SIGNATURE)
def Sign(SK, message):
return bls.sign(message_hash=message, privkey=SK, domain=b'')
return bls.Sign(SK, message)
@only_with_bls(alt_return=STUB_COORDINATES)
def signature_to_G2(signature):
return bls.api.signature_to_G2(signature)
return _signature_to_G2(signature)

View File

@@ -1,6 +1,6 @@
eth-utils>=1.3.0,<2
eth-typing>=2.1.0,<3.0.0
pycryptodome==3.9.4
py_ecc==1.7.1
py_ecc==2.0.0
dataclasses==0.6
ssz==0.1.3