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

eth_getStorageAt api can not work with go-etheruem/ethclient and umbracle/go-web3 #1822

Closed
laizy opened this issue Aug 25, 2021 · 6 comments
Closed

Comments

@laizy
Copy link

laizy commented Aug 25, 2021

#1700 (comment)

The storage‘s key/value in ethereum is fixed 20 bytes, and should be encoded as Hash. But it seems hardhat take it as integer and only accept data without leading zeros.

Here is the signature from ethereuem's go code :

func (ec *Client) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) 

and hardhat node will report error:

---> {"jsonrpc":"2.0","id":17,"method":"eth_getStorageAt","params":["0x851356ae760d987e095750cceb3bc6014560891c","0x0000000000000000000000000000000000000000000000000000000000000001","latest"]}
<--- {"code":-32602,"message":"Errors encountered in param 1: Invalid value \"0x0000000000000000000000000000000000000000000000000000000000000001\" supplied to : QUANTITY"}
@alcuadrado
Copy link
Member

Hey,

I don't think your description is correct. How geth represents these types internally doesn't necessary match the json rpc spec.

Take a look at this: https://eth.wiki/json-rpc/API#eth_getstorageat

@laizy laizy changed the title [bug] eth_getStorageAt api not working eth_getStorageAt api can not work with go-etheruem/ethclient and umbracle/go-web3 Aug 25, 2021
@laizy
Copy link
Author

laizy commented Aug 25, 2021

@alcuadrado thanks for the link. what I paste above is geth's client side code, not server side code. so it will send the key as hash with leading zeros. And I tried and found the geth server node will accept two forms of data.

But the eips also have some inconsistencies , like the eth_getproof api take the keys as 32bytes hash.

It is up to you to remove the restriction or just close this.

@fvictorio
Copy link
Member

I think this is a duplicate of #1585. Tentatively closing this, but please re-open if you think it's a different issue.

@meetmangukiya
Copy link

@fvictorio while the linked issue is correct about not accepting leading zeros for getBlockByNumber because it is a uint type according to the specl, for getStorageAt the spec is uint256 which does accept leading zeros:
https://github.com/ethereum/execution-apis/blob/9bc4c1afaa7ab7961fd0d82c9403860063cc20ac/src/eth/state.json#L39-L45
https://github.com/ethereum/execution-apis/blob/9bc4c1afaa7ab7961fd0d82c9403860063cc20ac/src/schemas/base-types.json#L42-L46

@fvictorio
Copy link
Member

@meetmangukiya you are right. In fact, I think the storage slot must always have 64 characters. We have a new issue about this: #2230

@meetmangukiya
Copy link

@fvictorio right, the regex certainly looks like it

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants