71
71
errInvalidDifficulty = errors .New ("non-positive difficulty" )
72
72
errInvalidMixDigest = errors .New ("invalid mix digest" )
73
73
errInvalidPoW = errors .New ("invalid proof-of-work" )
74
+ errGasLimitSet = errors .New ("GasLimit should not be set after EIP1559 has finalized" )
74
75
)
75
76
76
77
// Author implements consensus.Engine, returning the header's coinbase as the
@@ -258,26 +259,34 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
258
259
if expected .Cmp (header .Difficulty ) != 0 {
259
260
return fmt .Errorf ("invalid difficulty: have %v, want %v" , header .Difficulty , expected )
260
261
}
261
- // Verify that the gas limit is <= 2^63-1
262
- cap := uint64 (0x7fffffffffffffff )
263
- if header .GasLimit > cap {
264
- return fmt .Errorf ("invalid gasLimit: have %v, max %v" , header .GasLimit , cap )
265
- }
266
- // Verify that the gasUsed is <= gasLimit
267
- if header .GasUsed > header .GasLimit {
268
- return fmt .Errorf ("invalid gasUsed: have %d, gasLimit %d" , header .GasUsed , header .GasLimit )
269
- }
270
262
271
- // Verify that the gas limit remains within allowed bounds
272
- diff := int64 (parent .GasLimit ) - int64 (header .GasLimit )
273
- if diff < 0 {
274
- diff *= - 1
275
- }
276
- limit := parent .GasLimit / params .GasLimitBoundDivisor
263
+ // If we have not reached the EIP1559 finalization block we need to verify that the GasLimit field is valid
264
+ if ! chain .Config ().IsEIP1559Finalized (header .Number ) {
265
+ // Verify that the gas limit is <= 2^63-1
266
+ cap := uint64 (0x7fffffffffffffff )
267
+ if header .GasLimit > cap {
268
+ return fmt .Errorf ("invalid gasLimit: have %v, max %v" , header .GasLimit , cap )
269
+ }
270
+ // Verify that the gasUsed is <= gasLimit
271
+ if header .GasUsed > header .GasLimit {
272
+ return fmt .Errorf ("invalid gasUsed: have %d, gasLimit %d" , header .GasUsed , header .GasLimit )
273
+ }
274
+
275
+ // Verify that the gas limit remains within allowed bounds
276
+ diff := int64 (parent .GasLimit ) - int64 (header .GasLimit )
277
+ if diff < 0 {
278
+ diff *= - 1
279
+ }
280
+ limit := parent .GasLimit / params .GasLimitBoundDivisor
277
281
278
- if uint64 (diff ) >= limit || header .GasLimit < params .MinGasLimit {
279
- return fmt .Errorf ("invalid gas limit: have %d, want %d += %d" , header .GasLimit , parent .GasLimit , limit )
282
+ if uint64 (diff ) >= limit || header .GasLimit < params .MinGasLimit {
283
+ return fmt .Errorf ("invalid gas limit: have %d, want %d += %d" , header .GasLimit , parent .GasLimit , limit )
284
+ }
285
+ } else if header .GasLimit != 0 {
286
+ // If EIP1559 is finalized, GasLimit should be 0
287
+ return errGasLimitSet
280
288
}
289
+
281
290
// Verify that the block number is parent's +1
282
291
if diff := new (big.Int ).Sub (header .Number , parent .Number ); diff .Cmp (big .NewInt (1 )) != 0 {
283
292
return consensus .ErrInvalidNumber
@@ -289,6 +298,9 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
289
298
}
290
299
}
291
300
// If all checks passed, validate any special fields for hard forks
301
+ if err := misc .VerifyEIP1559BaseFee (chain .Config (), header , parent ); err != nil {
302
+ return err
303
+ }
292
304
if err := misc .VerifyDAOHeaderExtraData (chain .Config (), header ); err != nil {
293
305
return err
294
306
}
@@ -583,21 +595,41 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainReader, header *t
583
595
func (ethash * Ethash ) SealHash (header * types.Header ) (hash common.Hash ) {
584
596
hasher := sha3 .NewLegacyKeccak256 ()
585
597
586
- rlp .Encode (hasher , []interface {}{
587
- header .ParentHash ,
588
- header .UncleHash ,
589
- header .Coinbase ,
590
- header .Root ,
591
- header .TxHash ,
592
- header .ReceiptHash ,
593
- header .Bloom ,
594
- header .Difficulty ,
595
- header .Number ,
596
- header .GasLimit ,
597
- header .GasUsed ,
598
- header .Time ,
599
- header .Extra ,
600
- })
598
+ if header .BaseFee == nil {
599
+ rlp .Encode (hasher , []interface {}{
600
+ header .ParentHash ,
601
+ header .UncleHash ,
602
+ header .Coinbase ,
603
+ header .Root ,
604
+ header .TxHash ,
605
+ header .ReceiptHash ,
606
+ header .Bloom ,
607
+ header .Difficulty ,
608
+ header .Number ,
609
+ header .GasLimit ,
610
+ header .GasUsed ,
611
+ header .Time ,
612
+ header .Extra ,
613
+ })
614
+ } else {
615
+ rlp .Encode (hasher , []interface {}{
616
+ header .ParentHash ,
617
+ header .UncleHash ,
618
+ header .Coinbase ,
619
+ header .Root ,
620
+ header .TxHash ,
621
+ header .ReceiptHash ,
622
+ header .Bloom ,
623
+ header .Difficulty ,
624
+ header .Number ,
625
+ header .GasLimit ,
626
+ header .GasUsed ,
627
+ header .Time ,
628
+ header .Extra ,
629
+ header .BaseFee ,
630
+ })
631
+ }
632
+
601
633
hasher .Sum (hash [:0 ])
602
634
return hash
603
635
}
0 commit comments