Skip to content

Notes on probable bugs in filters #836

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

Open
pipermerriam opened this issue May 10, 2018 · 0 comments
Open

Notes on probable bugs in filters #836

pipermerriam opened this issue May 10, 2018 · 0 comments
Assignees

Comments

@pipermerriam
Copy link
Member

pipermerriam commented May 10, 2018

What is wrong?

There are probably (almost definitely) bugs lurking in contract event filters that filter on data values.

None of these have actually been verified, this is strictly from me looking over the code.

1. Variable length data elements.

suppose the log data has an ABI with a variable length value before other values. MyEvent(string,bytes32)

The code which constructs the regex here: https://github.com/ethereum/web3.py/blob/master/web3/utils/filters.py#L138 assumes fixed length placeholders for all variable length data elements which I don't believe is correct.

2. List types

suppose my event has a list type in it like MyEvent(bytes2[])

To filter on this value, one might pass in arguments like filters={'arg_a': [b'aa', b'xx']}.

However, when the data filters are constructed: https://github.com/ethereum/web3.py/blob/master/web3/utils/events.py#L99

With normal single value arguments, if you want to filter against multiple options, you pass those options in as a list. For single values, they should be passed in singularly. For example, to filter against a single uint you would do filters={'arg_X': 1234} and to filter against multiple options for field arg_X, filters={'arg_X', [1234, 4321]}.

In the linked code in the events.py utils, it assumes that anything that is_list_like has already been wrapped in a list, which will result in an error either during execution, or an incorrectly constructed regex.

3. dynamic sized types.

This one I'm not very sure of at all. however,

The data filter regex is constructed using encode_single, and then all of the values are joined together to form the regex. However, this is not how ABI encoding works... as dynamic sized things are actually shoved to a later offset in the encoded data. if events encode their data field the same way, the regex won't match.

How can we fix this.

All three of these issues deal with regex issues....

https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/

So, lets get rid of the regex. Rather than regexing the data, lets instead just try decoding it using the event ABI, and then matching against the provided arguments in their native python form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants