Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
036f4c0
Update L2 base fee calculation to account for Feynman
ranchalp Jun 9, 2025
aa2d6f5
Merge branch 'develop' into l2-fee-feynman
ranchalp Jun 9, 2025
43a698e
Update consensus/misc/eip1559.go
ranchalp Jun 10, 2025
a954f2d
Use dedicated system parameter provingBaseFee
ranchalp Jun 10, 2025
9b715c8
Merge and change initialBaseFee
ranchalp Jun 10, 2025
e2987e3
Merge branch 'develop' into l2-fee-feynman
ranchalp Jun 11, 2025
7ec3f2b
Check on parent not to fail tests
ranchalp Jun 11, 2025
7d70159
fix test
ranchalp Jun 11, 2025
6c5e44d
Merge branch 'develop' into l2-fee-feynman
colinlyguo Jun 17, 2025
e8f5a91
fix golint
Jun 17, 2025
b2bace1
fix goimport
Jun 17, 2025
d74395b
fix unit tests
Jun 17, 2025
1ca62bf
check config.IsFeynman(parent.Time)
Jun 17, 2025
e8f7257
Update consensus/misc/eip1559.go
colinlyguo Jun 24, 2025
dbf1a2f
Merge branch 'develop' into l2-fee-feynman
colinlyguo Jun 24, 2025
b0fa39f
fix fee transition
Jun 24, 2025
dc0accd
Merge branch 'develop' into l2-fee-feynman
colinlyguo Jun 25, 2025
13b13f9
remove an incorrect comment
Jun 25, 2025
e2f18ee
reuse baseFeeOverhead as proving base fee
Jun 25, 2025
d318278
update da-codec commit
Jun 26, 2025
88bab35
Merge branch 'develop' into l2-fee-feynman
colinlyguo Jun 26, 2025
ab13d1b
Merge branch 'develop' into l2-fee-feynman
colinlyguo Jun 26, 2025
4370957
address comments
Jun 26, 2025
8f9f962
add a comment
Jun 26, 2025
1cc13a6
add base fee max check
Thegaram Jun 26, 2025
52ee2b3
add upstream 1559 tests
Thegaram Jun 26, 2025
e294b40
Merge branch 'develop' into l2-fee-feynman
Thegaram Jun 26, 2025
67f8949
bump version
Thegaram Jun 26, 2025
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
67 changes: 65 additions & 2 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,71 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF
return big.NewInt(10000000) // 0.01 Gwei
}

scalar, overhead := ReadL2BaseFeeCoefficients()
return calcBaseFee(scalar, overhead, parentL1BaseFee)
if parent == nil || parent.Number == nil || !config.IsFeynman(parent.Time) {
scalar, overhead := ReadL2BaseFeeCoefficients()
return calcBaseFee(scalar, overhead, parentL1BaseFee)
}
return calcBaseFeeFeynman(config, parent)
}

// calcBaseFeeFeynman calculates the basefee of the header for Feynman fork.
func calcBaseFeeFeynman(config *params.ChainConfig, parent *types.Header) *big.Int {
baseFeeEIP1559 := calcBaseFeeEIP1559(config, parent)
baseFee := new(big.Int).Set(baseFeeEIP1559)
baseFee.Add(baseFee, config.ProvingBaseFee)

return baseFee
}

// CalcBaseFee calculates the basefee of the header.
func calcBaseFeeEIP1559(config *params.ChainConfig, parent *types.Header) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsFeynman(parent.Time) {
return new(big.Int).SetUint64(params.InitialBaseFee)
}

parentBaseFeeEIP1559 := extractBaseFeeEIP1559(config, parent.BaseFee)
parentGasTarget := parent.GasLimit / config.ElasticityMultiplier()
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
if parent.GasUsed == parentGasTarget {
return new(big.Int).Set(parentBaseFeeEIP1559)
}

var (
num = new(big.Int)
denom = new(big.Int)
)

if parent.GasUsed > parentGasTarget {
// If the parent block used more gas than its target, the baseFee should increase.
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parent.GasUsed - parentGasTarget)
num.Mul(num, parentBaseFeeEIP1559)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
if num.Cmp(common.Big1) < 0 {
return num.Add(parentBaseFeeEIP1559, common.Big1)
}
return num.Add(parentBaseFeeEIP1559, num)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasTarget - parent.GasUsed)
num.Mul(num, parentBaseFeeEIP1559)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))

baseFee := num.Sub(parentBaseFeeEIP1559, num)
if baseFee.Cmp(common.Big0) < 0 {
baseFee = common.Big0
}
return baseFee
}
}

func extractBaseFeeEIP1559(config *params.ChainConfig, baseFee *big.Int) *big.Int {
aux := new(big.Int).Set(baseFee)
return aux.Sub(baseFee, config.ProvingBaseFee)
}

// MinBaseFee calculates the minimum L2 base fee based on the current coefficients.
Expand Down
3 changes: 2 additions & 1 deletion core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestStateProcessorErrors(t *testing.T) {
EuclidTime: new(uint64),
EuclidV2Time: new(uint64),
FeynmanTime: new(uint64),
ProvingBaseFee: new(big.Int),
Ethash: new(params.EthashConfig),
}
signer = types.LatestSigner(config)
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{
mkSetCodeTx(0, common.Address{}, params.TxGas, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), nil),
},
want: "could not apply tx 0 [0xc18d10f4c809dbdfa1a074c3300de9bc4b7f16a20f0ec667f6f67312b71b956a]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
want: "could not apply tx 0 [0xa230ea82ab24a8e60aca9edfe901bab53c92d0d8850f13c3f72513608229e2f3]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
},
// ErrSetCodeTxCreate cannot be tested here: it is impossible to create a SetCode-tx with nil `to`.
// The EstimateGas API tests test this case.
Expand Down
12 changes: 12 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ var (
EuclidTime: new(uint64),
EuclidV2Time: new(uint64),
FeynmanTime: new(uint64),
ProvingBaseFee: new(big.Int),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -666,6 +667,7 @@ type ChainConfig struct {
EuclidTime *uint64 `json:"euclidTime,omitempty"` // Euclid switch time (nil = no fork, 0 = already on euclid)
EuclidV2Time *uint64 `json:"euclidv2Time,omitempty"` // EuclidV2 switch time (nil = no fork, 0 = already on euclidv2)
FeynmanTime *uint64 `json:"feynmanTime,omitempty"` // Feynman switch time (nil = no fork, 0 = already on feynman)
ProvingBaseFee *big.Int `json:"provingFee,omitempty"` // Proving base fee to be added to EIP1559 l2 base fee to account for proving costs

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
Expand Down Expand Up @@ -1028,6 +1030,16 @@ func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *Confi
return lasterr
}

// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
func (c *ChainConfig) BaseFeeChangeDenominator() uint64 {
return DefaultBaseFeeChangeDenominator
}

// ElasticityMultiplier bounds the maximum gas limit an EIP-1559 block may have.
func (c *ChainConfig) ElasticityMultiplier() uint64 {
return DefaultElasticityMultiplier
}

// CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough
// to guarantee that forks can be implemented in a different order than on official networks
func (c *ChainConfig) CheckConfigForkOrder() error {
Expand Down
6 changes: 3 additions & 3 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ const (
// Introduced in Tangerine Whistle (Eip 150)
CreateBySelfdestructGas uint64 = 25000

BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 10000000 // Initial base fee for EIP-1559 blocks.

MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions
Expand Down
Loading