Consensys / gnark

gnark is a fast zk-SNARK library that offers a high-level API to design circuits. The library is open source and developed under the Apache 2.0 license
https://hackmd.io/@gnark
Apache License 2.0
1.43k stars 368 forks source link

Is there mimc hash implemented by solidity language #219

Closed mdj33 closed 2 years ago

mdj33 commented 2 years ago

we are constructing a gnark proof system on ethereum. the public input part need be verified by mimc hash on solidity contract as the circuit implemented with gnark. could you tell me if there is corresponding solidiy implement to mimc hash in gnark? many thanks!

mdj33 commented 2 years ago

is this solidity implementation match to gnark's mimc hash? https://gist.github.com/HarryR/80b5ff2ce13da12edafda6d21c780730

ThomasPiellard commented 2 years ago

Hi @mdj33 , there is a discrepancy on our end, the comment on our mimc implementation says that it follows the Miyaguchi–Preneel scheme while it's in fact the Matyas–Meyer–Oseas scheme. The mimc encryption function on the other hand is the same (except that we use 5 for the exponent). It will be fixed on our side to follow Miyaguchi–Preneel.

mdj33 commented 2 years ago

@ThomasPiellard , it is ok. we have modified HarryR's solidity mimc implement to adapt gnark's for the time being.

mdj33 commented 2 years ago

@ThomasPiellard @gbotrel , BTW, Is there sha256 or keccak256 hash calculating circuit gadgets for gnark? It will save more gas to calculate hash by sha256 instead of mimc on ETH.

ThomasPiellard commented 2 years ago

No those hash functions are not implemented. It's our plan to add it at some point though. If you plan to add it soon on your side, don't hesitate to open a PR so we can look at it and integrate it in the std/.

mdj33 commented 2 years ago

it is ok, thanks!