Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with signatures, fixes #1074 #1102

Merged
merged 38 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4f3f68b
signatures in tests, most block-ops updated, still many to go
protolambda May 11, 2019
904e2e9
BLS on/off deco
protolambda May 13, 2019
ce4daea
Merge branch 'bls-test-deco' into tests-with-sigs
protolambda May 15, 2019
51c82c5
clean up helpers, make helpers pkg
protolambda May 15, 2019
a4e2263
fix/update bls funcs for testing
protolambda May 15, 2019
e07f1bc
update imports to new helpers + fix up imports
protolambda May 15, 2019
5c3e760
update remaining imports
protolambda May 15, 2019
8a43ec0
add signing methods
protolambda May 15, 2019
4dad74e
attestation signing
protolambda May 15, 2019
a9069cb
attester slashing signing
protolambda May 15, 2019
b92a9d8
sign block headers
protolambda May 15, 2019
242bb8c
sign deposits
protolambda May 15, 2019
32efe49
proposer slashing signing
protolambda May 15, 2019
9f00e4f
sign transfers
protolambda May 15, 2019
eea6c8f
voluntary exit testing sigs
protolambda May 15, 2019
62999d8
import fixes + fix import loop + fix minor signing things
protolambda May 17, 2019
f937dec
more keys, more validators, fix import
protolambda May 17, 2019
183e3a5
minor refactor import fix
protolambda May 17, 2019
08d0ff9
fix attestation aggregate bitfields
protolambda May 17, 2019
0f00b43
reduce validator key count again, fix valid attestation creation - sn…
protolambda May 17, 2019
a10aba4
make valid attest creation fill aggregate bitfield
protolambda May 17, 2019
90bcbd6
fix attester slashing test
protolambda May 17, 2019
b0aea2a
bugfix block proc transfer test
protolambda May 20, 2019
ab251d4
make tests work fast + bls signed optionally
protolambda May 20, 2019
4d08e9d
signed block header
protolambda May 21, 2019
ee9c1d9
test tagging pattern
protolambda May 21, 2019
cfc037f
tags applied after generation of vector (and only if), make BLS decor…
protolambda May 21, 2019
8303c58
bugfix, make BLS wrapper propagate test output properly
protolambda May 21, 2019
f1ba5aa
make test generator use BLS
protolambda May 21, 2019
0e136b1
update yaml and eth-utils dependencies
protolambda May 21, 2019
6b3b512
fix header format of operations tests
protolambda May 21, 2019
12af078
make decorators return wrapped fn results properly
protolambda May 21, 2019
b919d08
comment on the deposit signature being soft-rejected
protolambda May 21, 2019
a4363ba
tests for invalid signatures
protolambda May 21, 2019
7d3147d
add inconsistent bitfields test
protolambda May 22, 2019
dad89ae
minor lint
djrtwo May 22, 2019
58fd712
fix style issue with deposit processing helper
protolambda May 22, 2019
958f71b
minor underflow fix for proposer slashing test
protolambda May 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/phase0/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def build_phase0_spec(sourcefile, outfile):
Tuple,
)
from eth2spec.utils.minimal_ssz import *
from eth2spec.utils.bls_stub import *
from eth2spec.utils.bls import *

