web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.32k stars 4.95k forks source link

Error on getPastEvents for solidity@0.4.x #3680

Closed hbarcelos closed 3 years ago

hbarcelos commented 4 years ago

This relates to #3544.

Expected behavior

If I use web3<=1.2.6, everything works just fine.

Actual behavior

I get the following error:

Error: data out-of-bounds (length=110, offset=128, code=BUFFER_OVERRUN, version=abi/5.0.0-beta.153)
    at Logger.makeError (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/logger/lib/index.js:179:21)
    at Logger.throwError (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/logger/lib/index.js:188:20)
    at Reader._peekBytes (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:135:20)
    at Reader.readBytes (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:146:26)
    at StringCoder.DynamicBytesCoder.decode (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/bytes.js:30:23)
    at StringCoder.decode (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/string.js:27:63)
    at /home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/array.js:77:31
    at Array.forEach (<anonymous>)
    at Object.unpack (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/array.js:71:12)
    at TupleCoder.decode (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
    at AbiCoder.decode (/home/henrique/labs/web3-getPastEvents-issue/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22)
    at ABICoder.decodeParameters (/home/henrique/labs/web3-getPastEvents-issue/node_modules/web3-eth-abi/src/index.js:347:30)
    at ABICoder.decodeLog (/home/henrique/labs/web3-getPastEvents-issue/node_modules/web3-eth-abi/src/index.js:401:52)
    at Object.Contract._decodeEventABI (/home/henrique/labs/web3-getPastEvents-issue/node_modules/web3-eth-contract/src/index.js:482:31)
    at /home/henrique/labs/web3-getPastEvents-issue/node_modules/web3-core-method/src/index.js:166:57
    at Array.map (<anonymous>)

Steps to reproduce the behavior

  1. Here's the relevant part of the ABI for the contract:

    [{
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "_metaEvidenceID",
          "type": "uint256"
        },
        {
          "indexed": false,
          "name": "_evidence",
          "type": "string"
        }
      ],
      "name": "MetaEvidence",
      "type": "event"
    }]

    Here's the link to the smart contract implementation: https://github.com/kleros/kleros-interaction/blob/master/contracts/standard/arbitration/IArbitrable.sol#L27

    Here's the address of the deployed contract on Kovan network: 0x0825f16598AcB518851f8959b8267EF296c57f81.

  2. Using the following snippet:

    const Web3 = require("web3");
    const abi = require("./abi.json");
    
    const web3 = new Web3(
      new Web3.providers.HttpProvider(
        `https://kovan.infura.io/v3/${process.env.INFURA_API_KEY}`
      )
    );
    const address = "0x0825f16598AcB518851f8959b8267EF296c57f81";
    
    const contract = new web3.eth.Contract(abi, address);
    
    (async () => {
      const data = await contract.getPastEvents("MetaEvidence", {
        filter: { _metaEvidenceID: "28" },
        fromBlock: 0,
      });
    })();
    

Logs

N/A

Environment

GregTheGreek commented 4 years ago

Please see related issue: #3544

from https://github.com/ethers-io/ethers.js/issues/992#issuecomment-671112940:

There is a known Solidity v4.x bug that events emitted from an external (public is fine) function in Solidity that dynamic objects are encoded incorrectly. This is a compiler bug which makes it very hard to work around. :( The work around for it can break correctly functioning contracts, which is the problem.

ricmoo commented 4 years ago

I've added support in ethers 5.0.12 for supporting legacy Solidity 0.4 external event data. I believe web3 depends on the abi package directly, in which case web3 should upgrade to @ethersproject/abi version 5.0.4.

For more details, please see https://github.com/ethers-io/ethers.js/issues/891.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

spacesailor24 commented 4 years ago

I think #3738 is related, and the release candidate should fix this

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

GregTheGreek commented 3 years ago

@spacesailor24 can you confirm if the RC fixed this?

spacesailor24 commented 3 years ago

I copied over the provided code into a test repo

I'm getting the presumably expected output of:

[
  {
    address: '0x0825f16598AcB518851f8959b8267EF296c57f81',
    blockHash: '0xc6ccd170d9dd5d86906b0f7dd9c5d34cadc19bc8d9c54eba5c4b9a5f5cfe72bf',
    blockNumber: 19567645,
    logIndex: 7,
    removed: false,
    transactionHash: '0xae646874553121365f59bb08864a61b1a883f0a0d25d7ee100a3786e2a3a37b5',
    transactionIndex: 2,
    transactionLogIndex: '0x0',
    type: 'mined',
    id: 'log_dc96d986',
    returnValues: Result {
      '0': '28',
      '1': '/ipfs/QmTJXDEWMPwNq1qhXB9EKCT6L7oqcnZm5dbyqFZiPCQF2V/linguo-meta-evidence.json',
      _metaEvidenceID: '28',
      _evidence: '/ipfs/QmTJXDEWMPwNq1qhXB9EKCT6L7oqcnZm5dbyqFZiPCQF2V/linguo-meta-evidence.json'
    },
    event: 'MetaEvidence',
    signature: '0x61606860eb6c87306811e2695215385101daab53bd6ab4e9f9049aead9363c7d',
    raw: {
      data: '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004e2f697066732f516d544a584445574d50774e71317168584239454b4354364c376f71636e5a6d3564627971465a695043514632562f6c696e67756f2d6d6574612d65766964656e63652e6a736f6e',
      topics: [Array]
    }
  }
]

So @GregTheGreek I do believe this to be resolved