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

Replace Ahash with Fnv for Hashbrown #825

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

shamatar
Copy link
Contributor

@shamatar shamatar commented May 1, 2024

Alternative to #824 , will fix #812 too for systems without atomics. Fnv provides no key randomization, but it shouldn't be required for commitment scheme.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@shamatar shamatar requested review from a team as code owners May 1, 2024 12:22
@shamatar shamatar requested review from Pratyush, mmagician and weikengchen and removed request for a team May 1, 2024 12:22
@Pratyush
Copy link
Member

How about we use SipHash for non-atomic platforms, and ahash elsewhere?

@shamatar
Copy link
Contributor Author

To be honest I'm not sure from top of my head if I can make cargo dependency optional based on whether a platform has atomics. Will try

@shamatar
Copy link
Contributor Author

Another question is whether or not try to include aHash with or without randomization if it's done as external dependency instead of default hash in hashbrown. Hashbrown itself doesn't have and option to continue aHash's features, but maybe it can be imported independently and without randomization is may have no atomics by itself

@Pratyush
Copy link
Member

To be honest I'm not sure from top of my head if I can make cargo dependency optional based on whether a platform has atomics. Will try

I think it's possible like so: https://github.com/PyO3/pyo3/blob/fe79f548174eb8108813f202bb0df9428ddfd806/Cargo.toml#L48

@shamatar
Copy link
Contributor Author

restored features (inlines) on hashbrown + ahash is used on platforms with atomics

@Pratyush Pratyush enabled auto-merge June 19, 2024 13:16
@Pratyush Pratyush added this pull request to the merge queue Jun 19, 2024
Merged via the queue into arkworks-rs:master with commit ed7a187 Jun 19, 2024
37 checks passed
mmagician added a commit to arkworks-rs/crypto-primitives that referenced this pull request Jun 19, 2024
github-merge-queue bot pushed a commit to arkworks-rs/crypto-primitives that referenced this pull request Jun 19, 2024
@mmagician mmagician mentioned this pull request Jun 19, 2024
6 tasks
@autquis
Copy link

autquis commented Oct 22, 2024

Hi! Can anyone give me some pointers on why the default-hasher of hashbrown is not suitable for us? They have changed it rust-lang/hashbrown#563 to FoldHash orlp/foldhash.

@shamatar
Copy link
Contributor Author

Mainly because it was using atomics and would not compile on some platforms

@autquis
Copy link

autquis commented Oct 22, 2024

Thanks for the prompt answer!
I didn't know FoldHash also uses atomics.
Another question, so it is safe to replace aHash with FoldHash in the changes of this PR, right?

@shamatar
Copy link
Contributor Author

I didn’t check FoldHash. The main problem was that aHash was seeded, and seeing mechanism itself used atomics. So it may apply to FoldHash too as seeding is standard mechanism to avoid timing attacks on hash maps if queries could be externally provided/uncontrolled. For arkworks it’s not needed, but default configuration was to use such mechanism

@autquis
Copy link

autquis commented Oct 22, 2024

Thanks a lot for the pointers! I just checked the seeding mechanism in FoldHash here and it seems they provide a fixed global state for the platforms that do not support atomics.
I would appreciate it very much if you could have a look and confirm if I understood correctly.

In that case, I can go ahead and enable default-hasher from hashbrown and that would simplify things.

@autquis
Copy link

autquis commented Oct 24, 2024

Hi again! I would be very grateful if you could look into this.
I believe FoldHash is similar to FNV in the sense of seeding on non-atomic systems. A thumbs up from you would suffice :)

@shamatar
Copy link
Contributor Author

What’s the interest for the default hasher? It’s just a feature flag and only provides few extra constructor methods. Maybe Default::default() starts to work, but not sure. At the moment I do not have capacity to check building on atomic-free platforms. Seeding code will most likely work, but it also depends if hashbrown doesn’t do some manual seeding itself

@autquis
Copy link

autquis commented Oct 24, 2024

Thanks for the answer.
Regarding the interest in the default hasher: I think it simplifies the code. Currently, we have this conditional dependency on aHash and FNV, while having this feature enabled (assuming that FoldHash works for both atomic/non-atomic) we can get rid of the conditional dependency + we will have more concise code for instantiating a hashmap.

I will need this in some other repos of arkworks as well.

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.

Ark-ec pulls in full hashbrown without feature gate
4 participants