Circom Guide
In this guide we'll talk about how to run Circom (Groth16) Circuits on your iOS/Android devices. We won't go in details about how to setup and build your Circom Circuits or how to make an Expo App.
Quickstart
Prepping the Project
Let's get started with a blank expo project, you can also use any existing expo app, adding zk-proofs requires only a couple of lines really.
and then add our expo module and relevant libs.
We already have some sample files ready for you that you'll need to get your circuits running, create a directory /public
in the project root and put these files in it.
Expo throws some errors if the files have the same name regardless of extensions so make sure they have different names.
Next, create a file in the root called metro.config.js
so that expo can pick up the wasm
, zkey
& graph
extensions.
Running the circuits
Make the Proof
Voila 🥳 You just made a proof.
Make the Proof (Advanced)
This method is experimental but gives a 2.5 - 3X Speedup. It does so by precompting the static execution graph required for the witness generation and getting rid of the wasm runtime requirement. Not all Circom operations are supported but should work for most circuits, you can read more about this method at @iden3/circom-witness
Voila 🥳 You just made a super-fast proof.
On-chain Verification
- Tutorial on On-chain Verification
API Reference
ZkExpo.groth16Prove
ZkExpo.groth16ProveV2
Some Gotchas
- Make sure to update your dependencies, also use
npx expo install --fix
. - Use Development Client Builds, this won't work on Expo Go as it requires native code.
- If your app crashes while testing
groth16Prove
on a real iOS device, run the app usingbun expo prebuild
and XCode. iOS has some wierd quirks while running Wasm runtimes, this should be fine in the production versions of your app. You can also usegroth16ProveV2
which doesn't need the wasm runtime and is faster. - iOS has memory restrictions of around 2-3GB imposed on each app. If your circuits are really large you might run into issues, consider splitting the circuits or using
groth16ProveV2
to optimize your circuits. - If your iOS app runs into any linking issues on developement when using
eas build
, do anbun expo prebuild
and open theios
folder in XCode. XCode GUI uses certain Apple internals that perform better than eas builds that usexcodebuild
under the hood.