Coder Social home page Coder Social logo

chihchengliang / mopro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zkmopro/mopro

0.0 0.0 0.0 83.18 MB

Making client-side proving on mobile simple.

License: Apache License 2.0

Shell 9.09% JavaScript 1.51% Ruby 0.59% C 2.99% Rust 12.65% Kotlin 7.64% TypeScript 2.64% CSS 0.16% Swift 37.97% Makefile 0.05% Circom 24.70%

mopro's Introduction

mopro

Mopro is a toolkit for ZK app development on mobile. Mopro makes client-side proving on mobile simple.

Getting started

We recommend you use mopro-cli to create and maintain your application. Here's how you can get started with your example app in a few minutes.

You can also watch this short (<5m) tutorial.

Install dependencies

First, make sure you've installed the prerequisites.

Then, run the following commands:

# Clone the mopro repo
git clone [email protected]:oskarth/mopro.git

# Go to your newly cloned checkout
cd mopro

# Install mopro-cli locally
(cd mopro-cli && cargo install --path .)

# Set `MOPRO_ROOT` (replace with path to your git checkout of mopro)
# For example: `export MOPRO_ROOT=/Users/user/repos/github.com/oskarth/mopro`
export MOPRO_ROOT=$(PWD)

# Install `mopro` dependencies
mopro deps

Create a project

Create and initialize a project:

# Create a working directory
mkdir ~/my-zk-app && cd my-zk-app

# Initialize a project
mopro init --platforms ios android

# Go to your project folder
cd mopro-example-app

Configure mopro settings

You may adapt mopro-config.toml to your needs. For example, if you already have a Circom project you can use that.

Prepare your circuit artifacts:

mopro prepare

This only has to be done once when changing the circuit.

Build, test and run your project

Depending on what platforms you are targetting, you can run the following commands:

# Build the project
mopro build

# Run end-to-end test (in Rust only)
mopro test

# Build the project for iOS
mopro build --platforms ios

# Open in Xcode to run on simulator/device
open ios/ExampleApp/ExampleApp.xcworkspace

# Build the project for Android
mopro build --platforms android

# Open in Android Studio to run on simulator/device
open android -a Android\ Studio

See mopro-cli for more details on usage.

Overview

mopro consists of a set of libraries and utilities. Here's a list of the various subprojects:

  • mopro-cli - core Rust CLI util.
  • mopro-core - core mobile Rust library.
  • mopro-ffi - wraps mopro-core and exposes UniFFI bindings.
  • templates/mopro-example-app - example multi-platform app template.
  • ark-zkey - helper utility to make zkey more usable and faster in arkworks.
  • mopro-ios - iOS CocoaPod library exposing native Swift bindings. (will be deprecated)
  • mopro-android - Android library exposing native Kotlin bindings. (will be deprecated)
  • webprover - Prove example circuits through a browser, used for benchmarking.
  • scripts - various helper scripts for mopro-cli and testing.

Architecture

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

mopro architecture

Prerequisites

Depending on what platforms and adapters you use, there are several prerequisites to install before getting started.

Android configuration

Some additional configuration is required for Android.

First, install the latest SDK. In Android Studio, go to SDK Manager > SDK Tools and install NDK (Side by Side) (see Android Developer site).

After that, set the following environment variables:

# 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
ls $ANDROID_HOME/ndk # => 26.1.10909125

# Set it to your `NDK_PATH` environment variable
NDK_PATH=$ANDROID_HOME/ndk/26.1.10909125

(Reference: Running Rust on Android with UniFFI).

mopro configuration

This config file is best used together with mopro-cli.

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
ios_device_type = "simulator" # Options: x86_64, simulator, device
# For Android device_type can be x86_64, x86, arm, arm64
android_device_type = "arm64" # Options: x86_64, x86, 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

# Note: circom-witness-rs is experimental
# See https://github.com/oskarth/mopro/issues/32 for updates
# Only works for keccak256_256_test circuit now
[witness]
use_native_witness_generation = false       # Options: true, false

Community and Talks

Join the Telegram group here.

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

Talk by @oskarth at ETHTaipei (Taipei, March 2024): Slides, Video

Contribute

Contributions of all kinds welcome! Please see open GH issues. Also feel free to join the Telegram chat.

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

See Project MoPerf results for more benchmarks.

Acknowledgements

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

mopro's People

Contributors

oskarth avatar vivianjeng avatar moven0831 avatar meyanis95 avatar foodchain1028 avatar 0xturboblitz avatar omahs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.