From 931b11074f2192ca6ff700d90594fa328942ee38 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Sun, 21 Apr 2024 14:20:56 +0800 Subject: [PATCH 1/3] feat(core): update read_zkey with `new_unchecked` --- Cargo.lock | 32 ++++++- mopro-core/Cargo.toml | 2 +- .../target/multiplier2_js/multiplier2.wasm | Bin 34283 -> 34291 bytes mopro-core/src/middleware/circom/mod.rs | 82 ++++++++++-------- 4 files changed, 75 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0829515b..3bb0796d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -184,6 +184,34 @@ dependencies = [ "wasmer", ] +[[package]] +name = "ark-circom" +version = "0.1.0" +source = "git+https://github.com/vimwitch/circom-compat.git#21c6d43132c062364c270147e876dbc00d505a1c" +dependencies = [ + "ark-bn254", + "ark-crypto-primitives", + "ark-ec 0.4.1", + "ark-ff 0.4.1", + "ark-groth16", + "ark-poly 0.4.1", + "ark-relations 0.4.0", + "ark-serialize 0.4.1", + "ark-std 0.4.0", + "byteorder", + "cfg-if", + "color-eyre", + "criterion", + "ethers-core", + "fnv", + "hex", + "num", + "num-bigint", + "num-traits", + "thiserror", + "wasmer", +] + [[package]] name = "ark-crypto-primitives" version = "0.4.0" @@ -562,7 +590,7 @@ name = "ark-zkey" version = "0.1.0" dependencies = [ "ark-bn254", - "ark-circom", + "ark-circom 0.1.0 (git+https://github.com/arkworks-rs/circom-compat.git)", "ark-ec 0.4.1", "ark-ff 0.4.1", "ark-groth16", @@ -2012,7 +2040,7 @@ dependencies = [ "ark-bls12-377 0.4.0", "ark-bls12-381", "ark-bn254", - "ark-circom", + "ark-circom 0.1.0 (git+https://github.com/vimwitch/circom-compat.git)", "ark-crypto-primitives", "ark-ec 0.3.0", "ark-ec 0.4.1", diff --git a/mopro-core/Cargo.toml b/mopro-core/Cargo.toml index dc887487..de05f596 100644 --- a/mopro-core/Cargo.toml +++ b/mopro-core/Cargo.toml @@ -13,7 +13,7 @@ calc-native-witness = ["witness"] # experimental feature to calculate witness wi build-native-witness = ["witness/build-witness"] # only enable build-native-witness feature when building the witness graph [dependencies] -ark-circom = { git = "https://github.com/arkworks-rs/circom-compat.git" } +ark-circom = { git = "https://github.com/vimwitch/circom-compat.git" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ark-serialize = { version = "=0.4.1", features = ["derive"] } diff --git a/mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm b/mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm index 2d2b1cc3e0a4148ad3278041c09a2ed40e4fc43e..c8cecba52317dc317b96b279cb6e3325c263910e 100644 GIT binary patch delta 57 zcmV-90LK68ivshD0a&L08HiNYSSn?C; delta 49 zcmV-10M7sOivsJ50>; // TODO: Split up this namespace a bit, right now quite a lot of things going on pub struct CircomState { - arkzkey: Option<(ProvingKey, ConstraintMatrices)>, + zkey: Option<(ProvingKey, ConstraintMatrices)>, wtns: Option, } @@ -66,21 +67,21 @@ impl Default for CircomState { // TODO: Replace printlns with logging -//const ZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ZKEY_FILE")); +const ZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ZKEY_FILE")); -const ARKZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ARKZKEY_FILE")); +// const ARKZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ARKZKEY_FILE")); -// static ZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(|| { -// let mut reader = Cursor::new(ZKEY_BYTES); -// read_zkey(&mut reader).expect("Failed to read zkey") -// }); - -static ARKZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(|| { - //let mut reader = Cursor::new(ARKZKEY_BYTES); - // TODO: Use reader? More flexible; unclear if perf diff - read_arkzkey_from_bytes(ARKZKEY_BYTES).expect("Failed to read arkzkey") +static ZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(|| { + let mut reader = Cursor::new(ZKEY_BYTES); + read_zkey(&mut reader).expect("Failed to read zkey") }); +// static ARKZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(|| { +// //let mut reader = Cursor::new(ARKZKEY_BYTES); +// // TODO: Use reader? More flexible; unclear if perf diff +// read_arkzkey_from_bytes(ARKZKEY_BYTES).expect("Failed to read arkzkey") +// }); + #[cfg(not(feature = "dylib"))] const WASM: &[u8] = include_bytes!(env!("BUILD_RS_WASM_FILE")); @@ -140,7 +141,8 @@ pub fn initialize() { // Initialize ARKZKEY // TODO: Speed this up even more! let now = std::time::Instant::now(); - Lazy::force(&ARKZKEY); + Lazy::force(&ZKEY); + // Lazy::force(&ARKZKEY); println!("Initializing arkzkey took: {:.2?}", now.elapsed()); } @@ -157,17 +159,17 @@ fn from_dylib(path: &Path) -> Mutex { Mutex::new(result) } -// #[must_use] -// pub fn zkey() -> &'static (ProvingKey, ConstraintMatrices) { -// &ZKEY -// } - -// Experimental #[must_use] -pub fn arkzkey() -> &'static (ProvingKey, ConstraintMatrices) { - &ARKZKEY +pub fn zkey() -> &'static (ProvingKey, ConstraintMatrices) { + &ZKEY } +// Experimental +// #[must_use] +// pub fn arkzkey() -> &'static (ProvingKey, ConstraintMatrices) { +// &ARKZKEY +// } + /// Provides access to the `WITNESS_CALCULATOR` singleton, initializing it if necessary. /// It expects the path to the dylib file to be set in the `CIRCUIT_WASM_DYLIB` environment variable. #[cfg(feature = "dylib")] @@ -223,8 +225,8 @@ pub fn generate_proof2( println!("Witness generation took: {:.2?}", now.elapsed()); let now = std::time::Instant::now(); - //let zkey = zkey(); - let zkey = arkzkey(); + let zkey = zkey(); + // let zkey = arkzkey(); println!("Loading arkzkey took: {:.2?}", now.elapsed()); let public_inputs = full_assignment.as_slice()[1..zkey.1.num_instance_variables].to_vec(); @@ -253,7 +255,8 @@ pub fn verify_proof2( serialized_inputs: SerializableInputs, ) -> Result { let start = Instant::now(); - let zkey = arkzkey(); + let zkey = zkey(); + // let zkey = arkzkey(); let pvk = prepare_verifying_key(&zkey.0.vk); let proof_verified = @@ -268,15 +271,18 @@ pub fn verify_proof2( impl CircomState { pub fn new() -> Self { Self { - arkzkey: None, + zkey: None, + // arkzkey: None, wtns: None, } } - pub fn initialize(&mut self, arkzkey_path: &str, wasm_path: &str) -> Result<(), MoproError> { - let arkzkey = - read_arkzkey(arkzkey_path).map_err(|e| MoproError::CircomError(e.to_string()))?; - self.arkzkey = Some(arkzkey); + pub fn initialize(&mut self, zkey_path: &str, wasm_path: &str) -> Result<(), MoproError> { + let mut file = File::open(zkey_path).map_err(|e| MoproError::CircomError(e.to_string()))?; + let zkey = read_zkey(&mut file).map_err(|e| MoproError::CircomError(e.to_string()))?; + + // read_arkzkey(arkzkey_path).map_err(|e| MoproError::CircomError(e.to_string()))?; + self.zkey = Some(zkey); let wtns = WitnessCalculator::new(wasm_path) .map_err(|e| MoproError::CircomError(e.to_string())) @@ -309,7 +315,7 @@ impl CircomState { println!("Witness generation took: {:.2?}", now.elapsed()); let now = std::time::Instant::now(); - let zkey = self.arkzkey.as_ref().ok_or(MoproError::CircomError( + let zkey = self.zkey.as_ref().ok_or(MoproError::CircomError( "Zkey has not been set up".to_string(), ))?; println!("Loading arkzkey took: {:.2?}", now.elapsed()); @@ -339,7 +345,7 @@ impl CircomState { serialized_inputs: SerializableInputs, ) -> Result { let start = Instant::now(); - let zkey = self.arkzkey.as_ref().ok_or(MoproError::CircomError( + let zkey = self.zkey.as_ref().ok_or(MoproError::CircomError( "Zkey has not been set up".to_string(), ))?; let pvk = prepare_verifying_key(&zkey.0.vk); @@ -386,7 +392,7 @@ mod tests { #[test] fn test_setup_prove_verify_simple() { let wasm_path = "./examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; - let arkzkey_path = "./examples/circom/multiplier2/target/multiplier2_final.arkzkey"; + let arkzkey_path = "./examples/circom/multiplier2/target/multiplier2_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); @@ -432,7 +438,7 @@ mod tests { fn test_setup_prove_verify_keccak() { let wasm_path = "./examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm"; - let arkzkey_path = "./examples/circom/keccak256/target/keccak256_256_test_final.arkzkey"; + let arkzkey_path = "./examples/circom/keccak256/target/keccak256_256_test_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); @@ -485,7 +491,7 @@ mod tests { let mut circom_state = CircomState::new(); let wasm_path = "badpath/multiplier2.wasm"; - let arkzkey_path = "badpath/multiplier2.arkzkey"; + let arkzkey_path = "badpath/multiplier2.zkey"; // Act: Call the setup method let result = circom_state.initialize(arkzkey_path, wasm_path); @@ -558,7 +564,7 @@ mod tests { #[test] fn test_setup_prove_rsa() { let wasm_path = "./examples/circom/rsa/target/main_js/main.wasm"; - let arkzkey_path = "./examples/circom/rsa/target/main_final.arkzkey"; + let arkzkey_path = "./examples/circom/rsa/target/main_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); @@ -669,7 +675,7 @@ mod tests { fn test_setup_prove_anon_aadhaar() { let wasm_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_js/aadhaar-verifier.wasm"; - let arkzkey_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_final.arkzkey"; + let arkzkey_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); From 5e6ebfd8019c2fc60f6f8a57e919630ac3b78abb Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Tue, 23 Apr 2024 18:08:31 +0800 Subject: [PATCH 2/3] chore: update zkey names --- Cargo.lock | 33 +------- ark-zkey/Cargo.toml | 2 +- mopro-core/examples/circom.rs | 4 +- mopro-core/src/middleware/circom/mod.rs | 20 ++--- mopro-ffi/src/lib.rs | 17 ++-- mopro-ffi/src/mopro.udl | 2 +- mopro-ffi/tests/bindings/test_mopro.kts | 4 +- mopro-ffi/tests/bindings/test_mopro.swift | 4 +- .../tests/bindings/test_mopro_keccak.kts | 4 +- .../tests/bindings/test_mopro_keccak.swift | 4 +- mopro-ffi/tests/bindings/test_mopro_rsa.kts | 4 +- mopro-ffi/tests/bindings/test_mopro_rsa.swift | 4 +- mopro-ios/MoproKit/Bindings/mopro.swift | 81 +++++++++---------- .../MoproKit.xcodeproj/project.pbxproj | 6 ++ .../MoproKit/AnonAadhaarViewController.swift | 2 +- .../AnonAadhaarViewControllerNew.swift | 2 +- .../MoproKit/ComplexZkeyViewController.swift | 2 +- .../MoproKit/KeccakSetupViewController.swift | 18 ++--- .../MoproKit/KeccakZkeyViewController.swift | 2 +- .../Example/MoproKit/RSAViewController.swift | 2 +- .../MoproKit/Example/Tests/CircomTests.swift | 8 +- mopro-ios/MoproKit/Include/moproFFI.h | 9 ++- templates/mopro-example-app/core/src/lib.rs | 4 +- .../ios/ExampleApp/Bindings/mopro.swift | 2 +- 24 files changed, 109 insertions(+), 131 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3bb0796d..07307e2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,34 +156,6 @@ dependencies = [ "ark-std 0.4.0", ] -[[package]] -name = "ark-circom" -version = "0.1.0" -source = "git+https://github.com/arkworks-rs/circom-compat.git#170b10fc9ed182b5f72ecf379033dda023d0bf07" -dependencies = [ - "ark-bn254", - "ark-crypto-primitives", - "ark-ec 0.4.1", - "ark-ff 0.4.1", - "ark-groth16", - "ark-poly 0.4.1", - "ark-relations 0.4.0", - "ark-serialize 0.4.1", - "ark-std 0.4.0", - "byteorder", - "cfg-if", - "color-eyre", - "criterion", - "ethers-core", - "fnv", - "hex", - "num", - "num-bigint", - "num-traits", - "thiserror", - "wasmer", -] - [[package]] name = "ark-circom" version = "0.1.0" @@ -590,7 +562,7 @@ name = "ark-zkey" version = "0.1.0" dependencies = [ "ark-bn254", - "ark-circom 0.1.0 (git+https://github.com/arkworks-rs/circom-compat.git)", + "ark-circom", "ark-ec 0.4.1", "ark-ff 0.4.1", "ark-groth16", @@ -600,6 +572,7 @@ dependencies = [ "flame", "flamer", "memmap2 0.9.4", + "num-traits", ] [[package]] @@ -2040,7 +2013,7 @@ dependencies = [ "ark-bls12-377 0.4.0", "ark-bls12-381", "ark-bn254", - "ark-circom 0.1.0 (git+https://github.com/vimwitch/circom-compat.git)", + "ark-circom", "ark-crypto-primitives", "ark-ec 0.3.0", "ark-ec 0.4.1", diff --git a/ark-zkey/Cargo.toml b/ark-zkey/Cargo.toml index 6678c4c9..4bf95c12 100644 --- a/ark-zkey/Cargo.toml +++ b/ark-zkey/Cargo.toml @@ -18,7 +18,7 @@ flamer = "0.5" ark-serialize = { version = "=0.4.1", features = ["derive"] } ark-bn254 = { version = "=0.4.0" } ark-groth16 = { version = "=0.4.0" } -ark-circom = { git = "https://github.com/arkworks-rs/circom-compat.git" } +ark-circom = { git = "https://github.com/vimwitch/circom-compat.git" } ark-relations = { version = "=0.4.0" } ark-ff = { version = "=0.4.1" } ark-ec = { version = "=0.4.1" } diff --git a/mopro-core/examples/circom.rs b/mopro-core/examples/circom.rs index 567bc274..ae0491f9 100644 --- a/mopro-core/examples/circom.rs +++ b/mopro-core/examples/circom.rs @@ -4,13 +4,13 @@ use std::collections::HashMap; fn main() { let wasm_path = "./examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; - let arkzkey_path = "./examples/circom/multiplier2/target/multiplier2_final.arkzkey"; + let zkey_path = "./examples/circom/multiplier2/target/multiplier2_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Setup - let setup_res = circom_state.initialize(arkzkey_path, wasm_path); + let setup_res = circom_state.initialize(zkey_path, wasm_path); assert!(setup_res.is_ok()); let _serialized_pk = setup_res.unwrap(); diff --git a/mopro-core/src/middleware/circom/mod.rs b/mopro-core/src/middleware/circom/mod.rs index 079d11fa..2754530e 100644 --- a/mopro-core/src/middleware/circom/mod.rs +++ b/mopro-core/src/middleware/circom/mod.rs @@ -392,12 +392,12 @@ mod tests { #[test] fn test_setup_prove_verify_simple() { let wasm_path = "./examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; - let arkzkey_path = "./examples/circom/multiplier2/target/multiplier2_final.zkey"; + let zkey_path = "./examples/circom/multiplier2/target/multiplier2_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Setup - let setup_res = circom_state.initialize(arkzkey_path, wasm_path); + let setup_res = circom_state.initialize(zkey_path, wasm_path); assert!(setup_res.is_ok()); let _serialized_pk = setup_res.unwrap(); @@ -438,12 +438,12 @@ mod tests { fn test_setup_prove_verify_keccak() { let wasm_path = "./examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm"; - let arkzkey_path = "./examples/circom/keccak256/target/keccak256_256_test_final.zkey"; + let zkey_path = "./examples/circom/keccak256/target/keccak256_256_test_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Setup - let setup_res = circom_state.initialize(arkzkey_path, wasm_path); + let setup_res = circom_state.initialize(zkey_path, wasm_path); assert!(setup_res.is_ok()); let _serialized_pk = setup_res.unwrap(); @@ -491,10 +491,10 @@ mod tests { let mut circom_state = CircomState::new(); let wasm_path = "badpath/multiplier2.wasm"; - let arkzkey_path = "badpath/multiplier2.zkey"; + let zkey_path = "badpath/multiplier2.zkey"; // Act: Call the setup method - let result = circom_state.initialize(arkzkey_path, wasm_path); + let result = circom_state.initialize(zkey_path, wasm_path); // Assert: Check that the method returns an error assert!(result.is_err()); @@ -564,13 +564,13 @@ mod tests { #[test] fn test_setup_prove_rsa() { let wasm_path = "./examples/circom/rsa/target/main_js/main.wasm"; - let arkzkey_path = "./examples/circom/rsa/target/main_final.zkey"; + let zkey_path = "./examples/circom/rsa/target/main_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Setup - let setup_res = circom_state.initialize(arkzkey_path, wasm_path); + let setup_res = circom_state.initialize(zkey_path, wasm_path); assert!(setup_res.is_ok()); let _serialized_pk = setup_res.unwrap(); @@ -675,13 +675,13 @@ mod tests { fn test_setup_prove_anon_aadhaar() { let wasm_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_js/aadhaar-verifier.wasm"; - let arkzkey_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_final.zkey"; + let zkey_path = "./examples/circom/anonAadhaar/target/aadhaar-verifier_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Setup - let setup_res = circom_state.initialize(arkzkey_path, wasm_path); + let setup_res = circom_state.initialize(zkey_path, wasm_path); assert!(setup_res.is_ok()); let _serialized_pk = setup_res.unwrap(); diff --git a/mopro-ffi/src/lib.rs b/mopro-ffi/src/lib.rs index 93362434..b79239ba 100644 --- a/mopro-ffi/src/lib.rs +++ b/mopro-ffi/src/lib.rs @@ -168,9 +168,9 @@ impl MoproCircom { } } - pub fn initialize(&self, arkzkey_path: String, wasm_path: String) -> Result<(), MoproError> { + pub fn initialize(&self, zkey_path: String, wasm_path: String) -> Result<(), MoproError> { let mut state_guard = self.state.write().unwrap(); - state_guard.initialize(arkzkey_path.as_str(), wasm_path.as_str())?; + state_guard.initialize(zkey_path.as_str(), wasm_path.as_str())?; Ok(()) } @@ -320,17 +320,16 @@ mod tests { #[test] fn test_end_to_end() -> Result<(), MoproError> { - // Paths to your wasm and arkzkey files + // Paths to your wasm and zkey files let wasm_path = "./../mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; - let arkzkey_path = - "./../mopro-core/examples/circom/multiplier2/target/multiplier2_final.arkzkey"; + let zkey_path = "./../mopro-core/examples/circom/multiplier2/target/multiplier2_final.zkey"; // Create a new MoproCircom instance let mopro_circom = MoproCircom::new(); // Step 1: Initialize - let init_result = mopro_circom.initialize(arkzkey_path.to_string(), wasm_path.to_string()); + let init_result = mopro_circom.initialize(zkey_path.to_string(), wasm_path.to_string()); assert!(init_result.is_ok()); let mut inputs = HashMap::new(); @@ -374,14 +373,14 @@ mod tests { // Paths to your wasm and r1cs files let wasm_path = "./../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm"; - let arkzkey_path = - "./../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.arkzkey"; + let zkey_path = + "./../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey"; // Create a new MoproCircom instance let mopro_circom = MoproCircom::new(); // Step 1: Setup - let setup_result = mopro_circom.initialize(arkzkey_path.to_string(), wasm_path.to_string()); + let setup_result = mopro_circom.initialize(zkey_path.to_string(), wasm_path.to_string()); assert!(setup_result.is_ok()); // Prepare inputs diff --git a/mopro-ffi/src/mopro.udl b/mopro-ffi/src/mopro.udl index a8421101..e4e6dd13 100644 --- a/mopro-ffi/src/mopro.udl +++ b/mopro-ffi/src/mopro.udl @@ -61,7 +61,7 @@ interface MoproCircom { constructor(); [Throws=MoproError] - void initialize(string arkzkey_path, string wasm_path); + void initialize(string zkey_path, string wasm_path); [Throws=MoproError] GenerateProofResult generate_proof(record> circuit_inputs); diff --git a/mopro-ffi/tests/bindings/test_mopro.kts b/mopro-ffi/tests/bindings/test_mopro.kts index cb752c9c..2790ce68 100644 --- a/mopro-ffi/tests/bindings/test_mopro.kts +++ b/mopro-ffi/tests/bindings/test_mopro.kts @@ -1,12 +1,12 @@ import uniffi.mopro.* var wasmPath = "../mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm" -var arkzkeyPath = "../mopro-core/examples/circom/multiplier2/target/multiplier2_final.arkzkey" +var zkeyPath = "../mopro-core/examples/circom/multiplier2/target/multiplier2_final.zkey" try { // Setup var moproCircom = MoproCircom() - moproCircom.initialize(arkzkeyPath, wasmPath) + moproCircom.initialize(zkeyPath, wasmPath) // Prepare inputs val inputs = mutableMapOf>() diff --git a/mopro-ffi/tests/bindings/test_mopro.swift b/mopro-ffi/tests/bindings/test_mopro.swift index 52145fe2..390a9209 100644 --- a/mopro-ffi/tests/bindings/test_mopro.swift +++ b/mopro-ffi/tests/bindings/test_mopro.swift @@ -4,7 +4,7 @@ import Foundation let moproCircom = MoproCircom() let wasmPath = "./../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm" -let arkzkeyPath = "./../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_final.arkzkey" +let zkeyPath = "./../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_final.zkey" func serializeOutputs(_ stringArray: [String]) -> [UInt8] { var bytesArray: [UInt8] = [] @@ -33,7 +33,7 @@ func serializeOutputs(_ stringArray: [String]) -> [UInt8] { do { // Setup - try moproCircom.initialize(arkzkeyPath: arkzkeyPath ,wasmPath: wasmPath) + try moproCircom.initialize(zkeyPath: zkeyPath ,wasmPath: wasmPath) // Prepare inputs var inputs = [String: [String]]() diff --git a/mopro-ffi/tests/bindings/test_mopro_keccak.kts b/mopro-ffi/tests/bindings/test_mopro_keccak.kts index 3afc236f..59bc589e 100644 --- a/mopro-ffi/tests/bindings/test_mopro_keccak.kts +++ b/mopro-ffi/tests/bindings/test_mopro_keccak.kts @@ -2,11 +2,11 @@ import uniffi.mopro.* var wasmPath = "../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm" -var arkzkeyPath = "../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.arkzkey" +var zkeyPath = "../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey" try { var moproCircom = MoproCircom() - moproCircom.initialize(arkzkeyPath, wasmPath) + moproCircom.initialize(zkeyPath, wasmPath) val inputs = mutableMapOf>() inputs["in"] = diff --git a/mopro-ffi/tests/bindings/test_mopro_keccak.swift b/mopro-ffi/tests/bindings/test_mopro_keccak.swift index ed67a27b..45b47ca6 100644 --- a/mopro-ffi/tests/bindings/test_mopro_keccak.swift +++ b/mopro-ffi/tests/bindings/test_mopro_keccak.swift @@ -4,7 +4,7 @@ import Foundation let moproCircom = MoproCircom() let wasmPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm" -let arkzkeyPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.arkzkey" +let zkeyPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey" // Helper function to convert bytes to bits func bytesToBits(bytes: [UInt8]) -> [String] { @@ -45,7 +45,7 @@ func serializeOutputs(_ stringArray: [String]) -> [UInt8] { do { // Setup - try moproCircom.initialize(arkzkeyPath: arkzkeyPath, wasmPath: wasmPath) + try moproCircom.initialize(zkeyPath: zkeyPath, wasmPath: wasmPath) // Prepare inputs let inputVec: [UInt8] = [ diff --git a/mopro-ffi/tests/bindings/test_mopro_rsa.kts b/mopro-ffi/tests/bindings/test_mopro_rsa.kts index a1e6707f..09a8df37 100644 --- a/mopro-ffi/tests/bindings/test_mopro_rsa.kts +++ b/mopro-ffi/tests/bindings/test_mopro_rsa.kts @@ -1,11 +1,11 @@ import uniffi.mopro.*; var wasmPath = "../mopro-core/examples/circom/rsa/target/main_js/main.wasm" -var arkzkeyPath = "../mopro-core/examples/circom/rsa/target/main_final.arkzkey" +var zkeyPath = "../mopro-core/examples/circom/rsa/target/main_final.zkey" try { var moproCircom = MoproCircom() - moproCircom.initialize(arkzkeyPath, wasmPath) + moproCircom.initialize(zkeyPath, wasmPath) val inputs = mutableMapOf>() inputs["signature"] = listOf("3582320600048169363", diff --git a/mopro-ffi/tests/bindings/test_mopro_rsa.swift b/mopro-ffi/tests/bindings/test_mopro_rsa.swift index 6ba281a5..f80c8e38 100644 --- a/mopro-ffi/tests/bindings/test_mopro_rsa.swift +++ b/mopro-ffi/tests/bindings/test_mopro_rsa.swift @@ -4,7 +4,7 @@ import Foundation let moproCircom = MoproCircom() let wasmPath = "./../../../../mopro-core/examples/circom/rsa/target/main_js/main.wasm" -let arkzkeyPath = "./../../../../mopro-core/examples/circom/rsa/target/main_final.arkzkey" +let zkeyPath = "./../../../../mopro-core/examples/circom/rsa/target/main_final.zkey" // Helper function to convert bytes to bits func bytesToBits(bytes: [UInt8]) -> [String] { @@ -45,7 +45,7 @@ func serializeOutputs(_ stringArray: [String]) -> [UInt8] { do { // Setup - try moproCircom.initialize(arkzkeyPath: arkzkeyPath ,wasmPath: wasmPath) + try moproCircom.initialize(zkeyPath: zkeyPath ,wasmPath: wasmPath) // Prepare inputs let signature: [String] = [ diff --git a/mopro-ios/MoproKit/Bindings/mopro.swift b/mopro-ios/MoproKit/Bindings/mopro.swift index 58e4c07b..9102bf40 100644 --- a/mopro-ios/MoproKit/Bindings/mopro.swift +++ b/mopro-ios/MoproKit/Bindings/mopro.swift @@ -400,7 +400,7 @@ fileprivate struct FfiConverterData: FfiConverterRustBuffer { public protocol MoproCircomProtocol { func generateProof(circuitInputs: [String: [String]]) throws -> GenerateProofResult - func initialize(arkzkeyPath: String, wasmPath: String) throws + func initialize(zkeyPath: String, wasmPath: String) throws func verifyProof(proof: Data, publicInput: Data) throws -> Bool } @@ -440,11 +440,11 @@ public class MoproCircom: MoproCircomProtocol { ) } - public func initialize(arkzkeyPath: String, wasmPath: String) throws { + public func initialize(zkeyPath: String, wasmPath: String) throws { try rustCallWithError(FfiConverterTypeMoproError.lift) { uniffi_mopro_ffi_fn_method_moprocircom_initialize(self.pointer, - FfiConverterString.lower(arkzkeyPath), + FfiConverterString.lower(zkeyPath), FfiConverterString.lower(wasmPath),$0 ) } @@ -504,38 +504,38 @@ public func FfiConverterTypeMoproCircom_lower(_ value: MoproCircom) -> UnsafeMut public struct BenchmarkResult { - public var numMsm: UInt32 + public var instanceSize: UInt32 + public var numInstance: UInt32 public var avgProcessingTime: Double - public var totalProcessingTime: Double // Default memberwise initializers are never public by default, so we // declare one manually. - public init(numMsm: UInt32, avgProcessingTime: Double, totalProcessingTime: Double) { - self.numMsm = numMsm + public init(instanceSize: UInt32, numInstance: UInt32, avgProcessingTime: Double) { + self.instanceSize = instanceSize + self.numInstance = numInstance self.avgProcessingTime = avgProcessingTime - self.totalProcessingTime = totalProcessingTime } } extension BenchmarkResult: Equatable, Hashable { public static func ==(lhs: BenchmarkResult, rhs: BenchmarkResult) -> Bool { - if lhs.numMsm != rhs.numMsm { + if lhs.instanceSize != rhs.instanceSize { return false } - if lhs.avgProcessingTime != rhs.avgProcessingTime { + if lhs.numInstance != rhs.numInstance { return false } - if lhs.totalProcessingTime != rhs.totalProcessingTime { + if lhs.avgProcessingTime != rhs.avgProcessingTime { return false } return true } public func hash(into hasher: inout Hasher) { - hasher.combine(numMsm) + hasher.combine(instanceSize) + hasher.combine(numInstance) hasher.combine(avgProcessingTime) - hasher.combine(totalProcessingTime) } } @@ -543,16 +543,16 @@ extension BenchmarkResult: Equatable, Hashable { public struct FfiConverterTypeBenchmarkResult: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BenchmarkResult { return try BenchmarkResult( - numMsm: FfiConverterUInt32.read(from: &buf), - avgProcessingTime: FfiConverterDouble.read(from: &buf), - totalProcessingTime: FfiConverterDouble.read(from: &buf) + instanceSize: FfiConverterUInt32.read(from: &buf), + numInstance: FfiConverterUInt32.read(from: &buf), + avgProcessingTime: FfiConverterDouble.read(from: &buf) ) } public static func write(_ value: BenchmarkResult, into buf: inout [UInt8]) { - FfiConverterUInt32.write(value.numMsm, into: &buf) + FfiConverterUInt32.write(value.instanceSize, into: &buf) + FfiConverterUInt32.write(value.numInstance, into: &buf) FfiConverterDouble.write(value.avgProcessingTime, into: &buf) - FfiConverterDouble.write(value.totalProcessingTime, into: &buf) } } @@ -845,27 +845,6 @@ extension MoproError: Equatable, Hashable {} extension MoproError: Error { } -fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { - typealias SwiftType = UInt32? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterUInt32.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterUInt32.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] @@ -921,11 +900,13 @@ public func add(a: UInt32, b: UInt32) -> UInt32 { ) } -public func arkworksPippenger(numMsm: UInt32?) throws -> BenchmarkResult { +public func arkworksPippenger(instanceSize: UInt32, numInstance: UInt32, utilsDir: String) throws -> BenchmarkResult { return try FfiConverterTypeBenchmarkResult.lift( try rustCallWithError(FfiConverterTypeMoproError.lift) { uniffi_mopro_ffi_fn_func_arkworks_pippenger( - FfiConverterOptionUInt32.lower(numMsm),$0) + FfiConverterUInt32.lower(instanceSize), + FfiConverterUInt32.lower(numInstance), + FfiConverterString.lower(utilsDir),$0) } ) } @@ -982,6 +963,17 @@ public func toEthereumProof(proof: Data) -> ProofCalldata { ) } +public func trapdoortechZprizeMsm(instanceSize: UInt32, numInstance: UInt32, utilsDir: String) throws -> BenchmarkResult { + return try FfiConverterTypeBenchmarkResult.lift( + try rustCallWithError(FfiConverterTypeMoproError.lift) { + uniffi_mopro_ffi_fn_func_trapdoortech_zprize_msm( + FfiConverterUInt32.lower(instanceSize), + FfiConverterUInt32.lower(numInstance), + FfiConverterString.lower(utilsDir),$0) +} + ) +} + public func verifyProof2(proof: Data, publicInput: Data) throws -> Bool { return try FfiConverterBool.lift( try rustCallWithError(FfiConverterTypeMoproError.lift) { @@ -1010,7 +1002,7 @@ private var initializationResult: InitializationResult { if (uniffi_mopro_ffi_checksum_func_add() != 8411) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mopro_ffi_checksum_func_arkworks_pippenger() != 29839) { + if (uniffi_mopro_ffi_checksum_func_arkworks_pippenger() != 50067) { return InitializationResult.apiChecksumMismatch } if (uniffi_mopro_ffi_checksum_func_generate_proof2() != 40187) { @@ -1031,13 +1023,16 @@ private var initializationResult: InitializationResult { if (uniffi_mopro_ffi_checksum_func_to_ethereum_proof() != 60110) { return InitializationResult.apiChecksumMismatch } + if (uniffi_mopro_ffi_checksum_func_trapdoortech_zprize_msm() != 64807) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_mopro_ffi_checksum_func_verify_proof2() != 37192) { return InitializationResult.apiChecksumMismatch } if (uniffi_mopro_ffi_checksum_method_moprocircom_generate_proof() != 64602) { return InitializationResult.apiChecksumMismatch } - if (uniffi_mopro_ffi_checksum_method_moprocircom_initialize() != 36559) { + if (uniffi_mopro_ffi_checksum_method_moprocircom_initialize() != 50370) { return InitializationResult.apiChecksumMismatch } if (uniffi_mopro_ffi_checksum_method_moprocircom_verify_proof() != 61522) { diff --git a/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj b/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj index b302ba87..463734ba 100644 --- a/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj +++ b/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj @@ -62,6 +62,9 @@ 2A5149C92B87618000B57A44 /* main_final.arkzkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = main_final.arkzkey; path = "../../../../../mopro-core/examples/circom/rsa/target/main_final.arkzkey"; sourceTree = ""; }; 2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileDownloader.swift; sourceTree = ""; }; 2A6E5BAE2AF499460052A601 /* CircomTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomTests.swift; sourceTree = ""; }; + 2A921BA72BD7BF9A002DD6F2 /* keccak256_256_test_final.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test_final.zkey; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey"; sourceTree = ""; }; + 2A921BA82BD7BFAD002DD6F2 /* multiplier2_final.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = multiplier2_final.zkey; path = "../../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_final.zkey"; sourceTree = ""; }; + 2A921BA92BD7BFC2002DD6F2 /* main_final.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = main_final.zkey; path = "../../../../../mopro-core/examples/circom/rsa/target/main_final.zkey"; sourceTree = ""; }; 47F8ADB0AC4168C6E874818D /* MoproKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MoproKit.podspec; path = ../MoproKit.podspec; sourceTree = ""; }; 5DAF212A114DFA0C9F4282B2 /* Pods-MoproKit_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Tests.debug.xcconfig"; path = "Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests.debug.xcconfig"; sourceTree = ""; }; 607FACD01AFB9204008FA782 /* MoproKit_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MoproKit_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -207,7 +210,10 @@ CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */, CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */, 2A5149C62B87616600B57A44 /* multiplier2_final.arkzkey */, + 2A921BA82BD7BFAD002DD6F2 /* multiplier2_final.zkey */, + 2A921BA92BD7BFC2002DD6F2 /* main_final.zkey */, 2A5149C32B87615900B57A44 /* keccak256_256_test_final.arkzkey */, + 2A921BA72BD7BF9A002DD6F2 /* keccak256_256_test_final.zkey */, 2A5149C92B87618000B57A44 /* main_final.arkzkey */, CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */, CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */, diff --git a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift index 63604141..f4b7a704 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift @@ -81,7 +81,7 @@ class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNav // Again, update the UI on the main thread DispatchQueue.main.async { - self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + self.textView.text += "Initializing zkey took \(timeTaken) seconds.\n" } } catch { // Handle errors - update UI on main thread diff --git a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewControllerNew.swift b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewControllerNew.swift index 8a9c7252..1045d9ac 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewControllerNew.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewControllerNew.swift @@ -93,7 +93,7 @@ class AnonAadhaarViewControllerNew: UIViewController { // Again, update the UI on the main thread DispatchQueue.main.async { - self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + self.textView.text += "Initializing zkey took \(timeTaken) seconds.\n" } } catch { // Handle errors - update UI on main thread diff --git a/mopro-ios/MoproKit/Example/MoproKit/ComplexZkeyViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/ComplexZkeyViewController.swift index c992b686..8ca78975 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/ComplexZkeyViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/ComplexZkeyViewController.swift @@ -86,7 +86,7 @@ class ComplexZkeyViewController: UIViewController { let end = CFAbsoluteTimeGetCurrent() let timeTaken = end - start - textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + textView.text += "Initializing zkey took \(timeTaken) seconds.\n" } catch let error as MoproError { print("MoproError: \(error)") } catch { diff --git a/mopro-ios/MoproKit/Example/MoproKit/KeccakSetupViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/KeccakSetupViewController.swift index 558f9224..2da188e7 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/KeccakSetupViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/KeccakSetupViewController.swift @@ -11,7 +11,7 @@ import UIKit class KeccakSetupViewController: UIViewController { - let arkzkeyUrl = URL(string: "https://mopro.vivianjeng.xyz/keccak256_256_test_final.arkzkey") + let zkeyUrl = URL(string: "https://mopro.vivianjeng.xyz/keccak256_256_test_final.zkey") let wasmUrl = URL(string: "https://mopro.vivianjeng.xyz/keccak256_256_test.wasm") var downloadButton = UIButton(type: .system) @@ -87,11 +87,11 @@ class KeccakSetupViewController: UIViewController { } @objc func runDownloadAction() { - let arkzkeyStart = CFAbsoluteTimeGetCurrent() - FileDownloader.loadFileAsync(url: self.arkzkeyUrl!) { (path, error) in - print("Ark zkey File downloaded to : \(path!)") - let arkzkeyEnd = CFAbsoluteTimeGetCurrent() - print("Download ark key took:", arkzkeyEnd - arkzkeyStart) + let zkeyStart = CFAbsoluteTimeGetCurrent() + FileDownloader.loadFileAsync(url: self.zkeyUrl!) { (path, error) in + print("Zkey File downloaded to : \(path!)") + let zkeyEnd = CFAbsoluteTimeGetCurrent() + print("Download ark key took:", zkeyEnd - zkeyStart) } let wasmStart = CFAbsoluteTimeGetCurrent() @@ -109,7 +109,7 @@ class KeccakSetupViewController: UIViewController { .first { - let arkzkeyPath = documentsUrl.appendingPathComponent((arkzkeyUrl!).lastPathComponent) + let zkeyPath = documentsUrl.appendingPathComponent((zkeyUrl!).lastPathComponent) let wasmPath = documentsUrl.appendingPathComponent((wasmUrl!).lastPathComponent) // Multiplier example @@ -121,14 +121,14 @@ class KeccakSetupViewController: UIViewController { // Record start time let start = CFAbsoluteTimeGetCurrent() - try moproCircom.initialize(arkzkeyPath: arkzkeyPath.path, wasmPath: wasmPath.path) + try moproCircom.initialize(zkeyPath: zkeyPath.path, wasmPath: wasmPath.path) proveButton.isEnabled = true // Enable the Prove button upon successful setup // Record end time and compute duration let end = CFAbsoluteTimeGetCurrent() let timeTaken = end - start - textView.text += "Initializing arkzkey and wasm took \(timeTaken) seconds.\n" + textView.text += "Initializing zkey and wasm took \(timeTaken) seconds.\n" } catch let error as MoproError { print("MoproError: \(error)") } catch { diff --git a/mopro-ios/MoproKit/Example/MoproKit/KeccakZkeyViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/KeccakZkeyViewController.swift index 21852a58..807edeb7 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/KeccakZkeyViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/KeccakZkeyViewController.swift @@ -86,7 +86,7 @@ class KeccakZkeyViewController: UIViewController { let end = CFAbsoluteTimeGetCurrent() let timeTaken = end - start - textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + textView.text += "Initializing zkey took \(timeTaken) seconds.\n" } catch let error as MoproError { print("MoproError: \(error)") } catch { diff --git a/mopro-ios/MoproKit/Example/MoproKit/RSAViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/RSAViewController.swift index 80ddadc9..af502c92 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/RSAViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/RSAViewController.swift @@ -93,7 +93,7 @@ class RSAViewController: UIViewController { // Again, update the UI on the main thread DispatchQueue.main.async { - self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + self.textView.text += "Initializing zkey took \(timeTaken) seconds.\n" } } catch { // Handle errors - update UI on main thread diff --git a/mopro-ios/MoproKit/Example/Tests/CircomTests.swift b/mopro-ios/MoproKit/Example/Tests/CircomTests.swift index 2ec32d1d..1f450d6f 100644 --- a/mopro-ios/MoproKit/Example/Tests/CircomTests.swift +++ b/mopro-ios/MoproKit/Example/Tests/CircomTests.swift @@ -6,9 +6,9 @@ final class CircomTests: XCTestCase { let moproCircom = MoproKit.MoproCircom() func testMultiplier() { - let arkzkeyPath = Bundle.main.path(forResource: "multiplier2_final", ofType: "arkzkey")! + let zkeyPath = Bundle.main.path(forResource: "multiplier2_final", ofType: "zkey")! let wasmPath = Bundle.main.path(forResource: "multiplier2", ofType: "wasm")! - XCTAssertNoThrow(try moproCircom.initialize(arkzkeyPath: arkzkeyPath, wasmPath: wasmPath), "Mopro circom setup failed") + XCTAssertNoThrow(try moproCircom.initialize(zkeyPath: zkeyPath, wasmPath: wasmPath), "Mopro circom setup failed") do { var inputs = [String: [String]]() @@ -35,9 +35,9 @@ final class CircomTests: XCTestCase { } func testKeccak256() { - let arkzkeyPath = Bundle.main.path(forResource: "keccak256_256_test_final", ofType: "arkzkey")! + let zkeyPath = Bundle.main.path(forResource: "keccak256_256_test_final", ofType: "zkey")! let wasmPath = Bundle.main.path(forResource: "keccak256_256_test", ofType: "wasm")! - XCTAssertNoThrow(try moproCircom.initialize(arkzkeyPath: arkzkeyPath, wasmPath: wasmPath), "Mopro circom setup failed") + XCTAssertNoThrow(try moproCircom.initialize(zkeyPath: zkeyPath, wasmPath: wasmPath), "Mopro circom setup failed") do { // Prepare inputs diff --git a/mopro-ios/MoproKit/Include/moproFFI.h b/mopro-ios/MoproKit/Include/moproFFI.h index 172a5b29..0097fdcb 100644 --- a/mopro-ios/MoproKit/Include/moproFFI.h +++ b/mopro-ios/MoproKit/Include/moproFFI.h @@ -70,13 +70,13 @@ void*_Nonnull uniffi_mopro_ffi_fn_constructor_moprocircom_new(RustCallStatus *_N ); RustBuffer uniffi_mopro_ffi_fn_method_moprocircom_generate_proof(void*_Nonnull ptr, RustBuffer circuit_inputs, RustCallStatus *_Nonnull out_status ); -void uniffi_mopro_ffi_fn_method_moprocircom_initialize(void*_Nonnull ptr, RustBuffer arkzkey_path, RustBuffer wasm_path, RustCallStatus *_Nonnull out_status +void uniffi_mopro_ffi_fn_method_moprocircom_initialize(void*_Nonnull ptr, RustBuffer zkey_path, RustBuffer wasm_path, RustCallStatus *_Nonnull out_status ); int8_t uniffi_mopro_ffi_fn_method_moprocircom_verify_proof(void*_Nonnull ptr, RustBuffer proof, RustBuffer public_input, RustCallStatus *_Nonnull out_status ); uint32_t uniffi_mopro_ffi_fn_func_add(uint32_t a, uint32_t b, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_mopro_ffi_fn_func_arkworks_pippenger(RustBuffer num_msm, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_mopro_ffi_fn_func_arkworks_pippenger(uint32_t instance_size, uint32_t num_instance, RustBuffer utils_dir, RustCallStatus *_Nonnull out_status ); RustBuffer uniffi_mopro_ffi_fn_func_generate_proof2(RustBuffer circuit_inputs, RustCallStatus *_Nonnull out_status ); @@ -92,6 +92,8 @@ RustBuffer uniffi_mopro_ffi_fn_func_to_ethereum_inputs(RustBuffer inputs, RustCa ); RustBuffer uniffi_mopro_ffi_fn_func_to_ethereum_proof(RustBuffer proof, RustCallStatus *_Nonnull out_status ); +RustBuffer uniffi_mopro_ffi_fn_func_trapdoortech_zprize_msm(uint32_t instance_size, uint32_t num_instance, RustBuffer utils_dir, RustCallStatus *_Nonnull out_status +); int8_t uniffi_mopro_ffi_fn_func_verify_proof2(RustBuffer proof, RustBuffer public_input, RustCallStatus *_Nonnull out_status ); RustBuffer ffi_mopro_ffi_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status @@ -231,6 +233,9 @@ uint16_t uniffi_mopro_ffi_checksum_func_to_ethereum_inputs(void ); uint16_t uniffi_mopro_ffi_checksum_func_to_ethereum_proof(void +); +uint16_t uniffi_mopro_ffi_checksum_func_trapdoortech_zprize_msm(void + ); uint16_t uniffi_mopro_ffi_checksum_func_verify_proof2(void diff --git a/templates/mopro-example-app/core/src/lib.rs b/templates/mopro-example-app/core/src/lib.rs index 1512f27a..4bd032d5 100644 --- a/templates/mopro-example-app/core/src/lib.rs +++ b/templates/mopro-example-app/core/src/lib.rs @@ -11,13 +11,13 @@ mod tests { #[test] fn test_prove_verify_simple() { let wasm_path = "./circuits/multiplier2/target/multiplier2_js/multiplier2.wasm"; - let arkzkey_path = "./circuits/multiplier2/target/multiplier2_final.arkzkey"; + let zkey_path = "./circuits/multiplier2/target/multiplier2_final.zkey"; // Instantiate CircomState let mut circom_state = CircomState::new(); // Initialize - let init_res = circom_state.initialize(arkzkey_path, wasm_path); + let init_res = circom_state.initialize(zkey_path, wasm_path); assert!(init_res.is_ok()); let _serialized_pk = init_res.unwrap(); diff --git a/templates/mopro-example-app/ios/ExampleApp/Bindings/mopro.swift b/templates/mopro-example-app/ios/ExampleApp/Bindings/mopro.swift index 1bd73d5a..2b10434e 100644 --- a/templates/mopro-example-app/ios/ExampleApp/Bindings/mopro.swift +++ b/templates/mopro-example-app/ios/ExampleApp/Bindings/mopro.swift @@ -400,7 +400,7 @@ private struct FfiConverterData: FfiConverterRustBuffer { public protocol MoproCircomProtocol { func generateProof(circuitInputs: [String: [String]]) throws -> GenerateProofResult - func initialize(arkzkeyPath: String, wasmPath: String) throws + func initialize(zkeyPath: String, wasmPath: String) throws func verifyProof(proof: Data, publicInput: Data) throws -> Bool } From 435b423f40dce16f61f08bb92b9d391ab940e1b9 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Tue, 23 Apr 2024 20:27:50 +0800 Subject: [PATCH 3/3] fix: fix target --- .../Example/MoproKit.xcodeproj/project.pbxproj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj b/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj index 463734ba..27cb3c3a 100644 --- a/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj +++ b/mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj @@ -18,6 +18,12 @@ 2A5149CD2B8766DA00B57A44 /* FileDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */; }; 2A5149CE2B8766DA00B57A44 /* FileDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */; }; 2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6E5BAE2AF499460052A601 /* CircomTests.swift */; }; + 2A921BAA2BD7E08B002DD6F2 /* keccak256_256_test_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA72BD7BF9A002DD6F2 /* keccak256_256_test_final.zkey */; }; + 2A921BAB2BD7E08C002DD6F2 /* keccak256_256_test_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA72BD7BF9A002DD6F2 /* keccak256_256_test_final.zkey */; }; + 2A921BAC2BD7E08F002DD6F2 /* multiplier2_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA82BD7BFAD002DD6F2 /* multiplier2_final.zkey */; }; + 2A921BAD2BD7E08F002DD6F2 /* multiplier2_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA82BD7BFAD002DD6F2 /* multiplier2_final.zkey */; }; + 2A921BAE2BD7E095002DD6F2 /* main_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA92BD7BFC2002DD6F2 /* main_final.zkey */; }; + 2A921BAF2BD7E095002DD6F2 /* main_final.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A921BA92BD7BFC2002DD6F2 /* main_final.zkey */; }; 4384FD09A96F702A375841EE /* Pods_MoproKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */; }; 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; @@ -324,11 +330,14 @@ buildActionMask = 2147483647; files = ( CEA2D1322AB96AB500F292D2 /* multiplier2.r1cs in Resources */, + 2A921BAA2BD7E08B002DD6F2 /* keccak256_256_test_final.zkey in Resources */, 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 2A5149C42B87615900B57A44 /* keccak256_256_test_final.arkzkey in Resources */, 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 2A5149CA2B87618000B57A44 /* main_final.arkzkey in Resources */, + 2A921BAE2BD7E095002DD6F2 /* main_final.zkey in Resources */, CE5A5C062AD43A790074539D /* keccak256_256_test.wasm in Resources */, + 2A921BAC2BD7E08F002DD6F2 /* multiplier2_final.zkey in Resources */, CE2C1B8C2AFFCC5E002AF8BC /* main.wasm in Resources */, 2A5149C72B87616600B57A44 /* multiplier2_final.arkzkey in Resources */, 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, @@ -346,8 +355,11 @@ 2A5149C52B87615900B57A44 /* keccak256_256_test_final.arkzkey in Resources */, 2A5149C82B87616600B57A44 /* multiplier2_final.arkzkey in Resources */, CE2C1B8D2AFFCC5E002AF8BC /* main.wasm in Resources */, + 2A921BAD2BD7E08F002DD6F2 /* multiplier2_final.zkey in Resources */, CEA2D1332AB96AB500F292D2 /* multiplier2.r1cs in Resources */, CEA2D1302AB96A7A00F292D2 /* multiplier2.wasm in Resources */, + 2A921BAF2BD7E095002DD6F2 /* main_final.zkey in Resources */, + 2A921BAB2BD7E08C002DD6F2 /* keccak256_256_test_final.zkey in Resources */, 2A5149CB2B87618000B57A44 /* main_final.arkzkey in Resources */, ); runOnlyForDeploymentPostprocessing = 0;