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
This commit is contained in:
HAOYUatHZ 2024-08-10 09:04:55 +08:00 committed by GitHub
parent 0c6436db80
commit 94af17a0c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 13 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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)