Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XCFramework, error handling. #2

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Libs/Rapidsnark.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_arm64e</string>
<key>LibraryPath</key>
<string>librapidsnarkmerged.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>arm64e</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
Expand All @@ -26,14 +27,12 @@
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_arm64e_x86_64-simulator</string>
<string>ios-arm64-simulator</string>
<key>LibraryPath</key>
<string>librapidsnarkmerged.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>arm64e</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
Expand Down
51 changes: 51 additions & 0 deletions Libs/Rapidsnark.xcframework/ios-arm64-simulator/Headers/prover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef PROVER_HPP
#define PROVER_HPP

#ifdef __cplusplus
extern "C" {
#endif

//Error codes returned by the functions.
#define PROVER_OK 0x0
#define PROVER_ERROR 0x1
#define PROVER_ERROR_SHORT_BUFFER 0x2
#define PROVER_INVALID_WITNESS_LENGTH 0x3

/**
* Calculates buffer size to output public signals as json string
* @returns buffer size in bytes or 0 in case of an error
*/
unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_size);

/**
* groth16_prover
* @return error code:
* PROVER_OK - in case of success
* PROVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_prover_zkey_file
* @return error code:
* PROVER_OK - in case of success
* PROVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int groth16_prover_zkey_file(const char *zkey_file_path,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // PROVER_HPP
Binary file not shown.
70 changes: 0 additions & 70 deletions Libs/Rapidsnark.xcframework/ios-arm64/Headers/prover.h

This file was deleted.

Binary file not shown.
51 changes: 51 additions & 0 deletions Libs/Rapidsnark.xcframework/ios-arm64_arm64e/Headers/prover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef PROVER_HPP
#define PROVER_HPP

#ifdef __cplusplus
extern "C" {
#endif

//Error codes returned by the functions.
#define PROVER_OK 0x0
#define PROVER_ERROR 0x1
#define PROVER_ERROR_SHORT_BUFFER 0x2
#define PROVER_INVALID_WITNESS_LENGTH 0x3

/**
* Calculates buffer size to output public signals as json string
* @returns buffer size in bytes or 0 in case of an error
*/
unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_size);

/**
* groth16_prover
* @return error code:
* PROVER_OK - in case of success
* PROVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_prover_zkey_file
* @return error code:
* PROVER_OK - in case of success
* PROVER_ERROR - in case of an error
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess
*/
int groth16_prover_zkey_file(const char *zkey_file_path,
const void *wtns_buffer, unsigned long wtns_size,
char *proof_buffer, unsigned long *proof_size,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // PROVER_HPP
Binary file not shown.

This file was deleted.

23 changes: 22 additions & 1 deletion Sources/rapidsnark/rapidsnark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,42 @@ private func groth16proverStatusCodeErrors(_ statusCode: Int32, message: String)


public protocol RapidsnarkError : Error {
var message: String { get }
}

public enum RapidsnarkProverError : RapidsnarkError {
case error(message: String)
case shortBuffer(message: String)
case invalidWitnessLength(message: String)

public var message: String {
switch self {
case .error(let message):
return message
case .shortBuffer(let message):
return message
case .invalidWitnessLength(let message):
return message
}
}
}

public enum RapidsnarkVerifierError : RapidsnarkError {
case error(message: String)
case invalidProof(message: String)

public var message: String {
switch self {
case .error(let message):
return message
case .invalidProof(let message):
return message
}
}
}

public class RapidsnarkUnknownStatusError : RapidsnarkError {
let message: String
public let message: String

init(message: String) {
self.message = message
Expand Down
2 changes: 1 addition & 1 deletion rapidsnark.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'rapidsnark'
s.version = '0.0.1-alpha.2'
s.version = '0.0.1-alpha.3'
s.summary = 'Swift wrapper for the rapidsnark proof generation library.'

# This description is used to generate tags and improve search results.
Expand Down
48 changes: 48 additions & 0 deletions xcframework/Rapidsnark.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>librapidsnarkmerged.a</string>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_arm64e</string>
<key>LibraryPath</key>
<string>librapidsnarkmerged.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>arm64e</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>librapidsnarkmerged.a</string>
<key>HeadersPath</key>
<string>Headers</string>
<key>LibraryIdentifier</key>
<string>ios-arm64-simulator</string>
<key>LibraryPath</key>
<string>librapidsnarkmerged.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#import "verifier.h"
#import "prover.h"
Loading