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

The JSON-RPC layer is overly permissive about the number formats it accepts #509

Open
fvictorio opened this issue Jun 13, 2024 · 5 comments
Assignees

Comments

@fvictorio
Copy link
Member

These are all being accepted by EDR right now:

send("eth_getBlockByNumber", [0, false])
send("eth_getBlockByNumber", ["0", false])
send("eth_getBlockByNumber", ["0b0", false])
send("eth_getBlockByNumber", ["0o0", false])

send("eth_getStorageAt", ["0x63689f2aE7c74Db7A9D5523d5a1463a0F5bF0cf4", "0"])
send("eth_getStorageAt", ["0x63689f2aE7c74Db7A9D5523d5a1463a0F5bF0cf4", "0b0"])

Curiously, the last two are also accepted by geth, but that's clearly an error.

The full scope of this is not clear, but my guess is that fixing those (and any other examples that come to mind) will already uncover some issues. No need to do a thorough investigation.

@alcuadrado
Copy link
Member

alcuadrado commented Jun 13, 2024

eth_getStorageAt is a historically complex case, because different libraries (e.g. ethers) expected different formats at different points in time. See the last version of Hardhat without EDR, it's treated as a special case: https://github.com/NomicFoundation/hardhat/blob/5f0e42d5fdef3fb1f3b5592758f828f03612b8b2/packages/hardhat-core/src/internal/hardhat-network/provider/modules/eth.ts#L711-L719

While in that same file, you'd find that eth_getBlockByNumber uses a block tag, which is eventually a strict rpc quantity, which I think is the expected behaviour, and being more permissive is a bug.

@alcuadrado
Copy link
Member

alcuadrado commented Jun 13, 2024

Also note that only eth_getStorageAt accepts that weird type.

@fvictorio
Copy link
Member Author

@alcuadrado can you clarify exactly which of these cases you think we should support? Because to me supporting 0b and 0o prefixes is clearly wrong. I do see that supporting decimal numbers (stringified or not) might make sense in some scenarios (although I would happily remove support for those too).

@Wodann
Copy link
Member

Wodann commented Jun 25, 2024

Alloy has a crate with serde helpers to handle this nicely.

@Wodann Wodann self-assigned this Feb 5, 2025
@Wodann Wodann moved this from Todo to In Progress in EDR Feb 5, 2025
@Wodann
Copy link
Member

Wodann commented Feb 5, 2025

As part of my upgrade to the latest REVM, I had to change some types in the JSON-RPC layer. In doing so, I also started switching to the aforementioned alloy-serde crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

3 participants