Skip to content

Commit

Permalink
upgrade to Noir 0.31
Browse files Browse the repository at this point in the history
  • Loading branch information
madztheo committed Aug 8, 2024
1 parent 6d88615 commit b1e926f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.github.madztheo"
artifactId = "noir_android"
version = "v0.30.0-9"
version = "v0.31.0-1"
}
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ tasks.register<Copy>("copyRustLibs") {
} else {
// Download the .so file from the GitHub release
download.run {
src("https://github.com/madztheo/noir_android/releases/download/v0.30.0-9/libnoir_java_arm64-v8a.so")
src("https://github.com/madztheo/noir_android/releases/download/v0.31.0-1/libnoir_java_arm64-v8a.so")
dest("src/main/jniLibs/arm64-v8a/libnoir_java.so")
overwrite(false)
}
Expand Down
11 changes: 5 additions & 6 deletions lib/src/main/java/com/noirandroid/lib/Circuit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Circuit(public val bytecode: String, public val manifest: CircuitManifest,
if (num_points == 0) {
throw IllegalArgumentException("SRS not set up")
}
return Noir.verify(bytecode, proof, proofType, num_points.toString())
return Noir.verify(proof, proofType, num_points.toString())
}

private fun flattenMultiDimensionalArray(array: List<Any>): List<Any> {
Expand Down Expand Up @@ -152,11 +152,10 @@ class Circuit(public val bytecode: String, public val manifest: CircuitManifest,
var flattenedArray = flattenMultiDimensionalArray(value as List<Any>)
// Compute the expected length of the array
var totalLength = computeTotalLengthOfArray(parameter.type)
val array = flattenedArray as List<Any>
if (array.size != totalLength) {
if (flattenedArray.size != totalLength) {
throw IllegalArgumentException("Expected array of length ${parameter.type.length} for parameter: ${parameter.name}")
}
for (element in array) {
for (element in flattenedArray) {
if (element is Double) {
witness[index.toString()] = "0x${(element.toLong()).toString(16)}"
index++
Expand All @@ -181,8 +180,8 @@ class Circuit(public val bytecode: String, public val manifest: CircuitManifest,
if (value is Map<*, *>) {
val struct = value as Map<String, Any>
val structWitness = generateWitnessMap(struct, parameter.type.fields!!, index)
for ((key, value) in structWitness) {
witness[key] = value
for ((key, witnessValue) in structWitness) {
witness[key] = witnessValue
index++
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/noirandroid/lib/Noir.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Noir {
companion object {
external fun prove(circuitBytecode: String, initialWitness: Map<String, String>, proofType: String, numPoints: String): Proof

external fun verify(circuitBytecode: String, proof: Proof, proofType: String, numPoints: String): Boolean
external fun verify(proof: Proof, proofType: String, numPoints: String): Boolean

external fun setup_srs(circuitBytecode: String, srsPath: String?): Int
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/noir_java/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]

[dependencies]
jni = "0.21.1"
noir_rs = { git = "https://github.com/madztheo/noir_rs.git", branch = "v0.30.0", package = "noir_rs" }
noir_rs = { git = "https://github.com/madztheo/noir_rs.git", branch = "v0.31.0", package = "noir_rs" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
hex = "0.4.3"
Expand Down
12 changes: 2 additions & 10 deletions lib/src/main/java/noir_java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,10 @@ pub extern "system" fn Java_com_noirandroid_lib_Noir_00024Companion_prove<'local
pub extern "system" fn Java_com_noirandroid_lib_Noir_00024Companion_verify<'local>(
mut env: JNIEnv<'local>,
_class: JClass<'local>,
circuit_bytecode_jstr: JString<'local>,
mut proof_jobject: JObject<'local>,
proof_type_jstr: JString<'local>,
num_points_jstr: JString<'local>,
) -> jboolean {
let circuit_bytecode = env
.get_string(&circuit_bytecode_jstr)
.expect("Failed to get string from JString")
.to_str()
.expect("Failed to convert Java string to Rust string")
.to_owned();

let proof_field = env
.get_field(&mut proof_jobject, "proof", "Ljava/lang/String;")
.expect("Failed to get proof field")
Expand Down Expand Up @@ -198,9 +190,9 @@ pub extern "system" fn Java_com_noirandroid_lib_Noir_00024Companion_verify<'loca
.expect("Failed to parse num_points");

let verdict = if proof_type == "honk" {
verify_honk(circuit_bytecode, proof, verification_key).expect("Verification failed")
verify_honk(proof, verification_key).expect("Verification failed")
} else {
verify(circuit_bytecode, proof, verification_key, num_points).expect("Verification failed")
verify(proof, verification_key, num_points).expect("Verification failed")
};

jboolean::from(verdict)
Expand Down

0 comments on commit b1e926f

Please sign in to comment.