-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make eth_getStorageAt spec-compliant #2581
Conversation
HH-321 The slot parameter of `eth_getStorageAt` should accept hex encoded unsigned integers
We are expecting the storage slot parameter of
Notice that the value should have a length of 64, but we'll reject many of those (because values with leading zeros are not a valid I don't know if we can start rejecting shorter values though. On one hand, we try to be as spec-compliant as possible, but in the other hand that would be a breaking change. |
🦋 Changeset detectedLatest commit: 83914cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts
Outdated
Show resolved
Hide resolved
This fix does not resolve the issue I'm having in Foundry, which is related to failed eth_getStorageAt calls in hardhat vs direct full-node RPC. I installed this branch and ran the problem test and I get the following. I also reported this to Foundry at foundry-rs/foundry#1297
|
I think maybe the problem is from the calls to numberToRpcQuantity() in the eth_getStorageAt implementation itself, in getStorageAt.ts? Nevermind I did:
and was able to verify that the fixes in this PR resolve the eth_getStorageAt issue I was facing from Foundry/forge tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a suggestion and a question, this LGTM without necessarily resolving those.
"0x0101010101010101010101010101010101010101", | ||
"0xcd39aa866fd639607c7241f617cf83f33c646551f3d205f2905c5abacca2db85", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these bytestrings have any specific relevance? How does the expected output relate to these inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a random storage slot, and an address that is (almost surely) empty. Added some comments explaining this.
packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts
Outdated
Show resolved
Hide resolved
packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left a few comments, but LGTM
(Just a reminder for myself: we are not merging this until the network helpers are released) |
Co-authored-by: Patricio Palladino <email@patriciopalladino.com>
007494b
to
83914cb
Compare
This is now released in |
this is a bit confusing to me because this spec https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getstorageat says it's a QUANTITY... what am I missing? |
Hey @mattsse! We are trying to follow the OpenRPC-based spec, but it can have mistakes. When in doubt we try to copy whatever Geth does tbh. We want to avoid users thinking that what they are doing should work, just to realize it doesn't when going into production and switching to Geth. Note that in This was also surprising to me, as before that spec we also used that description of the JSON-RPC as our first-line source of truth, so I just re-checked it. In Geth it uses a |
I see, this is clear now, thank you! |
Hi guys, I've been following this thread since back in April when I reported a related issue to both the foundry and hardhat projects (see my comments on this bug in April). As a result I've dug into all of the history and my conclusion is that I believe there may be an error being made here on hardhat's side regarding the OpenRPC spec. Specifically: contains a reference to a spec that states:
However, the origin of that spec is unknown and, it seems NOT to be what's currently in the open rpc specification. In fact, the spec referenced at the opening of #2581 (this bug, yes, scroll to top) says:
(and by the way, @alcuadrado this is the same spec that appears in the spec you link to in your most recent comment) I also chased down the regex specification format used by open rpc, which is perl's: From https://perldoc.perl.org/perlre we have The issue of the hash vs uint vs uint256 type in the implementation seems distinct from what SHOULD be accepted by the RPC encoding specification. There is no source provided for the spec quoted in #2230, so it's not clear whether that is somehow more recent, but given that the current open rpc spec says {0,64} that seems doubtful. Note: That being said |
I looked at geth and it does not appear to enforce a length on hash types. In api.go:
which eventually calls:
which is implemented like this:
|
According to the spec, the storage slot in
eth_getStorageAt
should have a length of 66 (0x + 32 bytes).While this is technically a bug fix, it will probably break things for many people. There are two solutions:
helpers.getStorageAt
, since the network helpers will be released along with this change (or soon enough).ethers.utils.hexZeroPad(storageSlot, 32)
around the value to make it valid