Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
61 changes: 60 additions & 1 deletion consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,66 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF
}

scalar, overhead := ReadL2BaseFeeCoefficients()
return calcBaseFee(scalar, overhead, parentL1BaseFee)
if !config.IsFeynman(big.NewInt(0).Add(parent.Number, common.Big1)) {
return calcBaseFee(scalar, overhead, parentL1BaseFee)
}
baseFeeEIP1559 := calcBaseFeeEIP1559(config, parent, scalar, overhead)
return calcBaseFee(scalar, overhead, baseFeeEIP1559)
}

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

parentBaseFeeEIP1559 := extractBaseFeeEIP1559(parent.BaseFee, scalar, overhead)
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(baseFee *big.Int, scalar *big.Int, overhead *big.Int) *big.Int {
baseFeeEIP := new(big.Int).Set(baseFee)
baseFeeEIP.Sub(baseFeeEIP, overhead)
baseFeeEIP.Mul(baseFeeEIP, BaseFeePrecision)
baseFeeEIP.Div(baseFeeEIP, scalar)

return baseFeeEIP
}

// MinBaseFee calculates the minimum L2 base fee based on the current coefficients.
Expand Down
15 changes: 15 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ func (c *ChainConfig) IsEuclidV2(now uint64) bool {
return isForkedTime(now, c.EuclidV2Time)
}

// IsFeynman returns whether time is either equal to the Feyman fork time or greater.
func (c *ChainConfig) IsFeynman(num *big.Int) bool {
return false // placeholder
}

// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
if c.TerminalTotalDifficulty == nil {
Expand All @@ -1014,6 +1019,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 @@ -121,9 +121,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 = 1000000000 // 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