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
2 changes: 1 addition & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type PayloadAttributes struct {
// and contains encoded EIP-1559 parameters. See:
// https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip1559params-encoding
EIP1559Params []byte `json:"eip1559Params,omitempty" gencodec:"optional"`
// MinBaseFee is a field for rollups implementing the Jovian upgrade's minimum base fee feature.
// MinBaseFee is a field for rollups implementing the minimum base fee feature.
// See https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/jovian/exec-engine.md#minimum-base-fee-in-payloadattributesv3
MinBaseFee *uint64 `json:"minBaseFee,omitempty" gencodec:"optional"`
}
Expand Down
40 changes: 20 additions & 20 deletions consensus/misc/eip1559/eip1559_optimism.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
)

const HoloceneExtraDataVersionByte = uint8(0x00)
const JovianExtraDataVersionByte = uint8(0x01)
const MinBaseFeeExtraDataVersionByte = uint8(0x01)
Comment thread
sebastianst marked this conversation as resolved.

type ForkChecker interface {
IsHolocene(time uint64) bool
IsJovian(time uint64) bool
IsMinBaseFee(time uint64) bool
}

// ValidateOptimismExtraData validates the Optimism extra data.
// It uses the config and parent time to determine how to do the validation.
func ValidateOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) error {
if fc.IsJovian(time) {
return ValidateJovianExtraData(extraData)
if fc.IsMinBaseFee(time) {
return ValidateMinBaseFeeExtraData(extraData)
} else if fc.IsHolocene(time) {
return ValidateHoloceneExtraData(extraData)
} else if len(extraData) > 0 { // pre-Holocene
Expand All @@ -32,8 +32,8 @@ func ValidateOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) er
// It uses the config and parent time to determine how to do the decoding.
// The parent.extraData is expected to be valid (i.e. ValidateOptimismExtraData has been called previously)
func DecodeOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) (uint64, uint64, *uint64) {
if fc.IsJovian(time) {
denominator, elasticity, minBaseFee := DecodeJovianExtraData(extraData)
if fc.IsMinBaseFee(time) {
denominator, elasticity, minBaseFee := DecodeMinBaseFeeExtraData(extraData)
return denominator, elasticity, minBaseFee
} else if fc.IsHolocene(time) {
denominator, elasticity := DecodeHoloceneExtraData(extraData)
Expand All @@ -45,11 +45,11 @@ func DecodeOptimismExtraData(fc ForkChecker, time uint64, extraData []byte) (uin
// EncodeOptimismExtraData encodes the Optimism extra data.
// It uses the config and parent time to determine how to do the encoding.
func EncodeOptimismExtraData(fc ForkChecker, time uint64, denominator, elasticity uint64, minBaseFee *uint64) []byte {
if fc.IsJovian(time) {
if fc.IsMinBaseFee(time) {
if minBaseFee == nil {
panic("minBaseFee cannot be nil for Jovian")
panic("minBaseFee cannot be nil since the MinBaseFee feature is enabled")
}
return EncodeJovianExtraData(denominator, elasticity, *minBaseFee)
return EncodeMinBaseFeeExtraData(denominator, elasticity, *minBaseFee)
} else if fc.IsHolocene(time) {
return EncodeHoloceneExtraData(denominator, elasticity)
} else {
Expand Down Expand Up @@ -133,12 +133,12 @@ func ValidateHoloceneExtraData(extra []byte) error {
return ValidateHolocene1559Params(extra[1:])
}

// DecodeJovianExtraData decodes the extraData parameters from the encoded form defined here:
// DecodeMinBaseFeeExtraData decodes the extraData parameters from the encoded form defined here:
// https://specs.optimism.io/protocol/jovian/exec-engine.html
//
// Returns 0,0,nil if the format is invalid, and d, e, nil for the Holocene length, to provide best effort behavior for non-Jovian extradata, though ValidateMinBaseFeeExtraData should be used instead of this function for
// Returns 0,0,nil if the format is invalid, and d, e, nil for the Holocene length, to provide best effort behavior for non-MinBaseFee extradata, though ValidateMinBaseFeeExtraData should be used instead of this function for
// validity checking.
func DecodeJovianExtraData(extra []byte) (uint64, uint64, *uint64) {
func DecodeMinBaseFeeExtraData(extra []byte) (uint64, uint64, *uint64) {
// Best effort to decode the extraData for every block in the chain's history,
// including blocks before the minimum base fee feature was enabled.
if len(extra) == 9 {
Expand All @@ -154,27 +154,27 @@ func DecodeJovianExtraData(extra []byte) (uint64, uint64, *uint64) {
return 0, 0, nil
}

// EncodeJovianExtraData encodes the EIP-1559 and minBaseFee parameters into the header 'ExtraData' format.
// EncodeMinBaseFeeExtraData encodes the EIP-1559 and minBaseFee parameters into the header 'ExtraData' format.
// Will panic if EIP-1559 parameters are outside uint32 range.
func EncodeJovianExtraData(denom, elasticity, minBaseFee uint64) []byte {
func EncodeMinBaseFeeExtraData(denom, elasticity, minBaseFee uint64) []byte {
r := make([]byte, 17)
if denom > gomath.MaxUint32 || elasticity > gomath.MaxUint32 {
panic("eip-1559 parameters out of uint32 range")
}
r[0] = JovianExtraDataVersionByte
r[0] = MinBaseFeeExtraDataVersionByte
binary.BigEndian.PutUint32(r[1:5], uint32(denom))
binary.BigEndian.PutUint32(r[5:9], uint32(elasticity))
binary.BigEndian.PutUint64(r[9:], minBaseFee)
return r
}

// ValidateJovianExtraData checks if the header extraData is valid according to the minimum base fee feature.
func ValidateJovianExtraData(extra []byte) error {
// ValidateMinBaseFeeExtraData checks if the header extraData is valid according to the minimum base fee feature.
func ValidateMinBaseFeeExtraData(extra []byte) error {
if len(extra) != 17 {
return fmt.Errorf("jovian extraData should be 17 bytes, got %d", len(extra))
return fmt.Errorf("MinBaseFee extraData should be 17 bytes, got %d", len(extra))
}
if extra[0] != JovianExtraDataVersionByte {
return fmt.Errorf("jovian extraData version byte should be %d, got %d", JovianExtraDataVersionByte, extra[0])
if extra[0] != MinBaseFeeExtraDataVersionByte {
return fmt.Errorf("MinBaseFee extraData version byte should be %d, got %d", MinBaseFeeExtraDataVersionByte, extra[0])
}
return ValidateHolocene1559Params(extra[1:9])
}
2 changes: 1 addition & 1 deletion eth/catalyst/api_optimism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestCheckOptimismPayload(t *testing.T) {
ExtraData: validExtraData,
},
cfg: postJovian(),
expected: errors.New("jovian extraData should be 17 bytes, got 9"),
expected: errors.New("MinBaseFee extraData should be 17 bytes, got 9"),
},
}

Expand Down
12 changes: 6 additions & 6 deletions miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
db := rawdb.NewMemoryDatabase()

var minBaseFee *uint64
if config.IsOptimismJovian(testTimestamp) {
if config.IsMinBaseFee(testTimestamp) {
val := uint64(1e9)
minBaseFee = &val
}
Expand Down Expand Up @@ -301,8 +301,8 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
var expected []byte
if len(params1559) != 0 {
versionByte := eip1559.HoloceneExtraDataVersionByte
if config.IsOptimismJovian(testTimestamp) {
versionByte = eip1559.JovianExtraDataVersionByte
if config.IsMinBaseFee(testTimestamp) {
versionByte = eip1559.MinBaseFeeExtraDataVersionByte
}
expected = []byte{versionByte}

Expand All @@ -312,7 +312,7 @@ func testBuildPayload(t *testing.T, noTxPool, interrupt bool, params1559 []byte,
} else {
expected = append(expected, params1559...)
}
if versionByte == eip1559.JovianExtraDataVersionByte {
if versionByte == eip1559.MinBaseFeeExtraDataVersionByte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, *minBaseFee)
expected = append(expected, buf...)
Expand Down Expand Up @@ -426,14 +426,14 @@ func TestBuildPayloadInvalidHoloceneParams(t *testing.T) {
}
}

func TestBuildPayloadInvalidJovianExtraData(t *testing.T) {
func TestBuildPayloadInvalidMinBaseFeeExtraData(t *testing.T) {
t.Parallel()
db := rawdb.NewMemoryDatabase()
config := jovianConfig()
w, b := newTestWorker(t, config, ethash.NewFaker(), db, 0)

// 0 denominators shouldn't be allowed
badParams := eip1559.EncodeJovianExtraData(0, 6, 0)
badParams := eip1559.EncodeMinBaseFeeExtraData(0, 6, 0)

args := newPayloadArgs(b.chain.CurrentBlock().Hash(), badParams, &zero)
payload, err := w.buildPayload(args, false)
Expand Down
17 changes: 17 additions & 0 deletions params/optimism_feature_toggles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package params

// OPStack diff
// This file contains ephemeral feature toggles which should be removed
// after the fork scope is locked.

func (c *ChainConfig) IsMinBaseFee(time uint64) bool {
return c.IsJovian(time) // Replace with return false to disable
}

func (c *ChainConfig) IsDAFootprintBlockLimit(time uint64) bool {
Comment thread
sebastianst marked this conversation as resolved.
return c.IsJovian(time) // Replace with return false to disable
}

func (c *ChainConfig) IsOperatorFeeFix(time uint64) bool {
return c.IsJovian(time) // Replace with return false to disable
}