cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
645 stars 330 forks source link

blockResults: Input not in int53 range #1465

Closed AndreMiras closed 10 months ago

AndreMiras commented 1 year ago

I came across a block (88458) on evmos that triggers an Input not in int53 range error. I'm running @cosmjs/tendermint-rpc 0.31.0

Here's a simple reproduction:

import assert from "assert";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";

const TENDERMINT_RPC_URL = process.env.TENDERMINT_RPC_URL;
assert.ok(TENDERMINT_RPC_URL);

const main = async () => {
  const heights = [88457, 88458];
  const client = await Tendermint34Client.connect(TENDERMINT_RPC_URL);
  for (const height of heights) {
    console.log({height})
    const blockResults = await client.blockResults(height);
    console.log("OK")
  }
};

main();

Executed with:

node_modules/.bin/ts-node src/cosmos-int53-range-error.ts

Output was:

{ height: 88457 }
OK
{ height: 88458 }
Error: Input not in int53 range: 168139200000000000
    at new Int53 (/project/node_modules/@cosmjs/math/src/integers.ts:137:13)
    at Function.fromString (/project/node_modules/@cosmjs/math/src/integers.ts:122:12)
    at apiToSmallInt (/project/node_modules/@cosmjs/tendermint-rpc/src/inthelpers.ts:12:70)
    at decodeTxData (/project/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:161:29)
    at Array.map (<anonymous>)
    at decodeBlockResults (/project/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:298:39)
    at decodeBlockResults (/project/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:844:12)
    at Tendermint34Client.doCall (/project/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/tendermint34client.ts:344:12)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

These are some pretty old blocks so I've attached /block_results?height=88457 and /block_results?height=88458 in case you don't have access to an archive node. block_results?height=88457.txt block_results?height=88458.txt

webmaster128 commented 1 year ago
Bildschirmfoto 2023-08-21 um 09 53 17

Interesting, thanks for the detailed report. Seems like a gas_wanted value in a transaction. This value is higher than any reasonable amount but users can enter it.

The solution here would probably be to avoid using apiToSmallInt and return a bigint instead of number.