From ddddc4ba9958833aad4e2724c33a94de5c49d93c Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 23 Jun 2020 02:06:27 +0200 Subject: [PATCH 1/2] attester slashing with 0 indices and out of bounds indices --- .../test_process_attester_slashing.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py index 063514498..724e5bf6f 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py @@ -197,6 +197,74 @@ def test_participants_already_slashed(spec, state): # Some of the following tests are phase0 only: phase 1 lists participants with bitfields instead of index list. +@with_phases([PHASE0]) +@spec_state_test +@always_bls +def test_att1_high_index(spec, state): + attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True) + + indices = get_indexed_attestation_participants(spec, attester_slashing.attestation_1) + indices.append(spec.ValidatorIndex(len(state.validators))) # off by 1 + attester_slashing.attestation_1.attesting_indices = indices + + yield from run_attester_slashing_processing(spec, state, attester_slashing, False) + + +@with_phases([PHASE0]) +@spec_state_test +@always_bls +def test_att2_high_index(spec, state): + attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True) + + indices = get_indexed_attestation_participants(spec, attester_slashing.attestation_2) + indices.append(spec.ValidatorIndex(len(state.validators))) # off by 1 + attester_slashing.attestation_2.attesting_indices = indices + + yield from run_attester_slashing_processing(spec, state, attester_slashing, False) + + +EMPTY_SIGNATURE = b'\xc0' + (b'\x00' * 95) + + +@with_phases([PHASE0]) +@spec_state_test +@always_bls +def test_att1_empty_indices(spec, state): + attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=True) + + attester_slashing.attestation_1.attesting_indices = [] + attester_slashing.attestation_1.signature = EMPTY_SIGNATURE + + yield from run_attester_slashing_processing(spec, state, attester_slashing, False) + + +@with_phases([PHASE0]) +@spec_state_test +@always_bls +def test_att2_empty_indices(spec, state): + attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=False) + + attester_slashing.attestation_2.attesting_indices = [] + attester_slashing.attestation_2.signature = EMPTY_SIGNATURE + + yield from run_attester_slashing_processing(spec, state, attester_slashing, False) + + +@with_phases([PHASE0]) +@spec_state_test +@always_bls +def test_all_empty_indices(spec, state): + attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=False) + + attester_slashing.attestation_1.attesting_indices = [] + attester_slashing.attestation_1.signature = EMPTY_SIGNATURE + + attester_slashing.attestation_2.attesting_indices = [] + attester_slashing.attestation_2.signature = EMPTY_SIGNATURE + + yield from run_attester_slashing_processing(spec, state, attester_slashing, False) + + @with_phases([PHASE0]) @spec_state_test @always_bls From 4bf10be4ffd8a8b344240918fee69b4c21507338 Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 23 Jun 2020 21:14:43 +0200 Subject: [PATCH 2/2] use BLS constant for special signature --- .../test_process_attester_slashing.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py index 724e5bf6f..192e0390d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py @@ -223,9 +223,6 @@ def test_att2_high_index(spec, state): yield from run_attester_slashing_processing(spec, state, attester_slashing, False) -EMPTY_SIGNATURE = b'\xc0' + (b'\x00' * 95) - - @with_phases([PHASE0]) @spec_state_test @always_bls @@ -233,7 +230,7 @@ def test_att1_empty_indices(spec, state): attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=True) attester_slashing.attestation_1.attesting_indices = [] - attester_slashing.attestation_1.signature = EMPTY_SIGNATURE + attester_slashing.attestation_1.signature = spec.bls.Z2_SIGNATURE yield from run_attester_slashing_processing(spec, state, attester_slashing, False) @@ -245,7 +242,7 @@ def test_att2_empty_indices(spec, state): attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=False) attester_slashing.attestation_2.attesting_indices = [] - attester_slashing.attestation_2.signature = EMPTY_SIGNATURE + attester_slashing.attestation_2.signature = spec.bls.Z2_SIGNATURE yield from run_attester_slashing_processing(spec, state, attester_slashing, False) @@ -257,10 +254,10 @@ def test_all_empty_indices(spec, state): attester_slashing = get_valid_attester_slashing(spec, state, signed_1=False, signed_2=False) attester_slashing.attestation_1.attesting_indices = [] - attester_slashing.attestation_1.signature = EMPTY_SIGNATURE + attester_slashing.attestation_1.signature = spec.bls.Z2_SIGNATURE attester_slashing.attestation_2.attesting_indices = [] - attester_slashing.attestation_2.signature = EMPTY_SIGNATURE + attester_slashing.attestation_2.signature = spec.bls.Z2_SIGNATURE yield from run_attester_slashing_processing(spec, state, attester_slashing, False)