Skip to content

Commit

Permalink
add Holocene parameter validation to op-program engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Bayardo committed Oct 21, 2024
1 parent 02a63d9 commit a838dc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion op-program/client/l2/engineapi/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions op-program/client/l2/engineapi/l2_engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -322,6 +332,13 @@ func (ea *L2EngineAPI) NewPayloadV3(ctx context.Context, params *eth.ExecutionPa
return &eth.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 &eth.PayloadStatusV1{Status: eth.ExecutionInvalid}, engine.UnsupportedFork.With(errors.New("invalid holocene extraData post-holoocene"))
}
}

return ea.newPayload(ctx, params, versionedHashes, beaconRoot)
}

Expand Down

0 comments on commit a838dc9

Please sign in to comment.