This example uses Foundry to deploy and test a verifier.
Want to get started in a pinch? Start your project in a free Github Codespace!
In the meantime, follow these simple steps to work on your own machine:
Install noirup with
-
Install noirup:
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
-
Install Nargo:
noirup
-
Install foundryup and follow the instructions on screen. You should then have all the foundry tools like
forge
,cast
,anvil
andchisel
.
curl -L https://foundry.paradigm.xyz | bash
The deployment assumes a verifier contract has been generated by nargo. In order to do this, run:
cd circuits
nargo codegen-verifier
A file named plonk_vk.sol
should appear in the circuits/contracts/with_foundry
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
A file named with_foundry.proof
should appear in the ./circuits/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 london
You 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 --broadcast
If 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
anvil
This 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
LOCALHOST_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
LOCALHOST_PRIVATE_KEY=<the private key of the account with your coins>
You need to source your .env
file before deploying. Do that with:
source .env
Then run the deployment with:
forge script script/Starter.s.sol --rpc-url $ANVIL_RPC --broadcast --verify
Replace $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.