""")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
Expand Down
3 changes: 2 additions & 1 deletion specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
amount = deposit.data.amount
validator_pubkeys = [v.pubkey for v in state.validator_registry]
if pubkey not in validator_pubkeys:
# Verify the deposit signature (proof of possession)
# Verify the deposit signature (proof of possession).
# Invalid signatures are allowed by the deposit contract, and hence included on-chain, but must not be processed.
if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, get_domain(state, DOMAIN_DEPOSIT)):
return

Expand Down
2 changes: 1 addition & 1 deletion test_generators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ It's recommended to extend the base-generator.

Create a `requirements.txt` in the root of your generator directory:
```
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
../../test_libs/config_helpers
../../test_libs/pyspec
Expand Down
2 changes: 1 addition & 1 deletion test_generators/bls/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
py-ecc==1.6.0
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
2 changes: 1 addition & 1 deletion test_generators/operations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
../../test_libs/config_helpers
../../test_libs/pyspec
4 changes: 2 additions & 2 deletions test_generators/operations/suite_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_from_tests(pkg):
for name in fn_names:
tfn = getattr(pkg, name)
try:
out.append(tfn(generator_mode=True))
out.append(tfn(generator_mode=True, bls_active=True))
except AssertionError:
print("ERROR: failed to generate vector from test: %s (pkg: %s)" % (name, pkg.__name__))
return out
Expand All @@ -34,6 +34,6 @@ def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput:
forks=["phase0"],
config=config_name,
runner="operations",
handler=config_name,
handler=operation_name,
test_cases=get_cases()))
return suite_definition
2 changes: 1 addition & 1 deletion test_generators/shuffling/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
../../test_libs/config_helpers
../../test_libs/pyspec
2 changes: 1 addition & 1 deletion test_generators/ssz_generic/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
../../test_libs/config_helpers
ssz==0.1.0a2
2 changes: 1 addition & 1 deletion test_generators/ssz_static/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eth-utils==1.4.1
eth-utils==1.6.0
../../test_libs/gen_helpers
../../test_libs/config_helpers
../../test_libs/pyspec
2 changes: 1 addition & 1 deletion test_libs/config_helpers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruamel.yaml==0.15.87
ruamel.yaml==0.15.96
2 changes: 1 addition & 1 deletion test_libs/config_helpers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
name='config_helpers',
packages=['preset_loader'],
install_requires=[
"ruamel.yaml==0.15.87"
"ruamel.yaml==0.15.96"
]
)
4 changes: 2 additions & 2 deletions test_libs/gen_helpers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ruamel.yaml==0.15.87
eth-utils==1.4.1
ruamel.yaml==0.15.96
eth-utils==1.6.0
4 changes: 2 additions & 2 deletions test_libs/gen_helpers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name='gen_helpers',
packages=['gen_base'],
install_requires=[
"ruamel.yaml==0.15.87",
"eth-utils==1.4.1"
"ruamel.yaml==0.15.96",
"eth-utils==1.6.0"
]
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from copy import deepcopy

import eth2spec.phase0.spec as spec

from eth2spec.phase0.state_transition import (
state_transition,
)
from eth2spec.phase0.spec import (
get_current_epoch,
process_attestation
)
from eth2spec.test.helpers import (
build_empty_block_for_next_slot,
from eth2spec.phase0.state_transition import (
state_transition_to,
)
from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls
from eth2spec.test.helpers.attestations import (
get_valid_attestation,
sign_attestation,
)
from eth2spec.test.helpers.state import (
next_epoch,
next_slot,
)

from eth2spec.test.context import spec_state_test, expect_assertion_error
from eth2spec.test.helpers.block import apply_empty_block


def run_attestation_processing(state, attestation, valid=True):
Expand Down Expand Up @@ -56,37 +57,44 @@ def run_attestation_processing(state, attestation, valid=True):

@spec_state_test
def test_success(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=True)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

yield from run_attestation_processing(state, attestation)


@spec_state_test
def test_success_previous_epoch(state):
attestation = get_valid_attestation(state)
block = build_empty_block_for_next_slot(state)
block.slot = state.slot + spec.SLOTS_PER_EPOCH
state_transition(state, block)
attestation = get_valid_attestation(state, signed=True)
next_epoch(state)
apply_empty_block(state)

yield from run_attestation_processing(state, attestation)


@always_bls
@spec_state_test
def test_invalid_attestation_signature(state):
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_before_inclusion_delay(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=True)
# do not increment slot to allow for inclusion delay

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_after_epoch_slots(state):
attestation = get_valid_attestation(state)
block = build_empty_block_for_next_slot(state)
attestation = get_valid_attestation(state, signed=True)
# increment past latest inclusion slot
block.slot = state.slot + spec.SLOTS_PER_EPOCH + 1
state_transition(state, block)
state_transition_to(state, state.slot + spec.SLOTS_PER_EPOCH + 1)
apply_empty_block(state)

yield from run_attestation_processing(state, attestation, False)

Expand All @@ -97,44 +105,52 @@ def test_old_source_epoch(state):
state.finalized_epoch = 2
state.previous_justified_epoch = 3
state.current_justified_epoch = 4
attestation = get_valid_attestation(state, slot=(spec.SLOTS_PER_EPOCH * 3) + 1)
attestation = get_valid_attestation(state, slot=(spec.SLOTS_PER_EPOCH * 3) + 1, signed=False)

# test logic sanity check: make sure the attestation is pointing to oldest known source epoch
assert attestation.data.source_epoch == state.previous_justified_epoch

# Now go beyond that, it will be invalid
attestation.data.source_epoch -= 1

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_wrong_shard(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.shard += 1

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_new_source_epoch(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.source_epoch += 1

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_source_root_is_target_root(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.source_root = attestation.data.target_root

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


Expand All @@ -149,7 +165,7 @@ def test_invalid_current_source_root(state):
state.current_justified_epoch = 4
state.current_justified_root = b'\xff' * 32

attestation = get_valid_attestation(state, slot=(spec.SLOTS_PER_EPOCH * 3) + 1)
attestation = get_valid_attestation(state, slot=(spec.SLOTS_PER_EPOCH * 3) + 1, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

# Test logic sanity checks:
Expand All @@ -159,56 +175,81 @@ def test_invalid_current_source_root(state):
# Make attestation source root invalid: should be previous justified, not current one
attestation.data.source_root = state.current_justified_root

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_bad_source_root(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.source_root = b'\x42' * 32

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_non_zero_crosslink_data_root(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.data.crosslink_data_root = b'\x42' * 32

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_bad_previous_crosslink(state):
next_epoch(state)
attestation = get_valid_attestation(state)
apply_empty_block(state)

attestation = get_valid_attestation(state, signed=True)
for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(state)
apply_empty_block(state)

state.current_crosslinks[attestation.data.shard].epoch += 10

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_inconsistent_bitfields(state):
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.custody_bitfield = deepcopy(attestation.aggregation_bitfield) + b'\x00'

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_non_empty_custody_bitfield(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.custody_bitfield = deepcopy(attestation.aggregation_bitfield)

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)


@spec_state_test
def test_empty_aggregation_bitfield(state):
attestation = get_valid_attestation(state)
attestation = get_valid_attestation(state, signed=False)
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY

attestation.aggregation_bitfield = b'\x00' * len(attestation.aggregation_bitfield)

sign_attestation(state, attestation)

yield from run_attestation_processing(state, attestation, False)
Loading