add test for sync aggregate with bad domain in signature
This commit is contained in:
parent
2aa5bf8384
commit
21aaab5a1e
|
@ -63,6 +63,29 @@ def get_committee_indices(spec, state, duplicates=False):
|
||||||
state.randao_mixes[randao_index] = hash(state.randao_mixes[randao_index])
|
state.randao_mixes[randao_index] = hash(state.randao_mixes[randao_index])
|
||||||
|
|
||||||
|
|
||||||
|
@with_altair_and_later
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_invalid_signature_bad_domain(spec, state):
|
||||||
|
committee_indices = compute_committee_indices(spec, state, state.current_sync_committee)
|
||||||
|
rng = random.Random(2020)
|
||||||
|
random_participant = rng.choice(committee_indices)
|
||||||
|
|
||||||
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
# Exclude one participant whose signature was included.
|
||||||
|
block.body.sync_aggregate = spec.SyncAggregate(
|
||||||
|
sync_committee_bits=[index != random_participant for index in committee_indices],
|
||||||
|
sync_committee_signature=compute_aggregate_sync_committee_signature(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
block.slot - 1,
|
||||||
|
committee_indices, # full committee signs
|
||||||
|
domain_type=spec.DOMAIN_BEACON_ATTESTER,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
yield from run_sync_committee_processing(spec, state, block, expect_exception=True)
|
||||||
|
|
||||||
|
|
||||||
@with_altair_and_later
|
@with_altair_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
@always_bls
|
@always_bls
|
||||||
|
|
|
@ -7,8 +7,10 @@ from eth2spec.test.helpers.block import (
|
||||||
from eth2spec.utils import bls
|
from eth2spec.utils import bls
|
||||||
|
|
||||||
|
|
||||||
def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None):
|
def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None, domain_type=None):
|
||||||
domain = spec.get_domain(state, spec.DOMAIN_SYNC_COMMITTEE, spec.compute_epoch_at_slot(slot))
|
if not domain_type:
|
||||||
|
domain_type = spec.DOMAIN_SYNC_COMMITTEE
|
||||||
|
domain = spec.get_domain(state, domain_type, spec.compute_epoch_at_slot(slot))
|
||||||
if block_root is None:
|
if block_root is None:
|
||||||
if slot == state.slot:
|
if slot == state.slot:
|
||||||
block_root = build_empty_block_for_next_slot(spec, state).parent_root
|
block_root = build_empty_block_for_next_slot(spec, state).parent_root
|
||||||
|
@ -18,7 +20,7 @@ def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None
|
||||||
return bls.Sign(privkey, signing_root)
|
return bls.Sign(privkey, signing_root)
|
||||||
|
|
||||||
|
|
||||||
def compute_aggregate_sync_committee_signature(spec, state, slot, participants, block_root=None):
|
def compute_aggregate_sync_committee_signature(spec, state, slot, participants, block_root=None, domain_type=None):
|
||||||
if len(participants) == 0:
|
if len(participants) == 0:
|
||||||
return spec.G2_POINT_AT_INFINITY
|
return spec.G2_POINT_AT_INFINITY
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ def compute_aggregate_sync_committee_signature(spec, state, slot, participants,
|
||||||
slot,
|
slot,
|
||||||
privkey,
|
privkey,
|
||||||
block_root=block_root,
|
block_root=block_root,
|
||||||
|
domain_type=domain_type,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return bls.Aggregate(signatures)
|
return bls.Aggregate(signatures)
|
||||||
|
|
Loading…
Reference in New Issue