2019-05-15 15:17:01 +02:00
|
|
|
from py_ecc import bls
|
|
|
|
|
2019-05-16 12:10:08 +02:00
|
|
|
from tests.phase0.helpers import *
|
2019-05-15 15:17:01 +02:00
|
|
|
|
|
|
|
def get_valid_early_derived_secret_reveal(state, epoch=None):
|
2019-05-20 18:14:37 +02:00
|
|
|
current_epoch = spec.get_current_epoch(state)
|
|
|
|
revealed_index = spec.get_active_validator_indices(state, current_epoch)[-1]
|
|
|
|
masker_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
2019-05-15 15:17:01 +02:00
|
|
|
|
|
|
|
if epoch is None:
|
2019-05-20 18:14:37 +02:00
|
|
|
epoch = current_epoch + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING
|
2019-05-15 15:17:01 +02:00
|
|
|
|
|
|
|
reveal = bls.sign(
|
2019-05-20 18:14:37 +02:00
|
|
|
message_hash=spec.hash_tree_root(epoch),
|
2019-05-15 15:17:01 +02:00
|
|
|
privkey=privkeys[revealed_index],
|
2019-05-20 18:14:37 +02:00
|
|
|
domain=spec.get_domain(
|
2019-05-15 15:17:01 +02:00
|
|
|
state=state,
|
|
|
|
domain_type=spec.DOMAIN_RANDAO,
|
|
|
|
message_epoch=epoch,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
mask = bls.sign(
|
2019-05-20 18:14:37 +02:00
|
|
|
message_hash=spec.hash_tree_root(epoch),
|
2019-05-15 15:17:01 +02:00
|
|
|
privkey=privkeys[masker_index],
|
2019-05-20 18:14:37 +02:00
|
|
|
domain=spec.get_domain(
|
2019-05-15 15:17:01 +02:00
|
|
|
state=state,
|
|
|
|
domain_type=spec.DOMAIN_RANDAO,
|
|
|
|
message_epoch=epoch,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2019-05-20 18:14:37 +02:00
|
|
|
return spec.EarlyDerivedSecretReveal(
|
2019-05-15 15:17:01 +02:00
|
|
|
revealed_index=revealed_index,
|
|
|
|
epoch=epoch,
|
|
|
|
reveal=reveal,
|
|
|
|
masker_index=masker_index,
|
|
|
|
mask=mask,
|
|
|
|
)
|