From 6a699e51561c7d209ffa82fadd80558bd16593b3 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Tue, 9 Jul 2024 14:09:15 -0500 Subject: [PATCH] test: update bindings tests (#210) --- test-e2e/src/lib.rs | 4 + ...ccak_static.kts => test_circom_keccak.kts} | 9 +- .../tests/bindings/test_circom_keccak.swift | 78 +++++ ..._mopro.kts => test_circom_multiplier2.kts} | 0 .../bindings/test_circom_multiplier2.swift | 69 +++++ .../bindings/test_circom_multiplier2_bls.kts | 23 ++ .../test_circom_multiplier2_bls.swift | 63 ++++ test-e2e/tests/bindings/test_mopro.swift | 66 ----- .../bindings/test_mopro_gpu_benchmarks.swift | 42 --- test-e2e/tests/bindings/test_mopro_keccak.kts | 278 ------------------ .../tests/bindings/test_mopro_keccak.swift | 81 ----- .../bindings/test_mopro_keccak_static.swift | 83 ------ test-e2e/tests/bindings/test_mopro_rsa.kts | 114 ------- test-e2e/tests/bindings/test_mopro_rsa.swift | 173 ----------- .../bindings/test_mopro_rsa_static.swift | 167 ----------- test-e2e/tests/test_generated_bindings.rs | 17 +- 16 files changed, 248 insertions(+), 1019 deletions(-) rename test-e2e/tests/bindings/{test_mopro_keccak_static.kts => test_circom_keccak.kts} (96%) create mode 100644 test-e2e/tests/bindings/test_circom_keccak.swift rename test-e2e/tests/bindings/{test_mopro.kts => test_circom_multiplier2.kts} (100%) create mode 100644 test-e2e/tests/bindings/test_circom_multiplier2.swift create mode 100644 test-e2e/tests/bindings/test_circom_multiplier2_bls.kts create mode 100644 test-e2e/tests/bindings/test_circom_multiplier2_bls.swift delete mode 100644 test-e2e/tests/bindings/test_mopro.swift delete mode 100644 test-e2e/tests/bindings/test_mopro_gpu_benchmarks.swift delete mode 100644 test-e2e/tests/bindings/test_mopro_keccak.kts delete mode 100644 test-e2e/tests/bindings/test_mopro_keccak.swift delete mode 100644 test-e2e/tests/bindings/test_mopro_keccak_static.swift delete mode 100644 test-e2e/tests/bindings/test_mopro_rsa.kts delete mode 100644 test-e2e/tests/bindings/test_mopro_rsa.swift delete mode 100644 test-e2e/tests/bindings/test_mopro_rsa_static.swift diff --git a/test-e2e/src/lib.rs b/test-e2e/src/lib.rs index 2098658d..403290a7 100644 --- a/test-e2e/src/lib.rs +++ b/test-e2e/src/lib.rs @@ -1,7 +1,9 @@ use mopro_ffi::{app, WtnsFn}; rust_witness::witness!(multiplier2); +rust_witness::witness!(multiplier2bls); rust_witness::witness!(keccak256256test); +rust_witness::witness!(hashbenchbls); app!(); @@ -11,6 +13,8 @@ fn zkey_witness_map(name: &str) -> Result { match name { "multiplier2_final.zkey" => Ok(multiplier2_witness), "keccak256_256_test_final.zkey" => Ok(keccak256256test_witness), + "hashbench_bls_final.zkey" => Ok(hashbenchbls_witness), + "multiplier2_bls_final.zkey" => Ok(multiplier2bls_witness), _ => Err(MoproError::CircomError("Unknown circuit name".to_string())), } } diff --git a/test-e2e/tests/bindings/test_mopro_keccak_static.kts b/test-e2e/tests/bindings/test_circom_keccak.kts similarity index 96% rename from test-e2e/tests/bindings/test_mopro_keccak_static.kts rename to test-e2e/tests/bindings/test_circom_keccak.kts index 0be0e68b..982450ea 100644 --- a/test-e2e/tests/bindings/test_mopro_keccak_static.kts +++ b/test-e2e/tests/bindings/test_circom_keccak.kts @@ -1,8 +1,9 @@ import uniffi.mopro.* -try { - initializeMopro() +try { + var zkeyPath = "../test-vectors/circom/keccak256_256_test_final.zkey" + val inputs = mutableMapOf>() inputs["in"] = listOf( @@ -264,9 +265,9 @@ try { "0" ) - var generateProofResult = generateProofStatic(inputs) + var generateProofResult = generateCircomProof(zkeyPath, inputs) assert(generateProofResult.proof.size > 0) { "Proof is empty" } - var isValid = verifyProofStatic(generateProofResult.proof, generateProofResult.inputs) + var isValid = verifyCircomProof(zkeyPath, generateProofResult.proof, generateProofResult.inputs) assert(isValid) { "Proof is invalid" } } catch (e: Exception) { println(e) diff --git a/test-e2e/tests/bindings/test_circom_keccak.swift b/test-e2e/tests/bindings/test_circom_keccak.swift new file mode 100644 index 00000000..5dad57d0 --- /dev/null +++ b/test-e2e/tests/bindings/test_circom_keccak.swift @@ -0,0 +1,78 @@ +import Foundation +import mopro + +// Helper function to convert bytes to bits +func bytesToBits(bytes: [UInt8]) -> [String] { + var bits = [String]() + for byte in bytes { + for j in 0..<8 { + let bit = (byte >> j) & 1 + bits.append(String(bit)) + } + } + return bits +} + +func serializeOutputs(_ stringArray: [String]) -> [UInt8] { + var bytesArray: [UInt8] = [] + let length = stringArray.count + var littleEndianLength = length.littleEndian + let targetLength = 32 + withUnsafeBytes(of: &littleEndianLength) { + bytesArray.append(contentsOf: $0) + } + for value in stringArray { + // TODO: should handle 254-bit input + var littleEndian = Int32(value)!.littleEndian + var byteLength = 0 + withUnsafeBytes(of: &littleEndian) { + bytesArray.append(contentsOf: $0) + byteLength = byteLength + $0.count + } + if byteLength < targetLength { + let paddingCount = targetLength - byteLength + let paddingArray = [UInt8](repeating: 0, count: paddingCount) + bytesArray.append(contentsOf: paddingArray) + } + } + return bytesArray +} + +do { + let zkeyPath = "../../../test-vectors/circom/keccak256_256_test_final.zkey" + + // Prepare inputs + let inputVec: [UInt8] = [ + 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + ] + let bits = bytesToBits(bytes: inputVec) + var inputs = [String: [String]]() + inputs["in"] = bits + + // Expected outputs + let outputVec: [UInt8] = [ + 37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88, + 212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21, + ] + let outputBits: [String] = bytesToBits(bytes: outputVec) + let expectedOutput: [UInt8] = serializeOutputs(outputBits) + + // Generate Proof + let generateProofResult = try generateCircomProof(zkeyPath: zkeyPath, circuitInputs: inputs) + assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") + + // Verify Proof + assert( + Data(expectedOutput) == generateProofResult.inputs, + "Circuit outputs mismatch the expected outputs") + + let isValid = try verifyCircomProof( + zkeyPath: zkeyPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) + assert(isValid, "Proof verification should succeed") + +} catch let error as MoproError { + print("MoproError: \(error)") +} catch { + print("Unexpected error: \(error)") +} diff --git a/test-e2e/tests/bindings/test_mopro.kts b/test-e2e/tests/bindings/test_circom_multiplier2.kts similarity index 100% rename from test-e2e/tests/bindings/test_mopro.kts rename to test-e2e/tests/bindings/test_circom_multiplier2.kts diff --git a/test-e2e/tests/bindings/test_circom_multiplier2.swift b/test-e2e/tests/bindings/test_circom_multiplier2.swift new file mode 100644 index 00000000..8558fba1 --- /dev/null +++ b/test-e2e/tests/bindings/test_circom_multiplier2.swift @@ -0,0 +1,69 @@ +import Foundation +import mopro + +func serializeOutputs(_ stringArray: [String]) -> [UInt8] { + var bytesArray: [UInt8] = [] + let length = stringArray.count + var littleEndianLength = length.littleEndian + let targetLength = 32 + withUnsafeBytes(of: &littleEndianLength) { + bytesArray.append(contentsOf: $0) + } + for value in stringArray { + // TODO: should handle 254-bit input + var littleEndian = Int32(value)!.littleEndian + var byteLength = 0 + withUnsafeBytes(of: &littleEndian) { + bytesArray.append(contentsOf: $0) + byteLength = byteLength + $0.count + } + if byteLength < targetLength { + let paddingCount = targetLength - byteLength + let paddingArray = [UInt8](repeating: 0, count: paddingCount) + bytesArray.append(contentsOf: paddingArray) + } + } + return bytesArray +} + +do { + let zkeyPath = "../../../test-vectors/circom/multiplier2_final.zkey" + + // Prepare inputs + var inputs = [String: [String]]() + let a = 3 + let b = 5 + let c = a * b + inputs["a"] = [String(a)] + inputs["b"] = [String(b)] + + // Expected outputs + let outputs: [String] = [String(c), String(a)] + let expectedOutput: [UInt8] = serializeOutputs(outputs) + + // Generate Proof + let generateProofResult = try generateCircomProof(zkeyPath: zkeyPath, circuitInputs: inputs) + assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") + + // Verify Proof + assert( + Data(expectedOutput) == generateProofResult.inputs, + "Circuit outputs mismatch the expected outputs") + + let isValid = try verifyCircomProof( + zkeyPath: zkeyPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) + assert(isValid, "Proof verification should succeed") + + // Convert proof to Ethereum compatible proof + let convertProofResult = toEthereumProof(proof: generateProofResult.proof) + let convertInputsResult = toEthereumInputs(inputs: generateProofResult.inputs) + assert(convertProofResult.a.x.count > 0, "Proof should not be empty") + assert(convertInputsResult.count > 0, "Inputs should not be empty") + +} catch let error as MoproError { + print("MoproError: \(error)") + throw error +} catch { + print("Unexpected error: \(error)") + throw error +} diff --git a/test-e2e/tests/bindings/test_circom_multiplier2_bls.kts b/test-e2e/tests/bindings/test_circom_multiplier2_bls.kts new file mode 100644 index 00000000..0355edba --- /dev/null +++ b/test-e2e/tests/bindings/test_circom_multiplier2_bls.kts @@ -0,0 +1,23 @@ +import uniffi.mopro.* + +try { + var zkeyPath = "../test-vectors/circom/multiplier2_bls_final.zkey" + + // Prepare inputs + val inputs = mutableMapOf>() + inputs["a"] = listOf("3") + inputs["b"] = listOf("5") + + // Generate proof + var generateProofResult = generateCircomProof(zkeyPath, inputs) + assert(generateProofResult.proof.size > 0) { "Proof is empty" } + + // Verify proof + var isValid = verifyCircomProof(zkeyPath, generateProofResult.proof, generateProofResult.inputs) + assert(isValid) { "Proof is invalid" } + + +} catch (e: Exception) { + println(e) + throw e +} diff --git a/test-e2e/tests/bindings/test_circom_multiplier2_bls.swift b/test-e2e/tests/bindings/test_circom_multiplier2_bls.swift new file mode 100644 index 00000000..d8ccdcda --- /dev/null +++ b/test-e2e/tests/bindings/test_circom_multiplier2_bls.swift @@ -0,0 +1,63 @@ +import Foundation +import mopro + +func serializeOutputs(_ stringArray: [String]) -> [UInt8] { + var bytesArray: [UInt8] = [] + let length = stringArray.count + var littleEndianLength = length.littleEndian + let targetLength = 32 + withUnsafeBytes(of: &littleEndianLength) { + bytesArray.append(contentsOf: $0) + } + for value in stringArray { + // TODO: should handle 254-bit input + var littleEndian = Int32(value)!.littleEndian + var byteLength = 0 + withUnsafeBytes(of: &littleEndian) { + bytesArray.append(contentsOf: $0) + byteLength = byteLength + $0.count + } + if byteLength < targetLength { + let paddingCount = targetLength - byteLength + let paddingArray = [UInt8](repeating: 0, count: paddingCount) + bytesArray.append(contentsOf: paddingArray) + } + } + return bytesArray +} + +do { + let zkeyPath = "../../../test-vectors/circom/multiplier2_bls_final.zkey" + + // Prepare inputs + var inputs = [String: [String]]() + let a = 3 + let b = 5 + let c = a * b + inputs["a"] = [String(a)] + inputs["b"] = [String(b)] + + // Expected outputs + let outputs: [String] = [String(c)] + let expectedOutput: [UInt8] = serializeOutputs(outputs) + + // Generate Proof + let generateProofResult = try generateCircomProof(zkeyPath: zkeyPath, circuitInputs: inputs) + assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") + + // Verify Proof + assert( + Data(expectedOutput) == generateProofResult.inputs, + "Circuit outputs mismatch the expected outputs") + + let isValid = try verifyCircomProof( + zkeyPath: zkeyPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) + assert(isValid, "Proof verification should succeed") + +} catch let error as MoproError { + print("MoproError: \(error)") + throw error +} catch { + print("Unexpected error: \(error)") + throw error +} diff --git a/test-e2e/tests/bindings/test_mopro.swift b/test-e2e/tests/bindings/test_mopro.swift deleted file mode 100644 index de9ff61b..00000000 --- a/test-e2e/tests/bindings/test_mopro.swift +++ /dev/null @@ -1,66 +0,0 @@ -import mopro -import Foundation - -func serializeOutputs(_ stringArray: [String]) -> [UInt8] { - var bytesArray: [UInt8] = [] - let length = stringArray.count - var littleEndianLength = length.littleEndian - let targetLength = 32 - withUnsafeBytes(of: &littleEndianLength) { - bytesArray.append(contentsOf: $0) - } - for value in stringArray { - // TODO: should handle 254-bit input - var littleEndian = Int32(value)!.littleEndian - var byteLength = 0 - withUnsafeBytes(of: &littleEndian) { - bytesArray.append(contentsOf: $0) - byteLength = byteLength + $0.count - } - if byteLength < targetLength { - let paddingCount = targetLength - byteLength - let paddingArray = [UInt8](repeating: 0, count: paddingCount) - bytesArray.append(contentsOf: paddingArray) - } - } - return bytesArray -} - -do { - let zkeyPath = "../../../test-vectors/circom/multiplier2_final.zkey" - - // Prepare inputs - var inputs = [String: [String]]() - let a = 3 - let b = 5 - let c = a*b - inputs["a"] = [String(a)] - inputs["b"] = [String(b)] - - // Expected outputs - let outputs: [String] = [String(c), String(a)] - let expectedOutput: [UInt8] = serializeOutputs(outputs) - - // Generate Proof - let generateProofResult = try generateCircomProof(zkeyPath: zkeyPath, circuitInputs: inputs) - assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") - - // Verify Proof - assert(Data(expectedOutput) == generateProofResult.inputs, "Circuit outputs mismatch the expected outputs") - - let isValid = try verifyCircomProof(zkeyPath: zkeyPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) - assert(isValid, "Proof verification should succeed") - - // Convert proof to Ethereum compatible proof - let convertProofResult = toEthereumProof(proof: generateProofResult.proof) - let convertInputsResult = toEthereumInputs(inputs: generateProofResult.inputs) - assert(convertProofResult.a.x.count > 0, "Proof should not be empty") - assert(convertInputsResult.count > 0, "Inputs should not be empty") - -} catch let error as MoproError { - print("MoproError: \(error)") - throw error -} catch { - print("Unexpected error: \(error)") - throw error -} diff --git a/test-e2e/tests/bindings/test_mopro_gpu_benchmarks.swift b/test-e2e/tests/bindings/test_mopro_gpu_benchmarks.swift deleted file mode 100644 index 0d690631..00000000 --- a/test-e2e/tests/bindings/test_mopro_gpu_benchmarks.swift +++ /dev/null @@ -1,42 +0,0 @@ -import mopro -import Foundation - -let instanceSize: UInt32 = 16; -let numInstance: UInt32 = 10; -let utilsDir = "../../../mopro-core/src/middleware/gpu_explorations/utils/vectors/16x10"; - -// test with arkworks pippenger -do { - let result = try arkworksPippenger( - instanceSize: instanceSize, - numInstance: numInstance, - utilsDir: utilsDir - ); - print("Benchmark result: \(result)"); -} catch let error as MoproError{ - print("Error running benchmark: \(error)") -} - -// test with trapdoor zprize msm -// do { -// let result = try trapdoortechZprizeMsm( -// instanceSize: instanceSize, -// numInstance: numInstance, -// utilsDir: utilsDir -// ); -// print("Benchmark result: \(result)"); -// } catch let error as MoproError{ -// print("Error running benchmark: \(error)") -// } - -// test with metal_msm -do { - let result = try metalMsm( - instanceSize: 16, - numInstance: 10, - utilsDir: "../../../mopro-core/src/middleware/gpu_explorations/utils/vectors/16x10" - ); - print("Benchmark result: \(result)"); -} catch let error as MoproError{ - print("Error running benchmark: \(error)") -} \ No newline at end of file diff --git a/test-e2e/tests/bindings/test_mopro_keccak.kts b/test-e2e/tests/bindings/test_mopro_keccak.kts deleted file mode 100644 index 59bc589e..00000000 --- a/test-e2e/tests/bindings/test_mopro_keccak.kts +++ /dev/null @@ -1,278 +0,0 @@ -import uniffi.mopro.* - -var wasmPath = - "../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm" -var zkeyPath = "../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey" - -try { - var moproCircom = MoproCircom() - moproCircom.initialize(zkeyPath, wasmPath) - - val inputs = mutableMapOf>() - inputs["in"] = - listOf( - "0", - "0", - "1", - "0", - "1", - "1", - "1", - "0", - "1", - "0", - "1", - "0", - "0", - "1", - "1", - "0", - "1", - "1", - "0", - "0", - "1", - "1", - "1", - "0", - "0", - "0", - "1", - "0", - "1", - "1", - "1", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0" - ) - - var generateProofResult = moproCircom.generateProof(inputs) - assert(generateProofResult.proof.size > 0) { "Proof is empty" } - var isValid = moproCircom.verifyProof(generateProofResult.proof, generateProofResult.inputs) - assert(isValid) { "Proof is invalid" } -} catch (e: Exception) { - println(e) -} diff --git a/test-e2e/tests/bindings/test_mopro_keccak.swift b/test-e2e/tests/bindings/test_mopro_keccak.swift deleted file mode 100644 index 45b47ca6..00000000 --- a/test-e2e/tests/bindings/test_mopro_keccak.swift +++ /dev/null @@ -1,81 +0,0 @@ -import mopro -import Foundation - -let moproCircom = MoproCircom() - -let wasmPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm" -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] { - var bits = [String]() - for byte in bytes { - for j in 0..<8 { - let bit = (byte >> j) & 1 - bits.append(String(bit)) - } - } - return bits -} - -func serializeOutputs(_ stringArray: [String]) -> [UInt8] { - var bytesArray: [UInt8] = [] - let length = stringArray.count - var littleEndianLength = length.littleEndian - let targetLength = 32 - withUnsafeBytes(of: &littleEndianLength) { - bytesArray.append(contentsOf: $0) - } - for value in stringArray { - // TODO: should handle 254-bit input - var littleEndian = Int32(value)!.littleEndian - var byteLength = 0 - withUnsafeBytes(of: &littleEndian) { - bytesArray.append(contentsOf: $0) - byteLength = byteLength + $0.count - } - if byteLength < targetLength { - let paddingCount = targetLength - byteLength - let paddingArray = [UInt8](repeating: 0, count: paddingCount) - bytesArray.append(contentsOf: paddingArray) - } - } - return bytesArray -} - -do { - // Setup - try moproCircom.initialize(zkeyPath: zkeyPath, wasmPath: wasmPath) - - // Prepare inputs - let inputVec: [UInt8] = [ - 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - ] - let bits = bytesToBits(bytes: inputVec) - var inputs = [String: [String]]() - inputs["in"] = bits - - // Expected outputs - let outputVec: [UInt8] = [ - 37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88, - 212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21, - ] - let outputBits: [String] = bytesToBits(bytes: outputVec) - let expectedOutput: [UInt8] = serializeOutputs(outputBits) - - // Generate Proof - let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs) - assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") - - // Verify Proof - assert(Data(expectedOutput) == generateProofResult.inputs, "Circuit outputs mismatch the expected outputs") - - let isValid = try moproCircom.verifyProof(proof: generateProofResult.proof, publicInput: generateProofResult.inputs) - assert(isValid, "Proof verification should succeed") - -} catch let error as MoproError { - print("MoproError: \(error)") -} catch { - print("Unexpected error: \(error)") -} diff --git a/test-e2e/tests/bindings/test_mopro_keccak_static.swift b/test-e2e/tests/bindings/test_mopro_keccak_static.swift deleted file mode 100644 index 15b9d144..00000000 --- a/test-e2e/tests/bindings/test_mopro_keccak_static.swift +++ /dev/null @@ -1,83 +0,0 @@ -import Foundation -import mopro - -//let moproCircom = MoproCircom() - -// Using zkey and generate_proof_static - -// let wasmPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm" -// let r1csPath = "./../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test.r1cs" - -// Helper function to convert bytes to bits -func bytesToBits(bytes: [UInt8]) -> [String] { - var bits = [String]() - for byte in bytes { - for j in 0..<8 { - let bit = (byte >> j) & 1 - bits.append(String(bit)) - } - } - return bits -} - -func serializeOutputs(_ stringArray: [String]) -> [UInt8] { - var bytesArray: [UInt8] = [] - let length = stringArray.count - var littleEndianLength = length.littleEndian - let targetLength = 32 - withUnsafeBytes(of: &littleEndianLength) { - bytesArray.append(contentsOf: $0) - } - for value in stringArray { - // TODO: should handle 254-bit input - var littleEndian = Int32(value)!.littleEndian - var byteLength = 0 - withUnsafeBytes(of: &littleEndian) { - bytesArray.append(contentsOf: $0) - byteLength = byteLength + $0.count - } - if byteLength < targetLength { - let paddingCount = targetLength - byteLength - let paddingArray = [UInt8](repeating: 0, count: paddingCount) - bytesArray.append(contentsOf: paddingArray) - } - } - return bytesArray -} - -do { - - // Prepare inputs - let inputVec: [UInt8] = [ - 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - ] - let bits = bytesToBits(bytes: inputVec) - var inputs = [String: [String]]() - inputs["in"] = bits - - // Expected outputs - let outputVec: [UInt8] = [ - 37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88, - 212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21, - ] - let outputBits: [String] = bytesToBits(bytes: outputVec) - let expectedOutput: [UInt8] = serializeOutputs(outputBits) - - // // Generate Proof - let generateProofResult = try generateProofStatic(circuitInputs: inputs) - // let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs) - assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") - - // // Verify Proof - assert(Data(expectedOutput) == generateProofResult.inputs, "Circuit outputs mismatch the expected outputs") - - let isValid = try verifyProofStatic( - proof: generateProofResult.proof, publicInput: generateProofResult.inputs) - assert(isValid, "Proof verification should succeed") - -} catch let error as MoproError { - print("MoproError: \(error)") -} catch { - print("Unexpected error: \(error)") -} diff --git a/test-e2e/tests/bindings/test_mopro_rsa.kts b/test-e2e/tests/bindings/test_mopro_rsa.kts deleted file mode 100644 index 09a8df37..00000000 --- a/test-e2e/tests/bindings/test_mopro_rsa.kts +++ /dev/null @@ -1,114 +0,0 @@ -import uniffi.mopro.*; - -var wasmPath = "../mopro-core/examples/circom/rsa/target/main_js/main.wasm" -var zkeyPath = "../mopro-core/examples/circom/rsa/target/main_final.zkey" - -try { - var moproCircom = MoproCircom() - moproCircom.initialize(zkeyPath, wasmPath) - - val inputs = mutableMapOf>() - inputs["signature"] = listOf("3582320600048169363", - "7163546589759624213", - "18262551396327275695", - "4479772254206047016", - "1970274621151677644", - "6547632513799968987", - "921117808165172908", - "7155116889028933260", - "16769940396381196125", - "17141182191056257954", - "4376997046052607007", - "17471823348423771450", - "16282311012391954891", - "70286524413490741", - "1588836847166444745", - "15693430141227594668", - "13832254169115286697", - "15936550641925323613", - "323842208142565220", - "6558662646882345749", - "15268061661646212265", - "14962976685717212593", - "15773505053543368901", - "9586594741348111792", - "1455720481014374292", - "13945813312010515080", - "6352059456732816887", - "17556873002865047035", - "2412591065060484384", - "11512123092407778330", - "8499281165724578877", - "12768005853882726493") - inputs["modulus"] = listOf("13792647154200341559", - "12773492180790982043", - "13046321649363433702", - "10174370803876824128", - "7282572246071034406", - "1524365412687682781", - "4900829043004737418", - "6195884386932410966", - "13554217876979843574", - "17902692039595931737", - "12433028734895890975", - "15971442058448435996", - "4591894758077129763", - "11258250015882429548", - "16399550288873254981", - "8246389845141771315", - "14040203746442788850", - "7283856864330834987", - "12297563098718697441", - "13560928146585163504", - "7380926829734048483", - "14591299561622291080", - "8439722381984777599", - "17375431987296514829", - "16727607878674407272", - "3233954801381564296", - "17255435698225160983", - "15093748890170255670", - "15810389980847260072", - "11120056430439037392", - "5866130971823719482", - "13327552690270163501",) - inputs["base_message"] = listOf("18114495772705111902", - "2254271930739856077", - "2068851770", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0",) - - var generateProofResult = moproCircom.generateProof(inputs) - assert(generateProofResult.proof.size > 0) { "Proof is empty"} - var isValid = moproCircom.verifyProof(generateProofResult.proof, generateProofResult.inputs) - assert(isValid) { "Proof is invalid"} -} catch (e: Exception) { - println(e); -} diff --git a/test-e2e/tests/bindings/test_mopro_rsa.swift b/test-e2e/tests/bindings/test_mopro_rsa.swift deleted file mode 100644 index f80c8e38..00000000 --- a/test-e2e/tests/bindings/test_mopro_rsa.swift +++ /dev/null @@ -1,173 +0,0 @@ -import mopro -import Foundation - -let moproCircom = MoproCircom() - -let wasmPath = "./../../../../mopro-core/examples/circom/rsa/target/main_js/main.wasm" -let zkeyPath = "./../../../../mopro-core/examples/circom/rsa/target/main_final.zkey" - -// Helper function to convert bytes to bits -func bytesToBits(bytes: [UInt8]) -> [String] { - var bits = [String]() - for byte in bytes { - for j in 0..<8 { - let bit = (byte >> j) & 1 - bits.append(String(bit)) - } - } - return bits -} - -func serializeOutputs(_ stringArray: [String]) -> [UInt8] { - var bytesArray: [UInt8] = [] - let length = stringArray.count - var littleEndianLength = length.littleEndian - let targetLength = 32 - withUnsafeBytes(of: &littleEndianLength) { - bytesArray.append(contentsOf: $0) - } - for value in stringArray { - // TODO: should handle 254-bit input - var littleEndian = Int32(value)!.littleEndian - var byteLength = 0 - withUnsafeBytes(of: &littleEndian) { - bytesArray.append(contentsOf: $0) - byteLength = byteLength + $0.count - } - if byteLength < targetLength { - let paddingCount = targetLength - byteLength - let paddingArray = [UInt8](repeating: 0, count: paddingCount) - bytesArray.append(contentsOf: paddingArray) - } - } - return bytesArray -} - -do { - // Setup - try moproCircom.initialize(zkeyPath: zkeyPath ,wasmPath: wasmPath) - - // Prepare inputs - let signature: [String] = [ - "3582320600048169363", - "7163546589759624213", - "18262551396327275695", - "4479772254206047016", - "1970274621151677644", - "6547632513799968987", - "921117808165172908", - "7155116889028933260", - "16769940396381196125", - "17141182191056257954", - "4376997046052607007", - "17471823348423771450", - "16282311012391954891", - "70286524413490741", - "1588836847166444745", - "15693430141227594668", - "13832254169115286697", - "15936550641925323613", - "323842208142565220", - "6558662646882345749", - "15268061661646212265", - "14962976685717212593", - "15773505053543368901", - "9586594741348111792", - "1455720481014374292", - "13945813312010515080", - "6352059456732816887", - "17556873002865047035", - "2412591065060484384", - "11512123092407778330", - "8499281165724578877", - "12768005853882726493", - ] - - let modulus: [String] = [ - "13792647154200341559", - "12773492180790982043", - "13046321649363433702", - "10174370803876824128", - "7282572246071034406", - "1524365412687682781", - "4900829043004737418", - "6195884386932410966", - "13554217876979843574", - "17902692039595931737", - "12433028734895890975", - "15971442058448435996", - "4591894758077129763", - "11258250015882429548", - "16399550288873254981", - "8246389845141771315", - "14040203746442788850", - "7283856864330834987", - "12297563098718697441", - "13560928146585163504", - "7380926829734048483", - "14591299561622291080", - "8439722381984777599", - "17375431987296514829", - "16727607878674407272", - "3233954801381564296", - "17255435698225160983", - "15093748890170255670", - "15810389980847260072", - "11120056430439037392", - "5866130971823719482", - "13327552690270163501", - ] - let base_message: [String] = [ - "18114495772705111902", - "2254271930739856077", - "2068851770", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - ] - - var inputs = [String: [String]]() - inputs["signature"] = signature; - inputs["modulus"] = modulus; - inputs["base_message"] = base_message; - - - // Generate Proof - let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs) - assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") - - // Verifying the Proof - let isValid = try moproCircom.verifyProof(proof: generateProofResult.proof, publicInput: generateProofResult.inputs) - assert(isValid, "Proof verification should succeed") - -} catch let error as MoproError { - print("MoproError: \(error)") -} catch { - print("Unexpected error: \(error)") -} diff --git a/test-e2e/tests/bindings/test_mopro_rsa_static.swift b/test-e2e/tests/bindings/test_mopro_rsa_static.swift deleted file mode 100644 index 9c9efb40..00000000 --- a/test-e2e/tests/bindings/test_mopro_rsa_static.swift +++ /dev/null @@ -1,167 +0,0 @@ -import mopro -import Foundation - -// Helper function to convert bytes to bits -func bytesToBits(bytes: [UInt8]) -> [String] { - var bits = [String]() - for byte in bytes { - for j in 0..<8 { - let bit = (byte >> j) & 1 - bits.append(String(bit)) - } - } - return bits -} - -func serializeOutputs(_ stringArray: [String]) -> [UInt8] { - var bytesArray: [UInt8] = [] - let length = stringArray.count - var littleEndianLength = length.littleEndian - let targetLength = 32 - withUnsafeBytes(of: &littleEndianLength) { - bytesArray.append(contentsOf: $0) - } - for value in stringArray { - // TODO: should handle 254-bit input - var littleEndian = Int32(value)!.littleEndian - var byteLength = 0 - withUnsafeBytes(of: &littleEndian) { - bytesArray.append(contentsOf: $0) - byteLength = byteLength + $0.count - } - if byteLength < targetLength { - let paddingCount = targetLength - byteLength - let paddingArray = [UInt8](repeating: 0, count: paddingCount) - bytesArray.append(contentsOf: paddingArray) - } - } - return bytesArray -} - -do { - // Initialize - try initializeMopro() - - // Prepare inputs - let signature: [String] = [ - "3582320600048169363", - "7163546589759624213", - "18262551396327275695", - "4479772254206047016", - "1970274621151677644", - "6547632513799968987", - "921117808165172908", - "7155116889028933260", - "16769940396381196125", - "17141182191056257954", - "4376997046052607007", - "17471823348423771450", - "16282311012391954891", - "70286524413490741", - "1588836847166444745", - "15693430141227594668", - "13832254169115286697", - "15936550641925323613", - "323842208142565220", - "6558662646882345749", - "15268061661646212265", - "14962976685717212593", - "15773505053543368901", - "9586594741348111792", - "1455720481014374292", - "13945813312010515080", - "6352059456732816887", - "17556873002865047035", - "2412591065060484384", - "11512123092407778330", - "8499281165724578877", - "12768005853882726493", - ] - - let modulus: [String] = [ - "13792647154200341559", - "12773492180790982043", - "13046321649363433702", - "10174370803876824128", - "7282572246071034406", - "1524365412687682781", - "4900829043004737418", - "6195884386932410966", - "13554217876979843574", - "17902692039595931737", - "12433028734895890975", - "15971442058448435996", - "4591894758077129763", - "11258250015882429548", - "16399550288873254981", - "8246389845141771315", - "14040203746442788850", - "7283856864330834987", - "12297563098718697441", - "13560928146585163504", - "7380926829734048483", - "14591299561622291080", - "8439722381984777599", - "17375431987296514829", - "16727607878674407272", - "3233954801381564296", - "17255435698225160983", - "15093748890170255670", - "15810389980847260072", - "11120056430439037392", - "5866130971823719482", - "13327552690270163501", - ] - let base_message: [String] = [ - "18114495772705111902", - "2254271930739856077", - "2068851770", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - "0", - ] - - var inputs = [String: [String]]() - inputs["signature"] = signature; - inputs["modulus"] = modulus; - inputs["base_message"] = base_message; - - // Generate Proof - let generateProofResult = try generateProofStatic(circuitInputs: inputs) - assert(!generateProofResult.proof.isEmpty, "Proof should not be empty") - - // Verifying the Proof - let isValid = try verifyProofStatic(proof: generateProofResult.proof, publicInput: generateProofResult.inputs) - assert(isValid, "Proof verification should succeed") - -} catch let error as MoproError { - print("MoproError: \(error)") -} catch { - print("Unexpected error: \(error)") -} diff --git a/test-e2e/tests/test_generated_bindings.rs b/test-e2e/tests/test_generated_bindings.rs index e2721efc..12dc14a9 100644 --- a/test-e2e/tests/test_generated_bindings.rs +++ b/test-e2e/tests/test_generated_bindings.rs @@ -1,13 +1,8 @@ uniffi::build_foreign_language_testcases!( - "tests/bindings/test_mopro.swift", - "tests/bindings/test_mopro.kts", - // // "tests/bindings/test_mopro.rb", - // // "tests/bindings/test_mopro.py", - // "tests/bindings/test_mopro_keccak.swift", - // // "tests/bindings/test_mopro_keccak.kts", // FIXME: java.lang.OutOfMemoryError: Java heap space - // "tests/bindings/test_mopro_keccak_static.swift", - // "tests/bindings/test_mopro_keccak_static.kts", - // "tests/bindings/test_mopro_rsa.swift", - // // "tests/bindings/test_mopro_rsa.kts", // FIXME: java.lang.OutOfMemoryError: Java heap space - // // "tests/bindings/test_mopro_rsa_static.swift", + "tests/bindings/test_circom_multiplier2.swift", + "tests/bindings/test_circom_multiplier2.kts", + "tests/bindings/test_circom_keccak.swift", + "tests/bindings/test_circom_keccak.kts", + "tests/bindings/test_circom_multiplier2_bls.swift", + "tests/bindings/test_circom_multiplier2_bls.kts", );