BattleZips
  • Awesome Circom
  • 🔬Theory
    • Prerequisite Knowledge
    • Resources
      • White Papers & PDF's
      • Blogs and Writeups
      • Videos
      • Important Entities
      • Communities
    • Proving Schemes
    • Primitives
      • Hash Functions
      • Public Key Cryptosystems
        • Note on L1 key registry → L2 hot key + callback to circuit-optimized hash functions
        • ECDSA & secp256k1
        • EdDSA
      • Merkle Trees
        • What is a Merkle Tree?
        • What is a merkle proof of inclusion?
        • zk-kit
        • Incremental Merkle Trees
        • Sparse Merkle Trees
        • Tree Arity (Binary, Quinary)
      • Semaphore
      • Arithmetic Circuits
  • 🏗️Development
    • Circom Language
      • Installation
      • IDE
      • Signals and Variables
      • Signal Assignment and Constraint Generation
      • Conditional Statements
      • Components and Templates
      • Circuit Compilation
      • Syntax
    • SnarkJS
      • Proving Schemes
      • Powers of Tau
      • ZK Keys
      • Zero Knowledge Proofs
      • On-Chain ZKP
      • Page 2
    • circomlib
      • Basic Math Constraints
      • Multiplexing
      • Hashing
      • EdDSA
      • circomlibjs
    • circom-tester
    • hardhat-circom
    • SHIELD
    • Circomspect
  • 🌆Ecosystem
    • Circom vs Other Solutions
      • Domain-Specific Languages
      • ZK Virtual Machines
      • ZK Ethereum Virtual Machines
    • Communities to Join
    • Recorded Content
    • Projects
  • 🛳️Examples
    • BattleZips V1
      • On the BattleZips Project
      • Docs holder
        • Join Game UML Sequence Diagram
        • Play Game UML Sequence Diagram
        • End Game UML Sequence Diagram
      • ZK Privacy Stack
      • Deploying Artifacts to Prod
      • Browser Client
    • RollupNC
      • Smart Contracts
      • Account/ State Tree
      • Transaction Tree
      • Layer 1 Deposits to Layer 2
      • Layer 2 Transacting
      • Layer 2 Withdrawals to Layer 1
Powered by GitBook
On this page
  • Circom can be a lot to grasp
  • hardhat-circom to the rescue
  • Setup
  1. Development

hardhat-circom

Overview of the hardhat-circom npm package

Previouscircom-testerNextSHIELD

Last updated 2 years ago

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

Installation

npm install hardhat-circom

Import the plugin in your hardhat.config.js:

require("hardhat-circom");

Or if you are using TypeScript, in your hardhat.config.ts:

import "hardhat-circom";

Tasks

This plugin adds the circom task to build circuit(s) into wasm and zkey file and template them to seperate Verifier contracts saved to the Hardhat sources directory (usually contracts/).

Usage: hardhat [GLOBAL OPTIONS] circom --circuit <STRING> [--debug] [--deterministic]

OPTIONS:

  --circuit      	limit your circom task to a single circuit name
  --debug        	output intermediate files to artifacts directory, generally for debug
  --deterministic	enable deterministic builds for groth16 protocol circuits (except for .wasm)

circom: compile circom circuits and template Verifier

For global options help run: hardhat help

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 below.

Basic configuration

Set up your project (we'll use best_dapp_ever/) with the following minimal hardhat.config.js at the root. The two required properties are ptau (see ) and circuits.

module.exports = {
  solidity: "0.6.7",
  circom: {
    // (optional) Base path for input files, defaults to `./circuits/`
    inputBasePath: "./circuits",
    // (required) The final ptau file, relative to inputBasePath, from a Phase 1 ceremony
    ptau: "pot15_final.ptau",
    // (required) Each object in this array refers to a separate circuit
    circuits: [{ name: "init" }],
  },
};

Your project structure should look like this:

j:~/best_dapp_ever/ $ tree
└── circuits
    ├── init.circom
    ├── init.json
    └── pot15_final.ptau

Now, you can use npx hardhat circom --verbose to compile the circuits and output InitVerifier.sol, init.zkey, and init.wasm files into their respective directories:

j:~/best_dapp_ever/ $ tree
├── circuits
│   ├── init.circom
│   ├── init.json
│   ├── init.wasm
│   ├── init.zkey
│   └── pot15_final.ptau
└── contracts
    └── InitVerifier.sol

Source code:

🏗️
hardhat-cirom repository
Hooking compile
Powers of Tau
https://github.com/projectsophon/hardhat-circom