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
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")import uniffi.mopro.circomProve
import uniffi.mopro.verifyCircomProofPlease 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")val input_str: String = "{\"b\":[\"5\"],\"a\":[\"3\"]}"
val zkeyPath = zkeyFile.absolutePath
val graphPath = graphFile.absolutePath
val res = circomProve(graphPath, input_str, zkeyPath)val valid = verifyCircomProof(zkeyPath, res, ProofLib.ARKWORKS)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 initchoose 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 buildchoose 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/uniffilib/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/mainThis work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.