Minimal end-to-end demo for verifying a Circom Groth16 proof on Soroban.
- Circom circuit:
a * b = c(circuits/multiplier2.circom) - Soroban verifier contract using BLS12-381 pairing checks (
contract/src/lib.rs) - Rust CLI to convert
snarkjsJSON outputs into Soroban byte payloads (tools/circom_to_soroban_hex/) - Scripted flow to build, deploy, generate proof, and verify on-chain (
demo.sh) - React frontend for browser-side proof generation + contract verification (
frontend/)
circuits/: Circom sourcesproving/: proving artifacts and sample inputs (.zkey,.wtns,input.json)contract/: Soroban verifier contracttools/circom_to_soroban_hex/: JSON -> hex encoder for Soroban contract argumentsfrontend/: Vite + React demo UIbuild/: generated artifacts (proof.json,public.json, hex outputs); safe to regenerate
-
Rust toolchain (workspace uses Rust 2021; contract crate sets
rust-version = 1.89.0) -
Soroban target:
rustup target add wasm32v1-none
-
Node.js + npm
-
stellarCLI configured with a funded Testnet account as your active/default identity
Run everything with one command:
./demo.shBy default, this uses NETWORK=testnet. You can override it:
NETWORK=testnet ./demo.shExpected end state in output:
- Contract deployed (prints a
C...contract ID) - Local
snarkjsverification succeeds - On-chain verification result is
true
- Installs root Node dependency (
snarkjs) - Builds the Soroban contract WASM
- Deploys the verifier contract to the selected network
- Generates
proof.jsonandpublic.jsonfrom the witness - Verifies locally with
snarkjs - Encodes verification key/proof/public inputs into Soroban byte format
- Calls
set_vkthenverifyon-chain
Workspace checks:
cargo check --workspace
cargo test --workspaceManual encoding examples:
cargo run -p circom-to-soroban-hex -- vk build/verification_key.json
cargo run -p circom-to-soroban-hex -- proof build/proof.json
cargo run -p circom-to-soroban-hex -- public build/public.jsonFrontend:
cd frontend
cp .env.example .env
npm install
npm run devGenerate some keys at https://lab.stellar.org and fund it with friendbot to get some testnet xlm. Then add the secret key and public key to the .env file.
Frontend production build:
cd frontend
npm run buildstellar contract deployfails:- Ensure your active CLI identity is configured and funded on Testnet.
- On-chain result is not
true:- Regenerate
build/artifacts via./demo.shto avoid stale proof/key mismatch.
- Regenerate
- Frontend simulation errors:
- Check
VITE_RPC_URL,VITE_NETWORK_PASSPHRASE, and contract ID are on the same network.
- Check
- https://jamesbachini.com
- https://www.youtube.com/c/JamesBachini
- https://bachini.substack.com
- https://podcasters.spotify.com/pod/show/jamesbachini
- https://x.com/james_bachini
- https://www.linkedin.com/in/james-bachini/
- https://github.com/jamesbachini
This project is experimental and intended for learning, prototyping, and demonstration purposes. It has not been audited.
Use at your own risk.
MIT