Web3.js: new web3-eth-abi decodeLog throw error when the event's input are all indexed

Created on 23 Nov 2018  ·  11Comments  ·  Source: ChainSafe/web3.js

When the input of an event are all indexed, go-ethereum's JSON-RPC will response with data '0x', it will throw an error cause by the following code

ABICoder.prototype.decodeParameters = function (outputs, bytes) {
    if (!bytes || bytes === '0x' || bytes === '0X') {
        throw new Error('Returned values aren\'t valid, did it run Out of Gas?');
    }
    //...
}

I found the following test code, I assume Line 82 should be 0x not empty string

https://github.com/ethereum/web3.js/blob/0d54d94e637832abf97834e4fc444fbff87f874b/test/eth.abi.decodeLog.js#L70-L91

bug

Most helpful comment

I'd like to work on it.

All 11 comments

I'd like to work on it.

Confirmed same with 1.0.0-beta.36, appears to be a regression from unaffected 1.0.0-beta.35

Just in case you're wondering, ganache in this case returns: 0x00 which works.

btw. i think this one is related: https://github.com/ethereum/web3.js/issues/1916

Any simple workaround for this? My contract event filters are now broken.

@conscott I didn't manage to prepare a PR fixing it since current develop branch is much different so I used patch-package to fix it locally and create git patch applied on every yarn install. A dirty solution, but it works 🤷‍♂️

Here's patch:

patch-package
# FIX FOR: https://github.com/ethereum/web3.js/issues/2065
--- a/node_modules/web3-eth-abi/src/index.js
+++ b/node_modules/web3-eth-abi/src/index.js
@@ -222,7 +222,7 @@ ABICoder.prototype.decodeParameter = function (type, bytes) {
  * @return {Array} array of plain params
  */
 ABICoder.prototype.decodeParameters = function (outputs, bytes) {
-    if (!bytes || bytes === '0x' || bytes === '0X') {
+    if (!bytes) {
         throw new Error('Returned values aren\'t valid, did it run Out of Gas?');
     }

thanks @krzkaczor !

the behavior still occurs on 1.0.0-beta.37 even though is reported on the changelog to be fixed. how can I be of more help?

This is still not resolved in beta 37. I've monkey patched it for now, but it would be nice to get an official fix. Anything I can do to help, please let me know! @krzkaczor

@travisdmathis what is your patch?

I just did a test in beta 37, the test codes are:

const ethABI = require('web3-eth-abi')

const ABI = [{
    type: 'string',
    name: 'MyString',
    indexed: true
}, {
    type: 'bool',
    name: 'IsTrue',
    indexed: true
}, {
    type: 'uint8',
    name: 'myNumberWork',
    indexed: true
}]

const data = '0x'
const topics = ['0xffdd000000000000000000000000000000000000000000000000000000000003', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000fd44']

console.log(ethABI.decodeLog(ABI, data, topics))

Seems the problem is solved, @travisdmathis @rmujica can you provide some cases that will produce the error? Otherwise, I will close this issue

Was this page helpful?
0 / 5 - 0 ratings