From 21aaab5a1e7c5c1b21c302ce24418e628dac03f0 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 1 Jul 2021 16:36:54 -0700 Subject: [PATCH] add test for sync aggregate with bad domain in signature --- .../test_process_sync_aggregate.py | 23 +++++++++++++++++++ .../eth2spec/test/helpers/sync_committee.py | 9 +++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_aggregate.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_aggregate.py index 1dbe435b9..4b2f6f738 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_aggregate.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_aggregate.py @@ -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 diff --git a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py index fa753db52..71be65044 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py +++ b/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py @@ -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)