@@ -911,18 +911,9 @@ func (hph *HexPatriciaHashed) computeCellHash(cell *cell, depth int16, buf []byt
911911 hashedKeyOffset = depth - 64
912912 }
913913 singleton := depth <= 64
914- koffset := hph .accountKeyLen
915- if depth == 0 && cell .accountAddrLen == 0 {
916- // if account key is empty, then we need to hash storage key from the key beginning
917- koffset = 0
918- }
919- if err = cell .hashStorageKey (hph .keccak , koffset , 0 , hashedKeyOffset ); err != nil {
920- return nil , err
921- }
922- cell .hashedExtension [64 - hashedKeyOffset ] = terminatorHexByte // Add terminator
923914
915+ // Check cached stateHash BEFORE hashing key (optimization: skip key hash if using cache)
924916 if cell .stateHashLen > 0 {
925- hph .keccak .Reset ()
926917 if hph .trace {
927918 fmt .Printf ("REUSED stateHash %x spk %x\n " , cell .stateHash [:cell .stateHashLen ], cell .storageAddr [:cell .storageAddrLen ])
928919 }
@@ -934,6 +925,15 @@ func (hph *HexPatriciaHashed) computeCellHash(cell *cell, depth int16, buf []byt
934925 storageRootHashIsSet = true
935926 storageRootHash = * (* common .Hash )(cell .stateHash [:cell .stateHashLen ])
936927 } else {
928+ koffset := hph .accountKeyLen
929+ if depth == 0 && cell .accountAddrLen == 0 {
930+ // if account key is empty, then we need to hash storage key from the key beginning
931+ koffset = 0
932+ }
933+ if err = cell .hashStorageKey (hph .keccak , koffset , 0 , hashedKeyOffset ); err != nil {
934+ return nil , err
935+ }
936+ cell .hashedExtension [64 - hashedKeyOffset ] = terminatorHexByte // Add terminator
937937 if ! cell .loaded .storage () {
938938 return nil , fmt .Errorf ("storage %x was not loaded as expected: cell %v" , cell .storageAddr [:cell .storageAddrLen ], cell .String ())
939939 // update, err := hph.ctx.Storage(cell.storageAddr[:cell.storageAddrLen])
0 commit comments