This example uses Foundry to deploy and test a verifier.
Follow the Noir Docs to install nargo.
For this template, ensure you're using Noir version 0.9.0. You can install with noirup -v 0.9.0.
run
curl -L https://foundry.paradigm.xyz | bashand follow the instructions on screen. You should then have all the foundry tools like forge,
cast, anvil and chisel.
The deployment assumes a verifier contract has been generated by nargo. In order to do this, run:
cd circuits
nargo codegen-verifierA file named plonk_vk.sol should appear in the circuits folder.
You also need a proof, as this template currently doesn't employ ffi to call nargo prove by
itself. For this, ensure your prover parameters are correct in Prover.toml and run:
nargo prove pA file named p.proof should appear in the proofs folder.
We're ready to test with Foundry. There's a basic test inside the test folder that deploys the
verifier contract, the Starter contract and two bytes32 arrays correspondent to good and bad
solutions to your circuit.
By running the following command, forge will compile the contract with 5000 rounds of optimization and the London EVM version. You need to use these optimizer settings to supress the "stack too deep" error on the solc compiler. Then it will run the test, expecting it to pass with correct inputs, and fail with wrong inputs:
forge test --optimize --optimizer-runs 5000 --evm-version londonYou can test that the Noir Solidity verifier contract works on a given chain by running the
Verify.s.sol script against the appropriate RPC endpoint.
forge script script/Verify.s.sol --rpc-url $RPC_ENDPOINT --broadcastIf that doesn't work, you can add the network to Metamask and deploy and test via Remix.
Note that some EVM network infrastructure may behave differently and this script may fail for reasons unrelated to the compatibility of the verifier contract.
This template also has a script to help you deploy on your own network. But for that you need to run your own node or, alternatively, deploy on a testnet.
If you want to deploy locally, run a node by opening a terminal and running
anvilThis should start a local node listening on http://localhost:8545. It will also give you many
private keys.
Edit your .env file to look like:
ANVIL_RPC=http://localhost:8545
PRIVATE_KEY=<the private key you just got from anvil>
Pick a testnet like Sepolia or Goerli. Generate a private key and use a faucet (like this one for Sepolia) to get some coins in there.
Edit your .env file to look like:
SEPOLIA_RPC=https://rpc2.sepolia.org
PRIVATE_KEY=<the private key of the account with your coins>You need to source your .env file before deploying. Do that with:
source .envThen run the deployment with:
forge script script/Starter.s.sol --rpc-url $ANVIL_RPC --broadcast --verifyReplace $ANVIL_RPC with the testnet RPC, if you're deploying on a testnet.
This template doesn't include settings you may need to deal with syntax highlighting and IDE-specific settings (i.e. VScode). Please follow the instructions on the Foundy book to set that up.
It's highly recommended you get familiar with Foundry before developing on this template.