0xturboblitz / mopro

Making client-side proving on mobile simple.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proof of passport mopro

This is a fork of mopro to use with proof of passport. This will be cleaned and streamlined once mopro is ready and distributed as a pod/cli.

Only modifications:

  • proof of passport circuit in /mopro-core/examples/circom
  • in mopro-core/build.rs, added path to the new circuit

Once you have followed the instructions below, copy mopro-ffi/target/${ARCHITECTURE}/${LIB_DIR}/libmopro_ffi.a to proof-of-passport/app/ios/MoproKit/Libs

For better performance, build in release mode.

mopro

Making client-side proving on mobile simple (and fast).

Overview

  • mopro-cli - core Rust CLI util (NOTE: Very early; use mopro-core for now).
  • mopro-core - core mobile Rust library.
  • mopro-ffi - wraps mopro-core and exposes UniFFI bindings.
  • mopro-ios - iOS CocoaPod library exposing native Swift bindings.
  • mopro-android - Android library exposing native Kotlin bindings.
  • mopro-example-app - example iOS app using mopro-ios.
  • ark-zkey - helper utility to make zkey more usable and faster in arkworks.

Architecture

The following illustration shows how mopro and its components fit together into the wider ZKP ecosystem:

mopro architecture (full)

Zooming in a bit:

mopro architecture

How to use

Prepare circuits

  • Install circom and snarkjs
  • Run ./scripts/prepare.sh to check all prerequisites are set.

(Note that we require uniffi-bindgen to be 0.25, if you have an older version you might need to remove this to re-install the latest).

Configure settings

By creating a toml configuration file you can specify what build settings you want to use. Example is provided in config-example.toml:

# config-example.toml

[build]
# For iOS device_type can be x86_64, simulator, device
# For Android device_type can be x86_64, arm, arm64
device_type = "simulator" # Options: x86_64, simulator, device, arm, arm64

# debug is for Rust library to be in debug mode and release for release mode
# We recommend release mode by default for performance
build_mode = "release"    # Options: debug, release

[circuit]
dir = "examples/circom/keccak256" # Directory of the circuit
name = "keccak256_256_test"       # Name of the circuit

[dylib]
use_dylib = false         # Options: true, false
name = "keccak256.dylib" # Name of the dylib file, only used if use_dylib is true

iOS

Prepare

Build Bindings

To build bindings for iOS, adjust settings in your config file (we recommend starting with simulator and release) and run:

./scripts/build_ios.sh config-example.toml

Open the mopro-ios/MoproKit/Example/MoproKit.xcworkspace in Xcode.

Update Bindings

To update bindings, run ./scripts/update_bindings.sh config-example.

Android

Prepare

  • Install Android Studio
  • Open Android Studio, and navigate to SDK Manager > SDK Tools > NDK (Side by Side) as laid out on the Android Developer site.
  • Export $ANDROID_HOME and change {USER_NAME} to your username
    export ANDROID_HOME="/Users/{USER_NAME}/Library/Android/sdk"
  • Locate which NDK version you have by
    ls $ANDROID_HOME/ndk
    # 26.1.10909125
    and set it to your NDK_PATH environment variable. e.g.
    NDK_PATH=$ANDROID_HOME/ndk/26.1.10909125

    Reference: Running Rust on Android with UniFFI

Build and Update Bindings

To build bindings for android simulator debug mode, run

./scripts/build_android.sh config-example.toml
  • Device types: x86_64, x86, arm, arm64 Check your device architecture here: https://doc.e.foundation/devices For Android Studio simulator (Pixel series), choose arm64
  • Mode: debug, release

Community and Talks

Join the Telegram group here.

Talk by @oskarth at ProgCrypto/Devconnect (Istanbul, November 2023): Slides (video pending)

Performance

Preliminary benchmarks on an iPhone 14 Max Pro:

  • Keccak256 (150k constraints): 1.5s
    • ~x10-20 faster vs comparable circuit in browser
  • anon-aadhaar / RSA Verify: ~6.5s
    • ~5s for witness generation (still in WASM), ~2s prover time
    • 80% of time on witness generation
    • ~x10 faster vs browser on phone
  • Bottlenecks: loading zkey and wasm witness generation

Acknowledgements

This work is sponsored by a joint grant from PSE and 0xPARC.

About

Making client-side proving on mobile simple.

License:Apache License 2.0


Languages

Language:Swift 36.3%Language:Circom 32.6%Language:Rust 12.4%Language:Kotlin 6.2%Language:Shell 4.8%Language:C 3.6%Language:JavaScript 1.8%Language:TypeScript 1.7%Language:Ruby 0.4%Language:CSS 0.1%Language:Makefile 0.1%