From f668b2b43342e3fe0c93c24f91357a3f62111fc9 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Sat, 17 Jul 2021 16:26:18 +1000 Subject: [PATCH 1/3] Add tests for SyncAggregate with no participants and all zero signature. --- .../test_process_sync_aggregate.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 ad285f43c..effd01047 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 @@ -113,6 +113,21 @@ def test_invalid_signature_missing_participant(spec, state): yield from run_sync_committee_processing(spec, state, block, expect_exception=True) +@with_altair_and_later +@spec_state_test +@always_bls +def test_invalid_signature_no_participants(spec, state): + committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + + 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=[False for _ in committee_indices], + sync_committee_signature=b'\x00' * 96 + ) + yield from run_sync_committee_processing(spec, state, block, expect_exception=True) + + @with_altair_and_later @spec_state_test @always_bls From 11d54af89d382ea14de42593f87eaf82890c3d49 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Sat, 17 Jul 2021 16:34:41 +1000 Subject: [PATCH 2/3] Add test to confirm infinite signature is invalid when there are participants. --- .../test_process_sync_aggregate.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 effd01047..2557715e4 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 @@ -128,6 +128,21 @@ def test_invalid_signature_no_participants(spec, state): yield from run_sync_committee_processing(spec, state, block, expect_exception=True) +@with_altair_and_later +@spec_state_test +@always_bls +def test_invalid_signature_infinite_signature_with_participants(spec, state): + committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) + + 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=[True for _ in committee_indices], + sync_committee_signature=spec.G2_POINT_AT_INFINITY + ) + yield from run_sync_committee_processing(spec, state, block, expect_exception=True) + + @with_altair_and_later @spec_state_test @always_bls From f16cfe7c3a5933876d0e2b2006a8d5a57b9f3d03 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sat, 17 Jul 2021 14:46:25 +0200 Subject: [PATCH 3/3] update sync aggregate tests --- .../test_process_sync_aggregate.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 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 2557715e4..e4176ee58 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 @@ -117,27 +117,38 @@ def test_invalid_signature_missing_participant(spec, state): @spec_state_test @always_bls def test_invalid_signature_no_participants(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) - block = build_empty_block_for_next_slot(spec, state) - # Exclude one participant whose signature was included. + # No participants is an allowed case, but needs a specific signature, not the full-zeroed signature. block.body.sync_aggregate = spec.SyncAggregate( - sync_committee_bits=[False for _ in committee_indices], + sync_committee_bits=[False] * len(block.body.sync_aggregate.sync_committee_bits), sync_committee_signature=b'\x00' * 96 ) yield from run_sync_committee_processing(spec, state, block, expect_exception=True) +# No-participants, with valid signature, is tested in test_sync_committee_rewards_empty_participants already. + + +@with_altair_and_later +@spec_state_test +@always_bls +def test_invalid_signature_infinite_signature_with_all_participants(spec, state): + block = build_empty_block_for_next_slot(spec, state) + # Include all participants, try the special-case signature for no-participants + block.body.sync_aggregate = spec.SyncAggregate( + sync_committee_bits=[True] * len(block.body.sync_aggregate.sync_committee_bits), + sync_committee_signature=spec.G2_POINT_AT_INFINITY + ) + yield from run_sync_committee_processing(spec, state, block, expect_exception=True) + @with_altair_and_later @spec_state_test @always_bls -def test_invalid_signature_infinite_signature_with_participants(spec, state): - committee_indices = compute_committee_indices(spec, state, state.current_sync_committee) - +def test_invalid_signature_infinite_signature_with_single_participant(spec, state): block = build_empty_block_for_next_slot(spec, state) - # Exclude one participant whose signature was included. + # Try include a single participant with the special-case signature for no-participants. block.body.sync_aggregate = spec.SyncAggregate( - sync_committee_bits=[True for _ in committee_indices], + sync_committee_bits=[True] + ([False] * (len(block.body.sync_aggregate.sync_committee_bits) - 1)), sync_committee_signature=spec.G2_POINT_AT_INFINITY ) yield from run_sync_committee_processing(spec, state, block, expect_exception=True)