Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ElusAegis committed Oct 18, 2024
0 parents commit 240dcdb
Show file tree
Hide file tree
Showing 38 changed files with 4,128 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Test EzklPackage

on:
push:
branches:
- main

pull_request:
branches:
- main
types:
- ready_for_review

# Option to manually trigger the workflow
workflow_dispatch:


jobs:
build-and-test:
runs-on: macos-latest

steps:
- name: Checkout ezkl-ios-port
uses: actions/checkout@v3
with:
lfs: true

- name: Install Git LFS
run: |
brew install git-lfs
git lfs install
- name: Set up Xcode environment
run: |
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept
- name: Run Package Tests
run: |
xcodebuild test \
-scheme EzklPackage \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.5' \
-resultBundlePath ./testResults
# We avoid the UI test because it always times out on GitHub Actions
- name: Run Example App Tests
run: |
cd Example
xcodebuild test \
-project Example.xcodeproj \
-scheme EzklApp \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.5' \
-parallel-testing-enabled NO \
-resultBundlePath ./exampleTestResults \
-skip-testing:EzklAppUITests/EzklAppUITests/testButtonClicksInOrder
- name: Upload Test Results (Package)
if: always()
uses: actions/upload-artifact@v3
with:
name: package-test-results
path: ./testResults

- name: Upload Test Results (Example)
if: always()
uses: actions/upload-artifact@v3
with:
name: example-app-test-results
path: ./Example/exampleTestResults
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
707 changes: 707 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
11 changes: 11 additions & 0 deletions Example/EzklApp/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions Example/EzklApp/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example/EzklApp/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions Example/EzklApp/EzklApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct EzklApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
26 changes: 26 additions & 0 deletions Example/EzklApp/Utilities/FileHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import EzklPackage

struct FileHelper {
static func checkFileExists(fileName: String, fileType: String) -> String? {
let bundle = Bundle.main
guard let path = bundle.path(forResource: fileName, ofType: fileType) else {
print(fileName)
return nil
}
return path
}

static func saveJsonToFile(jsonString: String, fileName: String) throws -> String {
let tempDir = FileManager.default.temporaryDirectory
let filePath = tempDir.appendingPathComponent(fileName)

do {
try jsonString.write(to: filePath, atomically: true, encoding: .utf8)
} catch {
throw EzklError.InternalError("Failed to save JSON to file: \(error.localizedDescription)")
}

return filePath.path
}
}
30 changes: 30 additions & 0 deletions Example/EzklApp/ViewModel/ProofModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import EzklPackage

struct ProofModel {
func runGenProof(witnessJson: Data) async throws -> (vkData: Data, proofOutput: Data) {
guard let srsPath = FileHelper.checkFileExists(fileName: "kzg", fileType: "srs"),
let networkPath = FileHelper.checkFileExists(fileName: "network", fileType: "ezkl") else {
throw EzklError.InternalError("One or more files not found.")
}

let srsData = try Data(contentsOf: URL(fileURLWithPath: srsPath))
let networkData = try Data(contentsOf: URL(fileURLWithPath: networkPath))

// Generate the PK from VK, because PK is too large to be stored in the GitHub repo
// Usually you will be able to bundle it inside of the application
let vkData = try genVk(compiledCircuit: networkData, srs: srsData, compressSelectors: true)
let pkData = try genPk(vk: vkData, compiledCircuit: networkData, srs: srsData)

let proofOutput = try prove(witness: witnessJson, pk: pkData, compiledCircuit: networkData, srs: srsData)

return (vkData, proofOutput)
}

func handleEZKLError(_ error: EzklError, statusMessage: inout String) {
switch error {
case .InternalError(let message):
statusMessage = "Internal Error: \(message)"
}
}
}
23 changes: 23 additions & 0 deletions Example/EzklApp/ViewModel/VerifyModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation
import EzklPackage

struct VerifyModel {
func runVerify(vkData: Data, proofJson: Data) async throws -> Bool {
guard let srsPath = FileHelper.checkFileExists(fileName: "kzg", fileType: "srs"),
let settingsPath = FileHelper.checkFileExists(fileName: "settings", fileType: "json") else {
throw EzklError.InternalError("One or more files not found.")
}

let srsData = try Data(contentsOf: URL(fileURLWithPath: srsPath))
let settingsJson = try Data(contentsOf: URL(fileURLWithPath: settingsPath))

return try verify(proof: proofJson, vk: vkData, settings: settingsJson, srs: srsData)
}

func handleEZKLError(_ error: EzklError, statusMessage: inout String) {
switch error {
case .InternalError(let message):
statusMessage = "Internal Error: \(message)"
}
}
}
23 changes: 23 additions & 0 deletions Example/EzklApp/ViewModel/WitnessModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation
import EzklPackage

