Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 87724d3

Browse files
committed
Fixing handling the accounts without hashing in the trie
1 parent edb7a56 commit 87724d3

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

geth-utils/gethutil/mpt/state/statedb.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
298298

299299
// GetProof returns the Merkle proof for a given account.
300300
func (s *StateDB) GetProof(addr common.Address) ([][]byte, []byte, [][]byte, bool, bool, error) {
301-
return s.GetProofByHash(crypto.Keccak256Hash(addr.Bytes()))
301+
var newAddr common.Hash
302+
if oracle.PreventHashingInSecureTrie {
303+
bytes := append(addr.Bytes(), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}...)
304+
newAddr = common.BytesToHash(bytes)
305+
}
306+
return s.GetProofByHash(newAddr)
302307
}
303308

304309
// GetProofByHash returns the Merkle proof for a given account.
@@ -311,7 +316,13 @@ func (s *StateDB) GetProofByHash(addrHash common.Hash) ([][]byte, []byte, [][]by
311316
// GetStorageProof returns the Merkle proof for given storage slot.
312317
func (s *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, []byte, [][]byte, bool, bool, error) {
313318
var proof proofList
314-
trie := s.StorageTrie(a)
319+
newAddr := a
320+
if oracle.PreventHashingInSecureTrie {
321+
bytes := append(a.Bytes(), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}...)
322+
newAddr = common.BytesToAddress(bytes)
323+
}
324+
325+
trie := s.StorageTrie(newAddr)
315326
if trie == nil {
316327
return proof, nil, nil, false, false, errors.New("storage trie for requested address does not exist")
317328
}

geth-utils/gethutil/mpt/trie/secure_trie.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func (t *SecureTrie) Update(key, value []byte) {
109109
// If a node was not found in the database, a MissingNodeError is returned.
110110
func (t *SecureTrie) TryUpdate(key, value []byte) error {
111111
hk := t.hashKey(key)
112+
if oracle.PreventHashingInSecureTrie {
113+
hk = append(hk, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}...)
114+
}
112115
err := t.trie.TryUpdate(hk, value)
113116
if err != nil {
114117
return err

geth-utils/gethutil/mpt/witness/gen_witness_from_infura_blockchain_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,11 +2344,10 @@ func TestStorageWrongExtensionNode(t *testing.T) {
23442344
addr := common.HexToAddress("0x40efbf12580138bc623c95757286df4e24eb81c9")
23452345

23462346
statedb.DisableLoadingRemoteAccounts()
2347+
oracle.PreventHashingInSecureTrie = true // to store the unchanged key
23472348

23482349
statedb.CreateAccount(addr)
23492350

2350-
oracle.PreventHashingInSecureTrie = true // to store the unchanged key
2351-
23522351
key1 := common.HexToHash("0x1230000000000000000000000000000000000000000000000000000000000000")
23532352
key2 := common.HexToHash("0x1231000000000000000000000000000000000000000000000000000000000000")
23542353

geth-utils/gethutil/mpt/witness/prepare_witness.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
179179

180180
addr := tMod.Address
181181
addrh := crypto.Keccak256(addr.Bytes())
182+
if oracle.PreventHashingInSecureTrie {
183+
addrh = addr.Bytes()
184+
addrh = append(addrh, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}...)
185+
}
182186
accountAddr := trie.KeybytesToHex(addrh)
183187

184188
oracle.PrefetchAccount(statedb.Db.BlockNumber, tMod.Address, nil)

0 commit comments

Comments
 (0)