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

Break tests with a small hash function perturbation #4559

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

widlarizer
Copy link
Collaborator

What are the reasons/motivation for this change?

Test failures due to hashing refactoring have uncovered dfflibmap.ys to fail to prove the first step base case in the first equiv_opt call. This PR demonstrates that it is sufficient to slightly change the hashing function to break that test. Famously, go lang standard library and abseil randomize hash functions to prevent users on depending on the ordering of items in unordered maps like dicts and sets. In Yosys, the DJB2 hash function hasn't been touched in 10 years. This draft PR will be closed when this problem is resolved and the hash function has a mechanism when it's randomized. Until then, it's a reproducer.

There is no way to write an "incorrect" hash function that isn't meant to be cryptographic, since hash functions are only meant to be used for fast path handling of data. A return 1; hash function is just as valid as an actual hash function, though it make tests run for too long. Therefore this PR should never make correctness tests fail.

Explain how this is achieved.

Every time you hash, xorshift the result, and xor with a fudge constant. For example, you can reproduce this with a fudge constant of 123456 or 42069, but not 3.

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.

1 participant