Merge pull request #1209 from ethereum/early_secret_test

Resolves issue in early_secret_reveal() testing
This commit is contained in:
Carl Beekhuizen 2019-06-28 11:58:40 +02:00 committed by GitHub
commit 0ba933e088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions

View File

@ -211,7 +211,7 @@ class EarlyDerivedSecretReveal(Container):
# Index of the validator who revealed (whistleblower) # Index of the validator who revealed (whistleblower)
masker_index: ValidatorIndex masker_index: ValidatorIndex
# Mask used to hide the actual reveal signature (prevent reveal from being stolen) # Mask used to hide the actual reveal signature (prevent reveal from being stolen)
mask: Bytes32 mask: Hash
``` ```
### Phase 0 container updates ### Phase 0 container updates

View File

@ -1,5 +1,6 @@
from eth2spec.test.helpers.keys import privkeys from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils.bls import bls_sign from eth2spec.utils.bls import bls_sign, bls_aggregate_signatures
from eth2spec.utils.hash_function import hash
def get_valid_early_derived_secret_reveal(spec, state, epoch=None): def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
@ -10,6 +11,7 @@ def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
if epoch is None: if epoch is None:
epoch = current_epoch + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING epoch = current_epoch + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING
# Generate the secret that is being revealed
reveal = bls_sign( reveal = bls_sign(
message_hash=spec.hash_tree_root(spec.Epoch(epoch)), message_hash=spec.hash_tree_root(spec.Epoch(epoch)),
privkey=privkeys[revealed_index], privkey=privkeys[revealed_index],
@ -19,20 +21,24 @@ def get_valid_early_derived_secret_reveal(spec, state, epoch=None):
message_epoch=epoch, message_epoch=epoch,
), ),
) )
mask = bls_sign( # Generate the mask (any random 32 bytes that don't reveal the masker's secret will do)
message_hash=spec.hash_tree_root(spec.Epoch(epoch)), mask = hash(reveal)
# Generate masker's signature on the mask
masker_signature = bls_sign(
message_hash=mask,
privkey=privkeys[masker_index], privkey=privkeys[masker_index],
domain=spec.get_domain( domain=spec.get_domain(
state=state, state=state,
domain_type=spec.DOMAIN_RANDAO, domain_type=spec.DOMAIN_RANDAO,
message_epoch=epoch, message_epoch=epoch,
), ),
)[:32] # TODO(Carl): mask is 32 bytes, and signature is 96? Correct to slice the first 32 out? )
masked_reveal = bls_aggregate_signatures([reveal, masker_signature])
return spec.EarlyDerivedSecretReveal( return spec.EarlyDerivedSecretReveal(
revealed_index=revealed_index, revealed_index=revealed_index,
epoch=epoch, epoch=epoch,
reveal=reveal, reveal=masked_reveal,
masker_index=masker_index, masker_index=masker_index,
mask=mask, mask=mask,
) )

View File

@ -1,7 +1,13 @@
from eth2spec.test.helpers.custody import get_valid_early_derived_secret_reveal 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.block import apply_empty_block
from eth2spec.test.helpers.state import next_epoch, get_balance 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): def run_early_derived_secret_reveal_processing(spec, state, randao_key_reveal, valid=True):
@ -36,6 +42,7 @@ def run_early_derived_secret_reveal_processing(spec, state, randao_key_reveal, v
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@always_bls
@spec_state_test @spec_state_test
def test_success(spec, state): def test_success(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state) randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state)
@ -44,6 +51,7 @@ def test_success(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@never_bls
@spec_state_test @spec_state_test
def test_reveal_from_current_epoch(spec, state): def test_reveal_from_current_epoch(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state)) randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state))
@ -52,6 +60,7 @@ def test_reveal_from_current_epoch(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@never_bls
@spec_state_test @spec_state_test
def test_reveal_from_past_epoch(spec, state): def test_reveal_from_past_epoch(spec, state):
next_epoch(spec, state) next_epoch(spec, state)
@ -62,6 +71,7 @@ def test_reveal_from_past_epoch(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@always_bls
@spec_state_test @spec_state_test
def test_reveal_with_custody_padding(spec, state): def test_reveal_with_custody_padding(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal( randao_key_reveal = get_valid_early_derived_secret_reveal(
@ -73,6 +83,7 @@ def test_reveal_with_custody_padding(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@always_bls
@spec_state_test @spec_state_test
def test_reveal_with_custody_padding_minus_one(spec, state): def test_reveal_with_custody_padding_minus_one(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal( randao_key_reveal = get_valid_early_derived_secret_reveal(
@ -84,6 +95,7 @@ def test_reveal_with_custody_padding_minus_one(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@never_bls
@spec_state_test @spec_state_test
def test_double_reveal(spec, state): def test_double_reveal(spec, state):
randao_key_reveal1 = get_valid_early_derived_secret_reveal( randao_key_reveal1 = get_valid_early_derived_secret_reveal(
@ -108,6 +120,7 @@ def test_double_reveal(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@never_bls
@spec_state_test @spec_state_test
def test_revealer_is_slashed(spec, state): def test_revealer_is_slashed(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state)) randao_key_reveal = get_valid_early_derived_secret_reveal(spec, state, spec.get_current_epoch(state))
@ -117,6 +130,7 @@ def test_revealer_is_slashed(spec, state):
@with_all_phases_except(['phase0']) @with_all_phases_except(['phase0'])
@never_bls
@spec_state_test @spec_state_test
def test_far_future_epoch(spec, state): def test_far_future_epoch(spec, state):
randao_key_reveal = get_valid_early_derived_secret_reveal( randao_key_reveal = get_valid_early_derived_secret_reveal(