Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions beacon-chain/sync/validate_execution_payload_bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func (s *Service) validateExecutionPayloadBidGossip(ctx context.Context, pid pee
if err := v.VerifyParentBlockRootSeen(s.cfg.chain.InForkchoice); err != nil {
return pubsub.ValidationIgnore, err
}
// [REJECT] bid.slot is greater than the slot of the block with root bid.parent_block_root.
parentSlot, err := s.cfg.chain.RecentBlockSlot(parentBlockRoot)
if err != nil {
return pubsub.ValidationIgnore, err
}
if err := v.VerifyBidSlotHigherThanParent(parentSlot); err != nil {
return pubsub.ValidationReject, err
}
msg.ValidatorData = signedBid
return pubsub.ValidationAccept, nil
}
Expand Down
12 changes: 12 additions & 0 deletions beacon-chain/sync/validate_execution_payload_bid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/OffchainLabs/prysm/v7/config/params"
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v7/testing/require"
Expand Down Expand Up @@ -141,6 +142,12 @@ func TestValidateExecutionPayloadBidGossip_ErrorPathsWithMock(t *testing.T) {
result: pubsub.ValidationReject,
wantError: true,
},
{
name: "slot not higher than parent",
verifier: mockExecutionPayloadBidVerifier{errSlotHigherThanParent: errors.New("slot not higher than parent")},
result: pubsub.ValidationReject,
wantError: true,
},
{
name: "parent hash mismatch",
verifier: mockExecutionPayloadBidVerifier{errParentBlockHash: errors.New("wrong hash")},
Expand Down Expand Up @@ -307,6 +314,7 @@ type mockExecutionPayloadBidVerifier struct {
errFeeRecipientMismatch error
errGasLimitIncompatible error
errParentBlockRootSeen error
errSlotHigherThanParent error
errParentBlockHash error
errBuilderCanCoverBid error
errSignature error
Expand Down Expand Up @@ -338,6 +346,10 @@ func (m *mockExecutionPayloadBidVerifier) VerifyParentBlockRootSeen(func([32]byt
return m.errParentBlockRootSeen
}

func (m *mockExecutionPayloadBidVerifier) VerifyBidSlotHigherThanParent(primitives.Slot) error {
return m.errSlotHigherThanParent
}

func (m *mockExecutionPayloadBidVerifier) VerifyParentBlockHash(func([32]byte) ([32]byte, error)) error {
return m.errParentBlockHash
}
Expand Down
17 changes: 17 additions & 0 deletions beacon-chain/verification/execution_payload_bid.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/gloas"
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
"github.com/pkg/errors"
)

Expand All @@ -17,6 +18,7 @@ var ExecutionPayloadBidGossipRequirements = []Requirement{
RequireBidExecutionPaymentZero,
RequireBidFeeRecipientMatches,
RequireBidParentBlockRootSeen,
RequireBidSlotHigherThanParent,
RequireBidParentBlockHashValid,
RequireBidGasLimitCompatible,
RequireBidBuilderCanCover,
Expand All @@ -33,6 +35,7 @@ var (
ErrBidFeeRecipientMismatch = errors.New("fee recipient does not match proposer preferences")
ErrBidGasLimitIncompatible = errors.New("bid gas limit is incompatible with parent and target")
ErrBidParentBlockRootNotSeen = errors.New("parent block root not seen")
ErrBidSlotNotHigherThanParent = errors.New("bid slot is not higher than parent block slot")
ErrBidParentBlockHashMismatch = errors.New("parent block hash does not match forkchoice")
ErrBidBuilderCannotCover = errors.New("builder cannot cover bid")
)
Expand Down Expand Up @@ -165,6 +168,20 @@ func (v *BidVerifier) VerifyParentBlockRootSeen(parentSeen func([32]byte) bool)
return fmt.Errorf("%w: root=%#x", ErrBidParentBlockRootNotSeen, root)
}

// VerifyBidSlotHigherThanParent verifies the bid slot is greater than the slot of its parent block.
func (v *BidVerifier) VerifyBidSlotHigherThanParent(parentSlot primitives.Slot) (err error) {
defer v.record(RequireBidSlotHigherThanParent, &err)

bid, err := v.b.Bid()
if err != nil {
return errors.Wrap(err, "failed to get bid")
}
if bid.Slot() <= parentSlot {
return fmt.Errorf("%w: bid=%d parent=%d", ErrBidSlotNotHigherThanParent, bid.Slot(), parentSlot)
}
return nil
}

// VerifyParentBlockHash verifies the parent execution block hash matches forkchoice for the bid parent root.
func (v *BidVerifier) VerifyParentBlockHash(resolveBlockHash func([32]byte) ([32]byte, error)) (err error) {
defer v.record(RequireBidParentBlockHashValid, &err)
Expand Down
15 changes: 15 additions & 0 deletions beacon-chain/verification/execution_payload_bid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ func TestBidVerifier_VerifyParentBlockRootSeen(t *testing.T) {
require.ErrorIs(t, verifier.VerifyParentBlockRootSeen(func([32]byte) bool { return false }), ErrBidParentBlockRootNotSeen)
}

func TestBidVerifier_VerifyBidSlotHigherThanParent(t *testing.T) {
signed := testSignedExecutionPayloadBid(t, 10)
wrapped, err := blocks.WrappedROSignedExecutionPayloadBid(signed)
require.NoError(t, err)

verifier := &BidVerifier{results: newResults(RequireBidSlotHigherThanParent), b: wrapped}
require.NoError(t, verifier.VerifyBidSlotHigherThanParent(9))

verifier = &BidVerifier{results: newResults(RequireBidSlotHigherThanParent), b: wrapped}
require.ErrorIs(t, verifier.VerifyBidSlotHigherThanParent(10), ErrBidSlotNotHigherThanParent)

verifier = &BidVerifier{results: newResults(RequireBidSlotHigherThanParent), b: wrapped}
require.ErrorIs(t, verifier.VerifyBidSlotHigherThanParent(11), ErrBidSlotNotHigherThanParent)
}

func TestBidVerifier_VerifyParentBlockHash(t *testing.T) {
signed := testSignedExecutionPayloadBid(t, 1)
wrapped, err := blocks.WrappedROSignedExecutionPayloadBid(signed)
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/verification/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
payloadattestation "github.com/OffchainLabs/prysm/v7/consensus-types/payload-attestation"
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
)

Expand Down Expand Up @@ -103,6 +104,7 @@ type ExecutionPayloadBidVerifier interface {
VerifyExecutionPaymentZero() error
VerifyFeeRecipientMatches([]byte) error
VerifyParentBlockRootSeen(func([32]byte) bool) error
VerifyBidSlotHigherThanParent(parentSlot primitives.Slot) error
VerifyParentBlockHash(func([32]byte) ([32]byte, error)) error
VerifyGasLimitTargetCompatible(parentGasLimit, targetGasLimit uint64) error
VerifyBuilderCanCoverBid(state.ReadOnlyBeaconState) error
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/verification/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
RequireBidFeeRecipientMatches
RequireBidGasLimitCompatible
RequireBidParentBlockRootSeen
RequireBidSlotHigherThanParent
RequireBidParentBlockHashValid
RequireBidBuilderCanCover
RequireBidSignatureValid
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/verification/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (r Requirement) String() string {
return "RequireBidGasLimitCompatible"
case RequireBidParentBlockRootSeen:
return "RequireBidParentBlockRootSeen"
case RequireBidSlotHigherThanParent:
return "RequireBidSlotHigherThanParent"
case RequireBidParentBlockHashValid:
return "RequireBidParentBlockHashValid"
case RequireBidBuilderCanCover:
Expand Down
3 changes: 3 additions & 0 deletions changelog/terence_reject-bid-lower-slot-than-parent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Reject gossiped execution payload bids whose slot is not greater than the slot of their parent block.
Loading