Skip to content

signorecello/hardhat-noirenberg

 
 

Repository files navigation

Hardhat Noirenberg

Develop Noir projects with the Barretenberg proving backend within a Hardhat project without hassle.

[!INFO] This is a fork of @olehmisar's amazing hardhat-noir plugin that features a full JS experience interacting with Noir. It's also pretty minimal. If you're looking for a plugin that gives you Nargo workspaces support, CLI tooling installation, init commands, and other features, check out Oleh's project!

What is this

Write programs in Noir, generate Solidity verifiers with Barretenberg, and deploy them with Hardhat.

Installation

Within your hardhat project, install the plugin:

npm install hardhat-noirenberg

Import it your hardhat.config.js:

require("hardhat-noirenberg"); // for cjs, or
import "hardhat-noirenberg"; // for esm

Specify the Solidity configuration:

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: 200,
      },
    },
  }
};

Prerequisites

To get started, create a Noir circuit in noir folder. For example, if you're using nargo:

nargo init .

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

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

Usage

Your instance noirenberg now has compatible versions of NoirJS and BB.JS. Check their reference documentation here and here.

We're now ready to generate proofs. For example, in a hardhat test file or script:

  const { noir, backend } = await hre.noirenberg.compile();
  const { witness } = await noir.execute({ x: 1, y: 2 });
  const proof = await backend.generateProof(witness);

Generate a Solidity verifier in the default hardhat sources folder:

  await hre.noirenberg.getSolidityVerifier();

Configuration

You can choose between Barretenberg's UltraPlonk and UltraHonk proving systems. It defaults to UltraPlonk, but you can configure any of the two in the hardhat.config file like so:

export default {
  // ... your config
  noirenberg: {
    provingSystem: "UltraHonk"
  }
}

Important

UltraHonk verifier contracts the proof challenge to be generated with keccak hashes instead of poseidon. This means you need to specifically tell the backend to use keccak when generating proofs: backend.generateProof(witness, { keccak: true })

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding a noir field, and defines the path where your Noir project is. It defaults to a folder called noir at the root of the hardhat project.

For example, if you prefer to make it named circuits:

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

Examples

Refer to the test suite for an E2E example of a hardhat project using Noirenberg.

About

Develop Noir and Barretenberg with Hardhat without hassle.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.8%
  • Noir 1.2%