Skip to content

Commit

Permalink
feat(ios): Add Kimchi screen
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarth committed Nov 11, 2023
1 parent 7b7433e commit 137cc24
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 15 deletions.
6 changes: 6 additions & 0 deletions mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
7A38AEC233A3880A843B0133 /* Pods_MoproKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BE5A40EAC7D019B9C7566CA /* Pods_MoproKit_Example.framework */; };
CE2C1B8C2AFFCC5E002AF8BC /* main.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */; };
CE2C1B8D2AFFCC5E002AF8BC /* main.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */; };
CE2C1B8F2AFFE371002AF8BC /* KimchiViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2C1B8E2AFFE371002AF8BC /* KimchiViewController.swift */; };
CE2C1B902AFFE371002AF8BC /* KimchiViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2C1B8E2AFFE371002AF8BC /* KimchiViewController.swift */; };
CE5A5C062AD43A790074539D /* keccak256_256_test.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */; };
CE5A5C072AD43A790074539D /* keccak256_256_test.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */; };
CE5A5C092AD43A860074539D /* keccak256_256_test.r1cs in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */; };
Expand Down Expand Up @@ -63,6 +65,7 @@
B4016A34BBB20BC381CCFC2D /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
C61628A63419B5C140B24AF7 /* Pods-MoproKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Example.debug.xcconfig"; path = "Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example.debug.xcconfig"; sourceTree = "<group>"; };
CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = main.wasm; path = "../../../../../mopro-core/examples/circom/rsa/target/main_js/main.wasm"; sourceTree = "<group>"; };
CE2C1B8E2AFFE371002AF8BC /* KimchiViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KimchiViewController.swift; path = MoproKit/KimchiViewController.swift; sourceTree = SOURCE_ROOT; };
CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test.wasm; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm"; sourceTree = "<group>"; };
CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test.r1cs; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test.r1cs"; sourceTree = "<group>"; };
CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = multiplier2.wasm; path = "../../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -179,6 +182,7 @@
CEA2D1282AB9681E00F292D2 /* Resources */ = {
isa = PBXGroup;
children = (
CE2C1B8E2AFFE371002AF8BC /* KimchiViewController.swift */,
CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */,
CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */,
CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */,
Expand Down Expand Up @@ -407,6 +411,7 @@
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
CEB804502AFF81960063F091 /* KeccakSetupViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
CE2C1B8F2AFFE371002AF8BC /* KimchiViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -416,6 +421,7 @@
files = (
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */,
2A418AB02AF4B1200004B747 /* CircomUITests.swift in Sources */,
CE2C1B902AFFE371002AF8BC /* KimchiViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
122 changes: 122 additions & 0 deletions mopro-ios/MoproKit/Example/MoproKit/KimchiViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// ViewController.swift
// MoproKit
//
// Created by 1552237 on 09/16/2023.
// Copyright (c) 2023 1552237. All rights reserved.
//

import UIKit
import MoproKit

class KimchiViewController: UIViewController {

var benchButton = UIButton(type: .system)
// var initButton = UIButton(type: .system)
// var proveButton = UIButton(type: .system)
// var verifyButton = UIButton(type: .system)
var textView = UITextView()

//let moproCircom = MoproKit.MoproCircom()
//var setupResult: SetupResult?
// var generatedProof: Data?
// var publicInputs: Data?

override func viewDidLoad() {
super.viewDidLoad()

// Set title
let title = UILabel()
title.text = "Kimchi"
title.textColor = .white
title.textAlignment = .center
navigationItem.titleView = title
navigationController?.navigationBar.isHidden = false
navigationController?.navigationBar.prefersLargeTitles = true

setupUI()
}

func setupUI() {
benchButton.setTitle("Bench", for: .normal)
// initButton.setTitle("Init", for: .normal)
// proveButton.setTitle("Prove", for: .normal)
// verifyButton.setTitle("Verify", for: .normal)

// proveButton.isEnabled = true
// verifyButton.isEnabled = false
// textView.isEditable = false

// Setup actions for buttons
benchButton.addTarget(self, action: #selector(runBenchAction), for: .touchUpInside)
// initButton.addTarget(self, action: #selector(runInitAction), for: .touchUpInside)
// proveButton.addTarget(self, action: #selector(runProveAction), for: .touchUpInside)
// verifyButton.addTarget(self, action: #selector(runVerifyAction), for: .touchUpInside)

benchButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
// initButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
// proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
// verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)

//let stackView = UIStackView(arrangedSubviews: [initButton, proveButton, verifyButton, textView])
let stackView = UIStackView(arrangedSubviews: [benchButton, textView])
stackView.axis = .vertical
stackView.spacing = 10
stackView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stackView)

// Make text view visible
textView.heightAnchor.constraint(equalToConstant: 200).isActive = true

NSLayoutConstraint.activate([
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
])
}

@objc func runBenchAction() {
// Update the textView on the main thread
DispatchQueue.main.async {
self.textView.text += "Running bench library\n"
}

// Execute long-running tasks in the background
DispatchQueue.global(qos: .userInitiated).async {
// Record start time
let start = CFAbsoluteTimeGetCurrent()

do {
//try initializeMopro()
try kimchiBench()

// Record end time and compute duration
let end = CFAbsoluteTimeGetCurrent()
let timeTaken = end - start

// Again, update the UI on the main thread
DispatchQueue.main.async {
self.textView.text += "Running bench took \(timeTaken) seconds.\n"
}
} catch {
// Handle errors - update UI on main thread
DispatchQueue.main.async {
self.textView.text += "An error occurred during initialization: \(error)\n"
}
}
}
}

@objc func runInitAction() {
// Logic for init
}

@objc func runProveAction() {
// Logic for prove
}

@objc func runVerifyAction() {
// Logic for verify
}
}
28 changes: 13 additions & 15 deletions mopro-ios/MoproKit/Example/MoproKit/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ViewController: UIViewController {
let keccakSetupButton = UIButton(type: .system)
let keccakZkeyButton = UIButton(type: .system)
let rsaButton = UIButton(type: .system)
let kimchiButton = UIButton(type: .system)

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -43,16 +44,18 @@ class ViewController: UIViewController {
rsaButton.setTitle("RSA", for: .normal)
rsaButton.addTarget(self, action: #selector(openRSA), for: .touchUpInside)

kimchiButton.setTitle("Kimchi", for: .normal)
kimchiButton.addTarget(self, action: #selector(openKimchi), for: .touchUpInside)

keccakSetupButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
keccakZkeyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
rsaButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
keccakSetupButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
keccakZkeyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
rsaButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
kimchiButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)

// self.title = "Mopro Examples"
// navigationController?.navigationBar.prefersLargeTitles = true


let stackView = UIStackView(arrangedSubviews: [keccakSetupButton, keccakZkeyButton, rsaButton])
let stackView = UIStackView(arrangedSubviews: [keccakSetupButton, keccakZkeyButton, rsaButton, kimchiButton])
stackView.axis = .vertical
stackView.spacing = 20
stackView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -78,14 +81,9 @@ class ViewController: UIViewController {
let rsaVC = RSAViewController()
navigationController?.pushViewController(rsaVC, animated: true)
}
}

// // Make buttons bigger
// proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
// verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)

// NSLayoutConstraint.activate([
// stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
// stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
// stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20)
// ])
@objc func openKimchi() {
let kimchiVC = KimchiViewController()
navigationController?.pushViewController(kimchiVC, animated: true)
}
}

0 comments on commit 137cc24

Please sign in to comment.