Skip to content

Commit

Permalink
op-node/rollup/attributes: Add missing EIP1559Params consolidation ch…
Browse files Browse the repository at this point in the history
…ecks
  • Loading branch information
sebastianst committed Feb 5, 2025
1 parent 271a745 commit abae510
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 104 deletions.
36 changes: 35 additions & 1 deletion op-node/rollup/attributes/engine_consolidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

Expand Down Expand Up @@ -73,6 +74,10 @@ func AttributesMatchBlock(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes
if attrs.SuggestedFeeRecipient != block.FeeRecipient {
return fmt.Errorf("fee recipient data does not match, expected %s but got %s", block.FeeRecipient, attrs.SuggestedFeeRecipient)
}
if err := checkEIP1559ParamsMatch(attrs.EIP1559Params, block.ExtraData); err != nil {
return err
}

return nil
}

Expand All @@ -91,6 +96,36 @@ func checkParentBeaconBlockRootMatch(attrRoot, blockRoot *common.Hash) error {
return nil
}

func checkEIP1559ParamsMatch(attrParams *eth.Bytes8, blockExtraData []byte) error {
// Note that we can assume that the attributes' eip1559params are non-nil iff Holocene is active
// according to the local rollup config.
if attrParams != nil {
params := (*attrParams)[:]

// The validity checks are necessary because the Decode functions return 0,0 if the inputs are invalid.
// But 0,0 are valid values during derivation, namely, if the SystemConfig doesn't set the parameters yet,
// they are set to 0,0 and then the execution layer must translate them to the pre-Holocene constants.
if err := eip1559.ValidateHolocene1559Params(params); err != nil {
// This would be a critical error, because the attributes are generated by derivation and must be valid.
return fmt.Errorf("invalid attributes EIP1559 parameters: %w", err)
} else if err := eip1559.ValidateHoloceneExtraData(blockExtraData); err != nil {
// This can happen if the unsafe chain contains invalid (in particular, empty) extraData while Holocene
// is active. The extraData field of blocks from sequencer gossip isn't currently checked during import.
return fmt.Errorf("invalid block extraData: %w", err)
}

ad, ae := eip1559.DecodeHolocene1559Params(params)
bd, be := eip1559.DecodeHoloceneExtraData(blockExtraData)
if ad != bd || ae != be {
return fmt.Errorf("eip1559 parameters do not match, attributes: %d, %d, block: %d, %d", ad, ae, bd, be)
}
} else if len(blockExtraData) > 0 {
// When deriving pre-Holocene blocks, the extraData must be empty.
return fmt.Errorf("nil EIP1559Params in attributes but non-nil extraData in block: %v", blockExtraData)
}
return nil
}

// checkWithdrawals checks if the withdrawals list and withdrawalsRoot are as expected in the attributes and block,
// based on the active hard fork.
func checkWithdrawals(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes, block *eth.ExecutionPayload) error {
Expand Down Expand Up @@ -122,7 +157,6 @@ func checkWithdrawals(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes, bl
// bedrock: the withdrawals list should be nil
if attrWithdrawals != nil {
return fmt.Errorf("%w: got %d", ErrBedrockMustHaveEmptyWithdrawals, len(*attrWithdrawals))

}
}

Expand Down
Loading

0 comments on commit abae510

Please sign in to comment.