BaseProvider getStorageAt position is not spec-compliant
See original GitHub issueEthers 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:
- Created a year ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
5.6.7 should work too. I’ll re-open and look at it tomorrow.
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)