Skip to content

Commit

Permalink
Rm forkchoice attestation verification (#8301)
Browse files Browse the repository at this point in the history
* Rm fork choice attestation sig verification

* Unit test

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 20, 2021
1 parent 7c59615 commit ffcadcf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 4 additions & 5 deletions beacon-chain/blockchain/process_attestation.go
Expand Up @@ -39,7 +39,6 @@ var ErrTargetRootNotInDB = errors.New("target root does not exist in db")
//
// # Update latest messages for attesting indices
// update_latest_messages(store, indexed_attestation.attesting_indices, attestation)
// TODO(#6072): This code path is highly untested. Requires comprehensive tests and simpler refactoring.
func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]uint64, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.onAttestation")
defer span.End()
Expand Down Expand Up @@ -84,14 +83,14 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui
}

// Use the target state to validate attestation and calculate the committees.
indexedAtt, err := s.verifyAttestation(ctx, baseState, a)
indexedAtt, err := s.verifyAttestationIndices(ctx, baseState, a)
if err != nil {
return nil, err
}

if indexedAtt.AttestingIndices == nil {
return nil, errors.New("nil attesting indices")
}
// 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
// We assume trusted attestation in this function has verified signature.

// Update forkchoice store with the new attestation for updating weight.
s.forkChoiceStore.ProcessAttestation(ctx, indexedAtt.AttestingIndices, bytesutil.ToBytes32(a.Data.BeaconBlockRoot), a.Data.Target.Epoch)
Expand Down
9 changes: 4 additions & 5 deletions beacon-chain/blockchain/process_attestation_helpers.go
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
Expand Down Expand Up @@ -105,8 +104,8 @@ func (s *Service) verifyBeaconBlock(ctx context.Context, data *ethpb.Attestation
return nil
}

// verifyAttestation validates input attestation is valid.
func (s *Service) verifyAttestation(ctx context.Context, baseState *stateTrie.BeaconState, a *ethpb.Attestation) (*ethpb.IndexedAttestation, error) {
// 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
Expand All @@ -115,8 +114,8 @@ func (s *Service) verifyAttestation(ctx context.Context, baseState *stateTrie.Be
if err != nil {
return nil, err
}
if err := blocks.VerifyIndexedAttestation(ctx, baseState, indexedAtt); err != nil {
return nil, errors.Wrap(err, "could not verify indexed attestation")
if err := attestationutil.IsValidAttestationIndices(ctx, indexedAtt); err != nil {
return nil, err
}
return indexedAtt, nil
}
2 changes: 1 addition & 1 deletion shared/attestationutil/attestation_utils.go
Expand Up @@ -149,7 +149,7 @@ func IsValidAttestationIndices(ctx context.Context, indexedAttestation *ethpb.In
ctx, span := trace.StartSpan(ctx, "attestationutil.IsValidAttestationIndices")
defer span.End()

if indexedAttestation == nil || indexedAttestation.Data == nil || indexedAttestation.Data.Target == nil {
if indexedAttestation == nil || indexedAttestation.Data == nil || indexedAttestation.Data.Target == nil || indexedAttestation.AttestingIndices == nil {
return errors.New("nil or missing indexed attestation data")
}
indices := indexedAttestation.AttestingIndices
Expand Down
10 changes: 10 additions & 0 deletions shared/attestationutil/attestation_utils_test.go
Expand Up @@ -67,6 +67,16 @@ func TestIsValidAttestationIndices(t *testing.T) {
att *eth.IndexedAttestation
wantedErr string
}{
{
name: "Indices should not be nil",
att: &eth.IndexedAttestation{
Data: &eth.AttestationData{
Target: &eth.Checkpoint{},
},
Signature: make([]byte, 96),
},
wantedErr: "nil or missing indexed attestation data",
},
{
name: "Indices should be non-empty",
att: &eth.IndexedAttestation{
Expand Down

0 comments on commit ffcadcf

Please sign in to comment.