Skip to content

feat: add provekit Noir proof generation bindings#7

Merged
zmalatrax merged 8 commits into
mainfrom
feat/provekit
May 26, 2025
Merged

feat: add provekit Noir proof generation bindings#7
zmalatrax merged 8 commits into
mainfrom
feat/provekit

Conversation

@zmalatrax

Copy link
Copy Markdown
Contributor

Resolves CORE-691

@linear

linear Bot commented May 23, 2025

Copy link
Copy Markdown
CORE-691 Integrate proof generation/verification of Noir circuits with ProveKit backend to zINK

What

Implement a library to generate and verify Noir circuits with the ProveKit backend.

Why

We want to derive our native modules (Swift and Kotlin modules to be used in our React Native app) from a single source of truth (our Rust library)

How

Something similar to what MoPro has done with Barretenberg.

A Rust library, with bindings generated by UniFFI.

Dependencies

  • UniFFI with proc macros
  • Noir/Nargo as a dependency
  • ProveKit

Specs

  • Exported structured data: NoirProofWrapper which contains the serialized ProveKit's Spartan WHIR proof of the Noir circuit
    • In order to bridge the proof from Rust to React Native (through the Kotlin/Swift modules), the proof must be serialized.
  • Public functions
    • generateProof(circuit_json_str: &String, input_json_str: &String) -> NoirProofWrapper: Given the compiled Noir circuit as a JSON string and the input as another JSON string, generate the ProveKit proof
    • verifyProof(circuit_json_str: &String, proof: &NoirProofWrapper: Given the compiled Noir circuit as JSON string and the ProveKit proof, verifies the correctness of the proof.
    • generateAndVerifyProof(circuit_json_str: &String, proof: &NoirProofWrapper): Streamline the proof generation and verification in a single function. Useful for test purposes right now, might delete later.

Notes

For the Rust library making UniFFI bindings to generate Noir proofs with ProveKit, I've done a NoirProver class (i.e. struct + impl decorated by #[derive(uniffi::Object)] which implements the logic to prove and verify a given compiled Noir circuit with provided inputs.

  • The compiled Noir circuit is passed as a string to avoid Rust to manage opening files
  • The inputs are passed as a JSON stringified
    • The ProveKit prove function expects the ACIR witness map,

I've updated the app UI to include three buttons with an example circuit which computes a Poseidon hash

  • Compiled Noir circuit is stored in the assetsand load from the index.tsx as it is a JSON

  • The inputs are hardcoded in the button handlers, to mock the data flow

  • Generate Proof : calls generateProof, store the serialized proof in a state variable generatedProof

    • The generated proof is displayed into a collapsable box for showcase purposes
  • Verify Proof: calls verifyProofis the state variable generatedProofis not empty

  • Generate and Verify Proof: calls generateAndVerifyProof

Bugs

The iOS app works perfectly, but the Android app crashes instantly after the app is bundled

The root cause was the #[derive(uniffi::Record)] struct NoirProofWrapper combined with Expo Module:

  • The uniffi::Record attribute generates Kotlin/Swift type which is usable, but expo requires some wrapping for it to implement expo.modules.kotlin.records.Record. So I made a wrapper around NoirProofWrapper along with 2 fonctions toExpoNoirProofWrapperand toUniFFINoirProofWrapperto wrap/unwrap when returning/using the NoirProof…

When adding new native modules, remember to re-run the script node scripts/setup_rust_bindings.mjs --all

Comment thread README.md Outdated
Comment thread native_rust/src/lib.rs Outdated

@Eikix Eikix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ggg!!!! very cool

Comment thread .trunk/trunk.yaml Outdated

@Eikix Eikix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ploz:

  • rebase
  • incorporate react query in your frontend proving flow
  • test locally on both devices

after that, lgtm 🐦‍🔥🔥

@zmalatrax zmalatrax force-pushed the feat/provekit branch 2 times, most recently from d3af1c4 to 9da180c Compare May 23, 2025 17:52
Comment thread scripts/setup_rust_bindings.mjs Outdated
@expo

expo Bot commented May 26, 2025

Copy link
Copy Markdown

GitHub Build Trigger Failure

The build trigger failed with the following error:

You must be a collaborator on the repository to build from a pull request.

Check your GitHub app installation settings and your Expo project's GitHub settings to make sure you've configured everything correctly.

1 similar comment
@expo

expo Bot commented May 26, 2025

Copy link
Copy Markdown

GitHub Build Trigger Failure

The build trigger failed with the following error:

You must be a collaborator on the repository to build from a pull request.

Check your GitHub app installation settings and your Expo project's GitHub settings to make sure you've configured everything correctly.

Comment thread eas-hooks/01-install-rust-tools.sh Outdated
Comment thread scripts/setup_rust_bindings.mjs Outdated
Eikix
Eikix previously approved these changes May 26, 2025

@Eikix Eikix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, let's merge after the two other PRs, to make sure it builds on the new CI job

@Eikix Eikix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gg

@zmalatrax zmalatrax merged commit d01b9f4 into main May 26, 2025
2 checks passed
@zmalatrax zmalatrax deleted the feat/provekit branch May 26, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants