From 94af17a0c0237fcbebed9cb8fff06c91ae0a611c Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Sat, 10 Aug 2024 09:04:55 +0800 Subject: [PATCH] feat: update L2 base fee formula (#951) (#973) * feat: update L2 base fee formula (#951) * update `CalcBaseFee` * update `TestCalcBaseFee` * update `TestStateProcessorErrors` * bump version * update threshold * update core/state_processor_test.go --- consensus/misc/eip1559/eip1559_scroll.go | 8 ++++---- consensus/misc/eip1559/eip1559_scroll_test.go | 13 +++++++------ core/state_processor_test.go | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/consensus/misc/eip1559/eip1559_scroll.go b/consensus/misc/eip1559/eip1559_scroll.go index ad1ce83f37..2cd931666d 100644 --- a/consensus/misc/eip1559/eip1559_scroll.go +++ b/consensus/misc/eip1559/eip1559_scroll.go @@ -26,7 +26,7 @@ import ( ) // Protocol-enforced maximum L2 base fee. -// We would only go above this if L1 base fee hits 2164 Gwei. +// We would only go above this if L1 base fee hits 2931 Gwei. const MaximumL2BaseFee = 10000000000 // VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559, @@ -53,11 +53,11 @@ 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(1000000) // 0.001 Gwei - provingFee := big.NewInt(47700000) // 0.0477 Gwei + provingFee := big.NewInt(33700000) // 0.0337 Gwei - // L1_base_fee * 0.0046 + // L1_base_fee * 0.0034 verificationFee := parentL1BaseFee - verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(46)) + verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(34)) verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000)) baseFee := big.NewInt(0) diff --git a/consensus/misc/eip1559/eip1559_scroll_test.go b/consensus/misc/eip1559/eip1559_scroll_test.go index 2dd5d71c7d..ccf8d40efa 100644 --- a/consensus/misc/eip1559/eip1559_scroll_test.go +++ b/consensus/misc/eip1559/eip1559_scroll_test.go @@ -111,12 +111,13 @@ func TestCalcBaseFee(t *testing.T) { parentL1BaseFee int64 expectedL2BaseFee int64 }{ - {0, 48700000}, - {1000000000, 53300000}, - {2000000000, 57900000}, - {100000000000, 508700000}, - {111111111111, 559811111}, - {2164000000000, 10000000000}, // cap at max L2 base fee + {0, 34700000}, + {1000000000, 38100000}, + {2000000000, 41500000}, + {100000000000, 374700000}, + {111111111111, 412477777}, + {2164000000000, 7392300000}, + {2931000000000, 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 { diff --git a/core/state_processor_test.go b/core/state_processor_test.go index d260be365f..6e52853e9e 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -21,6 +21,7 @@ import ( "math/big" "testing" + "github.com/holiman/uint256" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/math" "github.com/scroll-tech/go-ethereum/consensus" @@ -34,7 +35,6 @@ import ( "github.com/scroll-tech/go-ethereum/crypto" "github.com/scroll-tech/go-ethereum/params" "github.com/scroll-tech/go-ethereum/trie" - "github.com/holiman/uint256" "golang.org/x/crypto/sha3" ) @@ -199,7 +199,7 @@ func TestStateProcessorErrors(t *testing.T) { txs: []*types.Transaction{ mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)), }, - want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000", + want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 38100000", }, { // ErrTipVeryHigh txs: []*types.Transaction{ @@ -252,7 +252,7 @@ func TestStateProcessorErrors(t *testing.T) { txs: []*types.Transaction{ mkBlobTx(0, common.Address{}, params.TxGas, big.NewInt(1), big.NewInt(1), []common.Hash{(common.Hash{1})}), }, - want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1 baseFee: 875000000", + want: "could not apply tx 0 [0x6c11015985ce82db691d7b2d017acda296db88b811c3c60dc71449c76256c716]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 1 baseFee: 38100000", }, } { block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config)