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

Remove hashbrown and use BTree{Map,Set} from the alloc crate #187

Merged
merged 2 commits into from Jun 12, 2019
Merged

Remove hashbrown and use BTree{Map,Set} from the alloc crate #187

merged 2 commits into from Jun 12, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jun 11, 2019

wasmi-validation must handle untrusted input and hence we switch from
Hash{Set,Map} (whether std's or hashbrown's) to BTree{Set,Map} to avoid
algorithmic complexity attacks while retaining no_std support.

Closes #183

wasmi-validation must handle untrusted input and hence we switch from
Hash{Set,Map} (whether std's or hashbrown's) to BTree{Set,Map} to avoid
algorithmic complexity attacks while retaining no_std support.

Closes #183
@parity-cla-bot
Copy link

It looks like @adam-rhebo signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Using a sorted slice gives us the same O(N log N) worst case execution
time as using a BTreeMap, but using a single allocation as with HashMap,
so that we should see better memory locality and hence better constant
factors when checking for duplicate exports.
@ghost
Copy link
Author

ghost commented Jun 11, 2019

@pepyakin I added an additional commit remove the *Set from wasmi-validation entirely, as we should get the same O(N log N) worst-case behaviour using a sorted slice that makes due with a single allocation and should yield better memory locality than the BTreeSet.

@pepyakin pepyakin merged commit 8dac328 into wasmi-labs:master Jun 12, 2019
@pepyakin
Copy link
Collaborator

Thanks!

@ghost ghost deleted the btree-instead-of-hash branch June 13, 2019 07:54
@goral09
Copy link

goral09 commented Jul 26, 2019

Recent version of Rust 1.36.0 started using hashbrown::HashMap implementation in the standard library. Just saying.

@ghost
Copy link
Author

ghost commented Jul 26, 2019

Recent version of Rust 1.36.0 started using hashbrown::HashMap implementation in the standard library. Just saying.

This was about replacing Hash Brown by a different hash map implementation (as it was for the standard library), but rather by replacing a hash map which is susceptible to collision complexity attacks by a BTree-based implemenation which has a much simpler worst-case complexity behavior and also has no_std support (which the standard libraries's Hash Brown implementation lacks for now). (Also the standard library uses SipHash as the default hasher instead of FxHash as Hash Brown exactly to harden itself against these complexity attacks.)

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

Successfully merging this pull request may close these issues.

Consider using BTreeMap for wasmi-validation
3 participants