Skip to content

saleel/noir-solidity-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

An example repo to verify Noir circuits (with bb backend) using a Solidity verifier.

  • /circuits - contains the Noir circuits.
  • /contract - Foundry project with a Solidity verifier and a Test contract that reads proof from a file and verifies it.
  • /js - JS code to generate proof and save as a file.

Tested with Noir 1.0.0-beta.3 and bb 0.82.2

Installation / Setup

# Foundry
git submodule update

# Build circuits, generate verifier contract
(cd circuits && ./build.sh)

# Install JS dependencies
(cd js && yarn)

Proof generation in JS

# 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)

Proof generation with bb cli

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=1
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)

Deployment

Deploying to base Sepolia:

forge script script/Deploy.s.sol:DeployScript --rpc-url https://mainnet.base.org --broadcast --legacy

Deployment output:

Verifier deployed at: 0x519845DF3Ead9be1B1217d422f5b40a4d43e737D
Starter deployed at: 0xaf78eFEf8B958eBa80D64e78fdBE655DC58e133b
Total Paid: 0.00000522658568628 ETH (5224287 gas * avg 0.00100044 gwei)

Verifying Proof onchain

Verify proof on base Sepolia:

forge script script/VerifyProof.s.sol:VerifyProofScript --rpc-url https://mainnet.base.org --broadcast --legacy

Here is a sample tx - Transaction Fee: 0.000011818559069182 ETH ($0.02)

Get number of verified proofs on-chain

forge script script/VerifyProof.s.sol:GetVerifiedCount --rpc-url https://mainnet.base.org --broadcast --legacy

Cost on Base Mainnet

Verifier deployed at: 0x519845DF3Ead9be1B1217d422f5b40a4d43e737D Starter deployed at: 0xaf78eFEf8B958eBa80D64e78fdBE655DC58e133b

Deployment cost of verifier contract: 0.000028411358047473 ETH ($0.11 when ETH = ~3800 USD) - Sample TX

Proof verification cost : 0.000009590438665493 ETH ($0.04 when ETH = ~3800 USD) - Sample Tx

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages