add test for sync aggregate with bad domain in signature

This commit is contained in:
Alex Stokes 2021-07-01 16:36:54 -07:00
parent 2aa5bf8384
commit 21aaab5a1e
No known key found for this signature in database
GPG Key ID: 99B3D88FD6C55A69
2 changed files with 29 additions and 3 deletions

View File

@ -63,6 +63,29 @@ def get_committee_indices(spec, state, duplicates=False):
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
@spec_state_test
@always_bls

View File

@ -7,8 +7,10 @@ from eth2spec.test.helpers.block import (
from eth2spec.utils import bls
def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None):
domain = spec.get_domain(state, spec.DOMAIN_SYNC_COMMITTEE, spec.compute_epoch_at_slot(slot))
def compute_sync_committee_signature(spec, state, slot, privkey, block_root=None, domain_type=None):
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 slot == state.slot:
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)
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:
return spec.G2_POINT_AT_INFINITY
@ -32,6 +34,7 @@ def compute_aggregate_sync_committee_signature(spec, state, slot, participants,
slot,
privkey,
block_root=block_root,
domain_type=domain_type,
)
)
return bls.Aggregate(signatures)