Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into voith/eip-1767
Browse files Browse the repository at this point in the history
  • Loading branch information
voith committed Aug 30, 2019
2 parents fd60de6 + d2283a1 commit 6b6d224
Show file tree
Hide file tree
Showing 241 changed files with 7,367 additions and 9,566 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ jobs:
- image: circleci/python:3.7
environment:
TOXENV: py37-lint
py36-lint-eth2:
<<: *common
docker:
- image: circleci/python:3.6
environment:
TOXENV: py36-lint-eth2
py37-lint-eth2:
<<: *common
docker:
- image: circleci/python:3.7
environment:
TOXENV: py37-lint-eth2

py36-docs:
<<: *common
Expand Down Expand Up @@ -418,6 +430,8 @@ workflows:
- py36-long_run_integration

- py36-lint
- py36-lint-eth2
- py37-lint
- py37-lint-eth2

- docker-image-build-test
4 changes: 4 additions & 0 deletions .flake8-eth2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length= 100
exclude=
ignore=W503,E203
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ clean-pyc:
lint:
tox -epy3{6,5}-lint

lint-eth2:
tox -epy37-lint-eth2

test:
py.test --tb native tests

Expand Down
20 changes: 5 additions & 15 deletions eth2/_utils/bitfield.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cytoolz import (
curry,
)
from cytoolz import curry

from eth2.beacon.typing import Bitfield

from .tuple import update_tuple_item


Expand All @@ -12,13 +12,7 @@ def has_voted(bitfield: Bitfield, index: int) -> bool:

@curry
def set_voted(bitfield: Bitfield, index: int) -> Bitfield:
return Bitfield(
update_tuple_item(
bitfield,
index,
True,
)
)
return Bitfield(update_tuple_item(bitfield, index, True))


def get_bitfield_length(bit_count: int) -> int:
Expand All @@ -32,9 +26,5 @@ def get_empty_bitfield(bit_count: int) -> Bitfield:

def get_vote_count(bitfield: Bitfield) -> int:
return len(
tuple(
index
for index in range(len(bitfield))
if has_voted(bitfield, index)
)
tuple(index for index in range(len(bitfield)) if has_voted(bitfield, index))
)
91 changes: 39 additions & 52 deletions eth2/_utils/bls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
from typing import (
Sequence,
Type,
)

from eth_typing import (
BLSPubkey,
BLSSignature,
Hash32,
)
from typing import Sequence, Type

from eth_typing import BLSPubkey, BLSSignature, Hash32
from py_ecc.bls.typing import Domain

from eth2.beacon.exceptions import (
SignatureError,
)
from eth2.beacon.exceptions import SignatureError

from .backends import (
DEFAULT_BACKEND,
NoOpBackend,
)
from .backends.base import (
BaseBLSBackend,
)
from .backends import DEFAULT_BACKEND, NoOpBackend
from .backends.base import BaseBLSBackend
from .validation import (
validate_many_public_keys,
validate_private_key,
validate_signature,
validate_public_key,
validate_many_public_keys,
validate_signature,
)


Expand All @@ -49,51 +34,51 @@ def use_noop_backend(cls) -> None:
cls.use(NoOpBackend)

@classmethod
def privtopub(cls,
privkey: int) -> BLSPubkey:
def privtopub(cls, privkey: int) -> BLSPubkey:
validate_private_key(privkey)
return cls.backend.privtopub(privkey)

@classmethod
def sign(cls,
message_hash: Hash32,
privkey: int,
domain: Domain) -> BLSSignature:
def sign(cls, message_hash: Hash32, privkey: int, domain: Domain) -> BLSSignature:
validate_private_key(privkey)
return cls.backend.sign(message_hash, privkey, domain)

@classmethod
def aggregate_signatures(cls,
signatures: Sequence[BLSSignature]) -> BLSSignature:
def aggregate_signatures(cls, signatures: Sequence[BLSSignature]) -> BLSSignature:
return cls.backend.aggregate_signatures(signatures)

