Skip to content

Commit

Permalink
feat: update L2 base fee formula (#892)
Browse files Browse the repository at this point in the history
feat: update L2 base fee formula (#891)

* feat: update L2 base fee formula

* update test tx hashes

Co-authored-by: Péter Garamvölgyi <[email protected]>
  • Loading branch information
0xmountaintop and Thegaram authored Jul 10, 2024
1 parent f777318 commit 65af7ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions consensus/misc/eip1559/eip1559_scroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// 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

// VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559,
Expand All @@ -52,13 +52,13 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade

// CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseFee *big.Int) *big.Int {
l2SequencerFee := big.NewInt(10000000) // 0.01 Gwei
provingFee := big.NewInt(140000000) // 0.14 Gwei
l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei
provingFee := big.NewInt(47700000) // 0.0477 Gwei

// L1_base_fee * 0.014
// L1_base_fee * 0.0046
verificationFee := parentL1BaseFee
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(14))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(1000))
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(46))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000))

baseFee := big.NewInt(0)
baseFee.Add(baseFee, l2SequencerFee)
Expand Down
12 changes: 6 additions & 6 deletions consensus/misc/eip1559/eip1559_scroll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func TestCalcBaseFee(t *testing.T) {
parentL1BaseFee int64
expectedL2BaseFee int64
}{
{0, 150000000},
{1000000000, 164000000},
{2000000000, 178000000},
{100000000000, 1550000000},
{111111111111, 1705555555},
{1000000000000, 10000000000}, // cap at max L2 base fee
{0, 48700000},
{1000000000, 53300000},
{2000000000, 57900000},
{100000000000, 508700000},
{111111111111, 559811111},
{2164000000000, 10000000000}, // cap at max L2 base fee
}
for i, test := range tests {
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {
Expand Down

0 comments on commit 65af7ee

Please sign in to comment.