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-plugin-noir

v0.1.3

Published

Hardhat plugin for Noir language

Downloads

542

Readme

Hardhat Noir

Develop Noir with Hardhat without hassle.

What

Write programs in Noir, generate Solidity verifiers and run tests.

This plugin automatically manages nargo and bb versions and compiles Noir on demand.

Installation

Install the plugin and Noir dependencies:

npm install hardhat-plugin-noir @noir-lang/noir_js @noir-lang/backend_barretenberg

Import the plugin in your hardhat.config.js:

require("hardhat-plugin-noir");

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

import "hardhat-plugin-noir";

Specify the Noir version in your Hardhat config:

You must enable Solidity optimizer in order to be able to deploy Solidity verifier contracts.

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.27",
    settings: {
      optimizer: {
        enabled: true,
        runs: 100000000,
      },
    },
  },
  noir: {
    version: "0.36.0",
  }
};

Usage

To get started, create a Noir circuit in noir folder:

npx hardhat noir-new my_noir

It will create noir/my_noir folder with the following src/main.nr:

fn main(x: Field, y: pub Field) {
    assert(x != y);
}

This circuit will prove that the private input x is not equal to the public input y using a zero-knowledge proof.

Compile Noir(it will also generate a Solidity verifier):

npx hardhat compile

Use the verifier contract in Solidity:

// contracts/MyContract.sol
import {UltraVerifier} from "../noir/target/my_noir.sol";

contract MyContract {
    UltraVerifier public verifier = new UltraVerifier();

    function verify(bytes calldata proof, uint256 y) external view returns (bool) {
        bytes32[] memory publicInputs = new bytes32[](1);
        publicInputs[0] = bytes32(y);
        bool result = verifier.verify(proof, publicInputs);
        return result;
    }
}

Generate a proof in TypeScript and verify it on chain:

// test/MyContract.test.ts
import { expect } from "chai";
import hre, { ethers } from "hardhat";

it("proves and verifies on-chain", async () => {
  // Deploy a verifier contract
  const contractFactory = await ethers.getContractFactory("MyContract");
  const contract = await contractFactory.deploy();
  await contract.waitForDeployment();

  // Generate a proof
  const { noir, backend } = await hre.noir.getCircuit("my_noir");
  const input = { x: 1, y: 2 };
  const { witness } = await noir.execute(input);
  const { proof, publicInputs } = await backend.generateProof(witness);
  // it matches because we marked y as `pub` in `main.nr`
  expect(BigInt(publicInputs[0])).to.eq(BigInt(input.y));

  // Verify the proof on-chain
  const result = await contract.verify(proof, input.y);
  expect(result).to.eq(true);

  // You can also verify in JavaScript.
  const resultJs = await backend.verifyProof({
    proof,
    publicInputs: [String(input.y)],
  });
  expect(resultJs).to.eq(true);
});

Tasks

This plugin creates no additional tasks. Run hardhat compile to compile Noir.

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding a noir field.

You can call hre.noir.getCircuit(name) to get a compiled circuit JSON.

Configuration

Configure Noir and Barretenberg (bb) versions in hardhat.config.ts:

export default {
  noir: {
    // Noir version, optional, will use the latest known Noir version by default
    version: "0.36.0",
    // bb version, optional, will be inferred if possible
    bbVersion: "0.58.0",
  },
};

The default folder where Noir is located is noir. You can change it in hardhat.config.js:

export default {
  paths: {
    noir: "circuits",
  },
};