The ultimate environment for building with Circom.
This hardhat plugin is a zero-config, one-stop Circom development environment that abstracts away circuits management hassle and let's you focus on the important - code.
- Developer-oriented abstractions that simplify
r1cs
,zkey
,vkey
, andwitness
generation processes. - Recompilation of only the modified circuits.
- Automatic downloads of phase-1
ptau
files. - Quick phase-2 contributions to
zkey
files. - Invisible
wasm
-based Circom compiler management. - Zero platform-specific dependencies: everything is in TypeScript.
- Extensive development and testing API.
- Rich plugin configuration.
- And much more!
npm install --save-dev @solarity/hardhat-zkit
And add the following line to your hardhat.config
:
require("@solarity/hardhat-zkit");
Or if you are using TypeScript:
import "@solarity/hardhat-zkit";
Tip
There is no need to download the Circom compiler separately. The plugin works with the WASM-based version under the hood.
The hardhat-zkit
is a zero-config plugin, however you may add the following to your hardhat.config
file:
module.exports = {
zkit: {
circuitsDir: "circuits",
compilationSettings: {
artifactsDir: "zkit/artifacts",
onlyFiles: [],
skipFiles: [],
c: false,
json: false,
sym: false,
contributionTemplate: "groth16",
contributions: 1,
},
quiet: false,
verifiersDir: "contracts/verifiers",
ptauDir: undefined,
ptauDownload: true,
},
};
Where:
circuitsDir
- The directory where to look for the circuits.compilationSettings
artifactsDir
- The directory where to save the circuits artifacts (r1cs, zkey, etc).onlyFiles
- The list of directories (or files) to be considered for the compilation.skipFiles
- The list of directories (or files) to be skipped for the compilation.c
- The flag to generate the c-based witness generator (generates wasm by default).json
- The flag to output the constraints in json format.sym
- The flag to output the constraint system in an annotated mode.contributionTemplate
- The option to indicate which proving system to use.contributions
- The number of phase-2zkey
contributions to make ifgroth16
is chosen.
quiet
- The flag indicating whether to suppress the output.verifiersDir
- The directory where to generate the Solidity verifiers.ptauDir
- The directory where to look for theptau
files.$HOME/.zkit/ptau/
by default.ptauDownload
- The flag to allow automatic dowload of requiredptau
files.
There are several hardhat tasks that the plugin provides:
zkit:compile
task that compiles or recompiles the modified circuits that have the main component.zkit:verifiers
task that generates Solidity verifiers for all the available circuits.
To view the available options, run the help command:
npx hardhat help zkit:compile
npx hardhat help zkit:verifiers
The plugin extends the hardhat environment with the zkit
object that allows circuits to be used in scripts and tests:
Circom circuit | Usage example |
---|---|
pragma circom 2.0.0;
template Multiplier(){
signal input in1;
signal input in2;
signal output out;
out <== in1 * in2;
}
component main = Multiplier(); |
import { zkit } from "hardhat";
async function main() {
const circuit = await zkit.getCircuit("multiplier"); // "multiplier" is the file name
const proof = await circuit.generateProof({ in1: "4", in2: "2" });
await circuit.verifyProof(proof); // success
await circuit.createVerifier();
}
main()
.then()
.catch((e) => console.log(e)); |
getCircuit(<filename>) -> zkit
The method accepts the filename of the circuit where its main
component is defined. Returns the instanciated zkit object.
Important
Check out the zkit
documentation to understand zkit objects capabilities.
- Currently the Circom
2.1.8
is used for the compilation of circuits. - Temporarily, the only supported proving system is
groth16
. - Full TypeScript typization of circuits is in progress.