Skip to content

Commit

Permalink
Refactor verifyAttestationIndices method (#8309)
Browse files Browse the repository at this point in the history
* Refactor verifyAttestationIndices

* Conflict

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
  • Loading branch information
terencechain and rauljordan committed Jan 22, 2021
1 parent 7842fd9 commit c5e9b1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
12 changes: 10 additions & 2 deletions beacon-chain/blockchain/process_attestation.go
Expand Up @@ -7,6 +7,7 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/timeutils"
Expand Down Expand Up @@ -82,11 +83,18 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) error
return err
}

// Use the target state to validate attestation and calculate the committees.
indexedAtt, err := s.verifyAttestationIndices(ctx, baseState, a)
// Use the target state to verify attesting indices are valid.
committee, err := helpers.BeaconCommitteeFromState(baseState, a.Data.Slot, a.Data.CommitteeIndex)
if err != nil {
return err
}
indexedAtt, err := attestationutil.ConvertToIndexed(ctx, a, committee)
if err != nil {
return err
}
if err := attestationutil.IsValidAttestationIndices(ctx, indexedAtt); err != nil {
return err
}

// Note that signature verification is ignored here because it was performed in sync's validation pipeline:
// validate_aggregate_proof.go and validate_beacon_attestation.go
Expand Down
17 changes: 0 additions & 17 deletions beacon-chain/blockchain/process_attestation_helpers.go
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/mputil"
"github.com/prysmaticlabs/prysm/shared/params"
Expand Down Expand Up @@ -102,19 +101,3 @@ func (s *Service) verifyBeaconBlock(ctx context.Context, data *ethpb.Attestation
}
return nil
}

// verifyAttestationIndices validates input attestation has valid attesting indices.
func (s *Service) verifyAttestationIndices(ctx context.Context, baseState *stateTrie.BeaconState, a *ethpb.Attestation) (*ethpb.IndexedAttestation, error) {
committee, err := helpers.BeaconCommitteeFromState(baseState, a.Data.Slot, a.Data.CommitteeIndex)
if err != nil {
return nil, err
}
indexedAtt, err := attestationutil.ConvertToIndexed(ctx, a, committee)
if err != nil {
return nil, err
}
if err := attestationutil.IsValidAttestationIndices(ctx, indexedAtt); err != nil {
return nil, err
}
return indexedAtt, nil
}

0 comments on commit c5e9b1e

Please sign in to comment.