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

Add CLI interface for verifier contract generation #74

Merged
merged 51 commits into from
Mar 18, 2024
Merged

Conversation

CPerezz
Copy link
Member

@CPerezz CPerezz commented Feb 21, 2024

This PR adds a new crate to the workspace which is a CLI interface that allows to create Solidity smart contracts which verify paritcular protocols.

It doesn't only include the CLI but also tools to serialize all the data required to be used by the CLI in a simple manner.

This is how the CLI --help command actually looks like:

 _____  ______  ______  ______  ______  ______  ______ 
| |__| || |__| || |__| || |__| || |__| || |__| || |__| |
|  ()  ||  ()  ||  ()  ||  ()  ||  ()  ||  ()  ||  ()  |
|______||______||______||______||______||______||______|
 ______                                          ______ 
| |__| |   ____        _ _     _ _ _            | |__| |
|  ()  |  / ___|  ___ | (_) __| (_) |_ _   _    |  ()  |
|______|  \___ \ / _ \| | |/ _` | | __| | | |   |______|
 ______    ___) | (_) | | | (_| | | |_| |_| |    ______ 
| |__| |  |____/ \___/|_|_|\__,_|_|\__|\__, |   | |__| |
|  ()  |  __     __        _  __ _     |___/    |  ()  |
|______|  \ \   / /__ _ __(_)/ _(_) ___ _ __    |______|
 ______    \ \ / / _ \ '__| | |_| |/ _ \ '__|    ______ 
| |__| |    \ V /  __/ |  | |  _| |  __/ |      | |__| |
|  ()  |     \_/ \___|_|  |_|_| |_|\___|_|      |  ()  |
|______|                                        |______|
 ______  ______  ______  ______  ______  ______  ______ 
| |__| || |__| || |__| || |__| || |__| || |__| || |__| |
|  ()  ||  ()  ||  ()  ||  ()  ||  ()  ||  ()  ||  ()  |
|______||______||______||______||______||______||______|

Welcome to Solidity Verifier, a powerful Command-Line Interface (CLI) tool designed to simplify the generation of Solidity smart contracts that verify proofs of Zero Knowledge cryptographic protocols.
for Zero Knowledge protocols. This tool is developed by the collaborative efforts of the PSE (Privacy & Scaling Explorations) and 0XPARC teams. 

As an open-source project, Solidity Verifier is released under the GPL3 license.

Solidity Verifier currently supports the generation of Solidity smart contracts for the verification of proofs in the following Zero Knowledge protocols:

    Groth16:
        Efficient and succinct zero-knowledge proof system.

    KZG:
        Uses the Kate-Zaverucha-Goldberg polynomial commitment scheme.

    Nova + CycleFold Decider:
        Implements the decider circuit verification for the Nova zero-knowledge proof system in conjunction with the CycleFold protocol optimization.


Usage: solidity-verifier [OPTIONS] --protocol <PROTOCOL> --protocol-data <PROTOCOL_DATA>

Options:
  -v, --verbose...
          Increase logging verbosity

  -q, --quiet...
          Decrease logging verbosity

  -p, --protocol <PROTOCOL>
          Selects the protocol for which we want to generate the Solidity Verifier contract
          
          [possible values: groth16, kzg, nova-cyclefold]

  -o, --out <OUT>
          Sets the output path for all the artifacts generated by the command
          
          [default: /PATH-TO/verifier.sol]

  -d, --protocol-data <PROTOCOL_DATA>
          Sets the input path for the file containing all the data required by the protocol chosen such that the verification contract can be generated

      --pragma <PRAGMA>
          Selects the Solidity compiler version to be set in the Solidity Verifier contract artifact

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

@CPerezz
Copy link
Member Author

CPerezz commented Feb 21, 2024

After this, I just need to bring back the assets to test the three different supported protocols, add logging and cleanup.

So far, this is what calling solidity-verifier --help looks like:

**A tool to create Solidity Contracts which act as verifiers for the major Folding Schemes implemented within the `folding-schemes` repo

Usage: solidity-verifier [OPTIONS] --protocol <PROTOCOL> --protocol-data <PROTOCOL_DATA>

Options:
  -v, --verbose...                     Increase logging verbosity
  -q, --quiet...                       Decrease logging verbosity
  -p, --protocol <PROTOCOL>            Selects the protocol for which we want to generate the Decider circuit Solidity Verifier [possible values: groth16, kzg, nova-cyclefold]
  -o, --out <OUT>                      Sets the output path for all the artifacts generated by the command [default: /path/to/the/place/where/we_want/verifier.sol]
  -d, --protocol-data <PROTOCOL_DATA>  Sets the input path for the file containing all the data required by the protocol chosen such that the verification contract can be generated
      --pragma <PRAGMA>                Selects the Solidity compiler version to be set in the Solidity Verifier contract artifact
  -h, --help                           Print help
  -V, --version                        Print version

Aside from that. We should be close to close this. It took me some time to figure out a way to don't need Protocol definitions in both crates but seems difficult to avoid unless I want to have a cli feature in folding-schemes-solidity where I also derive ValueEnum for Protocol enum there. In this way, I can reduce even further the duplication.

I also tried an aproach where I had clap::SubCommand for each protocol. Thus having it's required parameters inside each of the subcommand enum definitions.
While easier to impl that this, it requires the user to pass like 3 or 4 paths/files to the command for NovaCycleFold which is absurd.

With the ProtocolData approach instead, the CLI interface is significantly simpler and also much easier to handle the data associated to each protocol.

@CPerezz CPerezz marked this pull request as ready for review February 23, 2024 17:18
@CPerezz CPerezz requested review from arnaucube and dmpierre and removed request for arnaucube February 26, 2024 16:04
@CPerezz
Copy link
Member Author

CPerezz commented Feb 26, 2024

Will fix the asset deserialization issues in the tests tomorrow. And after that. I think we're good to go!

This includes a cli parser that serves as a way to the user to generate the desired Solidity contracts.
Now the template refers to Nova + Cyclefold and has a Warning attached to it
This trait helps to treat the serialized data required by the Template
as a single element while still allowing a flexible usage.

This is specially interesting as allows the cli to operate considering a
single path of input data where all the data for the selected protocol
co-exists. Reducing the amount of parsing and arguments the user needs
to pass to the cli.
Previously we had functions called `from` which had nothing to do with
the trait `From`. This addresses this issue and fixes it.

Now both `new` and `from` are avaliable. But `from` follows the `From`
trait.
This adds a `render` fn for `Protocol` which makes it easier to add new
protocols to the CLI as is mainly based in the `ProtocolData` impl
behind the scenes of the selected protocol.

Aside from that, this commit reworks some minor parts of the CLI config
as shorteners for commands or adding `pragma` as an optional parameter.
As seen, this allows to have a much easier `main.rs` which doesn't have
to do any `match` over the selected protocol.
When we use templates that are composed by others (as happens with
`NovaCyclefold` one) we sadly see that the License and the `pragma`
attributes are rendered once per sub-template.

This generic structure solves this issue by being actually the only item
rendered which has a sub-template the template we indeed want to render
at the end.
Copy link
Collaborator

@dmpierre dmpierre left a comment

Choose a reason for hiding this comment

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

lgtm! thanks for this Carlos. Added a few suggestions and questions here and there.

solidity-verifier/README.md Outdated Show resolved Hide resolved
solidity-verifier/README.md Outdated Show resolved Hide resolved
folding-schemes-solidity/src/verifiers/kzg.rs Outdated Show resolved Hide resolved
solidity-verifier/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

@arnaucube arnaucube left a comment

Choose a reason for hiding this comment

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

Great work! Left few suggestions

folding-schemes-solidity/src/verifiers/mod.rs Outdated Show resolved Hide resolved
rust-toolchain Show resolved Hide resolved
- folding-schemes-solidity -> soliity-verifiers
@CPerezz CPerezz requested a review from arnaucube March 12, 2024 08:41
Copy link
Collaborator

@arnaucube arnaucube left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@CPerezz CPerezz added this pull request to the merge queue Mar 18, 2024
Merged via the queue into main with commit 1072b66 Mar 18, 2024
5 checks passed
@arnaucube arnaucube deleted the feature/cli_tooling branch May 23, 2024 15:28
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