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

feat: solidity verifier generation #111

Merged
merged 3 commits into from
Feb 23, 2023

Conversation

weijiekoh
Copy link
Contributor

This PR adds the ability to generate a Solidity verifier.

Here is a document that describes the steps that a user can take to generate such a verifier. It can serve as a quick start guide. https://hackmd.io/QOHOPeryRsOraO7FUnG-tg

Context

Teams who want to build on ezkl and want to verify their proofs on-chain can now do so easily. This functionality is intended to be short-lived and only meant to make it easier teams at ETHDenver to use ezkl.

Overview of approach

I have added a --sol-code-path parameter to the create-evm-verifier subcommand. This subcommand will write the Yul code generated to snark-verifier to this file, then run fix_verifier_sol.py on it, and save the output to the same file.

What fix_verifier_sol.py does

  1. It rewrites the Yul code to be a Solidity contract with a verify() function that accepts a uint256 array of pubinputs and a bytes array for the proof.
  2. It rewrites the mload, mstore, mload8, keccak, and staticcall memory locations in the Yul code to use the transcript and elements from the function arguments as needed.

Limitations

The largest number of public inputs/outputs which has been confirmed to work is 6. This is due to the contract size limit and the way that snark-verifier constructs the verifier code - as straight-line implementation in Yul, without loops of any kind, which means that the contract size increases with the number of public inputs/outputs.

It is also infeasible to have different models which have the same number of outputs share the same verifier contract code, because snark-verifier generates very different Yul code even for these models even though their number of outputs is the same. Hence it is better for now to generate each verifier contract as needed, rather than have a universal one per n outputs.

Future work

Let's consider writing a Solidity/Yul verifier by hand, so that it can be more flexible and debuggable.

@alexander-camuto alexander-camuto self-requested a review February 22, 2023 13:00
Copy link
Collaborator

@alexander-camuto alexander-camuto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing. LGTM ! pending tests

@alexander-camuto alexander-camuto changed the title Solidity verifier generation feat: solidity verifier generation Feb 22, 2023
@jasonmorton jasonmorton merged commit 39bb7b8 into zkonduit:main Feb 23, 2023
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

Successfully merging this pull request may close these issues.

3 participants