ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Overflow error when decoding event logs that include invalid address data.

Open mhw0 opened this issue 10 months ago • 5 comments

Ethers Version

6.x.x

Search Terms

No response

Describe the Problem

Getting overflow error when decoding event logs.

Code Snippet

for(const log of tableReceipt?.logs!)
  console.log(contract.interface.decodeEventLog("TestEvent", txn.data, log.topics));

Contract ABI

["event TestEvent(address addr)"]

Errors

TypeError: overflow (argument="value", value=1725436586697640946858688965569256363112777243042596638790631055949824, code=INVALID_ARGUMENT, version=6.7.1)
    at makeError (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/utils/errors.ts:678:21)
    at assert (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/utils/errors.ts:702:25)
    at assertArgument (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/utils/errors.ts:714:5)
    at getNumber (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/utils/maths.ts:154:27)
    at toNumber (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/utils/maths.ts:177:12)
    at Reader.readIndex (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:465:24)
    at /Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/abi/coders/array.ts:90:33
    at Array.forEach (<anonymous>)
    at unpack (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/abi/coders/array.ts:86:12)
    at TupleCoder.decode (/Users/mhw0/oss/yyyy/node_modules/ethers/src.ts/abi/coders/tuple.ts:66:22) {
  code: 'INVALID_ARGUMENT',
  argument: 'value',
  value: 1725436586697640946858688965569256363112777243042596638790631055949824n
}

Environment

Hardhat

Environment (Other)

No response

mhw0 avatar Sep 24 '23 16:09 mhw0

Can you include the tx or log data and topics?

ricmoo avatar Sep 24 '23 17:09 ricmoo

Here is the event log:

  EventLog {                                                                                                                                                                                                                                                                                                                                                          
    transactionHash: '0x3d7e453b67815fdf878757fa9412d7be9942cc40b95869f7a9b560982159d114',                                                                                               
    blockHash: '0x1f0f530dc967938c7151bdb7a7fe2a52f273ff982fdaf09b77ca0e3a70e2bef4',                                                                                                     
    blockNumber: 3,
    removed: undefined,
    address: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
    data: '0x000000000000000000000000cafac3dd18ac6c6e92c921884f9e4176737c052c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000
000000000000000000a0000000000000000000000000000000000000000000000000000000000000000555736572730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000029e8ca8269648675696e743332cc846e616d6586737472696e67cf87757365725f69648675696e7433320000000000000000000000000000000000000000000000',
    topics: [
      '0x02324a3d06b1415ec5fbb329f5656481ec04bc4df6d31152eb573fcde08c60e0'
    ],
    index: 0,
    transactionIndex: 0,
    interface: Interface {
      fragments: [Array],
      deploy: [ConstructorFragment],
      fallback: null,
      receive: false
    },
    fragment: EventFragment {
      type: 'event',
      inputs: [Array],
      name: 'TableCreated',
      anonymous: false
    },
    args: Result(3) [
      '0xCafac3dD18aC6c6e92c921884f9E4176737C052c',
      'YYYY',
      '0xe8ca8269648675696e743332cc846e616d6586737472696e67cf87757365725f69648675696e743332'
    ]
  }

mhw0 avatar Sep 24 '23 17:09 mhw0

That event was successfully parsed though; it has an .args property.

ricmoo avatar Sep 24 '23 18:09 ricmoo

Yes, but when you do contract.interface.decodeEventLog("TestEvent", txn.data, log.topics), it throws that exception. Maybe it's already parsed, that's why?

mhw0 avatar Sep 24 '23 18:09 mhw0

Just didn't want to do (receipt!.logs[0] as any)["args"][0]. It looks ugly.

mhw0 avatar Sep 24 '23 18:09 mhw0