# The starknet chain locally network program. (memory storage by default)
starknet-devnet --version
#starknet-devnet 0.4.2

# The Noir(Nargo) it's a similar to Cargo build tooling for Universal Zero-Knowleage-Proof application development.
nargo --version
#nargo version = 1.0.0-beta.6
#noirc version = 1.0.0-beta.6+e796dfd67726cbc28eb9991782533b211025928d
#(git version hash: e796dfd67726cbc28eb9991782533b211025928d, is dirty: false)

# The bb it's Aztec (ZKP) chain barretenberg tooling.
bb --version
#v0.86.0-starknet.1

# Assuming installed in Conda environment..
conda activate starknet
garaga --version
#garaga version: 0.18.1

# The Bun it's a fast JavaScript runtime, package manager, bundler, and test runner. (Written in Zig and C++)
bun --version
#1.2.17

Prerequisite

Development & Deployment on Local

Building

git clone git@github.com:wl4g-blockchain/starknet-scaffold-garaga.git
cd ./starknet-scaffold-garaga/

make install-bun
make install-noir
make install-barretenberg
make install-starknet
make install-devnet
make install-garaga

# Custom the ZKP-Circuit defintion.
cat <<EOF > ./circuit/src/main.nr
fn main(x: Field, y: pub Field) {
    let yy = y * y;
    assert(x != yy);
}
EOF

# First of all we need to build our Noir circuit:
make build-circuit

# Sample inputs are already provided in Prover.toml, execute to generate witness:
make exec-circuit

# Generate verification key:
make gen-vk
#bb write_vk --scheme ultra_honk --oracle_hash starknet -b ./circuit/target/circuit.json -o ./circuit/target
#Scheme is: ultra_honk, num threads: 8
# ...
#VK saved to "./circuit/target/vk"

# Now we can generate the verifier contract in Cairo using Garaga:
make gen-verifier
#cd contracts && garaga gen --system ultra_starknet_honk --vk ../circuit/target/vk --project-name verifier
#⠼ Generating Smart Contract project for ProofSystem.UltraStarknetHonk using vk...

# Let's start our local starknet network in other terminal instance:
make devnet

# You now need to start a new terminal window. Initialize the account we will be using for deployment:
make accounts-file

# First we need to declare out contract ("upload" contract code):
make declare-verifier
# ...
#    Finished `release` profile target(s) in 12 seconds
#command: declare
#class_hash: 0x074b93dc3cddcd328f8b242b782deef775d60b0ff494a1f71c315ea579d15941
#transaction_hash: 0x0530e8cf680a1f628942cac8a883169f1e91949a8d206380b367fe7f6c029813

# Replace to current declare contract class hash.
sed -i -p 's/0x061dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f/0x074b93dc3cddcd328f8b242b782deef775d60b0ff494a1f71c315ea579d15941/g' Makefile

# Now we can instantiate the contract class we obtained (you might need to update the command in Makefile):
make deploy-verifier
# Use class hash from the result of the `make declare-verifier` step
#cd contracts && sncast deploy --salt 0x00 --class-hash 0x074b93dc3cddcd328f8b242b782deef775d60b0ff494a1f71c315ea579d15941
#command: deploy
#contract_address: 0x0486249e635381baff30e1ee12f99cb95a2ada789f68c708d7fdda28bd0a1a23
#transaction_hash: 0x052708396fc6ed2299b4b085e7e0ca40c5ac12b4ddd708b792478c10c8d19352

# Great! copy deploy generated artifact files to DApp project direcory for frontend calling cairo contracts:
make artifacts

# Build the DApp frontend
cd ./app && yarn
#yarn install v1.22.22
#info No lockfile found.
#[1/4] 🔍  Resolving packages...

# Start the DApp frontend (It's will load contracts ABI of just now)
make run-app
#VITE v6.3.5  ready in 366 ms
#  ➜  Local:   <http://localhost:5173/>

# Replace to frontend calling contract address.
sed -i -p 's/0x02b76ac09aea8957666f0fb3409b091e2bdca99700273af44358bd2ed0e14a32/0x0486249e635381baff30e1ee12f99cb95a2ada789f68c708d7fdda28bd0a1a23/g' ./app/src/App.tsx

Screenshots of DApp (proof:x≠y^2)

image.png

image.png

image.png

Deployment on Sepolia