diff --git a/cl/phase1/network/services/attestation_service.go b/cl/phase1/network/services/attestation_service.go index f30fb62326e..d1a150773c1 100644 --- a/cl/phase1/network/services/attestation_service.go +++ b/cl/phase1/network/services/attestation_service.go @@ -112,7 +112,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, targetEpoch uint64 signature [96]byte data *solid.AttestationData - attestation *solid.Attestation attHashKey [32]byte ) if att.Attestation != nil { @@ -135,7 +134,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, if err != nil { return err } - attestation = att.SingleAttestation.ToAttestation(memberIndexInCommittee) } else { // deneb and before case root = att.Attestation.Data.BeaconBlockRoot @@ -148,7 +146,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, if err != nil { return err } - attestation = att.Attestation } if _, ok := s.attestationProcessed.Get(attHashKey); ok { @@ -168,8 +165,9 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, } var ( - domain []byte - pubKey common.Bytes48 + domain []byte + pubKey common.Bytes48 + attestation *solid.Attestation // SingleAttestation will be transformed to Attestation struct with given member index in committee ) if err := s.syncedDataManager.ViewHeadState(func(headState *state.CachingBeaconState) error { // [REJECT] The committee index is within the expected range @@ -220,6 +218,7 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, return errors.New("on bit index out of committee range") } vIndex = beaconCommittee[onBitIndex] + attestation = att.Attestation } else { // electra and after // [REJECT] attestation.data.index == 0 @@ -227,10 +226,12 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64, return errors.New("committee index must be 0") } // [REJECT] The attester is a member of the committee -- i.e. attestation.attester_index in get_beacon_committee(state, attestation.data.slot, index). - if !contains(att.SingleAttestation.AttesterIndex, beaconCommittee) { + memIndexInCommittee := contains(att.SingleAttestation.AttesterIndex, beaconCommittee) + if memIndexInCommittee < 0 { return errors.New("attester is not a member of the committee") } vIndex = att.SingleAttestation.AttesterIndex + attestation = att.SingleAttestation.ToAttestation(memIndexInCommittee) } // [IGNORE] There has been no other valid attestation seen on an attestation subnet that has an identical attestation.data.target.epoch and participating validator index. // mark the validator as seen @@ -360,11 +361,11 @@ func (a *attestationService) loop(ctx context.Context) { } } -func contains[T comparable](target T, slices []T) bool { - for _, s := range slices { +func contains[T comparable](target T, slices []T) int { + for i, s := range slices { if s == target { - return true + return i } } - return false + return -1 }