An example repository demonstrating how to verify Noir circuits using a Solidity verifier and the bb backend.
/circuits— Contains the Noir circuit and logic./contract— Foundry project with Solidity verifier and test contract./js— JavaScript code for generating and saving proofs usingbb.js.
Tested with:
- Noir
v1.0.0-beta.3 bbCLIv0.82.2
The Noir circuit proves that:
Where:
xis a private inputyandexpectedare public inputs
This lets a user prove correctness without revealing their private input x.
The Noir circuit checks if x * 2 + y == expected, where:
xis a private inputyandexpectedare public inputs
# Foundry
git submodule update
# Build circuits, generate verifier contract
(cd circuits && ./build.sh)
# Install JS dependencies
(cd js && yarn)
# Use bb.js to generate proof and save to a file
(cd js && yarn generate-proof)
# Run foundry test to read generated proof and verify
(cd contract && forge test --optimize --optimizer-runs 5000 --gas-report -vvv)
cd circuits
# Generate witness
nargo execute
# Generate proof
bb prove -b ./target/noir_solidity.json -w target/noir_solidity.gz -o ./target --oracle_hash keccak
# Split this proof and public inputs into two files
# Convert proof to hex, and slice first 4 bytes of metadata
PROOF_HEX=$(cat ./target/proof | od -An -v -t x1 | tr -d $' \n' | sed 's/^.\{8\}//')
NUM_PUBLIC_INPUTS=2
HEX_PUBLIC_INPUTS=${PROOF_HEX:0:$((32 * $NUM_PUBLIC_INPUTS * 2))}
SPLIT_HEX_PUBLIC_INPUTS=$(sed -e 's/.\{64\}/0x&,/g' <<<$HEX_PUBLIC_INPUTS)
PROOF_WITHOUT_PUBLIC_INPUTS="${PROOF_HEX:$((NUM_PUBLIC_INPUTS * 32 * 2))}"
# Save proof and public inputs to files
echo $PROOF_WITHOUT_PUBLIC_INPUTS | xxd -r -p > ./target/proof
echo "[\"$SPLIT_HEX_PUBLIC_INPUTS\"]" > ./target/public-inputs
# Run foundry test to read generated proof and verify
cd ..
(cd contract && forge test --optimize --optimizer-runs 5000 --gas-report -vvv)
The project supports two approaches for generating proofs:
- JavaScript-based workflow using
bb.js - CLI-based workflow using
nargoandbbdirectly
Use the run.sh script with an argument to select the approach:
# JavaScript workflow using bb.js
./circuits/run.sh js
# CLI workflow using nargo + bb
./circuits/run.sh cliThis script will:
- Build the circuit
- Generate a proof
- Run Solidity tests using Foundry
Use the build.sh script to compile the circuit and generate the Solidity verifier:
./build.shThis will:
- Compile the Noir circuit
- Generate the verification key (
vk) - Export the Solidity verifier to
contract/Verifier.sol
This project is indexed in the Electric Capital Crypto Ecosystems Map.
Source: Electric Capital Crypto Ecosystems
Link: https://github.com/electric-capital/crypto-ecosystems
Logo:
💡 If you’re working in open source crypto, submit your repository here to be counted.
Thank you for contributing and for reading the contribution guide! ❤️