hardhat-circom
Overview of the hardhat-circom npm package
Circom can be a lot to grasp
If you are like most individuals starting their ZK journey then it can be a bit overwhelming. In the case of circom you have to learn an entirely new language with a unique syntactical structure. On top of this there are many repetitive commands used for the trusted setup ceremony, key generation, creating proofs, and verifying proofs. An initial read of the circom documentation is not sufficient for digesting all the steps in the process and one may find themselves returning back to the documentation over and over again.
hardhat-circom to the rescue
Luckily hardhat-circom provides a solution to all the repetition. It is an npm package that integrates abstracts snarkjs and circom so that it can be used to effortless create proofs. The hefty commands required in the proof setup are replaced with a configuration file where one can specify where the output files will be written to, proving scheme, and much more
Setup
Quoted from hardhat-cirom repository
InstallationImport the plugin in your
hardhat.config.js
:Or if you are using TypeScript, in your
hardhat.config.ts
:
TasksThis plugin adds the
circom
task to build circuit(s) intowasm
andzkey
file and template them to seperate Verifier contracts saved to the Hardhat sources directory (usuallycontracts/
).You must run
hardhat circom
at least once to build the assets before compiling or deploying your contracts. Additionally, you can hook Hardhat's compile task to build your circuits before every compile, see Hooking compile below.
Basic configurationSet up your project (we'll use
best_dapp_ever/
) with the following minimalhardhat.config.js
at the root. The two required properties areptau
(see Powers of Tau) andcircuits
.Your project structure should look like this:
Now, you can use
npx hardhat circom --verbose
to compile the circuits and outputInitVerifier.sol
,init.zkey
, andinit.wasm
files into their respective directories:
Source code: https://github.com/projectsophon/hardhat-circom
Last updated