@classmethod
def aggregate_pubkeys(cls,
pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
def aggregate_pubkeys(cls, pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
return cls.backend.aggregate_pubkeys(pubkeys)

@classmethod
def verify(cls,
message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain) -> bool:
def verify(
cls,
message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain,
) -> bool:
return cls.backend.verify(message_hash, pubkey, signature, domain)

@classmethod
def verify_multiple(cls,
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain) -> bool:
def verify_multiple(
cls,
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain,
) -> bool:
return cls.backend.verify_multiple(pubkeys, message_hashes, signature, domain)

@classmethod
def validate(cls,
message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain) -> None:
def validate(
cls,
message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain,
) -> None:
if cls.backend != NoOpBackend:
validate_signature(signature)
validate_public_key(pubkey)
Expand All @@ -108,11 +93,13 @@ def validate(cls,
)

@classmethod
def validate_multiple(cls,
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain) -> None:
def validate_multiple(
cls,
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain,
) -> None:
if cls.backend != NoOpBackend:
validate_signature(signature)
validate_many_public_keys(pubkeys)
Expand Down
10 changes: 4 additions & 6 deletions eth2/_utils/bls/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from typing import Tuple, Type # noqa: F401

from .base import BaseBLSBackend # noqa: F401
from .noop import NoOpBackend
from .py_ecc import PyECCBackend
from .base import BaseBLSBackend # noqa: F401
from typing import ( # noqa: F401
Type,
Tuple,
)


AVAILABLE_BACKENDS = (
NoOpBackend,
Expand All @@ -18,13 +14,15 @@

try:
from .milagro import MilagroBackend

DEFAULT_BACKEND = MilagroBackend
AVAILABLE_BACKENDS += (MilagroBackend,)
except ImportError:
pass

try:
from .chia import ChiaBackend

AVAILABLE_BACKENDS += (ChiaBackend,)
except ImportError:
pass
37 changes: 13 additions & 24 deletions eth2/_utils/bls/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
from abc import (
ABC,
abstractmethod,
)
from typing import (
Sequence,
)

from eth_typing import (
BLSPubkey,
BLSSignature,
Hash32,
)
from abc import ABC, abstractmethod
from typing import Sequence

from eth_typing import BLSPubkey, BLSSignature, Hash32
from py_ecc.bls.typing import Domain


Expand All @@ -23,17 +13,14 @@ def privtopub(k: int) -> BLSPubkey:

@staticmethod
@abstractmethod
def sign(message_hash: Hash32,
privkey: int,
domain: Domain) -> BLSSignature:
def sign(message_hash: Hash32, privkey: int, domain: Domain) -> BLSSignature:
...

@staticmethod
@abstractmethod
def verify(message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain) -> bool:
def verify(
message_hash: Hash32, pubkey: BLSPubkey, signature: BLSSignature, domain: Domain
) -> bool:
...

@staticmethod
Expand All @@ -48,8 +35,10 @@ def aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:

@staticmethod
@abstractmethod
def verify_multiple(pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain) -> bool:
def verify_multiple(
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain,
) -> bool:
...
36 changes: 13 additions & 23 deletions eth2/_utils/bls/backends/chia/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
from typing import (
Sequence,
)

from eth_typing import (
BLSPubkey,
BLSSignature,
Hash32,
)
from typing import Sequence

from eth_typing import BLSPubkey, BLSSignature, Hash32
from py_ecc.bls.typing import Domain

from eth2._utils.bls.backends.base import (
BaseBLSBackend,
)
from eth2._utils.bls.backends.base import BaseBLSBackend

from .api import (
aggregate_pubkeys,
Expand All @@ -30,16 +21,13 @@ def privtopub(k: int) -> BLSPubkey:
return privtopub(k)

@staticmethod
def sign(message_hash: Hash32,
privkey: int,
domain: Domain) -> BLSSignature:
def sign(message_hash: Hash32, privkey: int, domain: Domain) -> BLSSignature:
return sign(message_hash, privkey, domain)

@staticmethod
def verify(message_hash: Hash32,
pubkey: BLSPubkey,
signature: BLSSignature,
domain: Domain) -> bool:
def verify(
message_hash: Hash32, pubkey: BLSPubkey, signature: BLSSignature, domain: Domain
) -> bool:
return verify(message_hash, pubkey, signature, domain)

@staticmethod
Expand All @@ -51,8 +39,10 @@ def aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
return aggregate_pubkeys(pubkeys)

@staticmethod
def verify_multiple(pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain) -> bool:
def verify_multiple(
pubkeys: Sequence[BLSPubkey],
message_hashes: Sequence[Hash32],
signature: BLSSignature,
domain: Domain,
) -> bool:
return verify_multiple(pubkeys, message_hashes, signature, domain)
Loading

0 comments on commit 6b6d224

Please sign in to comment.