Skip to main content
Version: 0.3

Noir Adapter

Mopro supports the integration of Noir circuits, enabling zero-knowledge proofs in native mobile applications with ease. This adapter builds upon foundational work from the zkPassport team and streamlines cross-platform integration with performance, reliability, and developer experience in mind.

Samples​

You can explore real examples of how the Noir adapter works in these projects:

Or follow the mopro CLI getting started and select the Noir adapter to see how to implement a Noir prover using mopro.

Setting Up the Rust Project​

To get started, follow the Rust Setup Guide and ensure the noir_rs package is imported:

[dependencies]
noir_rs = { package = "noir", git = "https://github.com/zkmopro/noir-rs", features = [
"barretenberg",
], tag = "v1.0.0-beta.19" }
# ...
info

The Noir adapter depends on zkmopro/noir-rs. Please checkout the usage and the version here.

Current version: Supports Noir v1.0.0-beta.19 via the official barretenberg-rs crate (=4.2.0-aztecnr-rc.2).

Backend: The adapter uses the Barretenberg backend via the official barretenberg-rs crate from crates.io. Prebuilt FFI binaries are fetched automatically at build time — no separate download script required.

Hash Function Selection​

The Noir adapter supports two functions as oracle hash options for different use cases:

  • Poseidon hash: Default choice, optimized for performance and off-chain verification
  • Keccak256 hash: Gas-efficient, required for Solidity verifier compatibility and on-chain verification

The hash function is automatically selected based on the on_chain parameter.

Key Features​

  • Automatic Hash Selection: Automatically chooses between Poseidon (performance) and Keccak256 (EVM compatibility) based on your use case
  • Memory Optimization: Low memory mode available for mobile devices
  • Cross-Platform: Works across iOS, Android, and other supported platforms

Proving and Verifying Functions​

Preparing SRS​

Please follow this guide to generate the SRS for your Noir circuit: Downloading SRS (Structured Reference String)

Rust API​

The Noir adapter provides three main functions that automatically handle hash function selection based on the on_chain parameter:

pub fn generate_noir_proof(
circuit_path: String,
srs_path: Option<String>,
inputs: Vec<String>,
on_chain: bool,
vk: Vec<u8>,
low_memory_mode: bool,
) -> Result<Vec<u8>, MoproError>;

pub fn verify_noir_proof(
circuit_path: String,
proof: Vec<u8>,
on_chain: bool,
vk: Vec<u8>,
low_memory_mode: bool,
) -> Result<bool, MoproError>;

pub fn get_noir_verification_key(
circuit_path: String,
srs_path: Option<String>,
on_chain: bool,
low_memory_mode: bool,
) -> Result<Vec<u8>, MoproError>;

Parameters​

  • circuit_path: Path to the compiled Noir .json circuit
  • srs_path: Optional path to the structured reference string
  • inputs: List of strings representing public/private inputs (proof generation only)
  • proof: The serialized proof to verify (verification only)
  • on_chain: If true, uses Keccak256 hash for Solidity compatibility; if false, uses Poseidon hash for better performance
  • vk: Pre-generated verification key bytes
  • low_memory_mode: Enables memory optimization for resource-constrained environments

Usage Notes​

  • Hash Selection: Set on_chain = true for Ethereum/EVM compatibility, or on_chain = false for better performance
  • Verification Keys: Pre-generate verification keys using get_noir_verification_key and reuse them for better performance
  • Memory Optimization: Enable low_memory_mode = true for resource-constrained mobile environments

Platform Support​

The Noir adapter supports the following target platforms with Barretenberg backend binaries:

PlatformTarget TripleStatus
macOS (Intel)x86_64-apple-darwin✅
macOS (M Series)aarch64-apple-darwin✅
iOS Deviceaarch64-apple-ios✅
iOS aarch64 Simulatoraarch64-apple-ios-sim✅
Android aarch64 Deviceaarch64-linux-android✅
Android x86_64 Emulatorx86_64-linux-android✅
Linux Desktopx86_64-unknown-linux-gnu✅

All platforms use pre-compiled Barretenberg binaries fetched by the official barretenberg-rs crate from crates.io during the build process.

Using the Library​

After you have specified the circuits you want to use, you can follow the usual steps to build the library and use it in your project.

iOS API​

The Noir adapter exposes the following functions to be used in the iOS project:

generateNoirProof​

public func generateNoirProof(circuitPath: String, srsPath: String?, inputs: [String], onChain: Bool, vk: Data, lowMemoryMode: Bool)throws  -> Data 

verifyNoirProof​

public func verifyNoirProof(circuitPath: String, proof: Data, onChain: Bool, vk: Data, lowMemoryMode: Bool)throws  -> Bool  

getNoirVerificationKey​

public func getNoirVerificationKey(circuitPath: String, srsPath: String?, onChain: Bool, lowMemoryMode: Bool)throws  -> Data  {

Android API​

The Noir adapter exposes the equivalent functions and types to be used in the Android project.

generateNoirProof​

fun `generateNoirProof`(
`circuitPath`: kotlin.String,
`srsPath`: kotlin.String?,
`inputs`: List<kotlin.String>,
`onChain`: kotlin.Boolean,
`vk`: kotlin.ByteArray,
`lowMemoryMode`: kotlin.Boolean,
): kotlin.ByteArray

verifyNoirProof​

fun `verifyNoirProof`(
`circuitPath`: kotlin.String,
`proof`: kotlin.ByteArray,
`onChain`: kotlin.Boolean,
`vk`: kotlin.ByteArray,
`lowMemoryMode`: kotlin.Boolean,
): kotlin.Boolean

getNoirVerificationKey​

fun `getNoirVerificationKey`(
`circuitPath`: kotlin.String,
`srsPath`: kotlin.String?,
`onChain`: kotlin.Boolean,
`lowMemoryMode`: kotlin.Boolean,
): kotlin.ByteArray