feat: solidity verifier generation #111
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thecreate-evm-verifier
subcommand. This subcommand will write the Yul code generated to snark-verifier to this file, then runfix_verifier_sol.py
on it, and save the output to the same file.What
fix_verifier_sol.py
doesverify()
function that accepts auint256
array of pubinputs and a bytes array for the proof.mload
,mstore
,mload8
,keccak
, andstaticcall
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.