Skip to content

zkmopro/CircomKotlin

Repository files navigation

Circom Kotlin Package

CircomKotlin is a Kotlin package for generating and verifying Circom zero-knowledge proofs using the groth16 backend.

The Kotlin bindings are generated by the mopro CLI using the Circom adapter, which utilizes circom-prover with circom-witnesscalc for witness generation and arkworks for groth16 proof construction.

To learn more about the original Rust implementation before generating bindings, please refer to zkmopro documentation.

Note

To use circom-witnesscalc, follow the README instructions to generate the graph file from your Circom circuits. Or the script from semaphore-rs

Getting mopro via JitPack

To get this library from GitHub using JitPack:

Step 1. Add the JitPack repository to your settings.gradle.kts at the end of repositories:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}

Step 2. Add the dependency to your build.gradle.kts:

  dependencies {
      implementation("com.github.zkmopro:CircomKotlin:v1.0.0")
  }

Checkout the JitPack page for more available versions.

Note: If you're using an Android template from mopro create, comment out these UniFFI dependencies in your build file to prevent duplicate class errors.

  // // Uniffi
  // implementation("net.java.dev.jna:jna:5.13.0@aar")
  // implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

Usage Example

Import the package

import uniffi.mopro.circomProve
import uniffi.mopro.verifyCircomProof

Load graph and zkey

Please checkout circom and circom-witensscalc to see how to generate the zkey and the graph.

To load the circuit and graph in an Expo app, please checkout e.g. zkeyFilePath to get the path. Then define the file path, e.g.

val zkeyFile = getFilePathFromAssets("multiplier2_final.zkey")
val graphFile = getFilePathFromAssets("multiplier2.bin")

circomProve

val input_str: String = "{\"b\":[\"5\"],\"a\":[\"3\"]}"
val zkeyPath = zkeyFile.absolutePath
val graphPath = graphFile.absolutePath
val res = circomProve(graphPath, input_str, zkeyPath)

verifyCircomProof

val valid = verifyCircomProof(zkeyPath, res, ProofLib.ARKWORKS)

How to Build the Package

This package relies on bindings generated by the Mopro CLI. To learn how to build Mopro bindings, refer to the Getting Started section.

Use mopro-cli and choose circom

mopro init

choose circom

Update the circom-prover resource in Cargo.toml

circom-prover = { git = "https://github.com/zkmopro/mopro", branch = "circom-witnesscalc-path", features = [
    "circom-witnesscalc",
] }

and run

mopro build

choose android and build for aarch64-linux-android and x86_64-linux-android architectures.

Then, replace the entire bindings directory with your generated files in the following location:

  • lib/src/main/kotlin/uniffi
  • lib/src/main/jniLibs

Alternatively, you can run the following commands to copy your generated bindings into the correct location:

cp -r MoproAndroidBindings/uniffi lib/src/main/kotlin
cp -r MoproAndroidBindings/jniLibs lib/src/main

Community

  • X account:
  • Telegram group:

Acknowledgements

This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages