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

fix(beacon): Hardened sidecars validation #2108

Open
wants to merge 18 commits into
base: harden-proposer-validation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
16 changes: 8 additions & 8 deletions beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ func DefaultComponents() []any {
components.ProvideBlsSigner,
components.ProvideBlobProcessor[
*AvailabilityStore, *BeaconBlockBody, *BeaconBlockHeader,
*BlobSidecar, *BlobSidecars, *Logger,
*ConsensusSidecars, *BlobSidecar, *BlobSidecars, *Logger,
],
components.ProvideBlobProofVerifier,
components.ProvideBlobVerifier[
*BeaconBlockHeader, *BlobSidecar, *BlobSidecars,
],
components.ProvideChainService[
*AvailabilityStore,
*ConsensusBlock, *BeaconBlock, *BeaconBlockBody,
Expand All @@ -77,8 +74,8 @@ func DefaultComponents() []any {
// *BeaconStateMarshallable, *BlockStore, *KVStore, *StorageBackend,
// ],
components.ProvideDAService[
*AvailabilityStore, *BeaconBlockBody, *BlobSidecar,
*BlobSidecars, *Logger,
*AvailabilityStore, *BeaconBlockBody, *BeaconBlockHeader,
*ConsensusSidecars, *BlobSidecar, *BlobSidecars, *Logger,
],
components.ProvideDBManager[*AvailabilityStore, *DepositStore, *Logger],
components.ProvideDepositPruner[
Expand All @@ -92,7 +89,9 @@ func DefaultComponents() []any {
],
components.ProvideDepositStore[*Deposit],
components.ProvideDispatcher[
*ConsensusBlock, *BeaconBlock, *BlobSidecars, *Genesis, *Logger,
*ConsensusBlock, *BeaconBlock,
*ConsensusSidecars, *BlobSidecars,
*Genesis, *Logger,
],
components.ProvideEngineClient[
*ExecutionPayload, *ExecutionPayloadHeader, *Logger,
Expand All @@ -111,7 +110,8 @@ func DefaultComponents() []any {
*AvailabilityStore,
*ConsensusBlock, *BeaconBlock, *BeaconBlockBody,
*BeaconBlockHeader, *BlockStore, *BeaconState,
*BeaconStateMarshallable, *BlobSidecar, *BlobSidecars,
*BeaconStateMarshallable,
*ConsensusSidecars, *BlobSidecar, *BlobSidecars,
*Deposit, *DepositStore, *ExecutionPayload, *ExecutionPayloadHeader,
*Genesis, *KVStore, *Logger,
NodeAPIContext,
Expand Down
23 changes: 11 additions & 12 deletions beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ type (
*AvailabilityStore,
*BeaconBlockBody,
*BeaconBlockHeader,
*BlobSidecar,
*BlobSidecars,
]

// BlobVerifier is a type alias for the blob verifier.
BlobVerifier = dablob.Verifier[
*BeaconBlockHeader,
*ConsensusSidecars,
*BlobSidecar,
*BlobSidecars,
]
Expand All @@ -107,7 +101,10 @@ type (
CometBFTService = cometbft.Service[*Logger]

// DAService is a type alias for the DA service.
DAService = da.Service[*AvailabilityStore, *BlobSidecars]
DAService = da.Service[
*AvailabilityStore,
*ConsensusSidecars, *BlobSidecars, *BeaconBlockHeader,
]

// DBManager is a type alias for the database manager.
DBManager = manager.DBManager
Expand Down Expand Up @@ -267,10 +264,12 @@ type (
Validator,
]

// BlobSidecar is a type alias for the blob sidecar.
BlobSidecar = datypes.BlobSidecar

// BlobSidecars is a type alias for the blob sidecars.
// BlobSidecars type aliases.
ConsensusSidecars = consruntimetypes.ConsensusSidecars[
*BlobSidecars,
*BeaconBlockHeader,
]
BlobSidecar = datypes.BlobSidecar
BlobSidecars = datypes.BlobSidecars

// BlockStore is a type alias for the block store.
Expand Down
4 changes: 2 additions & 2 deletions build/scripts/testing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ start-erigon: ## start an ephemeral `erigon` node
docker run \
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
-v $(PWD)/.tmp:/.tmp \
thorax/erigon:latest init \
erigontech/erigon:latest init \
calbera marked this conversation as resolved.
Show resolved Hide resolved
--datadir .tmp/erigon \
${ETH_GENESIS_PATH}

Expand All @@ -212,7 +212,7 @@ start-erigon: ## start an ephemeral `erigon` node
-p 8551:8551 \
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
-v $(PWD)/.tmp:/.tmp \
thorax/erigon:latest \
erigontech/erigon:latest \
--http \
--http.addr 0.0.0.0 \
--http.api eth,net \
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/beaconkit-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ node_settings:
max_memory: 2048
images:
besu: hyperledger/besu:24.5.4
erigon: thorax/erigon:v2.60.1
erigon: erigontech/erigon:v2.60.9
ethereumjs: ethpandaops/ethereumjs:stable
geth: ethereum/client-go:latest
nethermind: nethermind/nethermind:latest
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/beaconkit-base-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ node_settings:
max_memory: 32768
images:
besu: hyperledger/besu:latest
erigon: thorax/erigon:v2.60.1
erigon: erigontech/erigon:v2.60.9
ethereumjs: ethpandaops/ethereumjs:stable
geth: ethereum/client-go:latest
nethermind: nethermind/nethermind:latest
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/src/nodes/nodes.star
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EXECUTION_DEFAULT_SETTINGS = {
},
"images": {
"besu": "hyperledger/besu:latest",
"erigon": "thorax/erigon:v2.60.1",
"erigon": "erigontech/erigon:v2.60.9",
"ethereumjs": "ethpandaops/ethereumjs:stable",
"geth": "ethereum/client-go:latest",
"nethermind": "nethermind/nethermind:latest",
Expand Down
9 changes: 9 additions & 0 deletions mod/consensus-types/pkg/types/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ func (b *BeaconBlockHeader) GetTree() (*fastssz.Node, error) {
/* Getters and Setters */
/* -------------------------------------------------------------------------- */

// Equals returns true if the Withdrawal is equal to the other.
func (b *BeaconBlockHeader) Equals(rhs *BeaconBlockHeader) bool {
return b.Slot == rhs.Slot &&
b.ProposerIndex == rhs.ProposerIndex &&
b.ParentBlockRoot == rhs.ParentBlockRoot &&
b.StateRoot == rhs.StateRoot &&
b.BodyRoot == rhs.BodyRoot
}

// GetSlot retrieves the slot of the BeaconBlockHeader.
func (b *BeaconBlockHeader) GetSlot() math.Slot {
return b.Slot
Expand Down
59 changes: 33 additions & 26 deletions mod/consensus/pkg/cometbft/service/middleware/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import (
/* -------------------------------------------------------------------------- */

// InitGenesis is called by the base app to initialize the state of the.
func (h *ABCIMiddleware[
_, _, GenesisT, _,
]) InitGenesis(
func (h *ABCIMiddleware[_, _, _, GenesisT, _]) InitGenesis(
ctx sdk.Context,
bz []byte,
) (transition.ValidatorUpdates, error) {
Expand All @@ -65,9 +63,7 @@ func (h *ABCIMiddleware[

// waitForGenesisProcessed waits until the genesis data has been processed and
// returns the validator updates, or err if the context is cancelled.
func (h *ABCIMiddleware[
_, _, _, _,
]) waitForGenesisProcessed(
func (h *ABCIMiddleware[_, _, _, _, _]) waitForGenesisProcessed(
ctx context.Context,
) (transition.ValidatorUpdates, error) {
select {
Expand All @@ -84,8 +80,7 @@ func (h *ABCIMiddleware[

// prepareProposal is the internal handler for preparing proposals.
func (h *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, _, SlotDataT,
]) PrepareProposal(
BeaconBlockT, _, BlobSidecarsT, _, SlotDataT]) PrepareProposal(
ctx sdk.Context,
slotData SlotDataT,
) ([]byte, []byte, error) {
Expand Down Expand Up @@ -133,7 +128,7 @@ func (h *ABCIMiddleware[

// waitForBuiltBeaconBlock waits for the built beacon block to be received.
func (h *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, _, SlotDataT,
BeaconBlockT, _, BlobSidecarsT, _, SlotDataT,
]) waitForBuiltBeaconBlock(
ctx context.Context,
) (BeaconBlockT, error) {
Expand All @@ -147,7 +142,7 @@ func (h *ABCIMiddleware[

// waitForBuiltSidecars waits for the built sidecars to be received.
func (h *ABCIMiddleware[
_, BlobSidecarsT, _, _,
_, _, BlobSidecarsT, _, _,
]) waitForBuiltSidecars(
ctx context.Context,
) (BlobSidecarsT, error) {
Expand All @@ -162,7 +157,7 @@ func (h *ABCIMiddleware[
// handleBuiltBeaconBlockAndSidecars gossips the built beacon block and blob
// sidecars to the network.
func (h *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, _, _,
BeaconBlockT, _, BlobSidecarsT, _, _,
]) handleBuiltBeaconBlockAndSidecars(
bb BeaconBlockT,
sc BlobSidecarsT,
Expand All @@ -185,7 +180,7 @@ func (h *ABCIMiddleware[
// ProcessProposal processes the proposal for the ABCI middleware.
// It handles both the beacon block and blob sidecars concurrently.
func (h *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, _, _,
BeaconBlockT, BeaconBlockHeaderT, BlobSidecarsT, _, _,
]) ProcessProposal(
ctx sdk.Context,
req *cmtabci.ProcessProposalRequest,
Expand All @@ -209,7 +204,7 @@ func (h *ABCIMiddleware[

defer h.metrics.measureProcessProposalDuration(startTime)

// Request the beacon block.
// Decode the beacon block.
blk, err := encoding.
UnmarshalBeaconBlockFromABCIRequest[BeaconBlockT](
req,
Expand All @@ -221,18 +216,18 @@ func (h *ABCIMiddleware[
}

// notify that the beacon block has been received.
var enrichedBlk *types.ConsensusBlock[BeaconBlockT]
enrichedBlk = enrichedBlk.New(
var consensusBlk *types.ConsensusBlock[BeaconBlockT]
consensusBlk = consensusBlk.New(
blk,
req.GetProposerAddress(),
req.GetTime().Add(h.minPayloadDelay),
)
blkEvent := async.NewEvent(ctx, async.BeaconBlockReceived, enrichedBlk)
blkEvent := async.NewEvent(ctx, async.BeaconBlockReceived, consensusBlk)
if err = h.dispatcher.Publish(blkEvent); err != nil {
return h.createProcessProposalResponse(errors.WrapNonFatal(err))
}

// Request the blob sidecars.
// Decode the blob sidecars.
sidecars, err := encoding.
UnmarshalBlobSidecarsFromABCIRequest[BlobSidecarsT](
req,
Expand All @@ -243,7 +238,15 @@ func (h *ABCIMiddleware[
}

// notify that the sidecars have been received.
blobEvent := async.NewEvent(ctx, async.SidecarsReceived, sidecars)
var consensusSidecars *types.ConsensusSidecars[
BlobSidecarsT,
BeaconBlockHeaderT,
]
consensusSidecars = consensusSidecars.New(
sidecars,
blk.GetHeader(),
)
blobEvent := async.NewEvent(ctx, async.SidecarsReceived, consensusSidecars)
if err = h.dispatcher.Publish(blobEvent); err != nil {
return h.createProcessProposalResponse(errors.WrapNonFatal(err))
}
Expand All @@ -263,7 +266,7 @@ func (h *ABCIMiddleware[
// waitForBeaconBlockVerification waits for the built beacon block to be
// verified.
func (h *ABCIMiddleware[
BeaconBlockT, _, _, _,
BeaconBlockT, _, _, _, _,
]) waitForBeaconBlockVerification(
ctx context.Context,
) (BeaconBlockT, error) {
Expand All @@ -277,7 +280,7 @@ func (h *ABCIMiddleware[

// waitForSidecarVerification waits for the built sidecars to be verified.
func (h *ABCIMiddleware[
_, BlobSidecarsT, _, _,
_, _, BlobSidecarsT, _, _,
]) waitForSidecarVerification(
ctx context.Context,
) (BlobSidecarsT, error) {
Expand All @@ -292,7 +295,7 @@ func (h *ABCIMiddleware[
// createResponse generates the appropriate ProcessProposalResponse based on the
// error.
func (*ABCIMiddleware[
BeaconBlockT, _, BlobSidecarsT, _,
BeaconBlockT, _, _, BlobSidecarsT, _,
]) createProcessProposalResponse(
err error,
) (*cmtabci.ProcessProposalResponse, error) {
Expand All @@ -310,7 +313,7 @@ func (*ABCIMiddleware[

// EndBlock returns the validator set updates from the beacon state.
func (h *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, _, _,
BeaconBlockT, _, BlobSidecarsT, _, _,
]) FinalizeBlock(
ctx sdk.Context,
req *cmtabci.FinalizeBlockRequest,
Expand Down Expand Up @@ -339,13 +342,17 @@ func (h *ABCIMiddleware[

// notify that the final beacon block has been received.
// notify that the beacon block has been received.
var enrichedBlk *types.ConsensusBlock[BeaconBlockT]
enrichedBlk = enrichedBlk.New(
var consensusBlk *types.ConsensusBlock[BeaconBlockT]
consensusBlk = consensusBlk.New(
blk,
req.GetProposerAddress(),
req.GetTime().Add(h.minPayloadDelay),
)
blkEvent := async.NewEvent(ctx, async.FinalBeaconBlockReceived, enrichedBlk)
blkEvent := async.NewEvent(
ctx,
async.FinalBeaconBlockReceived,
consensusBlk,
)
if err = h.dispatcher.Publish(blkEvent); err != nil {
return nil, err
}
Expand All @@ -364,7 +371,7 @@ func (h *ABCIMiddleware[
// waitForFinalValidatorUpdates waits for the final validator updates to be
// received.
func (h *ABCIMiddleware[
_, _, _, _,
_, _, _, _, _,
]) waitForFinalValidatorUpdates(
ctx context.Context,
) (transition.ValidatorUpdates, error) {
Expand Down
16 changes: 8 additions & 8 deletions mod/consensus/pkg/cometbft/service/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (

// ABCIMiddleware is a middleware between ABCI and the validator logic.
type ABCIMiddleware[
BeaconBlockT BeaconBlock[BeaconBlockT],
BeaconBlockT BeaconBlock[BeaconBlockT, BeaconBlockHeaderT],
BeaconBlockHeaderT any,
BlobSidecarsT BlobSidecars[BlobSidecarsT],
GenesisT json.Unmarshaler,
SlotDataT any,
Expand Down Expand Up @@ -67,7 +68,8 @@ type ABCIMiddleware[

// NewABCIMiddleware creates a new instance of the Handler struct.
func NewABCIMiddleware[
BeaconBlockT BeaconBlock[BeaconBlockT],
BeaconBlockT BeaconBlock[BeaconBlockT, BeaconBlockHeaderT],
BeaconBlockHeaderT any,
BlobSidecarsT BlobSidecars[BlobSidecarsT],
GenesisT json.Unmarshaler,
SlotDataT any,
Expand All @@ -78,7 +80,7 @@ func NewABCIMiddleware[
logger log.Logger,
telemetrySink TelemetrySink,
) *ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, GenesisT, SlotDataT,
BeaconBlockT, BeaconBlockHeaderT, BlobSidecarsT, GenesisT, SlotDataT,
] {
// We may build execution payload optimistically (i.e. build the execution
// payload for next block while current block is being verified and not yet
Expand All @@ -100,7 +102,7 @@ func NewABCIMiddleware[
)

return &ABCIMiddleware[
BeaconBlockT, BlobSidecarsT, GenesisT, SlotDataT,
BeaconBlockT, BeaconBlockHeaderT, BlobSidecarsT, GenesisT, SlotDataT,
]{
chainSpec: chainSpec,
minPayloadDelay: minPayloadDelay,
Expand All @@ -117,7 +119,7 @@ func NewABCIMiddleware[
}

// Start subscribes the middleware to the events it needs to listen for.
func (am *ABCIMiddleware[_, _, _, _]) Start(
func (am *ABCIMiddleware[_, _, _, _, _]) Start(
_ context.Context,
) error {
var err error
Expand Down Expand Up @@ -155,8 +157,6 @@ func (am *ABCIMiddleware[_, _, _, _]) Start(
}

// Name returns the name of the middleware.
func (am *ABCIMiddleware[
_, _, _, _,
]) Name() string {
func (am *ABCIMiddleware[_, _, _, _, _]) Name() string {
return "abci-middleware"
}
Loading
Loading