A Flutter plugin for generating and verifying zero-knowledge proofs (ZKPs) on mobile platforms (iOS/Android). This package provides a simple interface to interact with proof systems such as Circom and Halo2, supporting multiple proof libraries (e.g., Arkworks, Rapidsnark).
Follow these steps to integrate the Mopro Flutter package into your project.
-
Add Dependency: You can add
mopro_flutter_bindingsto your project by manually editingpubspec.yaml.-
Manual Edit (Required for local path or specific Git dependencies): Open your
pubspec.yamlfile and addmopro_flutter_bindingsunderdependencies.dependencies: flutter: sdk: flutter mopro_flutter_bindings: git: url: https://github.com/zkmopro/mopro_flutter_package # Or # mopro_flutter_package: # path: ../mopro_flutter_package
-
-
Update Circuit Asset: Include your compiled Circom
.zkeyfile as an asset. Add the asset path to yourpubspec.yamlunder theflutter:section:flutter: uses-material-design: true # Ensure this is present assets: # Add the directory containing your .zkey file(s) - assets/...zkey # Or specify the file directly: # - assets/multiplier2_final.zkey
Make sure the path points correctly to where you've placed your
.zkeyfile within your Flutter project. -
Install Package: Run the following command in your terminal from the root of your Flutter project:
flutter pub get
Here's a basic example demonstrating how to use the package to generate and verify a proof for a simple multiplier circuit.
Update the main function to initialize the Rust library before running the app:
void main() async {
await RustLib.init();
runApp(const MyApp());
}Import the package and use it:
// Import the package
import 'package:mopro_flutter_bindings/src/rust/third_party/mopro_example_app.dart'; // Change to your library name
import 'package:mopro_flutter_bindings/src/rust/frb_generated.dart';
final zkeyPath = await copyAssetToFileSystem(
'assets/multiplier2_final.zkey',
)
// Corresponds to the inputs of multiplier2.circom
const int a = 3;
const int b = 5;
final Map<String, List<String>> inputs = {
'a': [a.toString()],
'b': [b.toString()],
};
// Convert inputs to JSON string
final String inputsJson = jsonEncode(inputs);
// Use the zkey asset path provided in pubspec.yaml
final CircomProofResult proofResult = await generateCircomProof(
zkeyPath: zkeyPath,
circuitInputs: inputsJson,
proofLib: ProofLib.arkworks,
);
final bool isValid = await verifyCircomProof(
zkeyPath: zkeyPath,
proofResult: proofResult,
proofLib: ProofLib.arkworks,
);
print('Generated Proof: ${proofResult.proof}');
print('Public Inputs/Outputs: ${proofResult.inputs}');
print('Verification result: $isValid');Note
To learn how to read a .zkey file from an app, please refer to the copyAssetToFileSystem function in the Flutter app.
Warning
The default bindings are built specifically for the multiplier2 circom circuit. If you'd like to update the circuit or switch to a different proving scheme, please refer to the How to Build the Package section.
Circuit source code: https://github.com/zkmopro/circuit-registry/tree/main/multiplier2
Example .zkey file for the circuit: http://ci-keys.zkmopro.org/multiplier2_final.zkey
This package relies on bindings generated by the Mopro CLI. To learn how to build Mopro bindings, refer to the Getting Started section. If you'd like to generate custom bindings for your own circuits or proving schemes, check out the guide on how to use the Mopro CLI: Rust Setup for Android/iOS Bindings.
Choose Flutter to build the bindings, or run
mopro build --platforms flutterto generate the flutter package.
Then, replace the entire bindings directory mopro_flutter_package with your generated files in the current folder:
├── android
├── cargokit
├── flutter_rust_bridge.yaml
├── ios
├── lib
├── pubspec.yaml
└── rustor running e.g.
cp -R \
mopro_flutter_bindings/android \
mopro_flutter_bindings/cargokit \
mopro_flutter_bindings/flutter_rust_bridge.yaml \
mopro_flutter_bindings/ios \
mopro_flutter_bindings/lib \
mopro_flutter_bindings/pubspec.yaml \
mopro_flutter_bindings/rust \
mopro_flutter_package/- Open the example app that uses the defined flutter package in the
example/foldercd example - Install the dependencies
flutter pub get
- Open an iOS simulator/device or an Android emulator/device and run the example app
flutter run
- Clean the cache if you update the bindings and it throws errors
flutter clean
![WARNING] Bindings generated by the mopro CLI use local crate paths by default, which makes them non-reproducible on other devices. To make the build reproducible, publish your Rust crate and reference it via a Git source instead of a local path at here. If you’d like to help address this limitation, contributions are welcome — see zkmopro/mopro#647 .
This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.