Consensys / abi-decoder

Nodejs and Javascript library for decoding data params and events from ethereum transactions
GNU General Public License v3.0
633 stars 218 forks source link

Event log decode error: BigNumber Error: new BigNumber() not a base 16 number: #19

Closed mikeshultz closed 6 years ago

mikeshultz commented 6 years ago

Having an issue decoding an event log with abi-decoder@1.0.9. Perhaps the problem is with an event string argument, but the error message doesn't point out exactly what it's having an issue with. Here's a simple test case:

const abiDecoder = require('abi-decoder');
const simpleABI = [{
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "name": "tagHash",
        "type": "bytes32"
      }, {
          "indexed": true,
          "name": "firstProposer",
          "type": "address"
      }, {
          "indexed": true,
          "name": "secondProposer",
          "type": "address"
      }, {
          "indexed": false,
          "name": "tagName",
          "type": "string"
      }
    ],
    "name": "TagActivated",
    "type": "event"
}];
const testLog = { 
  address: '0x045f938bd53f87d745938fdb7c36af3a228494b7',
  topics: [ 
    '0xe3be63cadbca73f1ec47cb1e6e478b35a17056c269e8637aa60c65853efe05c2',
    '0x3d03b3af6b873f883e8316435fedcb99ad340ac5d26ff776cfe84e9f6d8e0420'
  ],
  data: '0x000000000000000000000000f2a3047bc98fb43dd782948e88c785475609dce4000000000000000000000000b89c7bf13e8c852d29b3ce7bd1be0e6c47d81b8c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000056c756e7972000000000000000000000000000000000000000000000000000000',
  blockNumber: '0x151',
  transactionHash: '0x4e91ae4d9c76ad68271e647dff9b19a5d876a9cc4ff1fe372cb2009981bad639',
  transactionIndex: '0x0',
  blockHash: '0xcb1e027a0996177a2151f541eaccdc51cce38d1b975f0719c0ca1f4e09b9cac0',
  logIndex: '0x1',
  removed: false 
};
abiDecoder.addABI(simpleABI);
abiDecoder.decodeLogs([testLog])

And the resulting error:

BigNumber Error: new BigNumber() not a base 16 number: 
    at raise (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:1177:25)
    at /home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:1165:33
    at new BigNumber (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/bignumber.js/bignumber.js:212:28)
    at SolidityTypeString.formatOutputString [as _outputFormatter] (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/formatters.js:220:19)
    at /home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/type.js:246:25
    at SolidityTypeString.SolidityType.decode (/home/mike/dev/Test-Project/backend/node_modules/abi-decoder/node_modules/web3/lib/solidity/type.js:247:11)

Let me know if I can provide any more info.

mikeshultz commented 6 years ago

Simplest test case so far, seems to lay the blame with web3.js, or how abi-decoder is calling SolidityCoder.

const SolidityCoder = require("./lib/solidity/coder.js");
SolidityCoder.decodeParams([ 'string' ], '000000000000000000000000f2a3047bc98fb43dd782948e88c785475609dce4000000000000000000000000b89c7bf13e8c852d29b3ce7bd1be0e6c47d81b8c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000056c756e7972000000000000000000000000000000000000000000000000000000')

I'm not super familiar with dynamic type parsing, so I don't yet know where exactly the blame lies.

mikeshultz commented 6 years ago

This does not look to be a parser issue, but perhaps a solidity bug, problem with the contract, or the node running the test network. The event is not what I'd expect. There's only 2 elements in topics, when there's 3 indexed event params, which I believe should mean topics.length === 4.

I'll look into the problem from that angle and assume it's not an abi-decoder issue for now.

benediamond commented 5 years ago

I'm getting the same issue when decoding a method call. any further insights on this?

denisgranha commented 5 years ago

Sorry I haven't maintained this for a while, I will check the issues this week and perform some updates