Skip to content

m-kus/sn-noir-quickstart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating a privacy preserving application on Starknet

In this tutorial, we will create a privacy preserving application on Starknet.
We will use Noir to write the circuit, Cairo for the smart contract, and finally Garaga for gluing everything together.

Install dependencies

Follow the steps, or run the command below to install all the dependencies at once:

make install

Step 1: Install Noir toolchain

curl -L noirup.dev | bash
noirup --version 1.0.0-beta.1

Step 2: Install Barretenberg

Barretenberg is a proving backend for Noir.

curl -L bbup.dev | bash
bbup --version 0.67.0

Step 3: Install Scarb

Scarb is a Cairo package manager and compiler toolchain.

curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.9.2

Note

Scarb 2.9.2 is required to Garaga work correctly.

Step 4: Install Starknet Foundry

Starknet Foundry is a smart contract development framework for Starknet.

curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
snfoundryup

Step 5: Install Garaga

Garaga is a code generation tool, SDK, and Cairo library.
It is shipped with a Python CLI:

pip install garaga

Note

Python 3.10 is required to install Garaga. Use pyenv to manage your Python versions.

Create and prove a circuit

Step 6: Create a Noir project

nargo new circuit
cd circuit
nargo check

Fill the Prover.toml file with the inputs:

x = "1"
y = "2"

Step 7: Prove the circuit

Execute the circuit to generate a witness:

nargo execute witness

Prove the circuit:

bb prove_ultra_keccak_honk -b ./target/circuit.json -w ./target/witness.gz -o ./target/proof

Generate a verifying key and verify the proof:

bb write_vk_ultra_keccak_honk -b ./target/circuit.json -o ./target/vk
bb verify_ultra_keccak_honk -k ./target/vk -p ./target/proof

Create a Cairo smart contract

Step 8: Generate Noir proof verifier

In the project folder, run:

garaga gen --system ultra_keccak_honk --vk circuit/target/vk.bin --project-name contract
cd contract
scarb build

Step 9: Create Starknet account

Create a foundry config file named snfoundry.toml inside the contract folder:

[sncast.default]
account = "test"
url = "https://starknet-sepolia.public.blastapi.io/rpc/v0_7"

Create a Starknet account:

sncast account create --type oz --name test

Step 10: Send some money to the generated address

Go to https://starknet-faucet.vercel.app/ and paste the address of the account you created.
Use STRK as the fee token.

Note

You might need to prepend a zero to your account in case of an error. Ex. 0x123... -> 0x0123...

Step 11: Deploy the account contract

On Starknet all accounts are contracts, even your wallet, so you need to deploy an account contract to interact with your application.

sncast account deploy --fee-token strk --name test

Step 12: Initialize Garaga environment

Create a .secrets file in the contract folder and add the following variables:

SEPOLIA_RPC_URL="https://free-rpc.nethermind.io/sepolia-juno"
SEPOLIA_ACCOUNT_PRIVATE_KEY=<your_private_key>
SEPOLIA_ACCOUNT_ADDRESS=<your_address>

The values can be obtained by running:

sncast account list -p

Step 13: Deploy the verifier contract

First we need to declare the contract ("upload it's code hash to the network"):

garaga declare --fee strk

Then we can instantiate it (change class-hash according to the output on the previous step):

garaga deploy --fee strk --class-hash 0x62412c03a6d8f5d1b721757a67e5e2d092ae0bbbdb487eb1c7c598835324a76

Verify the proof on Starknet

Step 14: Invoke the verifier contract

garaga verify-onchain \
    --system ultra_keccak_honk \
    --contract-address 0x52691054da2ae92e7dd55afe4201adc6da412c97539f0f5b8687d069581165b \
    --proof ../circuit/target/proof \
    --vk ../circuit/target/vk \
    --fee strk

About

Starknet x Noir workshop

Topics

Resources

License

Stars

Watchers

Forks

Languages