Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Using SHA256 gadget with arbitrary sized input #163

Open
amadilsons opened this issue Jun 25, 2020 · 1 comment
Open

Using SHA256 gadget with arbitrary sized input #163

amadilsons opened this issue Jun 25, 2020 · 1 comment

Comments

@amadilsons
Copy link

I'm new to the zk-snarks world, still trying to figure out how everything works.

I would like to generate a proof of pre-image using SHA256 and an arbitrary sized input.

I was wondering if you could make available some sort of tutorial on how to achieve this, or at least provide some general guidelines on how to use the SHA256 gadget.

Thank you in advance!

@HarryR
Copy link
Owner

HarryR commented Jun 27, 2020

Hi,

https://github.com/Ethsnarks/ethsnarks-hashpreimage is an example of how to prove the preimage to hash.

The problem with an arbitrary input size is that the zk-snark circuit is fixed sized, you can hash an arbitrary number of bits (in a way which is compatible with the SHA256 function on Ethereum and everywhere else), as long as you only ever have to prove that you've hashed that specific number of bits.

There is a 'gadget' at https://github.com/HarryR/ethsnarks/blob/master/src/gadgets/sha256_many.cpp which will take an arbitrary number of input bytes and hash them in a way which is compatible with a normal SHA256 function (as-long as you pad it to full bytes, rather than e.g. 12 bits)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants