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

Overflow converting to i32 error #204

Open
JavierTrujilloG opened this issue Mar 20, 2024 · 2 comments
Open

Overflow converting to i32 error #204

JavierTrujilloG opened this issue Mar 20, 2024 · 2 comments

Comments

@JavierTrujilloG
Copy link

JavierTrujilloG commented Mar 20, 2024

Hi there,
We are experiencing an overflow error across multiple chains. Here's an example for ethereum:

transaction 83f11ad653a9cdee52e54db2365947c61dd054af250f7fcf52240967eea4095a: Mapping aborted at ~lib/@graphprotocol/graph-ts/common/collections.ts, line 150, column 9, with message: overflow converting 0x0000000000000000000000000000000000000000000000000000000067e53c31 to i32
    wasm backtrace:
        0: 0x4b36 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value#toI32
        1: 0x6058 - <unknown>!src/common/getters/getOrCreateToken
        2: 0x7db5 - <unknown>!src/common/creators/createLiquidityPool
        3: 0x824e - <unknown>!src/mappings/Factory/handlePoolCreated
     in handler `handlePoolCreated` at block #19473885 (f4f2c65bcd633fd2b82a716f1de6315dbed65bb95218cbbd6140958a3fd46470)
Subgraph instance failed to run: transaction 83f11ad653a9cdee52e54db2365947c61dd054af250f7fcf52240967eea4095a
Mapping aborted at ~lib/@graphprotocol/graph-ts/index.ts, line 380, column 8
Message: Overflow converting 0x0000000000000000000000000000000000000000000000000000000067e53c31 to i32

Wasm backtrace:
0: 0x242a - <unknown>!~lib/@graphprotocol/graph-ts/index/ByteArray#toI32
1: 0x2536 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value#toI32
2: 0x2569 - <unknown>!src/types/Factory/ERC20/ERC20#try_decimals
3: 0x257b - <unknown>!src/utils/token/fetchTokenDecimals
4: 0x2b44 - <unknown>!src/mappings/factory/handlePoolCreated in handler `handlePoolCreated`
at block #19473885 (f4f2c65bcd633fd2b82a716f1de6315dbed65bb95218cbbd6140958a3fd46470)

Code: SubgraphSyncingFailure
Sgd: 25807
Subgraph_id: QmZeCuoZeadgHkGwLwMeguyqUKz1WPWQYKcKyMCeQqGhsF
Component: SubgraphInstanceManager
Subgraph error 1/1:
Code: SubgraphSyncingFailure
Error: Transaction 83f11ad653a9cdee52e54db2365947c61dd054af250f7fcf52240967eea4095a
Mapping aborted at ~lib/@graphprotocol/graph-ts/index.ts, line 380, column 8
Message: Overflow converting 0x0000000000000000000000000000000000000000000000000000000067e53c31 to i32

Wasm backtrace:
0: 0x242a - <unknown>!~lib/@graphprotocol/graph-ts/index/ByteArray#toI32
1: 0x2536 - <unknown>!~lib/@graphprotocol/graph-ts/chain/ethereum/ethereum.Value#toI32
2: 0x2569 - <unknown>!src/types/Factory/ERC20/ERC20#try_decimals
3: 0x257b - <unknown>!src/utils/token/fetchTokenDecimals
4: 0x2b44 - <unknown>!src/mappings/factory/handlePoolCreated in handler `handlePoolCreated`
At block #19473885 (block hash: 0xf4f2c65bcd633fd2b82a716f1de6315dbed65bb95218cbbd6140958a3fd46470)

SGD: 25807
Subgraph ID: QmZeCuoZeadgHkGwLwMeguyqUKz1WPWQYKcKyMCeQqGhsF
Component: SubgraphInstanceManager

Here’s the transaction.

This seems to also affecting https://info.uniswap.org/
It could be caused by this change ac71c01

@paulbarclay
Copy link

(This un-merged PR contains the fix: #194 )

There's definitely a problem, but it's in the try_decimals part, not the conversion of that to a bigint. The problem is that the graph expects erc20 contracts to follow the erc20 standard, which includes defining decimals as uint8. The challenge is this particular contract does not follow the erc20 standard; its Decimals doesn't return a uint8, but instead a bytes32.

So, the bytes32 (0x0000000000000000000000000000000000000000000000000000000067e53c31) overflows the toI32() in graph-ts (now graph-tooling), as it expects the first 4 bytes of the array to be the number, not the last 4 bytes.

There's a couple of issues going on here:

  1. Decimals really shouldn't be converted using an int32; a negative decimal value is an unwanted result.
  2. There should be a safety valve around getting the decimals in case of unexpected (ie non-uint8) values.

Code for toInt32(): https://github.com/graphprotocol/graph-tooling/blob/5a3ec8626a860e3df4cca8da14cdd908191b2258/packages/ts/common/collections.ts#L120

@paymog
Copy link

paymog commented Apr 9, 2024

Interesting, I tried building the subgraph at #194 and I'm running into build time issues

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

No branches or pull requests

3 participants