How to call mimc to input a string and output the mimc hashed result?
fengyin450 opened this issue · 1 comments
fengyin450 commented
In the example of https://play.gnark.io/#, it can be seen that the hash result of "Secret": "0xdeadf00d" is "Hash": "1037254799353855871006189384309576393135431139055333626960622147300727 796413", how to call https://github.com/Consensys/gnark-crypto/blob/master/ecc/bn254/fr/mimc/mimc.go can input Secret to get Hash by implementing mimc function? I tried many methods, but the output is 0 or wrong result. The following is one of them:
func mimcHash(data []byte) string {
f := bn254.NewMiMC()
f.Write(data)
hash := f.Sum(nil)
hashInt := big.NewInt(0).SetBytes(hash)
return hashInt.String()
}
gbotrel commented
Hi:
h := mimc.NewMiMC()
var message fr.Element
message.SetString("0xdeadf00d")
h.Write(message.Marshal())
res := h.Sum(nil)
var result fr.Element
result.SetBytes(res)
fmt.Println(result.String())