Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding nil checks on attestation interface #14638

Merged
merged 18 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Small log imporvement, removing some redundant or duplicate logs
- EIP7521 - Fixes withdrawal bug by accounting for pending partial withdrawals and deducting already withdrawn amounts from the sweep balance. [PR](https://github.com/prysmaticlabs/prysm/pull/14578)
- unskip electra merkle spec test
- corrects nil check on some interface attestation types


### Security
Expand Down
17 changes: 1 addition & 16 deletions beacon-chain/core/helpers/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,7 @@ var (
// Access to these nil fields will result in run time panic,
// it is recommended to run these checks as first line of defense.
func ValidateNilAttestation(attestation ethpb.Att) error {
if attestation == nil {
return errors.New("attestation can't be nil")
}
if attestation.GetData() == nil {
return errors.New("attestation's data can't be nil")
}
if attestation.GetData().Source == nil {
return errors.New("attestation's source can't be nil")
}
if attestation.GetData().Target == nil {
return errors.New("attestation's target can't be nil")
}
if attestation.GetAggregationBits() == nil {
return errors.New("attestation's bitfield can't be nil")
}
return nil
return attestation.IsNil()
}

// ValidateSlotTargetEpoch checks if attestation data's epoch matches target checkpoint's epoch.
Expand Down
5 changes: 4 additions & 1 deletion beacon-chain/db/slasherkv/slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,12 @@ func decodeSlasherChunk(enc []byte) ([]uint16, error) {
// Encode attestation record to bytes.
// The output encoded attestation record consists in the signing root concatenated with the compressed attestation record.
func encodeAttestationRecord(att *slashertypes.IndexedAttestationWrapper) ([]byte, error) {
if att == nil || att.IndexedAttestation == nil {
if att == nil {
return []byte{}, errors.New("nil proposal record")
}
if err := att.IndexedAttestation.IsNil(); err != nil {
return []byte{}, err
}

// Encode attestation.
encodedAtt, err := att.IndexedAttestation.MarshalSSZ()
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/operations/attestations/kv/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (

// SaveBlockAttestation saves an block attestation in cache.
func (c *AttCaches) SaveBlockAttestation(att ethpb.Att) error {
if att == nil {
if err := att.IsNil(); err != nil {
//nolint:nilerr
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions beacon-chain/operations/attestations/kv/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (

// SaveForkchoiceAttestation saves an forkchoice attestation in cache.
func (c *AttCaches) SaveForkchoiceAttestation(att ethpb.Att) error {
if att == nil {
if err := att.IsNil(); err != nil {
//nolint:nilerr
return nil
}

Expand Down Expand Up @@ -50,7 +51,8 @@ func (c *AttCaches) ForkchoiceAttestations() []ethpb.Att {

// DeleteForkchoiceAttestation deletes a forkchoice attestation in cache.
func (c *AttCaches) DeleteForkchoiceAttestation(att ethpb.Att) error {
if att == nil {
if err := att.IsNil(); err != nil {
//nolint:nilerr
return nil
}

Expand Down
11 changes: 8 additions & 3 deletions beacon-chain/operations/attestations/kv/unaggregated.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (

// SaveUnaggregatedAttestation saves an unaggregated attestation in cache.
func (c *AttCaches) SaveUnaggregatedAttestation(att ethpb.Att) error {
if att == nil {
if err := att.IsNil(); err != nil {
//nolint:nilerr
return nil
}
if helpers.IsAggregated(att) {
Expand Down Expand Up @@ -130,7 +131,8 @@ func (c *AttCaches) UnaggregatedAttestationsBySlotIndexElectra(

// DeleteUnaggregatedAttestation deletes the unaggregated attestations in cache.
func (c *AttCaches) DeleteUnaggregatedAttestation(att ethpb.Att) error {
if att == nil {
if err := att.IsNil(); err != nil {
//nolint:nilerr
return nil
}
if helpers.IsAggregated(att) {
Expand Down Expand Up @@ -161,7 +163,10 @@ func (c *AttCaches) DeleteSeenUnaggregatedAttestations() (int, error) {

count := 0
for r, att := range c.unAggregatedAtt {
if att == nil || helpers.IsAggregated(att) {
if err := att.IsNil(); err != nil {
continue
}
if helpers.IsAggregated(att) {
continue
}
if seen, err := c.hasSeenBit(att); err == nil && seen {
Expand Down
5 changes: 1 addition & 4 deletions beacon-chain/slasher/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ func (s *Service) filterAttestations(
// detection (except for the genesis epoch).
func validateAttestationIntegrity(att ethpb.IndexedAtt) bool {
// If an attestation is malformed, we drop it.
if att == nil ||
att.GetData() == nil ||
att.GetData().Source == nil ||
att.GetData().Target == nil {
if err := att.IsNil(); err != nil {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/stateutil/field_root_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
}

func pendingAttestationRoot(att *ethpb.PendingAttestation) ([32]byte, error) {
if att == nil {
if err := att.IsNil(); err != nil {
return [32]byte{}, errors.New("nil pending attestation")
}
return PendingAttRootWithHasher(att)
Expand Down
Loading
Loading