@@ -16,6 +16,7 @@ import {
16
16
createZeroAddress ,
17
17
equalsBytes ,
18
18
hexToBytes ,
19
+ ssz ,
19
20
toType ,
20
21
zeros ,
21
22
} from '@ethereumjs/util'
@@ -30,6 +31,9 @@ import { fakeExponential } from '../helpers.js'
30
31
import { paramsBlock } from '../params.js'
31
32
32
33
import type { BlockHeaderBytes , BlockOptions , HeaderData , JSONHeader } from '../types.js'
34
+ import type { ValueOf } from '@chainsafe/ssz'
35
+
36
+ export type SSZHeaderType = ValueOf < typeof ssz . BlockHeader >
33
37
34
38
interface HeaderCache {
35
39
hash : Uint8Array | undefined
@@ -633,17 +637,55 @@ export class BlockHeader {
633
637
return rawItems
634
638
}
635
639
640
+ sszRaw ( ) : SSZHeaderType {
641
+ const header = {
642
+ parentHash : this . parentHash ,
643
+ uncleHash : this . uncleHash ,
644
+ coinbase : this . coinbase . bytes ,
645
+ stateRoot : this . stateRoot ,
646
+ transactionsTrie : this . transactionsTrie ,
647
+ receiptTrie : this . receiptTrie ,
648
+ number : this . number ,
649
+ gasLimits : {
650
+ regular : this . gasLimit ,
651
+ blob : this . common . isActivatedEIP ( 4844 ) ? this . common . param ( 'maxblobGasPerBlock' ) : null ,
652
+ } ,
653
+ gasUsed : { regular : this . gasUsed , blob : this . blobGasUsed ?? null } ,
654
+ timestamp : this . timestamp ,
655
+ extraData : this . extraData ,
656
+ mixHash : this . mixHash ,
657
+ baseFeePerGas : {
658
+ regular : this . baseFeePerGas ?? null ,
659
+ blob : this . common . isActivatedEIP ( 4844 ) ? this . getBlobGasPrice ( ) : null ,
660
+ } ,
661
+ withdrawalsRoot : this . withdrawalsRoot ?? null ,
662
+ excessBlobGas : this . excessBlobGas ?? null ,
663
+ parentBeaconBlockRoot : this . parentBeaconBlockRoot ?? null ,
664
+ requestsRoot : this . requestsRoot ?? null ,
665
+ }
666
+
667
+ return header
668
+ }
669
+
670
+ calcHash ( ) : Uint8Array {
671
+ if ( this . common . isActivatedEIP ( 6493 ) ) {
672
+ return ssz . BlockHeader . hashTreeRoot ( this . sszRaw ( ) )
673
+ } else {
674
+ return this . keccakFunction ( RLP . encode ( this . raw ( ) ) )
675
+ }
676
+ }
677
+
636
678
/**
637
679
* Returns the hash of the block header.
638
680
*/
639
681
hash ( ) : Uint8Array {
640
682
if ( Object . isFrozen ( this ) ) {
641
683
if ( ! this . cache . hash ) {
642
- this . cache . hash = this . keccakFunction ( RLP . encode ( this . raw ( ) ) ) as Uint8Array
684
+ this . cache . hash = this . calcHash ( )
643
685
}
644
686
return this . cache . hash
645
687
}
646
- return this . keccakFunction ( RLP . encode ( this . raw ( ) ) )
688
+ return this . calcHash ( )
647
689
}
648
690
649
691
/**
0 commit comments