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

Ability to set seed, number of rounds and exponent in MIMC hash #221

Open
shreyas-londhe opened this issue Jul 21, 2022 · 4 comments
Open
Labels
good first issue Good for newcomers

Comments

@shreyas-londhe
Copy link

Referencing to https://github.com/ConsenSys/gnark-crypto/blob/master/ecc/bn254/fr/mimc/mimc.go

There should be a way to set mimcNbRounds, seed and exponent (which is currently set to 5).
I find that this modularity would help us get more control over the hash.

I was using the snark to verify on ethereum and the mimc implementation on solidity was using a different seed and exponent value, so I had to change it manually in the go modules which I think is not a great way to do things.

If I get an idea of how I should implement this issue, I would love to make a PR to solve this.

Thanks!

@shreyas-londhe shreyas-londhe changed the title Ability to set seed, number of rounds and exponent in mimc hash Ability to set seed, number of rounds and exponent in MIMC hash Jul 21, 2022
@ThomasPiellard
Copy link
Contributor

Hi @shryasss , where does the 7 come from? Normally for BN254, the smallest permutation is x -> x^5. Ok for a PR to change the number of rounds, etc. But one advantage of hard coding the exponent is that the permutation is slightly more efficient because we don't need to do a double&add algo but rather we can directly write the shortest addition chain.

@shreyas-londhe
Copy link
Author

So you are saying that having exponent 5 is efficient? but I have seen some libraries for solidity which use the mimc7 so I thought that should also be possible using gnark.

Even iden3 has a mimc7 implementation.

you can check it here - https://github.com/iden3/go-iden3-crypto/blob/master/mimc7/mimc7.go

@gbotrel
Copy link
Collaborator

gbotrel commented Jul 29, 2022

@shryasss parametrizing MiMC could make sense. If you want to take a shot at it, let me know. I think it's a good opportunity to experiment with generic. Recently in gnark we did:
https://github.com/ConsenSys/gnark/blob/develop/std/math/emulated/params.go

Which enables a clean usage across in-circuit / out-of-circuit:

secp256k1, err := emulated.NewField[emulated.Secp256k1](api)

Which would translate similarly to MiMC instantiation.

@shreyas-londhe
Copy link
Author

Hey @gbotrel! I would love to take this up and make a PR, please let me know on how to proceed on this.

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

No branches or pull requests

3 participants