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

Issues with eth_getStorageAt using hardhat #1685

Closed
ehabhussein opened this issue Sep 6, 2022 · 1 comment
Closed

Issues with eth_getStorageAt using hardhat #1685

ehabhussein opened this issue Sep 6, 2022 · 1 comment

Comments

@ehabhussein
Copy link

Description:

when using and deploying contracts on hardhat, mythril tries to call eth_getStorageAt it returns an exception as it is calling a storage slot with less than 66 bytes in the rpc call. Example:

mythril.ethereum.interface.rpc.client [DEBUG]: rpc send: {"jsonrpc": "2.0", "method": "eth_getStorageAt", "params": ["0xE7F1725E7734CE288F8367E1BB143E90BB3F0512", **"0x7",** "latest"], "id": 1} urllib3.connectionpool [DEBUG]: http://localhost:8545 "POST / HTTP/1.1" 200 335 mythril.ethereum.interface.rpc.client [DEBUG]: rpc response: {'jsonrpc': '2.0', 'id': 1, 'error': {'code': -32602, 'message': 'Errors encountered in param 1: **Storage slot argument must have a length of 66 ("0x" + 32 bytes), but \'0x7\' has a length of 3', 'data':** {'message': 'Errors encountered in param 1: Storage slot argument must have a length of 66 ("0x" + 32 bytes), but \'0x7\' has a length of 3'}}} mythril.mythril.mythril_analyzer [CRITICAL]: Exception occurred, aborting analysis. Please report this issue to the Mythril GitHub page. Traceback (most recent call last): File "/usr/local/lib/python3.9/dist-packages/mythril/ethereum/interface/rpc/client.py", line 82, in _call return response["result"] KeyError: 'result'

This Exception is raised in File "/usr/local/lib/python3.9/dist-packages/mythril/ethereum/interface/rpc/client.py", line 90

As seen above the data sent was 0x7 but it should 0x000000000000000000000000000000000000000000000000000000007

Testing a solution by modifying the client.py:

 def _call(self, method, params=None, _id=1):
        params = params or []

        print(f"params is: {params}")
        if len(params) > 2 :
            params[1] = "0x"+str(params[1]).replace("0x",'').rjust(67-len(params[1]),"0")
            print(f"params is: {params}")`

How to Reproduce

launch a contract on hardhat and the exception will be raised.

$ myth -v4 analyze --solver-timeout 90000 --rpc localhost:8545 -a 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

Expected behavior

$ curl -X POST --data '{"jsonrpc": "2.0", "method": "eth_getStorageAt", "params": ["0xE7F1725E7734CE288F8367E1BB143E90BB3F0512","0x0000000000000000000000000000000000000000000000000000000000000007" ,"0x2"], "id": 1}' http://127.0.0.1:8545

{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000000"}

return a successful response with the value

Environment

└─# pip3 show mythril
Name: mythril
Version: 0.23.9
# uname -a
Linux koli 5.10.0-kali9-amd64 #1 SMP Debian 5.10.46-4kali1 (2021-08-09) x86_64 GNU/Linux
@norhh
Copy link
Collaborator

norhh commented Sep 8, 2022

The hardhat version you are using is not compliant with the eth RPC standard (ethers-io/ethers.js#2982).
Since eth_getStorageAt takes its second value as an int.
Try switching to a different hardhat version.

@norhh norhh closed this as completed Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants