Skip to content

Commit

Permalink
chore: add ios, android e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianjeng committed Oct 22, 2024
1 parent 1e87ea6 commit 980be53
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 819 deletions.
14 changes: 9 additions & 5 deletions test-e2e/ios/mopro-test.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2A5992962CC79C1700135402 /* example.ar1cs in Resources */ = {isa = PBXBuildFile; fileRef = 2A5992952CC79C1700135402 /* example.ar1cs */; };
4C05CDB22C327C4F00BEBACD /* mopro_test_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C05CDB12C327C4F00BEBACD /* mopro_test_UITests.swift */; };
4CBAB2782C3334B300B536B7 /* MoproBindings.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CBAB2772C3334B300B536B7 /* MoproBindings.xcframework */; };
4CBAB27A2C3334B800B536B7 /* mopro.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBAB2792C3334B800B536B7 /* mopro.swift */; };
Expand All @@ -31,6 +32,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
2A5992952CC79C1700135402 /* example.ar1cs */ = {isa = PBXFileReference; lastKnownFileType = text; name = example.ar1cs; path = "/Users/zhengyawen/Documents/GitHub/mopro/test-vectors/ashlang/example.ar1cs"; sourceTree = "<absolute>"; };
4C05CDAF2C327C4F00BEBACD /* mopro-test-UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "mopro-test-UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
4C05CDB12C327C4F00BEBACD /* mopro_test_UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = mopro_test_UITests.swift; sourceTree = "<group>"; };
4CBAB2772C3334B300B536B7 /* MoproBindings.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MoproBindings.xcframework; path = ../MoproiOSBindings/MoproBindings.xcframework; sourceTree = "<group>"; };
Expand All @@ -41,9 +43,9 @@
4CF977F02C2BCF0000CE1139 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
4CF977F22C2BCF0300CE1139 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4CF977F52C2BCF0300CE1139 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
60A8E4352C40404200D3A953 /* fibonacci_srs.bin */ = {isa = PBXFileReference; lastKnownFileType = file; name = fibonacci_srs.bin; path = "../../test-vectors/halo2/fibonacci_srs.bin"; sourceTree = "<group>"; };
60A8E4362C40404300D3A953 /* fibonacci_pk.bin */ = {isa = PBXFileReference; lastKnownFileType = file; name = fibonacci_pk.bin; path = "../../test-vectors/halo2/fibonacci_pk.bin"; sourceTree = "<group>"; };
60A8E4372C40404300D3A953 /* fibonacci_vk.bin */ = {isa = PBXFileReference; lastKnownFileType = file; name = fibonacci_vk.bin; path = "../../test-vectors/halo2/fibonacci_vk.bin"; sourceTree = "<group>"; };
60A8E4352C40404200D3A953 /* fibonacci_srs.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = fibonacci_srs.bin; path = "../../test-vectors/halo2/fibonacci_srs.bin"; sourceTree = "<group>"; };
60A8E4362C40404300D3A953 /* fibonacci_pk.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = fibonacci_pk.bin; path = "../../test-vectors/halo2/fibonacci_pk.bin"; sourceTree = "<group>"; };
60A8E4372C40404300D3A953 /* fibonacci_vk.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = fibonacci_vk.bin; path = "../../test-vectors/halo2/fibonacci_vk.bin"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -80,6 +82,7 @@
60A8E4352C40404200D3A953 /* fibonacci_srs.bin */,
60A8E4372C40404300D3A953 /* fibonacci_vk.bin */,
4CCB9BDE2C33C20100C659C4 /* multiplier2_final.zkey */,
2A5992952CC79C1700135402 /* example.ar1cs */,
4CF977ED2C2BCF0000CE1139 /* mopro-test */,
4C05CDB02C327C4F00BEBACD /* mopro-test-UITests */,
4CF977EC2C2BCF0000CE1139 /* Products */,
Expand Down Expand Up @@ -218,6 +221,7 @@
60A8E4382C40404300D3A953 /* fibonacci_srs.bin in Resources */,
4CF977F32C2BCF0300CE1139 /* Assets.xcassets in Resources */,
60A8E4392C40404300D3A953 /* fibonacci_pk.bin in Resources */,
2A5992962CC79C1700135402 /* example.ar1cs in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -412,7 +416,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"mopro-test/Preview Content\"";
DEVELOPMENT_TEAM = R92BA9L62G;
DEVELOPMENT_TEAM = N3ESL929H7;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -441,7 +445,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"mopro-test/Preview Content\"";
DEVELOPMENT_TEAM = R92BA9L62G;
DEVELOPMENT_TEAM = N3ESL929H7;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
66 changes: 66 additions & 0 deletions test-e2e/ios/mopro-test/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ struct ContentView: View {
@State private var isCircomVerifyButtonEnabled = false
@State private var isHalo2roveButtonEnabled = true
@State private var isHalo2VerifyButtonEnabled = false
@State private var isAshlangroveButtonEnabled = true
@State private var isAshlangVerifyButtonEnabled = false
@State private var generatedCircomProof: Data?
@State private var circomPublicInputs: Data?
@State private var generatedHalo2Proof: Data?
@State private var halo2PublicInputs: Data?
@State private var generatedAshlangProof: Data?
@State private var ashlangPublicInputs: Data?
private let zkeyPath = Bundle.main.path(forResource: "multiplier2_final", ofType: "zkey")!
private let srsPath = Bundle.main.path(forResource: "fibonacci_srs.bin", ofType: "")!
private let vkPath = Bundle.main.path(forResource: "fibonacci_vk.bin", ofType: "")!
private let pkPath = Bundle.main.path(forResource: "fibonacci_pk.bin", ofType: "")!
private let ar1csPath = Bundle.main.path(forResource: "example.ar1cs", ofType: "")!

var body: some View {
VStack(spacing: 10) {
Expand All @@ -57,6 +62,8 @@ struct ContentView: View {
Button("Verify Circom", action: runCircomVerifyAction).disabled(!isCircomVerifyButtonEnabled).accessibilityIdentifier("verifyCircom")
Button("Prove Halo2", action: runHalo2ProveAction).disabled(!isHalo2roveButtonEnabled).accessibilityIdentifier("proveHalo2")
Button("Verify Halo2", action: runHalo2VerifyAction).disabled(!isHalo2VerifyButtonEnabled).accessibilityIdentifier("verifyHalo2")
Button("Prove Ashlang", action: runAshlangProveAction).disabled(!isAshlangroveButtonEnabled).accessibilityIdentifier("proveAshlang")
Button("Verify Ashlang", action: runAshlangVerifyAction).disabled(!isAshlangVerifyButtonEnabled).accessibilityIdentifier("verifyAshlang")

ScrollView {
Text(textViewText)
Expand Down Expand Up @@ -204,5 +211,64 @@ extension ContentView {
print("\nUnexpected error: \(error)")
}
}

func runAshlangProveAction() {
textViewText += "Generating Ashlang proof... "
do {
// Prepare inputs
var inputs = [String(55)]

let start = CFAbsoluteTimeGetCurrent()

// Generate Proof
let generateProofResult = try generateAshlangSpartanProof( ar1csPath: ar1csPath, inputs: inputs)
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
assert(!generateProofResult.inputs.isEmpty, "Inputs should not be empty")


let end = CFAbsoluteTimeGetCurrent()
let timeTaken = end - start

// Store the generated proof and public inputs for later verification
generatedAshlangProof = generateProofResult.proof
ashlangPublicInputs = generateProofResult.inputs

textViewText += "\(String(format: "%.3f", timeTaken))s 1️⃣\n"

isAshlangVerifyButtonEnabled = true
} catch {
textViewText += "\nProof generation failed: \(error.localizedDescription)\n"
}
}

func runAshlangVerifyAction() {
guard let proof = generatedAshlangProof,
let inputs = ashlangPublicInputs else {
textViewText += "Proof has not been generated yet.\n"
return
}

textViewText += "Verifying Ashlang proof... "
do {
let start = CFAbsoluteTimeGetCurrent()

let isValid = try verifyAshlangSpartanProof(
ar1csPath: ar1csPath, proof: generatedAshlangProof!)
let end = CFAbsoluteTimeGetCurrent()
let timeTaken = end - start


if isValid {
textViewText += "\(String(format: "%.3f", timeTaken))s 2️⃣\n"
} else {
textViewText += "\nProof verification failed.\n"
}
isAshlangVerifyButtonEnabled = false
} catch let error as MoproError {
print("\nMoproError: \(error)")
} catch {
print("\nUnexpected error: \(error)")
}
}
}

Loading

0 comments on commit 980be53

Please sign in to comment.