Mopro: ZK Toolkit for Mobile

repository·main·Indexed 42 days ago

https://github.com/zkmopro/mopro

A toolkit for efficient client-side Zero-Knowledge (ZK) proving on mobile devices and web browsers. It provides high-performance provers for Circom, Halo2, and Noir through cross-platform bindings. The ecosystem includes mopro-ffi for automating language bindings and mopro-cli (v0.3.7) for managing project templates and builds across iOS, Android, Flutter, React Native, and Web (WASM).

Tokens
66.7K
Snippets
199
Records
308
Agent score
53%

What's inside Mopro

  1. Overview of Mopro Mobile SDKs

    main
    Mopro enables protocol developers to build mobile SDKs using native bindings. Instead of building complete mobile applications with frontends, developers can focus on creating SDKs that allow mobile app developers to integrate specific protocols into their existing applications.
  2. What is MoPro FFI

    main

    MoPro FFI (Mobile Prover FFI) is a component of the MoPro framework designed to simplify the development of client-side zero-knowledge (ZK) proof systems on mobile platforms. It automates the generation of platform-specific bindings from Rust code, abstracting the complexities of tools like UniFFI, wasm-bindgen, flutter_rust_bridge, and uniffi-bindgen-react-native.

    Instead of manual configuration, MoPro FFI provides ready-to-use frameworks and packages for iOS, Android, Flutter, React Native, and Web (WASM). For the best experience, it is recommended to use the companion mopro-cli tool, which provides project templates and built-in support for ZK proof systems like Circom, Halo2, and Noir.

  3. Overview of Mopro: ZK Toolkit for Mobile

    main

    Mopro (Mobile Prover) is a toolkit designed to simplify client-side Zero-Knowledge (ZK) proving on mobile devices. It provides the necessary infrastructure to build ZK applications that run directly on mobile hardware.

    Core Components

    • mopro-ffi: Uses UniFFI to generate language bindings for ZK provers, including Circom, Halo2, and Noir. It includes build scripts to streamline integration with iOS and Android.
    • mopro-cli: A command-line tool used to scaffold ZK projects. It supports multiple target platforms: Swift (Xcode), Kotlin (Android Studio), React Native, Flutter, and Web.
    • tests: Contains end-to-end test examples to verify mopro-ffi integrations.
  4. Overview of Mopro: The Mobile Prover Toolkit

    main

    Mopro is a developer toolkit designed to facilitate the creation of mobile-native Zero-Knowledge (ZK) applications. It provides a streamlined workflow for bringing ZK proving systems to mobile devices by abstracting the complexity of FFI (Foreign Function Interface) and providing cross-platform tooling.

    Key Features

    • mopro-ffi: Simplifies manual FFI setup and enables a modular approach to proving systems.
    • CLI Tooling: A powerful command-line interface to scaffold, build, and update projects.
    • Platform Templates: Prebuilt templates for iOS, Android, React Native, and Flutter.
    • Cross-platform Rust Tooling: Enables building native apps with high performance.

    Core Benefits of Mobile-Native ZK

    • Performance: Up to 10× performance boost compared to browser-based ZK applications.
    • Device Integration: Seamless access to biometrics, GPS, NFC, camera, Bluetooth, and more.
    • Offline Capability: Improved reliability and offline readiness for real-world usage.
  5. What is Multi-Scalar Multiplication (MSM) and how is it accelerated?

    main

    Multi-Scalar Multiplication (MSM) is a core cryptographic primitive used in elliptic curve cryptography (specifically for pairing-based proving systems like BN254). It involves computing a sum of the form $Q = \sum_{i=1}^{n}(k_i \cdot P_i)$, where $k_i$ are scalars and $P_i$ are points on an elliptic curve.

    Because MSM is computationally intensive, it is a primary candidate for GPU acceleration. Mopro's Metal MSM v2 implementation optimizes this process on Apple GPUs using the Metal Shading Language (MSL) to speed up zero-knowledge proof (ZKP) generation.

  6. How Mopro handles multiplatform bindings

    main

    Mopro uses a Rust-based adapter pattern to encapsulate different proving systems (such as Circom, Noir, or Halo2) behind a unified interface.

    To bridge the Rust logic to mobile environments, Mopro leverages several FFI frameworks to automatically generate native bindings:

    • Swift (iOS) via UniFFI
    • Kotlin (Android) via UniFFI
    • Flutter via flutter_rust_bridge
    • React Native via uniffi-bindgen-react-native

    This architecture allows developers to write the core proving logic once in Rust and consume it across multiple mobile platforms using platform-specific templates.

  7. How mopro-ai automates ZK mobile app development

    main

    When using mopro-ai with an AI coding agent, the agent automates the complex plumbing required to bridge Zero-Knowledge (ZK) circuits with mobile platforms.

    What the developer provides:

    • A one-sentence prompt describing the app.
    • Choice of proof system (e.g., Circom).
    • Choice of platform (e.g., Flutter).
    • Circuit logic (e.g., Poseidon challenge-response).
    • UI requirements (e.g., step-by-step auth flow).

    What mopro-ai automates:

    • CLI & Build Sequencing: Selecting correct CLI flags and managing build order.
    • Scaffolding: Rust project scaffolding and dependency wiring.
    • Cross-compilation: Compiling for target mobile architectures.
    • FFI Bindings: Generating bindings using flutter_rust_bridge.
    • Asset Management: Bundling .zkey files into Flutter assets.
    • Macro Registration: Handling rust_witness! and set_circom_circuits! macros.
    • Platform Configuration: Managing pubspec.yaml, Gradle, and background build execution.
  8. Strategies for Mobile GPU Proving

    main

    Proving on mobile devices requires balancing performance with hardware constraints like thermal limits and battery life.

    Hybrid CPU-GPU Architecture

    To avoid crashes or thermal throttling, consider a hybrid approach (inspired by the 'Glue and Coprocessor' architecture) where tasks are distributed based on their nature:

    • GPU: Best for highly parallelizable tasks (e.g., NTT in lattice-based primitives).
    • CPU: Best for sequential tasks and managing the overall proving logic.

    Optimization Techniques

    • Unified Memory: On platforms like Apple Silicon, the CPU and GPU share system memory (Unified Memory Model). Utilizing zero-cost CPU-GPU transfers via unified memory can reduce I/O overhead.
    • Sustained Performance: When tuning for mobile, prioritize sustained performance over short-lived peak performance to prevent thermal throttling.
  9. Choosing a development path for Mopro

    main

    Depending on your goals, choose one of the following development approaches:

    For Quick Prototyping and Experimentation

    Use Swift (iOS) or Kotlin (Android). These allow you to interact directly with the native module with minimal setup complexity.

    For Cross-Platform Mobile Apps

    Use React Native or Flutter:

    • React Native: Best if your team is more familiar with TypeScript or JavaScript.
    • Flutter: Generally offers faster development performance and a smoother UI experience out of the box.

    Note: Using React Native or Flutter requires defining and bridging APIs across multiple layers (e.g., TypeScript/Dart to the iOS/Android native modules).

  10. How `noir-rs` optimizes Noir builds

    main

    Building the Barretenberg backend (the proving system for Noir) can take up to 20 minutes and requires a specific developer environment.

    To solve this, noir-rs (maintained by the Mopro team) prebuilds the backend binaries and hosts them on a server. During the build process, these binaries are downloaded automatically. This reduces build time from ~20 minutes to approximately 8 seconds and removes the need for local compilation or special environment setup. No additional dependencies are required for this process.