The mimc packages (of at least bn254 and bls12-381) has the following description of digest.Write()
https://github.com/Consensys/gnark-crypto/blob/master/ecc/bn254/fr/mimc/mimc.go#L97-L105
This digest is returned as a hash.Hash by NewMiMC. However, this Write() method departs from the the following description in the hash.Hash interface:
// Write (via the embedded io.Writer interface) adds more data to the running hash.
// It never returns an error.
It seems very surprising to return a hash.Hash that cannot hash arbitrary bytes, neither in size nor in content (the caller needs to know they are really sending encoded elements that never exceed the modulus).
The WriteString() method is provided in an apparent effort to allow hashing of arbitrary bytes, but that method is unusable, since it is defined on digest, which cannot be obtained from external callers.
It's unclear how best to fix these issues, as I'm unsure if there are standards to be adhered to. If there are, I would expect those standards to define the MiMC hash of any byte sequence, so they would need to address how those bytes should be turned into fr.Element. If WriteString is the proper way to do so, then Write should be written to accumulate bytes until Sum() is called, and then the WriteString() technique can be used.
Description
Expected Behavior
Actual Behavior
Possible Fix
Steps to Reproduce
Context
Your Environment
- gnark-crypto version used:
- go version (e.g. 1.20.6):
- Operating System and version:
The mimc packages (of at least bn254 and bls12-381) has the following description of
digest.Write()https://github.com/Consensys/gnark-crypto/blob/master/ecc/bn254/fr/mimc/mimc.go#L97-L105
This
digestis returned as ahash.HashbyNewMiMC. However, thisWrite()method departs from the the following description in thehash.Hashinterface:It seems very surprising to return a
hash.Hashthat cannot hash arbitrary bytes, neither in size nor in content (the caller needs to know they are really sending encoded elements that never exceed the modulus).The
WriteString()method is provided in an apparent effort to allow hashing of arbitrary bytes, but that method is unusable, since it is defined ondigest, which cannot be obtained from external callers.It's unclear how best to fix these issues, as I'm unsure if there are standards to be adhered to. If there are, I would expect those standards to define the MiMC hash of any byte sequence, so they would need to address how those bytes should be turned into
fr.Element. IfWriteStringis the proper way to do so, thenWriteshould be written to accumulate bytes untilSum()is called, and then theWriteString()technique can be used.Description
Expected Behavior
Actual Behavior
Possible Fix
Steps to Reproduce
Context
Your Environment