Skip to content

Commit

Permalink
chore(ios): update bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianjeng committed Jan 18, 2024
1 parent 4f29b4f commit 45b1bb3
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
117 changes: 117 additions & 0 deletions mopro-ios/MoproKit/Bindings/mopro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
}
}

fileprivate struct FfiConverterDouble: FfiConverterPrimitive {
typealias FfiType = Double
typealias SwiftType = Double

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double {
return try lift(readDouble(&buf))
}

public static func write(_ value: Double, into buf: inout [UInt8]) {
writeDouble(&buf, lower(value))
}
}

fileprivate struct FfiConverterBool : FfiConverter {
typealias FfiType = Int8
typealias SwiftType = Bool
Expand Down Expand Up @@ -492,6 +505,77 @@ public func FfiConverterTypeMoproCircom_lower(_ value: MoproCircom) -> UnsafeMut
}


public struct BenchmarkResult {
public var numMsm: UInt32
public var avgProcessingTime: Double
public var totalProcessingTime: Double
public var allocatedMemory: UInt32

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(numMsm: UInt32, avgProcessingTime: Double, totalProcessingTime: Double, allocatedMemory: UInt32) {
self.numMsm = numMsm
self.avgProcessingTime = avgProcessingTime
self.totalProcessingTime = totalProcessingTime
self.allocatedMemory = allocatedMemory
}
}


extension BenchmarkResult: Equatable, Hashable {
public static func ==(lhs: BenchmarkResult, rhs: BenchmarkResult) -> Bool {
if lhs.numMsm != rhs.numMsm {
return false
}
if lhs.avgProcessingTime != rhs.avgProcessingTime {
return false
}
if lhs.totalProcessingTime != rhs.totalProcessingTime {
return false
}
if lhs.allocatedMemory != rhs.allocatedMemory {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(numMsm)
hasher.combine(avgProcessingTime)
hasher.combine(totalProcessingTime)
hasher.combine(allocatedMemory)
}
}


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),
allocatedMemory: FfiConverterUInt32.read(from: &buf)
)
}

public static func write(_ value: BenchmarkResult, into buf: inout [UInt8]) {
FfiConverterUInt32.write(value.numMsm, into: &buf)
FfiConverterDouble.write(value.avgProcessingTime, into: &buf)
FfiConverterDouble.write(value.totalProcessingTime, into: &buf)
FfiConverterUInt32.write(value.allocatedMemory, into: &buf)
}
}


public func FfiConverterTypeBenchmarkResult_lift(_ buf: RustBuffer) throws -> BenchmarkResult {
return try FfiConverterTypeBenchmarkResult.lift(buf)
}

public func FfiConverterTypeBenchmarkResult_lower(_ value: BenchmarkResult) -> RustBuffer {
return FfiConverterTypeBenchmarkResult.lower(value)
}


public struct G1 {
public var x: String
public var y: String
Expand Down Expand Up @@ -818,6 +902,27 @@ 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]

Expand Down Expand Up @@ -907,6 +1012,15 @@ public func initializeMoproDylib(dylibPath: String) throws {



public func runMsmBenchmark(numMsm: UInt32?) throws -> BenchmarkResult {
return try FfiConverterTypeBenchmarkResult.lift(
try rustCallWithError(FfiConverterTypeMoproError.lift) {
uniffi_mopro_ffi_fn_func_run_msm_benchmark(
FfiConverterOptionUInt32.lower(numMsm),$0)
}
)
}

public func toEthereumInputs(inputs: Data) -> [String] {
return try! FfiConverterSequenceString.lift(
try! rustCall() {
Expand Down Expand Up @@ -965,6 +1079,9 @@ private var initializationResult: InitializationResult {
if (uniffi_mopro_ffi_checksum_func_initialize_mopro_dylib() != 64476) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_mopro_ffi_checksum_func_run_msm_benchmark() != 7930) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_mopro_ffi_checksum_func_to_ethereum_inputs() != 30405) {
return InitializationResult.apiChecksumMismatch
}
Expand Down
5 changes: 5 additions & 0 deletions mopro-ios/MoproKit/Include/moproFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void uniffi_mopro_ffi_fn_func_initialize_mopro(RustCallStatus *_Nonnull out_stat
);
void uniffi_mopro_ffi_fn_func_initialize_mopro_dylib(RustBuffer dylib_path, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_mopro_ffi_fn_func_run_msm_benchmark(RustBuffer num_msm, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_mopro_ffi_fn_func_to_ethereum_inputs(RustBuffer inputs, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_mopro_ffi_fn_func_to_ethereum_proof(RustBuffer proof, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -220,6 +222,9 @@ uint16_t uniffi_mopro_ffi_checksum_func_initialize_mopro(void
);
uint16_t uniffi_mopro_ffi_checksum_func_initialize_mopro_dylib(void

);
uint16_t uniffi_mopro_ffi_checksum_func_run_msm_benchmark(void

);
uint16_t uniffi_mopro_ffi_checksum_func_to_ethereum_inputs(void

Expand Down

0 comments on commit 45b1bb3

Please sign in to comment.