eth-json-rpc-filters icon indicating copy to clipboard operation
eth-json-rpc-filters copied to clipboard

`intToHex` util produces invalid Quantities

Open josepot opened this issue 3 years ago • 2 comments

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:

{
    "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, 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.

josepot avatar Sep 01 '22 10:09 josepot

Hello. I am also facing the same issue and am closely monitoring this issue. I believe resolving this problem is crucial for many users. I would greatly appreciate any progress on this matter.

[FYI] Related issue in metamask-extension repository:

  • https://github.com/MetaMask/metamask-extension/issues/8220

YuyaMaruyama21D4E avatar Nov 05 '24 01:11 YuyaMaruyama21D4E

Related:

  • https://github.com/MetaMask/metamask-extension/pull/28146
    • https://github.com/MetaMask/metamask-extension/pull/28169
  • https://github.com/MetaMask/metamask-mobile/pull/12043
    • https://github.com/MetaMask/metamask-mobile/pull/11972

legobeat avatar Nov 05 '24 02:11 legobeat