Skip to content

Commit

Permalink
core/tracker: harden inclusion proposal checks (#3150)
Browse files Browse the repository at this point in the history
Always recover when dealing with malformed proposals, and log some context to aid debugging.

category: refactor
ticket: none
  • Loading branch information
gsora authored Jun 22, 2024
1 parent b66e063 commit 7157154
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/tracker/inclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ type inclusionCore struct {

// Submitted is called when a duty is submitted to the beacon node.
// It adds the duty to the list of submitted duties.
func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.SignedData, delay time.Duration) error {
func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.SignedData, delay time.Duration) (err error) {
if !inclSupported[duty.Type] {
return nil
}

var (
attRoot eth2p0.Root
err error
)
if duty.Type == core.DutyAttester {
att, ok := data.(core.Attestation)
Expand Down Expand Up @@ -120,6 +119,20 @@ func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.
}
}

defer func() {
if r := recover(); r != nil {
proposal := fmt.Sprintf("%+v", block)
if blinded {
proposal = fmt.Sprintf("%+v", blindedBlock)
}

err = errors.New("could not determine if proposal was synthetic or not",
z.Str("proposal", proposal),
z.Bool("blinded", blinded),
)
}
}()

switch blinded {
case true:
if eth2wrap.IsSyntheticBlindedBlock(&blindedBlock.VersionedSignedBlindedProposal) {
Expand Down Expand Up @@ -152,7 +165,7 @@ func (i *inclusionCore) Submitted(duty core.Duty, pubkey core.PubKey, data core.
Delay: delay,
}

return nil
return err
}

// Trim removes all duties that are older than the specified slot.
Expand Down
10 changes: 10 additions & 0 deletions core/tracker/tracker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

eth2api "github.com/attestantio/go-eth2-client/api"
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
eth2spec "github.com/attestantio/go-eth2-client/spec"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -1333,4 +1334,13 @@ func TestSubmittedProposals(t *testing.T) {

err = ic.Submitted(core.NewProposerDuty(42), testutil.RandomCorePubKey(t), testutil.RandomDenebVersionedSignedBlindedProposal(), 1*time.Millisecond)
require.NoError(t, err)

require.NotPanics(t, func() {
err = ic.Submitted(core.NewProposerDuty(42), testutil.RandomCorePubKey(t), core.VersionedSignedBlindedProposal{
VersionedSignedBlindedProposal: eth2api.VersionedSignedBlindedProposal{
Version: eth2spec.DataVersionDeneb,
},
}, 1*time.Millisecond)
require.ErrorContains(t, err, "could not determine if proposal was synthetic or not")
})
}

0 comments on commit 7157154

Please sign in to comment.