fixing electra attestation inconsistencies (#14331)

* fixing electra attestation inconsistencies

* adding dependencies

* removing helper circular dependency

* adding error

* simplifying function

* improving get committee index function

* fixing more instances of GetData().committeeIndex and fixing tests

* Update proto/prysm/v1alpha1/attestation.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* addressing feedback and fixing linting

* removing unused functions and associated tests

* fixing test error checks

* removing helpers.VerifyAttestationBitfieldLengths to reduce beaconCommitteeFromState calls

* small optimizations

* fixing linting

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
james-prysm
2024-08-14 10:24:53 -05:00
committed by GitHub
parent de2c866707
commit 6cb845660a
18 changed files with 170 additions and 446 deletions

View File

@@ -332,6 +332,7 @@ go_library(
"//proto/engine/v1:go_default_library",
"//proto/eth/ext:go_default_library",
"//runtime/version:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_grpc_ecosystem_grpc_gateway_v2//protoc-gen-openapiv2/options:options_go_proto",
"@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library",

View File

@@ -1,6 +1,9 @@
package eth
import (
"fmt"
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
@@ -21,6 +24,7 @@ type Att interface {
GetData() *AttestationData
CommitteeBitsVal() bitfield.Bitfield
GetSignature() []byte
GetCommitteeIndex() (primitives.CommitteeIndex, error)
}
// IndexedAtt defines common functionality for all indexed attestation types.
@@ -123,6 +127,14 @@ func (a *Attestation) CommitteeBitsVal() bitfield.Bitfield {
return cb
}
// GetCommitteeIndex --
func (a *Attestation) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
if a == nil || a.Data == nil {
return 0, errors.New("nil attestation data")
}
return a.Data.CommitteeIndex, nil
}
// Version --
func (a *PendingAttestation) Version() int {
return version.Phase0
@@ -156,6 +168,14 @@ func (a *PendingAttestation) GetSignature() []byte {
return nil
}
// GetCommitteeIndex --
func (a *PendingAttestation) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
if a == nil || a.Data == nil {
return 0, errors.New("nil attestation data")
}
return a.Data.CommitteeIndex, nil
}
// Version --
func (a *AttestationElectra) Version() int {
return version.Electra
@@ -184,6 +204,24 @@ func (a *AttestationElectra) CommitteeBitsVal() bitfield.Bitfield {
return a.CommitteeBits
}
// GetCommitteeIndex --
func (a *AttestationElectra) GetCommitteeIndex() (primitives.CommitteeIndex, error) {
if a == nil || a.Data == nil {
return 0, errors.New("nil attestation data")
}
if len(a.CommitteeBits) == 0 {
return 0, errors.New("no committee bits found in attestation")
}
if a.Data.CommitteeIndex != 0 {
return 0, fmt.Errorf("attestation data's committee index must be 0 but was %d", a.Data.CommitteeIndex)
}
indices := a.CommitteeBits.BitIndices()
if len(indices) != 1 {
return 0, fmt.Errorf("exactly 1 committee index must be set but %d were set", len(indices))
}
return primitives.CommitteeIndex(uint64(indices[0])), nil
}
// Version --
func (a *IndexedAttestation) Version() int {
return version.Phase0