Skip to content

Commit

Permalink
core: fixes some more panics (#2137)
Browse files Browse the repository at this point in the history
Fixes some more panics found by beacon fuzz.

category: misc
ticket: #1962
  • Loading branch information
dB2510 authored Apr 27, 2023
1 parent 7072464 commit 9fb17a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (f *Fetcher) fetchAttesterData(ctx context.Context, slot int64, defSet core
eth2AttData, err = f.eth2Cl.AttestationData(ctx, eth2p0.Slot(uint64(slot)), commIdx)
if err != nil {
return nil, err
} else if eth2AttData == nil {
return nil, errors.New("attestation data cannot be nil")
}

dataByCommIdx[commIdx] = eth2AttData
Expand Down
4 changes: 4 additions & 0 deletions core/tracker/inclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func (a *InclusionChecker) checkBlock(ctx context.Context, slot int64) error {
return errors.New("invalid attestation")
}

if att.Data.Target == nil || att.Data.Source == nil {
return errors.New("invalid attestation data checkpoint")
}

root, err := att.Data.HashTreeRoot()
if err != nil {
return errors.Wrap(err, "hash attestation")
Expand Down
10 changes: 9 additions & 1 deletion testutil/beaconmock/beaconmock_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,20 @@ func WithBeaconMockFuzzer() Option {

// Return expected attester duties
vals := getValidators()
if vals == nil {
return
}
var resp []*eth2v1.AttesterDuty
for _, vIdx := range indices {
var duty eth2v1.AttesterDuty
c.Fuzz(&duty)

duty.PubKey = vals[vIdx].Validator.PublicKey
val, ok := vals[vIdx]
if !ok {
continue
}

duty.PubKey = val.Validator.PublicKey
duty.ValidatorIndex = vIdx
duty.Slot = eth2p0.Slot(int(epoch*16) + c.Intn(16))
resp = append(resp, &duty)
Expand Down

0 comments on commit 9fb17a6

Please sign in to comment.