Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: quantity-encode storage keys in eth_getProof response #27309

Merged
merged 9 commits into from Jun 21, 2023
7 changes: 4 additions & 3 deletions internal/ethapi/api.go
Expand Up @@ -650,7 +650,7 @@ type AccountResult struct {
}

type StorageResult struct {
Key string `json:"key"`
Key *hexutil.Big `json:"key"`
Value *hexutil.Big `json:"value"`
Proof []string `json:"proof"`
}
Expand Down Expand Up @@ -680,6 +680,7 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
// create the proof for the storageKeys
for i, hexKey := range storageKeys {
key, err := decodeHash(hexKey)
keyInt := (*hexutil.Big)(new(big.Int).SetBytes(key[:]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unorthodox to do this operation, involving key, before checking/handling the err. It's safe, in this instance, but not "The Way" :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my go is far from idiomatic

if err != nil {
return nil, err
}
Expand All @@ -688,9 +689,9 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
if storageError != nil {
return nil, storageError
}
storageProof[i] = StorageResult{hexKey, (*hexutil.Big)(state.GetState(address, key).Big()), toHexSlice(proof)}
storageProof[i] = StorageResult{keyInt, (*hexutil.Big)(state.GetState(address, key).Big()), toHexSlice(proof)}
} else {
storageProof[i] = StorageResult{hexKey, &hexutil.Big{}, []string{}}
storageProof[i] = StorageResult{keyInt, &hexutil.Big{}, []string{}}
}
}

Expand Down