Skip to content

Commit e0c7ad0

Browse files
consensus: verify the nonexistence of shanghai- and cancun-specific header fields (#28605)
1 parent 34dcd74 commit e0c7ad0

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

consensus/clique/clique.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,22 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
302302
if chain.Config().IsShanghai(header.Number, header.Time) {
303303
return errors.New("clique does not support shanghai fork")
304304
}
305+
// Verify the non-existence of withdrawalsHash.
306+
if header.WithdrawalsHash != nil {
307+
return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash)
308+
}
305309
if chain.Config().IsCancun(header.Number, header.Time) {
306310
return errors.New("clique does not support cancun fork")
307311
}
312+
// Verify the non-existence of cancun-specific header fields
313+
switch {
314+
case header.ExcessBlobGas != nil:
315+
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
316+
case header.BlobGasUsed != nil:
317+
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
318+
case header.ParentBeaconRoot != nil:
319+
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
320+
}
308321
// All basic checks passed, verify cascading fields
309322
return c.verifyCascadingFields(chain, header, parents)
310323
}
@@ -753,6 +766,15 @@ func encodeSigHeader(w io.Writer, header *types.Header) {
753766
if header.WithdrawalsHash != nil {
754767
panic("unexpected withdrawal hash value in clique")
755768
}
769+
if header.ExcessBlobGas != nil {
770+
panic("unexpected excess blob gas value in clique")
771+
}
772+
if header.BlobGasUsed != nil {
773+
panic("unexpected blob gas used value in clique")
774+
}
775+
if header.ParentBeaconRoot != nil {
776+
panic("unexpected parent beacon root value in clique")
777+
}
756778
if err := rlp.Encode(w, enc); err != nil {
757779
panic("can't encode: " + err.Error())
758780
}

consensus/ethash/consensus.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,22 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
266266
if chain.Config().IsShanghai(header.Number, header.Time) {
267267
return errors.New("ethash does not support shanghai fork")
268268
}
269+
// Verify the non-existence of withdrawalsHash.
270+
if header.WithdrawalsHash != nil {
271+
return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash)
272+
}
269273
if chain.Config().IsCancun(header.Number, header.Time) {
270274
return errors.New("ethash does not support cancun fork")
271275
}
276+
// Verify the non-existence of cancun-specific header fields
277+
switch {
278+
case header.ExcessBlobGas != nil:
279+
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
280+
case header.BlobGasUsed != nil:
281+
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
282+
case header.ParentBeaconRoot != nil:
283+
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
284+
}
272285
// Add some fake checks for tests
273286
if ethash.fakeDelay != nil {
274287
time.Sleep(*ethash.fakeDelay)
@@ -533,6 +546,15 @@ func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
533546
if header.WithdrawalsHash != nil {
534547
panic("withdrawal hash set on ethash")
535548
}
549+
if header.ExcessBlobGas != nil {
550+
panic("excess blob gas set on ethash")
551+
}
552+
if header.BlobGasUsed != nil {
553+
panic("blob gas used set on ethash")
554+
}
555+
if header.ParentBeaconRoot != nil {
556+
panic("parent beacon root set on ethash")
557+
}
536558
rlp.Encode(hasher, enc)
537559
hasher.Sum(hash[:0])
538560
return hash

0 commit comments

Comments
 (0)