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

Use 11-bit mask in Bloom.check #311

Merged
merged 1 commit into from Jul 23, 2018

Conversation

gkaemmer
Copy link
Contributor

Fixes #303.

Page 5-6 of the Ethereum Yellow Paper specifies that the bloom filter take the low-order 11 bits from each of the first 3 pair of bytes of the hash. The proper bitmask for the low 11 bits is 2^11 - 1 = 2047.

For some reason the check function in bloom.js only takes the low-order 9 bits using a mask of 511, so check always returns false.

I think the check method is not used anywhere in this library (I only found this by trying to use bloom.js in my own code), but probably still worth fixing.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.739% when pulling ae5bcf6 on gkaemmer:bloom-check-fix into 4ecae8a on ethereumjs:master.

@axic
Copy link
Member

axic commented Jul 17, 2018

Is there a way to include tests for this?

@holgerd77
Copy link
Member

@axic Tests will be covered with #310 (currently running as a Gitcoin bounty), so it would be rather conflicting to introduce separate tests here.

@holgerd77
Copy link
Member

@gkaemmer I am also realizing though, that I am not the super-bloom filter expert. From reading up on this, I would says this is correct, but could you provide at least one (here in the comments) working code example where a value is not checked correctly before and checked correctly with the PR?

@holgerd77
Copy link
Member

@gkaemmer Would also be good if you could rebase on this occasion.

@gkaemmer
Copy link
Contributor Author

gkaemmer commented Jul 21, 2018

@holgerd77 Rebased on master. Here's a quick check:

// After `git checkout origin/master`
const Bloom = require("./lib/bloom.js");
const bloom = new Bloom();
bloom.add("test");
bloom.check("test"); // false
bloom.check("test2"); // false
// After `git checkout gkaemmer/bloom-check-fix`
const Bloom = require("./lib/bloom.js");
const bloom = new Bloom();
bloom.add("test");
bloom.check("test"); // true
bloom.check("test2"); // false

@holgerd77
Copy link
Member

@gkaemmer Ah, sorry, wasn't aware that this can be tested so easily and initialized without passing any value, this really needs better documentation.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Looks good, tested this locally, will merge.

@holgerd77 holgerd77 merged commit 64753d5 into ethereumjs:master Jul 23, 2018
@axic
Copy link
Member

axic commented Jul 23, 2018

I would have merged this after #315, so that unit tests can cover it.

@holgerd77
Copy link
Member

This is so obviously wrong and can very easily be tested manually. #315 may very well take 3-4 more weeks.

@axic
Copy link
Member

axic commented Jul 23, 2018

I had the feeling #315 was kind of ready 😉

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

Successfully merging this pull request may close these issues.

Bloom filter implementation is broken
5 participants