0xPARC / circom-starter

basic circom project using hardhat-circom (upgrade to circom2 is WIP)
126 stars 44 forks source link

feat: Upgrade to hardhat-circom 2.1.0 #5

Closed phated closed 2 years ago

phated commented 2 years ago

This updates the circom-starter to use hardhat-circom v2.0.0

The major updates in this version of hardhat-circom are that I upgraded snarkjs to v0.4.x and added plonk protocol support. You'll also notice that the default is to generate separate Verifier contracts for each circuit. This is the upstream pattern in snarkjs and allows you to build separate circuits with different protocols.

I also did a bunch of cleanup of the package and even added a --circuit CLI parameter, which I documented in this PR.

Please note that there's still one major thing missing from this release of hardhat-circom: Circom 2 support. The current plan is to add circom 2 support in v2.1.0 and have each circuit configuration specify which version of circom it needs to compile.

phated commented 2 years ago

can we also gitignore the Verifiers?

Yep, I thought about it, but we'll need to add a .gitsave file to keep the contracts directory around.

would it be possible to also generate the proof.json and public.json files to the artifacts folder? or is that something that hardhat-circom doesn't do?

That's not something it does. You point hardhat-circom at the output directory you want, which defaults to the input directory. Why do you want them in the artifacts folder? Maybe the next question will inform that more.

is it intentional that artifact files are both created in ./artifacts as well as in ./circuits when the dev command is run?

hardhat-circom takes an input and output directory as configuration, it outputs all of the stuff we need for Dark Forest into the output directory. The output directory defaults to the same directory as input if not specified. When running with --debug, all virtual files that circom/snarkjs output are dumped into hardhat's artifacts directory—Jake made this decision, but I also assumed that artifacts is gitignored and you don't want to put your production-generated files into it. Do you have a different opinion of the artifacts directory?

gubsheep commented 2 years ago

Yep, I thought about it, but we'll need to add a .gitsave file to keep the contracts directory around.

.gitsave in contracts directory sounds good

Why do you want them in the artifacts folder? Maybe the next question will inform that more.

One thing we do during the learning group is go through each generated file to understand what it does, why it's there, etc. It's not a big deal if not, because we'll probably run all the commands sequentially regardless during the workshop. But it's a nice-to-have to be able to show people everything generated by the end-to-end SNARK compilation process.

Do you have a different opinion of the artifacts directory?

That makes sense. Can hardhat-circom be configured such that not all virtual files will be generated and saved (either to configured output directory, or default input directory)? If so, I think always saving everything to artifacts makers sense. If not, and we're just saving these files redundantly, I can imagine the user wouldn't lose anything by not having files saved to artifacts, since they are already saved to the output directory.

phated commented 2 years ago

That makes sense. Can hardhat-circom be configured such that not all virtual files will be generated and saved (either to configured output directory, or default input directory)? If so, I think always saving everything to artifacts makers sense. If not, and we're just saving these files redundantly, I can imagine the user wouldn't lose anything by not having files saved to artifacts, since they are already saved to the output directory.

To clarify this, a subset of files are written into the outputBasePath (these are generally the only files needed by a dApp) but if you want all of the files for debugging purposes, you run with --debug and hardhat-circom will write every intermediate file to the artifacts/ directory.