mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/ethapi: fix codehash lookup in eth_getProof
This commit is contained in:
parent
1e55e52b26
commit
ca99a741c6
1 changed files with 29 additions and 35 deletions
|
|
@ -676,8 +676,7 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
keyLengths = make([]int, len(storageKeys))
|
keyLengths = make([]int, len(storageKeys))
|
||||||
storageProof = make([]StorageResult, len(storageKeys))
|
storageProof = make([]StorageResult, len(storageKeys))
|
||||||
|
|
||||||
storageTrie state.Trie
|
storageRoot = types.EmptyRootHash
|
||||||
storageHash = types.EmptyRootHash
|
|
||||||
codeHash = types.EmptyCodeHash
|
codeHash = types.EmptyCodeHash
|
||||||
)
|
)
|
||||||
// Deserialize all keys. This prevents state access on invalid input.
|
// Deserialize all keys. This prevents state access on invalid input.
|
||||||
|
|
@ -692,20 +691,15 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
if state == nil || err != nil {
|
if state == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if storageRoot := state.GetStorageRoot(address); storageRoot != types.EmptyRootHash && storageRoot != (common.Hash{}) {
|
codeHash = state.GetCodeHash(address)
|
||||||
|
storageRoot = state.GetStorageRoot(address)
|
||||||
|
|
||||||
|
if len(keys) > 0 && storageRoot != types.EmptyRootHash && storageRoot != (common.Hash{}) { // Create storage proof
|
||||||
id := trie.StorageTrieID(header.Root, crypto.Keccak256Hash(address.Bytes()), storageRoot)
|
id := trie.StorageTrieID(header.Root, crypto.Keccak256Hash(address.Bytes()), storageRoot)
|
||||||
tr, err := trie.NewStateTrie(id, state.Database().TrieDB())
|
storageTrie, err := trie.NewStateTrie(id, state.Database().TrieDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
storageTrie = tr
|
|
||||||
}
|
|
||||||
// If we have a storageTrie, the account exists and we must update
|
|
||||||
// the storage root hash and the code hash.
|
|
||||||
if storageTrie != nil {
|
|
||||||
storageHash = storageTrie.Hash()
|
|
||||||
codeHash = state.GetCodeHash(address)
|
|
||||||
}
|
|
||||||
// Create the proofs for the storageKeys.
|
// Create the proofs for the storageKeys.
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
// Output key encoding is a bit special: if the input was a 32-byte hash, it is
|
// Output key encoding is a bit special: if the input was a 32-byte hash, it is
|
||||||
|
|
@ -730,7 +724,7 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
value := (*hexutil.Big)(state.GetState(address, key).Big())
|
value := (*hexutil.Big)(state.GetState(address, key).Big())
|
||||||
storageProof[i] = StorageResult{outputKey, value, proof}
|
storageProof[i] = StorageResult{outputKey, value, proof}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Create the accountProof.
|
// Create the accountProof.
|
||||||
tr, err := trie.NewStateTrie(trie.StateTrieID(header.Root), state.Database().TrieDB())
|
tr, err := trie.NewStateTrie(trie.StateTrieID(header.Root), state.Database().TrieDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -746,7 +740,7 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
Balance: (*hexutil.Big)(state.GetBalance(address)),
|
Balance: (*hexutil.Big)(state.GetBalance(address)),
|
||||||
CodeHash: codeHash,
|
CodeHash: codeHash,
|
||||||
Nonce: hexutil.Uint64(state.GetNonce(address)),
|
Nonce: hexutil.Uint64(state.GetNonce(address)),
|
||||||
StorageHash: storageHash,
|
StorageHash: storageRoot,
|
||||||
StorageProof: storageProof,
|
StorageProof: storageProof,
|
||||||
}, state.Error()
|
}, state.Error()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue