mopro_ffi/
lib.rs

1#![allow(unexpected_cfgs)]
2
3#[cfg(feature = "build")]
4pub mod app_config;
5
6// UniFFI re-export
7//
8// Uniffi macros use fully qualified paths (`::uniffi::*`) internally.
9// To allow downstream crates to transparently resolve these macros to `mopro_ffi`,
10// users must alias it (`extern crate mopro_ffi as uniffi;`, automated via `app!` macro).
11//
12// However, for this alias to work correctly, `mopro_ffi` must provide the exact same
13// exported items as the original `uniffi`. Hence, we re-export all individual items.
14#[cfg(feature = "uniffi")]
15pub use uniffi::*;
16
17#[cfg(feature = "uniffi")]
18#[macro_export]
19macro_rules! uniffi_setup {
20    () => {
21        // `::uniffi` must be available in the caller’s extern-prelude.
22        extern crate mopro_ffi as uniffi;
23        uniffi::setup_scaffolding!();
24    };
25}
26
27#[cfg(not(feature = "uniffi"))]
28#[macro_export]
29macro_rules! uniffi_setup {
30    () => {
31        // No-op when `uniffi` feature isn't enabled in `mopro_ffi`.
32    };
33}
34
35#[cfg(feature = "flutter")]
36pub use flutter_rust_bridge::*;
37
38#[cfg(feature = "flutter")]
39#[macro_export]
40macro_rules! flutter_setup {
41    () => {
42        // ::uniffi must be available in the caller’s extern-prelude.
43        extern crate mopro_ffi as flutter_rust_bridge;
44        pub fn init_app() {
45            // Default utilities - feel free to customize
46            flutter_rust_bridge::setup_default_user_utils();
47        }
48    };
49}
50
51#[cfg(not(feature = "flutter"))]
52#[macro_export]
53macro_rules! flutter_setup {
54    () => {};
55}
56
57/// This macro is used to setup the Mopro FFI library
58/// It should be included in the `lib.rs` file of the project
59///
60/// This should be used with the adapter-specific macros, such as `set_circom_circuits!(...)`
61/// and `set_halo2_circuits!(...)`, etc.
62///
63/// # Circom Example
64/// ```ignore
65/// // Setup the Mopro FFI library
66/// mopro_ffi::app!();
67///
68/// // Generate a Witness Generation function for the `multiplier2` circom circuit
69/// rust_witness::witness!(multiplier2);
70///
71/// // Add `multiplier2` circom circuit to be exposed to the FFI
72/// mopro_ffi::set_circom_circuits!(
73///     "multiplier2_final.zkey",
74///     WitnessFn::RustWitness(multiplier2_witness),
75/// )
76/// ```
77///
78/// # Halo2 Example
79/// ```ignore
80/// // Setup the Mopro FFI library
81/// mopro_ffi::app!();
82///
83/// // Add `Fibonacci` circuit to generate proofs and verify proofs
84/// mopro_ffi::set_halo2_circuits!(
85///     "plonk_fibonacci_pk.bin",
86///     plonk_fibonacci::prove,
87///     "plonk_fibonacci_vk.bin",
88///     plonk_fibonacci::verify
89/// );
90/// ```
91///
92/// # Noir Example
93///
94/// Noir integration supports two hash functions for different use cases:
95/// - **Poseidon hash**: Default choice, optimized for performance and off-chain verification
96/// - **Keccak256 hash**: Required for Solidity verifier compatibility and on-chain verification
97///
98/// The hash function is automatically selected based on the `on_chain` parameter:
99/// - `on_chain = false` → Uses Poseidon (better performance)
100/// - `on_chain = true` → Uses Keccak256 (Solidity compatible)
101///
102/// Reference: https://noir-lang.org/docs/how_to/how-to-solidity-verifier
103///
104/// You don't need to generate Witness Generation functions first, like `Circom` or `Halo2` does.
105/// All you need to do is to setup the Mopro FFI library as below.
106///
107/// ```ignore
108/// // Setup the Mopro FFI library
109/// mopro_ffi::app!();
110///
111/// ```
112///
113#[macro_export]
114macro_rules! app {
115    () => {
116        mopro_ffi::uniffi_setup!();
117        mopro_ffi::flutter_setup!();
118    };
119}