From a838dc9b41fed1b4de8e2823b7dc428c4d426c6b Mon Sep 17 00:00:00 2001 From: Roberto Bayardo Date: Mon, 21 Oct 2024 07:36:59 -0700 Subject: [PATCH] add Holocene parameter validation to op-program engine --- .../client/l2/engineapi/block_processor.go | 1 - .../client/l2/engineapi/l2_engine_api.go | 21 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/op-program/client/l2/engineapi/block_processor.go b/op-program/client/l2/engineapi/block_processor.go index 4f549eb7f6422..18f11a71313bd 100644 --- a/op-program/client/l2/engineapi/block_processor.go +++ b/op-program/client/l2/engineapi/block_processor.go @@ -52,7 +52,6 @@ func NewBlockProcessorFromPayloadAttributes(provider BlockDataProvider, parent c ParentBeaconRoot: attrs.ParentBeaconBlockRoot, } if attrs.EIP1559Params != nil { - // Do we need to check if holocene is active? d, e := eip1559.DecodeHolocene1559Params(attrs.EIP1559Params[:]) if d == 0 { d = provider.Config().BaseFeeChangeDenominator(header.Time) diff --git a/op-program/client/l2/engineapi/l2_engine_api.go b/op-program/client/l2/engineapi/l2_engine_api.go index 10414e2227311..fdcf6229b7e3b 100644 --- a/op-program/client/l2/engineapi/l2_engine_api.go +++ b/op-program/client/l2/engineapi/l2_engine_api.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/types" @@ -260,15 +261,24 @@ func (ea *L2EngineAPI) ForkchoiceUpdatedV3(ctx context.Context, state *eth.Forkc // Ported from: https://github.com/ethereum-optimism/op-geth/blob/c50337a60a1309a0f1dca3bf33ed1bb38c46cdd7/eth/catalyst/api.go#L206-L218 func (ea *L2EngineAPI) verifyPayloadAttributes(attr *eth.PayloadAttributes) error { c := ea.config() + t := uint64(attr.Timestamp) // Verify withdrawals attribute for Shanghai. - if err := checkAttribute(c.IsShanghai, attr.Withdrawals != nil, c.LondonBlock, uint64(attr.Timestamp)); err != nil { + if err := checkAttribute(c.IsShanghai, attr.Withdrawals != nil, c.LondonBlock, t); err != nil { return fmt.Errorf("invalid withdrawals: %w", err) } // Verify beacon root attribute for Cancun. - if err := checkAttribute(c.IsCancun, attr.ParentBeaconBlockRoot != nil, c.LondonBlock, uint64(attr.Timestamp)); err != nil { + if err := checkAttribute(c.IsCancun, attr.ParentBeaconBlockRoot != nil, c.LondonBlock, t); err != nil { return fmt.Errorf("invalid parent beacon block root: %w", err) } + // Verify EIP-1559 params for Holocene. + if c.IsHolocene(t) { + if err := eip1559.ValidateHolocene1559Params(attr.EIP1559Params[:]); err != nil { + return fmt.Errorf("invalid Holocene params: %w", err) + } + } else if attr.EIP1559Params != nil { + return errors.New("got Holocene params though fork not active") + } return nil } @@ -322,6 +332,13 @@ func (ea *L2EngineAPI) NewPayloadV3(ctx context.Context, params *eth.ExecutionPa return ð.PayloadStatusV1{Status: eth.ExecutionInvalid}, engine.UnsupportedFork.With(errors.New("newPayloadV3 called pre-cancun")) } + // Payload must have eip-1559 params in ExtraData after Holocene + if ea.config().IsHolocene(uint64(params.Timestamp)) { + if err := eip1559.ValidateHoloceneExtraData(params.ExtraData); err != nil { + return ð.PayloadStatusV1{Status: eth.ExecutionInvalid}, engine.UnsupportedFork.With(errors.New("invalid holocene extraData post-holoocene")) + } + } + return ea.newPayload(ctx, params, versionedHashes, beaconRoot) }