mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Revert "internal/ethapi: prevent unnecessary resource usage in eth_getProof implementation (#27310)"
This reverts commit 4fb4311887.
This commit is contained in:
parent
185aa5e1a3
commit
7cc5d3c1bc
1 changed files with 23 additions and 42 deletions
|
|
@ -655,62 +655,43 @@ type StorageResult struct {
|
||||||
Proof []string `json:"proof"`
|
Proof []string `json:"proof"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// proofList implements ethdb.KeyValueWriter and collects the proofs as
|
|
||||||
// hex-strings for delivery to rpc-caller.
|
|
||||||
type proofList []string
|
|
||||||
|
|
||||||
func (n *proofList) Put(key []byte, value []byte) error {
|
|
||||||
*n = append(*n, hexutil.Encode(value))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *proofList) Delete(key []byte) error {
|
|
||||||
panic("not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetProof returns the Merkle-proof for a given account and optionally some storage keys.
|
// GetProof returns the Merkle-proof for a given account and optionally some storage keys.
|
||||||
func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) {
|
func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) {
|
||||||
var (
|
|
||||||
keys = make([]common.Hash, len(storageKeys))
|
|
||||||
storageProof = make([]StorageResult, len(storageKeys))
|
|
||||||
storageTrie state.Trie
|
|
||||||
storageHash = types.EmptyRootHash
|
|
||||||
codeHash = types.EmptyCodeHash
|
|
||||||
)
|
|
||||||
// Greedily deserialize all keys. This prevents state access on invalid input
|
|
||||||
for i, hexKey := range storageKeys {
|
|
||||||
if key, err := decodeHash(hexKey); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
keys[i] = key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
||||||
if state == nil || err != nil {
|
if state == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if storageTrie, err = state.StorageTrie(address); err != nil {
|
storageTrie, err := state.StorageTrie(address)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// if we have a storageTrie, the account exists and we must update
|
storageHash := types.EmptyRootHash
|
||||||
// the storage root hash and the code hash.
|
codeHash := state.GetCodeHash(address)
|
||||||
|
storageProof := make([]StorageResult, len(storageKeys))
|
||||||
|
|
||||||
|
// if we have a storageTrie, (which means the account exists), we can update the storagehash
|
||||||
if storageTrie != nil {
|
if storageTrie != nil {
|
||||||
storageHash = storageTrie.Hash()
|
storageHash = storageTrie.Hash()
|
||||||
codeHash = state.GetCodeHash(address)
|
} else {
|
||||||
|
// no storageTrie means the account does not exist, so the codeHash is the hash of an empty bytearray.
|
||||||
|
codeHash = crypto.Keccak256Hash(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the proof for the storageKeys
|
// create the proof for the storageKeys
|
||||||
for i, key := range keys {
|
for i, hexKey := range storageKeys {
|
||||||
if storageTrie == nil {
|
key, err := decodeHash(hexKey)
|
||||||
storageProof[i] = StorageResult{storageKeys[i], &hexutil.Big{}, []string{}}
|
if err != nil {
|
||||||
continue
|
|
||||||
}
|
|
||||||
var proof proofList
|
|
||||||
if err := storageTrie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
storageProof[i] = StorageResult{storageKeys[i],
|
if storageTrie != nil {
|
||||||
(*hexutil.Big)(state.GetState(address, key).Big()),
|
proof, storageError := state.GetStorageProof(address, key)
|
||||||
proof}
|
if storageError != nil {
|
||||||
|
return nil, storageError
|
||||||
|
}
|
||||||
|
storageProof[i] = StorageResult{hexKey, (*hexutil.Big)(state.GetState(address, key).Big()), toHexSlice(proof)}
|
||||||
|
} else {
|
||||||
|
storageProof[i] = StorageResult{hexKey, &hexutil.Big{}, []string{}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the accountProof
|
// create the accountProof
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue