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.
Follow the steps, or run the command below to install all the dependencies at once:
make installcurl -L noirup.dev | bash
noirup --version 1.0.0-beta.1Barretenberg is a proving backend for Noir.
curl -L bbup.dev | bash
bbup --version 0.67.0Scarb 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.2Note
Scarb 2.9.2 is required to Garaga work correctly.
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
snfoundryupGaraga is a code generation tool, SDK, and Cairo library.
It is shipped with a Python CLI:
pip install garagaNote
Python 3.10 is required to install Garaga.
Use pyenv to manage your Python versions.
nargo new circuit
cd circuit
nargo checkFill the Prover.toml file with the inputs:
x = "1"
y = "2"Execute the circuit to generate a witness:
nargo execute witnessProve the circuit:
bb prove_ultra_keccak_honk -b ./target/circuit.json -w ./target/witness.gz -o ./target/proofGenerate 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/proofIn the project folder, run:
garaga gen --system ultra_keccak_honk --vk circuit/target/vk.bin --project-name contract
cd contract
scarb buildCreate 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 testGo 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...
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 testCreate 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 -pFirst we need to declare the contract ("upload it's code hash to the network"):
garaga declare --fee strkThen we can instantiate it (change class-hash according to the output on the previous step):
garaga deploy --fee strk --class-hash 0x62412c03a6d8f5d1b721757a67e5e2d092ae0bbbdb487eb1c7c598835324a76garaga verify-onchain \
--system ultra_keccak_honk \
--contract-address 0x52691054da2ae92e7dd55afe4201adc6da412c97539f0f5b8687d069581165b \
--proof ../circuit/target/proof \
--vk ../circuit/target/vk \
--fee strk