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

Resolves issue in early_secret_reveal() testing #1209

Merged
merged 4 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 specs/core/1_custody-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class EarlyDerivedSecretReveal(Container):
# Index of the validator who revealed (whistleblower)
masker_index: ValidatorIndex
# Mask used to hide the actual reveal signature (prevent reveal from being stolen)
mask: Bytes32
mask: Hash
```

### Phase 0 container updates
Expand Down
13 changes: 9 additions & 4 deletions test_libs/pyspec/eth2spec/test/helpers/custody.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils.bls import bls_sign
from eth2spec.utils.bls import bls_sign, bls_aggregate_signatures


def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
Expand All @@ -10,6 +10,7 @@ def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
if epoch is None:
epoch = current_epoch + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING

# Generate the secret that is being revealed
reveal = bls_sign(
message_hash=spec.hash_tree_root(epoch),
privkey=privkeys[revealed_index],
Expand All @@ -19,20 +20,24 @@ def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
message_epoch=epoch,
),
)
mask = bls_sign(
message_hash=spec.hash_tree_root(epoch),
# Generate the mask (any random 32 bytes will do)
mask = reveal[:32]
CarlBeek marked this conversation as resolved.
Show resolved Hide resolved
# Generate masker's signature on the mask
masker_signature = bls_sign(
message_hash=mask,
privkey=privkeys[masker_index],
domain=spec.get_domain(
state=state,
domain_type=spec.DOMAIN_RANDAO,
message_epoch=epoch,
),
)
masked_reveal = bls_aggregate_signatures([reveal, masker_signature])

return spec.EarlyDerivedSecretReveal(
revealed_index=revealed_index,
epoch=epoch,
reveal=reveal,
reveal=masked_reveal,
masker_index=masker_index,
mask=mask,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from eth2spec.test.helpers.custody import get_valid_early_derived_secret_reveal
from eth2spec.test.helpers.block import apply_empty_block
from eth2spec.test.helpers.state import next_epoch, get_balance
from eth2spec.test.context import with_all_phases_except, spec_state_test, expect_assertion_error
from eth2spec.test.context import (
with_all_phases_except,
spec_state_test,
expect_assertion_error,
always_bls,
never_bls,
)


def run_early_derived_secret_reveal_processing(spec, state, randao_key_reveal, valid=True):
Expand Down Expand Up @@ -36,6 +42,7 @@ def run_early_derived_secret_reveal_processing(spec, state, randao_key_reveal, v


@with_all_phases_except(['phase0'])
@always_bls
@spec_state_test
def test_success(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state)
Expand All @@ -44,6 +51,7 @@ def test_success(spec, state):


@with_all_phases_except(['phase0'])
@never_bls
@spec_state_test
def test_reveal_from_current_epoch(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state))
Expand All @@ -52,6 +60,7 @@ def test_reveal_from_current_epoch(spec, state):


@with_all_phases_except(['phase0'])
@never_bls
@spec_state_test
def test_reveal_from_past_epoch(spec, state):
next_epoch(spec, state)
Expand All @@ -62,6 +71,7 @@ def test_reveal_from_past_epoch(spec, state):


@with_all_phases_except(['phase0'])
@always_bls
@spec_state_test
def test_reveal_with_custody_padding(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(
Expand All @@ -73,6 +83,7 @@ def test_reveal_with_custody_padding(spec, state):


@with_all_phases_except(['phase0'])
@always_bls
@spec_state_test
def test_reveal_with_custody_padding_minus_one(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(
Expand All @@ -84,6 +95,7 @@ def test_reveal_with_custody_padding_minus_one(spec, state):


@with_all_phases_except(['phase0'])
@never_bls
@spec_state_test
def test_double_reveal(spec, state):
randao_key_reveal1 = get_valid_early_derived_secret_reveal(
Expand All @@ -108,6 +120,7 @@ def test_double_reveal(spec, state):


@with_all_phases_except(['phase0'])
@never_bls
@spec_state_test
def test_revealer_is_slashed(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state))
Expand All @@ -117,6 +130,7 @@ def test_revealer_is_slashed(spec, state):


@with_all_phases_except(['phase0'])
@never_bls
@spec_state_test
def test_far_future_epoch(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(
Expand Down