feat: update L2 base fee formula (#892)

feat: update L2 base fee formula (#891)

* feat: update L2 base fee formula

* update test tx hashes

Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
This commit is contained in:
HAOYUatHZ 2024-07-10 09:36:29 +08:00 committed by GitHub
parent f777318776
commit 65af7ee9e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 12 deletions

View file

@ -26,7 +26,7 @@ import (
) )
// Protocol-enforced maximum L2 base fee. // Protocol-enforced maximum L2 base fee.
// We would only go above this if L1 base fee hits 700 Gwei. // We would only go above this if L1 base fee hits 2164 Gwei.
const MaximumL2BaseFee = 10000000000 const MaximumL2BaseFee = 10000000000
// VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559, // VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559,
@ -52,13 +52,13 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
// CalcBaseFee calculates the basefee of the header. // CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseFee *big.Int) *big.Int { func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseFee *big.Int) *big.Int {
l2SequencerFee := big.NewInt(10000000) // 0.01 Gwei l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei
provingFee := big.NewInt(140000000) // 0.14 Gwei provingFee := big.NewInt(47700000) // 0.0477 Gwei
// L1_base_fee * 0.014 // L1_base_fee * 0.0046
verificationFee := parentL1BaseFee verificationFee := parentL1BaseFee
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(14)) verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(46))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(1000)) verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000))
baseFee := big.NewInt(0) baseFee := big.NewInt(0)
baseFee.Add(baseFee, l2SequencerFee) baseFee.Add(baseFee, l2SequencerFee)

View file

@ -111,12 +111,12 @@ func TestCalcBaseFee(t *testing.T) {
parentL1BaseFee int64 parentL1BaseFee int64
expectedL2BaseFee int64 expectedL2BaseFee int64
}{ }{
{0, 150000000}, {0, 48700000},
{1000000000, 164000000}, {1000000000, 53300000},
{2000000000, 178000000}, {2000000000, 57900000},
{100000000000, 1550000000}, {100000000000, 508700000},
{111111111111, 1705555555}, {111111111111, 559811111},
{1000000000000, 10000000000}, // cap at max L2 base fee {2164000000000, 10000000000}, // cap at max L2 base fee
} }
for i, test := range tests { for i, test := range tests {
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 { if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {