Uniswap / v3-subgraph

Subgraph for Uniswap V3
GNU General Public License v3.0
338 stars 464 forks source link

Overflow converting to i32 error #204

Open JavierTrujilloG opened 5 months ago

JavierTrujilloG commented 5 months ago

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 https://github.com/Uniswap/v3-subgraph/commit/ac71c01902164c31827760a342acc20ab8f69177

paulbarclay commented 5 months ago

(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 commented 5 months ago

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