MetaMask / MetaMask/eth-json-rpc-filters
`intToHex` util produces invalid Quantities
- Dominant language
- JavaScript
- Stars
- 29
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
Hi and thank you for maintaining this library!
Our dApp stopped working once we tested it against a recently deployed tenderly fork.
After spending some hours trying to find the root cause, it turns out that the problem is that some of the calls that metamask makes to `eth_getLogs` (as a result of a `logs` subscription) have an invalid payload.
An example of an invalid payload produced from metamask in order to query the logs of the newest block:
```json
{
"id": 2265185671823508,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"fromBlock": "0x01470640",
"toBlock": "0x1470641",
"address": [
"0xda10009cbd5d07dd0cecc66161fc93d7c9000da1"
],
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}
]
}
```
At a first glance everything looks fine. However, if we pay closer attention to the `fromBlock` field we will notice that it has [an invalid leading zero](https://ethereum.org/en/developers/docs/apis/json-rpc/#quantities-encoding), which causes the node to reject the request due to invalid parameters.
My guess is that this issue doesn't come up very often b/c most nodes must tolerate invalid "Quantity" fields. However, according to the official spec:
> When encoding quantities (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0").
Another reason why I think that this issue doesn't come up often is because I've noticed that most of the times that the queries are created, the quantity fields come from the result of other requests, which are returning properly encoded Quantity fields.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the `intToHex` utility and tracing how it is used when building `eth_getLogs` requests from logs subscriptions. Reproduce the example quantity encoding and verify that the resulting request follows the JSON-RPC quantity specification, including the absence of invalid leading zeroes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100