Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants