@@ -23,7 +23,6 @@ import (
2323 "encoding/hex"
2424 "errors"
2525 "fmt"
26- "hash"
2726 "io"
2827 "math/bits"
2928 "runtime"
@@ -32,7 +31,7 @@ import (
3231 "sync/atomic"
3332 "time"
3433
35- "golang.org/x/crypto/sha3 "
34+ keccak "github.com/erigontech/fastkeccak "
3635
3736 "github.com/erigontech/erigon/common"
3837 "github.com/erigontech/erigon/common/crypto"
@@ -48,14 +47,6 @@ import (
4847 "github.com/erigontech/erigon/execution/types/accounts"
4948)
5049
51- // keccakState wraps sha3.state. In addition to the usual hash methods, it also supports
52- // Read to get a variable amount of data from the hash state. Read is faster than Sum
53- // because it doesn't copy the internal state, but also modifies the internal state.
54- type keccakState interface {
55- hash.Hash
56- Read ([]byte ) (int , error )
57- }
58-
5950// DomainPutter is an interface for putting data into domains.
6051// Used by commitment to write branch data.
6152type DomainPutter = stateifs.DomainPutter
@@ -82,8 +73,8 @@ type HexPatriciaHashed struct {
8273 branchBefore [128 ]bool // For each row, whether there was a branch node in the database loaded in unfold
8374 touchMap [128 ]uint16 // For each row, bitmap of cells that were either present before modification, or modified or deleted
8475 afterMap [128 ]uint16 // For each row, bitmap of cells that were present after modification
85- keccak keccakState
86- keccak2 keccakState
76+ keccak keccak. KeccakState
77+ keccak2 keccak. KeccakState
8778 rootChecked bool // Set to false if it is not known whether the root is empty, set to true if it is checked
8879 rootTouched bool
8980 rootPresent bool
@@ -133,8 +124,8 @@ func (hph *HexPatriciaHashed) SpawnSubTrie(ctx PatriciaContext, forNibble int) *
133124func NewHexPatriciaHashed (accountKeyLen int16 , ctx PatriciaContext ) * HexPatriciaHashed {
134125 hph := & HexPatriciaHashed {
135126 ctx : ctx ,
136- keccak : sha3 . NewLegacyKeccak256 ().( keccakState ),
137- keccak2 : sha3 . NewLegacyKeccak256 ().( keccakState ),
127+ keccak : keccak . NewFastKeccak ( ),
128+ keccak2 : keccak . NewFastKeccak ( ),
138129 accountKeyLen : accountKeyLen ,
139130 auxBuffer : bytes .NewBuffer (make ([]byte , 8192 )),
140131 hadToLoadL : make (map [uint64 ]skipStat ),
@@ -207,11 +198,11 @@ var (
207198 emptyRootHashBytes = empty .RootHash .Bytes ()
208199)
209200
210- func (cell * cell ) hashAccKey (keccak keccakState , depth int16 , hashBuf []byte ) error {
201+ func (cell * cell ) hashAccKey (keccak keccak. KeccakState , depth int16 , hashBuf []byte ) error {
211202 return hashKey (keccak , cell .accountAddr [:cell .accountAddrLen ], cell .hashedExtension [:], depth , hashBuf )
212203}
213204
214- func (cell * cell ) hashStorageKey (keccak keccakState , accountKeyLen , downOffset int16 , hashedKeyOffset int16 , hashBuf []byte ) error {
205+ func (cell * cell ) hashStorageKey (keccak keccak. KeccakState , accountKeyLen , downOffset int16 , hashedKeyOffset int16 , hashBuf []byte ) error {
215206 return hashKey (keccak , cell .storageAddr [accountKeyLen :cell .storageAddrLen ], cell .hashedExtension [downOffset :], hashedKeyOffset , hashBuf )
216207}
217208
@@ -376,7 +367,7 @@ func (cell *cell) fillFromLowerCell(lowCell *cell, lowDepth int16, preExtension
376367 cell .loaded = lowCell .loaded
377368}
378369
379- func (cell * cell ) deriveHashedKeys (depth int16 , keccak keccakState , accountKeyLen int16 , hashBuf []byte ) error {
370+ func (cell * cell ) deriveHashedKeys (depth int16 , keccak keccak. KeccakState , accountKeyLen int16 , hashBuf []byte ) error {
380371 extraLen := int16 (0 )
381372 if cell .accountAddrLen > 0 {
382373 if depth > 64 {
0 commit comments