mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/ethapi: fix regression in getstorage for eth_getProof
This commit is contained in:
parent
ca99a741c6
commit
d9f7ac98a0
1 changed files with 18 additions and 18 deletions
|
|
@ -675,9 +675,6 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
keys = make([]common.Hash, len(storageKeys))
|
keys = make([]common.Hash, len(storageKeys))
|
||||||
keyLengths = make([]int, len(storageKeys))
|
keyLengths = make([]int, len(storageKeys))
|
||||||
storageProof = make([]StorageResult, len(storageKeys))
|
storageProof = make([]StorageResult, len(storageKeys))
|
||||||
|
|
||||||
storageRoot = types.EmptyRootHash
|
|
||||||
codeHash = types.EmptyCodeHash
|
|
||||||
)
|
)
|
||||||
// Deserialize all keys. This prevents state access on invalid input.
|
// Deserialize all keys. This prevents state access on invalid input.
|
||||||
for i, hexKey := range storageKeys {
|
for i, hexKey := range storageKeys {
|
||||||
|
|
@ -687,18 +684,22 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
statedb, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
||||||
if state == nil || err != nil {
|
if statedb == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
codeHash = state.GetCodeHash(address)
|
codeHash := statedb.GetCodeHash(address)
|
||||||
storageRoot = state.GetStorageRoot(address)
|
storageRoot := statedb.GetStorageRoot(address)
|
||||||
|
|
||||||
if len(keys) > 0 && storageRoot != types.EmptyRootHash && storageRoot != (common.Hash{}) { // Create storage proof
|
if len(keys) > 0 {
|
||||||
id := trie.StorageTrieID(header.Root, crypto.Keccak256Hash(address.Bytes()), storageRoot)
|
var storageTrie state.Trie
|
||||||
storageTrie, err := trie.NewStateTrie(id, state.Database().TrieDB())
|
if storageRoot != types.EmptyRootHash && storageRoot != (common.Hash{}) {
|
||||||
if err != nil {
|
id := trie.StorageTrieID(header.Root, crypto.Keccak256Hash(address.Bytes()), storageRoot)
|
||||||
return nil, err
|
st, err := trie.NewStateTrie(id, statedb.Database().TrieDB())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
storageTrie = st
|
||||||
}
|
}
|
||||||
// Create the proofs for the storageKeys.
|
// Create the proofs for the storageKeys.
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
|
|
@ -712,7 +713,6 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
} else {
|
} else {
|
||||||
outputKey = hexutil.Encode(key[:])
|
outputKey = hexutil.Encode(key[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
if storageTrie == nil {
|
if storageTrie == nil {
|
||||||
storageProof[i] = StorageResult{outputKey, &hexutil.Big{}, []string{}}
|
storageProof[i] = StorageResult{outputKey, &hexutil.Big{}, []string{}}
|
||||||
continue
|
continue
|
||||||
|
|
@ -721,12 +721,12 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
if err := storageTrie.Prove(crypto.Keccak256(key.Bytes()), &proof); err != nil {
|
if err := storageTrie.Prove(crypto.Keccak256(key.Bytes()), &proof); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
value := (*hexutil.Big)(state.GetState(address, key).Big())
|
value := (*hexutil.Big)(statedb.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), statedb.Database().TrieDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -737,12 +737,12 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||||
return &AccountResult{
|
return &AccountResult{
|
||||||
Address: address,
|
Address: address,
|
||||||
AccountProof: accountProof,
|
AccountProof: accountProof,
|
||||||
Balance: (*hexutil.Big)(state.GetBalance(address)),
|
Balance: (*hexutil.Big)(statedb.GetBalance(address)),
|
||||||
CodeHash: codeHash,
|
CodeHash: codeHash,
|
||||||
Nonce: hexutil.Uint64(state.GetNonce(address)),
|
Nonce: hexutil.Uint64(statedb.GetNonce(address)),
|
||||||
StorageHash: storageRoot,
|
StorageHash: storageRoot,
|
||||||
StorageProof: storageProof,
|
StorageProof: storageProof,
|
||||||
}, state.Error()
|
}, statedb.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeHash parses a hex-encoded 32-byte hash. The input may optionally
|
// decodeHash parses a hex-encoded 32-byte hash. The input may optionally
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue