npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hardhat-noir

v0.2.1

Published

Hardhat plugin for Aztec Noir

Downloads

5

Readme

hardhat-noir

An unofficial Hardhat plugin for working with circuits written in Noir.

Inspired by vezenovm/basic_mul_noir_example.

What

This plugin adds convenience methods to the Hardhat Runtime Environment for generating and verifying proofs for a circuit.

import { noir } from "hardhat";

it("verifies proof for mul", async function () {
  const input = { x: 3, y: 4, result: 12 };
  expect(await noir.getCircuit().verifyProofFor(input)).to.be.true;
});

This plugin also hooks to the default compile task so circuits are automatically compiled whenever you run hardhat compile Circuits will only be recompiled if there are any changes detected in the source files. The same applies to the Solidity verifier contract, which is generated in Hardhat's configured contracts folder, and the pragma is tweaked to support Solidity 0.8. These tasks can also be manually invoked via noir:compile and noir:contract.

$ hardhat compile
Compiling circuit mul with nargo...
ACIR gates generated : 13
Generated ACIR code into build/mul.acir
Ok("/home/spalladino/Projects/hardhat-noir/example/circuits/build/mul.acir")

Generating verifier contract for mul with nargo...
ACIR gates generated : 13
Contract successfully created and located at contract/plonk_vk.sol
Moved verifier contract to MulVerifier.sol in contracts folder

Compiled 1 Solidity file successfully
Done in 2.59s.

Installation

npm install hardhat-noir

Import the plugin in your hardhat.config.js:

require("hardhat-noir");

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

import "hardhat-noir";

Tasks

These tasks only run if there are no changes detected so circuit source files, or are invoked with the --force flag. Both tasks will use the WASM libraries, unless the flag --nargo is set or useNargo is set to true in the config, in which case they will use the nargo binary available in the PATH.

  • noir:compile: Compiles the circuit in the circuitsPath.
  • noir:contract: Generates a verifier contract for the circuit in Hardhat's contracts folder.

:wink: The solidity pragma of the generated contract is automatically changed from >=0.6.0 <0.8.0 to >=0.6.0 <0.9.0 to support the latest versions of solc, since the generated verifier is compatible with the 0.8 releases.

Environment extensions

This plugin adds a noir field to the Hardhat Runtime Environment, which exposes a getCircuit method. This returns a Circuit abstraction with the following convenience methods, which are wrappers over the ones in @noir-lang/barretenberg/dest/client_proofs.

  • getProof(input): Generates a proof for the circuit given the input variables.
  • verifyProof(proof): Verifies a proof.
  • verifyProofFor(input): Generates and verifies a proof in a single call.

As an example:

import { noir } from "hardhat";

async function run(): Promise<boolean> {
  const input = { x: 3, y: 4, result: 12 };
  return noir.getCircuit().verifyProofFor(input);
}

The equivalent code without the plugin would be the following, as adapted from the basic_mul_noir_example:

import { acir_from_bytes } from '@noir-lang/noir_wasm';
import { setup_generic_prover_and_verifier, create_proof, verify_proof } from '@noir-lang/barretenberg/dest/client_proofs';

async function run(): Promise<boolean> {
  const acirBuffer = readFileSync('./circuits/build/mul.acir');
  const acirByteArray = new Uint8Array(buffer);
  const acir = acir_from_bytes(acirByteArray);

  const abi = { x: 3, y: 4, result: 12 };

  const [prover, verifier] = await setup_generic_prover_and_verifier(acir);
  const proof = await create_proof(prover, acir, abi);
  return await verify_proof(verifier, proof);
}

Configuration

This plugin extends the Hardhat config with a noir field with the following fields. See the config.ts file for more info.

module.exports = {
  noir: {
    circuitsPath: 'circuits',
    mainCircuitName: 'main',
    nargoBin: 'nargo',
    useNargo: false,
    autoCompile: true,
    autoGenerateContract: true,
  }
};

Next

Ideas for future improvements:

  • [ ] Support multiple circuits within the same Hardhat project, each on their individual folder
  • [x] Fall back to compilation and verifier generation using node libraries, if nargo is unavailable