Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decodeLog() for non indexed params #2272

Merged
merged 9 commits into from
Feb 6, 2019
Merged

Fix decodeLog() for non indexed params #2272

merged 9 commits into from
Feb 6, 2019

Conversation

AlexanderC
Copy link

@AlexanderC AlexanderC commented Jan 30, 2019

Fix decodeLog() for non indexed params.

Description

The issue can be reproduced for events like this:

event Authorize(
        bytes32 indexed platformId,
        bytes32 indexed uid,
        address indexed user,
        AuthorizationRequest request
    );

It is cause by _mapTypes(types) used in decodeParameters(outputs, bytes) (var res = this.ethersAbiCoder.decode(this._mapTypes(outputs), "0x".concat(bytes.replace(/0x/i, '')));) which returns [ { indexed: false, name: 'request', type: 'address' } ] for types = outputs = [null, null, null, {"indexed":false,"name":"request","type":"address"}] passed as argument.

So when the iteration outputs.forEach(function (output, i) {} is performed the returnValues do not get res[i] assigned correctly because the index is shifted due to empty types cleanup.

Fixes #2268

Type of change

  • Bug fix

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I ran npm run test in the root folder with success and extended the tests if necessary.
  • My changes generate no warnings.
  • I ran npm run build in the root folder and tested it in the browser and with node.
  • I have tested my code on the live network.

Fix `decodeLog()` for non indexed params. 

The issue can be reproduced for events like this:

```
event Authorize(
        bytes32 indexed platformId,
        bytes32 indexed uid,
        address indexed user,
        AuthorizationRequest request
    );
```

It is cause by `_mapTypes(types)` used in `decodeParameters(outputs, bytes)` (`var res = this.ethersAbiCoder.decode(this._mapTypes(outputs), "0x".concat(bytes.replace(/0x/i, '')));`) which returns `[ { indexed: false, name: 'request', type: 'address' } ]` for `types = outputs = [null, null, null, {"indexed":false,"name":"request","type":"address"}]` passed as argument. 
So when the iteration `outputs.forEach(function (output, i) {}` is performed the `returnValues` do not get `res[i]` assigned correctly because the index is shifted due to empty types cleanup.

The fix might be linked to the following issue: web3#2268
@nivida nivida added the Bug Addressing a bug label Feb 3, 2019
Copy link
Contributor

@nivida nivida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the AbiCoder and AbiCoder test in the eth-abi module? the created test case "calls decodeLog and returns the expected object" should run without a error :-)

@AlexanderC
Copy link
Author

Could you update the AbiCoder and AbiCoder test in the eth-abi module? the created test case "calls decodeLog and returns the expected object" should run without a error :-)

@nivida Done

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 92.98% when pulling 5455f15 on AlexanderC:patch-1 into 9feb075 on ethereum:1.0.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 92.98% when pulling 5455f15 on AlexanderC:patch-1 into 9feb075 on ethereum:1.0.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 92.98% when pulling 5455f15 on AlexanderC:patch-1 into 9feb075 on ethereum:1.0.

@coveralls
Copy link

coveralls commented Feb 5, 2019

Coverage Status

Coverage increased (+0.005%) to 92.98% when pulling fcc2744 on AlexanderC:patch-1 into f34c646 on ethereum:1.0.

@AlexanderC
Copy link
Author

AlexanderC commented Feb 6, 2019

@nivida I see Travis failing due to other tests/linting checks performed. How can i help to fix it?

@nivida
Copy link
Contributor

nivida commented Feb 6, 2019

@AlexanderC Because dtslint is failing will I merge this PR in the 1.0 branch and fix this before I prepare the release. Thanks for fixing this bug!

@nivida nivida merged commit 8d4da2d into web3:1.0 Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decodeLog() is broken after updating to beta.41 from beta.35
3 participants