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!
Write programs in Noir, generate Solidity verifiers with Barretenberg, and deploy them with Hardhat.
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,
},
},
}
};
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);
}
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();
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 })
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",
},
};
Refer to the test suite for an E2E example of a hardhat project using Noirenberg.