question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BaseProvider getStorageAt position is not spec-compliant

See original GitHub issue

Ethers Version

@ethersproject/providers 5.6.5

Search Terms

BaseProvider,getStorageAt

Describe the Problem

I came across this while trying to use provider.getStorageAt(someAddress, 0); against a fresh install of Hardhat. The fresh install evidently used Hardhat v2.9.5 that includes a change to make Hardhat network’s eth_getStorageAt spec compliant (Hardhat PR here, references spec found here). Apparently the spec requires the storage position passed into eth_getStorageAt to be a 32 byte hex string, which BaseProvider doesn’t do.

Calling getStorageAt would give this Hardhat error: InvalidArgumentsError: Errors encountered in param 1: Storage slot argument must have a length of 66 ("0x" + 32 bytes), but '0x0' has a length of 3. Eventually I tracked it down to this line: https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/base-provider.ts#L1482

I was able to fix it locally by changing the hexValue(p) to hexZeroPad(p, 32). I’m happy to open a PR but I’m not sure if that’s the best place to make the change / if it totally preserves backward compatibility for other use cases.

For any passerby, downgrading Hardhat version to <= v2.9.4 seems to be a sufficient workaround for now

Code Snippet

provider.getStorageAt(someAddress, 0);
// or even
provider.getStorageAt(someAddress, '0x0000000000000000000000000000000000000000000000000000000000000000');

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer), Hardhat

Environment (Other)

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ricmoocommented, May 26, 2022

5.6.7 should work too. I’ll re-open and look at it tomorrow.

2reactions
ricmoocommented, May 13, 2022

The change should probably go into JsonRpcProvider for going over the JSON-RPC wire protocol, since I don’t want to change the behaviour of the the class BaseProvider which has other sub-classes.

Thanks! I’ll fix this today. 😃

(Note: in v6, the formatter has a storageSlot method, which is used to safely transform this value based on the network)

Read more comments on GitHub >

github_iconTop Results From Across the Web

web3.eth — web3.js 1.0.0 documentation - Read the Docs
This default address is used as the default "from" property, if no "from" property is ... getStorageAt(address, position [, defaultBlock] [, callback]).
Read more >
Provider - Ethers.js
Returns the Bytes32 value of the position pos at address addr, as of the blockTag. await provider.getStorageAt("registrar.firefly.eth", ...
Read more >
web3.eth.getStorageAt for mapping - Ethereum Stack Exchange
You can retrieve storage entries via RPC using the getStorageAt call. There is no need to manually interact with the trie.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found