34 lines
1.0 KiB
Python
Raw Normal View History

2019-08-01 14:22:01 +08:00
from eth2spec.test.helpers.keys import privkeys
from eth2spec.utils.bls import (
2019-12-17 12:04:56 +02:00
Aggregate,
Sign,
2019-08-01 14:22:01 +08:00
)
2019-09-27 13:02:16 +09:00
def sign_shard_attestation(spec, beacon_state, shard_state, block, participants):
2019-08-01 14:22:01 +08:00
signatures = []
2019-09-27 13:02:16 +09:00
message_hash = spec.ShardAttestationData(
slot=block.slot,
parent_root=block.parent_root,
).hash_tree_root()
block_epoch = spec.compute_epoch_of_shard_slot(block.slot)
2019-08-01 14:22:01 +08:00
for validator_index in participants:
privkey = privkeys[validator_index]
signatures.append(
get_attestation_signature(
spec,
beacon_state,
2019-09-27 13:02:16 +09:00
shard_state,
2019-08-01 14:22:01 +08:00
message_hash,
block_epoch,
privkey,
)
)
2019-12-17 12:04:56 +02:00
return Aggregate(signatures)
2019-08-01 14:22:01 +08:00
2019-09-27 13:02:16 +09:00
def get_attestation_signature(spec, beacon_state, shard_state, message_hash, block_epoch, privkey):
2019-12-17 12:30:46 +02:00
domain = spec.get_domain(beacon_state, spec.DOMAIN_SHARD_ATTESTER, block_epoch)
2019-12-17 12:04:56 +02:00
message = spec.compute_domain_wrapper(message_hash, domain)
return Sign(privkey, message)