gnark icon indicating copy to clipboard operation
gnark copied to clipboard

docs: document behavior of hash function inside and outside a circuit

Open gbotrel opened this issue 4 years ago • 6 comments

See #99 and here.

In short, when using MiMC inside a circuit, each input is treated as a field element on size(element) bytes.

Example

To mimic this the following (inside a circuit):

hash.Write([]byte{0x01})
hash.Write([]byte{0x02})

outside a circuit, one needs to add padding to the byte slices. The easiest way is to use fr.Element objects.

var b1, b2 fr.Element
b1.SetBytes([]byte{0x01})
b2.SetBytes([]byte{0x02})
hash.Write(b1.Marshal()) // writes size(element) bytes, like in a circuit, NOT a single byte.
hash.Write(b1.Marshal()) // writes size(element) bytes, like in a circuit, NOT a single byte.

gbotrel avatar May 21 '21 20:05 gbotrel

Hi @gbotrel . I'm looking to contribute to this repo. Can I take up one of these issues??

xenowits avatar Aug 31 '21 17:08 xenowits

hi @xenowits -- sure, any contribution is welcome / appreciated :-) . Are you looking for something more dev? more doc? more crypto? Few hours work, or few days? (we've several things in mind that may not appear in the github backlog)

gbotrel avatar Aug 31 '21 17:08 gbotrel

Something more crypto would work @gbotrel . I actually want to learn about zksnarks in general. I can take up the easier ones first, u can assign me those

xenowits avatar Aug 31 '21 18:08 xenowits

3 ideas come to mind, of independent tasks (crypto);

  • SSWU hash to curve implementation in gnark-crypto
  • adding new components in gnark/std; for example, we have a MiMC hash function available to use in a circuit, it could be interesting to add Poseidon hash function. That would likely involve implementing Poseidon in gnark-crypto and adding a circuit component under gnark/std .
  • a PLONK solidity verifier

more software oriented, would be:

  • #70 (find elegant ways to generate "type safe" witness in non-Go code bases)
  • or explore any of the blockers that may arise with #74 #76 #75 (using gnark in WASM, iOS or Android).

more exploratory;

  • add a (Groth16) batch-verify algorithm, from this

gbotrel avatar Aug 31 '21 18:08 gbotrel

@gbotrel can we connect on discord??

xenowits avatar Sep 07 '21 13:09 xenowits

mhhh prefer email; can you reach out at our team email?

gbotrel avatar Sep 07 '21 13:09 gbotrel