struct WitnessModel {
func runGenWitness() async throws -> Data {
guard let networkPath = FileHelper.checkFileExists(fileName: "network", fileType: "ezkl"),
let inputPath = FileHelper.checkFileExists(fileName: "input", fileType: "json") else {
throw EzklError.InternalError("One or more files not found.")
}

let networkData = try Data(contentsOf: URL(fileURLWithPath: networkPath))
let inputData = try Data(contentsOf: URL(fileURLWithPath: inputPath))

return try genWitness(compiledCircuit: networkData, input: inputData)
}

func handleEZKLError(_ error: EzklError, statusMessage: inout String) {
switch error {
case .InternalError(let message):
statusMessage = "Internal Error: \(message)"
}
}
}
97 changes: 97 additions & 0 deletions Example/EzklApp/Views/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import SwiftUI

struct ContentView: View {
@State private var vkData: Data = Data()
@State private var witnessOutput: Data = Data()
@State private var proofOutput: Data = Data()
@State private var verifyOutput: String = ""

@State private var witnessTime: String = "0.0"
@State private var proofTime: String = "0.0"
@State private var verifyTime: String = "0.0"

@State private var isWitnessButtonEnabled: Bool = true
@State private var isProofButtonEnabled: Bool = false
@State private var isVerifyButtonEnabled: Bool = false

@State private var witnessStartTime: Date? = nil
@State private var proofStartTime: Date? = nil
@State private var verifyStartTime: Date? = nil

@State private var statusMessage: String = "Waiting for user input"


var body: some View {
VStack {
GenerateWitnessButtonView(
witnessOutput: $witnessOutput,
isWitnessButtonEnabled: $isWitnessButtonEnabled,
isProofButtonEnabled: $isProofButtonEnabled,
isVerifyButtonEnabled: $isVerifyButtonEnabled,
witnessStartTime: $witnessStartTime,
statusMessage: $statusMessage,
witnessTime: $witnessTime

)

GenerateProofButtonView(
witnessOutput: $witnessOutput,
vkData: $vkData,
proofOutput: $proofOutput,
isProofButtonEnabled: $isProofButtonEnabled,
isVerifyButtonEnabled: $isVerifyButtonEnabled,
proofStartTime: $proofStartTime,
statusMessage: $statusMessage,
proofTime: $proofTime
)

VerifyProofButtonView(
proofOutput: $proofOutput,
vkData: $vkData,
verifyOutput: $verifyOutput,
isVerifyButtonEnabled: $isVerifyButtonEnabled,
verifyStartTime: $verifyStartTime,
statusMessage: $statusMessage,
verifyTime: $verifyTime
)

// Status message display
Text("Status: \(statusMessage)")
.font(.subheadline)
.padding()
.accessibilityLabel("Status")

ResetButtonView(
witnessOutput: $witnessOutput,
proofOutput: $proofOutput,
verifyOutput: $verifyOutput,
witnessTime: $witnessTime,
proofTime: $proofTime,
verifyTime: $verifyTime,
isWitnessButtonEnabled: $isWitnessButtonEnabled,
isProofButtonEnabled: $isProofButtonEnabled,
isVerifyButtonEnabled: $isVerifyButtonEnabled,
statusMessage: $statusMessage
)
}
// Timer updates
.onReceive(Timer.publish(every: 0.001, on: .main, in: .common).autoconnect()) { _ in
if let startTime = witnessStartTime {
witnessTime = String(format: "%.3f", Date().timeIntervalSince(startTime)) + " seconds"
}
if let startTime = proofStartTime {
proofTime = String(format: "%.3f", Date().timeIntervalSince(startTime)) + " seconds"
}
if let startTime = verifyStartTime {
verifyTime = String(format: "%.3f", Date().timeIntervalSince(startTime)) + " seconds"
}
}
}
}


struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Loading

0 comments on commit 240dcdb

Please sign in to comment.