@@ -20,90 +20,53 @@ import (
20
20
"fmt"
21
21
"math/big"
22
22
23
- "github.com/scroll-tech/go-ethereum/common"
24
- "github.com/scroll-tech/go-ethereum/common/math"
25
23
"github.com/scroll-tech/go-ethereum/core/types"
26
24
"github.com/scroll-tech/go-ethereum/params"
27
25
)
28
26
27
+ // Protocol-enforced maximum L2 base fee.
28
+ // We would only go above this if L1 base fee hits 700 Gwei.
29
+ const MaximumL2BaseFee = 10000000000
30
+
29
31
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
30
32
// - gas limit check
31
33
// - basefee check
32
34
func VerifyEip1559Header (config * params.ChainConfig , parent , header * types.Header ) error {
33
35
// Verify that the gas limit remains within allowed bounds
34
- parentGasLimit := parent .GasLimit
35
- if ! config .IsLondon (parent .Number ) {
36
- parentGasLimit = parent .GasLimit * params .ElasticityMultiplier
37
- }
38
- if err := VerifyGaslimit (parentGasLimit , header .GasLimit ); err != nil {
36
+ if err := VerifyGaslimit (parent .GasLimit , header .GasLimit ); err != nil {
39
37
return err
40
38
}
41
39
// Verify the header is not malformed
42
- if header .BaseFee == nil && config .Scroll .BaseFeeEnabled () {
43
- return fmt .Errorf ("header is missing baseFee" )
44
- }
45
- // Now BaseFee can be nil, because !config.Scroll.BaseFeeEnabled()
46
40
if header .BaseFee == nil {
47
- return nil
48
- }
49
- // Verify the baseFee is correct based on the parent header.
50
-
51
- var expectedBaseFee * big.Int
52
-
53
- // compatible check with the logic in commitNewWork
54
- if config .Clique == nil || config .Scroll .BaseFeeEnabled () {
55
- expectedBaseFee = CalcBaseFee (config , parent )
56
- } else {
57
- expectedBaseFee = big .NewInt (0 )
41
+ return fmt .Errorf ("header is missing baseFee" )
58
42
}
59
-
60
- if header .BaseFee .Cmp (expectedBaseFee ) != 0 {
61
- return fmt .Errorf ("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d" ,
62
- expectedBaseFee , header .BaseFee , parent .BaseFee , parent .GasUsed )
43
+ // note: we do not verify L2 base fee, the sequencer has the
44
+ // right to set any base fee below the maximum. L2 base fee
45
+ // is not subject to L2 consensus or zk verification.
46
+ if header .BaseFee .Cmp (big .NewInt (MaximumL2BaseFee )) > 0 {
47
+ return fmt .Errorf ("invalid baseFee: have %s, maximum %d" , header .BaseFee , MaximumL2BaseFee )
63
48
}
64
49
return nil
65
50
}
66
51
67
52
// CalcBaseFee calculates the basefee of the header.
68
- func CalcBaseFee (config * params.ChainConfig , parent * types.Header ) * big.Int {
69
- // If the current block is the first EIP-1559 block, return the InitialBaseFee.
70
- if ! config .IsLondon (parent .Number ) {
71
- return new (big.Int ).SetUint64 (params .InitialBaseFee )
72
- }
53
+ func CalcBaseFee (config * params.ChainConfig , parent * types.Header , parentL1BaseFee * big.Int ) * big.Int {
54
+ l2SequencerFee := big .NewInt (10000000 ) // 0.01 Gwei
55
+ provingFee := big .NewInt (140000000 ) // 0.14 Gwei
73
56
74
- var (
75
- parentGasTarget = parent .GasLimit / params .ElasticityMultiplier
76
- parentGasTargetBig = new (big.Int ).SetUint64 (parentGasTarget )
77
- baseFeeChangeDenominator = new (big.Int ).SetUint64 (params .BaseFeeChangeDenominator )
78
- )
79
- if ! config .Scroll .BaseFeeEnabled () {
80
- return nil
81
- }
82
- // If the parent gasUsed is the same as the target, the baseFee remains unchanged.
83
- if parent .GasUsed == parentGasTarget {
84
- return new (big.Int ).Set (parent .BaseFee )
85
- }
86
- if parent .GasUsed > parentGasTarget {
87
- // If the parent block used more gas than its target, the baseFee should increase.
88
- gasUsedDelta := new (big.Int ).SetUint64 (parent .GasUsed - parentGasTarget )
89
- x := new (big.Int ).Mul (parent .BaseFee , gasUsedDelta )
90
- y := x .Div (x , parentGasTargetBig )
91
- baseFeeDelta := math .BigMax (
92
- x .Div (y , baseFeeChangeDenominator ),
93
- common .Big1 ,
94
- )
57
+ // L1_base_fee * 0.014
58
+ verificationFee := parentL1BaseFee
59
+ verificationFee = new (big.Int ).Mul (verificationFee , big .NewInt (14 ))
60
+ verificationFee = new (big.Int ).Div (verificationFee , big .NewInt (1000 ))
95
61
96
- return x .Add (parent .BaseFee , baseFeeDelta )
97
- } else {
98
- // Otherwise if the parent block used less gas than its target, the baseFee should decrease.
99
- gasUsedDelta := new (big.Int ).SetUint64 (parentGasTarget - parent .GasUsed )
100
- x := new (big.Int ).Mul (parent .BaseFee , gasUsedDelta )
101
- y := x .Div (x , parentGasTargetBig )
102
- baseFeeDelta := x .Div (y , baseFeeChangeDenominator )
62
+ baseFee := big .NewInt (0 )
63
+ baseFee .Add (baseFee , l2SequencerFee )
64
+ baseFee .Add (baseFee , provingFee )
65
+ baseFee .Add (baseFee , verificationFee )
103
66
104
- return math .BigMax (
105
- x .Sub (parent .BaseFee , baseFeeDelta ),
106
- common .Big0 ,
107
- )
67
+ if baseFee .Cmp (big .NewInt (MaximumL2BaseFee )) > 0 {
68
+ baseFee = big .NewInt (MaximumL2BaseFee )
108
69
}
70
+
71
+ return baseFee
109
72
}
0 commit comments