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

Align Bloom Filter Hashing with Mainnet Compatible Clients #295

Merged
merged 4 commits into from
Jul 24, 2018

Conversation

AusIV
Copy link
Contributor

@AusIV AusIV commented Apr 24, 2018

When clients like Go-ethereum and Parity create bloom filters, they trim leading zeroes off the topic before applying keccak to hash the value. As far as I can tell, this is inconsistent with the yellow paper (see: ethereum/yellowpaper#690), but for ethereumjs-vm generated bloom filters to be compatible with tools that consume mainnet bloom filters, it should follow the same pattern.

See https://github.com/ethereum/go-ethereum/blob/master/core/types/bloom9.go#L60 where go-ethereum casts topics as big.Int then back to bytes, effectively stripping away leading zeroes before hashing.

@coveralls
Copy link

coveralls commented Apr 24, 2018

Coverage Status

Coverage increased (+0.03%) to 85.497% when pulling 8c46ddb on NoteGio:master into 4f1d427 on ethereumjs:master.

@holgerd77
Copy link
Member

Hi @AusIV, thanks for the PR!

I would generally support this. Any comments from other team members?

@holgerd77
Copy link
Member

Can you rebase this (if you haven't done before you should do a local repository backup)? You also have some linting errors which prevent the tests above to pass (run npm run lint), can you fix these? You can ease this by (temporarily) add --fix to the npm command in package.json. Optimally you can then do a fixup with git rebase to have these changes included in the previous commit.

@AusIV
Copy link
Contributor Author

AusIV commented Apr 26, 2018

I've made the requested changes.

@holgerd77
Copy link
Member

Cool, thanks

lib/bloom.js Outdated
* For example, if a topic is an address, it will trim off the first 12 bytes
* before hashing the value to add it to the bloom filter.
*/
function trimBuffer (buff) {
Copy link
Member

Choose a reason for hiding this comment

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

If you name this dropLeadingZeroes then less explanation is needed.

@holgerd77
Copy link
Member

Hi @AusIV, I would really like to get this merged. Could you maybe do a last rebase and rename to dropLeadingZeros like suggested? Would be cool if you find the time!

@holgerd77
Copy link
Member

Hi @AusIV, thanks for taking up on this again, cool! 😄

The add and the check functions still use the old name, this is why the tests are still failing.

I don't know if you hesitate on the rebase part if you haven't done rebasing that much before. Sorry for that, but we have relatively strict rules on that every PR needs to follow that
a) a PR has to be rebased on top of all other changes and
b) the commit history has to be somewhat clean so that other devs can follow up what is going on

If you want to prevent rebasing I would suggest the following:

  1. Make a local backup of your repository
  2. Delete your fork on GitHub and refork again, like this you have a clean and updated master branch
  3. Create a new branch bloom-filter or something and manually add the changes from your backup repository
  4. Do a new PR

I know this is a bit annoying but I think at the end that's the easiest way to go. I have also already gone through this and can say that it is actually less work than it sounds! 😄

@holgerd77
Copy link
Member

Hi @AusIV, I would really like to get this merged. If you don't find any time to update this atm, would it be ok if I take your changes and submit a new PR on this?

lib/bloom.js Outdated
@@ -41,7 +54,7 @@ Bloom.prototype.add = function (e) {
* @param {Buffer} element
*/
Bloom.prototype.check = function (e) {
e = utils.sha3(e)
e = utils.sha3(trimBuffer(e))
Copy link
Member

Choose a reason for hiding this comment

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

I think these should be renamed also to use dropLeadingZeroes.

@AusIV
Copy link
Contributor Author

AusIV commented Jul 24, 2018

Sorry, I've been busy. I'l knock this out this morning.

@holgerd77
Copy link
Member

👍

AusIV added 4 commits July 24, 2018 08:17
When clients like Go-ethereum and Parity create bloom filters, they
trim leading zeroes off the topic before applying keccak to hash the
value. As far as I can tell, this is inconsistent with the yellow paper
(see: ethereum/yellowpaper#690), but for
ethereumjs-vm generated bloom filters to be compatible with tools that
consume mainnet bloom filters, it should follow the same pattern.

See https://github.com/ethereum/go-ethereum/blob/master/core/types/bloom9.go#L60
where go-ethereum casts topics as big.Int then back to bytes, effectively
stripping away leading zeroes before hashing.
@AusIV
Copy link
Contributor Author

AusIV commented Jul 24, 2018

It looks like the tests failed when trying to report coverage via coveralls. I'm not sure how to resolve this.

@holgerd77
Copy link
Member

Hmm, not sure, we had some recent related changes. Will have a look tomorrow.

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.

Ah, or since tests are passing will just merge, problem is definitely not introduced by your code.

@holgerd77 holgerd77 merged commit 914dfd6 into ethereumjs:master Jul 24, 2018
@holgerd77
Copy link
Member

@AusIV thanks for updating this!

mattdean-digicatapult added a commit that referenced this pull request Nov 7, 2018
This fixes the last set of blockchain tests:

* RPC_API_Test
* randomStatetest224BC
* randomStatetest234BC
* randomStatetest529BC
* ExtraData32
* log1_correct
* timeDiff0
* timeDiff12
* timeDiff13
* timeDiff14

These were mostly caused by missing block validation and the intentional disparity between the bloom filter implementation and the yellow paper introduced in #295.
mattdean-digicatapult added a commit that referenced this pull request Nov 7, 2018
This fixes the last set of blockchain tests:

* RPC_API_Test
* randomStatetest224BC
* randomStatetest234BC
* randomStatetest529BC
* ExtraData32
* log1_correct
* timeDiff0
* timeDiff12
* timeDiff13
* timeDiff14

These were mostly caused by missing block validation and the intentional disparity between the bloom filter implementation and the yellow paper introduced in #295.
mattdean-digicatapult added a commit that referenced this pull request Nov 14, 2018
This fixes the last set of blockchain tests:

* RPC_API_Test
* randomStatetest224BC
* randomStatetest234BC
* randomStatetest529BC
* ExtraData32
* log1_correct
* timeDiff0
* timeDiff12
* timeDiff13
* timeDiff14

These were mostly caused by missing block validation and the intentional disparity between the bloom filter implementation and the yellow paper introduced in #295.
holgerd77 pushed a commit that referenced this pull request Nov 15, 2018
This fixes the last set of blockchain tests:

* RPC_API_Test
* randomStatetest224BC
* randomStatetest234BC
* randomStatetest529BC
* ExtraData32
* log1_correct
* timeDiff0
* timeDiff12
* timeDiff13
* timeDiff14

These were mostly caused by missing block validation and the intentional disparity between the bloom filter implementation and the yellow paper introduced in #295.
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.

5 participants