39 lines
1.1 KiB
Python
Raw Normal View History

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):
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:
epoch = current_epoch + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING
2019-05-15 15:17:01 +02:00
reveal = bls.sign(
message_hash=spec.hash_tree_root(epoch),
2019-05-15 15:17:01 +02:00
privkey=privkeys[revealed_index],
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(
message_hash=spec.hash_tree_root(epoch),
2019-05-15 15:17:01 +02:00
privkey=privkeys[masker_index],
domain=spec.get_domain(
2019-05-15 15:17:01 +02:00
state=state,
domain_type=spec.DOMAIN_RANDAO,
message_epoch=epoch,
),
)
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,
)