Skip to content

Commit

Permalink
Initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
5eeman committed Apr 4, 2024
1 parent 5392868 commit ee42154
Show file tree
Hide file tree
Showing 18 changed files with 629 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.idea
79 changes: 79 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/rapidsnark.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "rapidsnark"
BuildableName = "rapidsnark"
BlueprintName = "rapidsnark"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "rapidsnarkTests"
BuildableName = "rapidsnarkTests"
BlueprintName = "rapidsnarkTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "rapidsnark"
BuildableName = "rapidsnark"
BlueprintName = "rapidsnark"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
49 changes: 49 additions & 0 deletions Libs/Rapidsnark.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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</string>
<key>LibraryPath</key>
<string>librapidsnarkmerged.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</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_arm64e_x86_64-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>
<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"
70 changes: 70 additions & 0 deletions Libs/Rapidsnark.xcframework/ios-arm64/Headers/prover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#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 PROVER_OK in case of success, and the size of public buffer is written to public_size
*/
int
groth16_public_size_for_zkey_buf(const void *zkey_buffer, unsigned long zkey_size,
size_t *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_public_size_for_zkey_file calculates minimum buffer size for
* JSON-formatted public signals. The calculated buffer size is written
* to the public_size variable.
*
* @return error code:
* PROVER_OK (0) - in case of success
* PROVER_ERROR - in case of an error, error_msg contains the error message
*/
int
groth16_public_size_for_zkey_file(const char *zkey_fname,
unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_prover
* @return error code:
* PROVER_OK - in case of success
* PPOVER_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
* @return error code:
* PROVER_OK - in case of success
* PPOVER_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
34 changes: 34 additions & 0 deletions Libs/Rapidsnark.xcframework/ios-arm64/Headers/verifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef VERIFIER_HPP
#define VERIFIER_HPP

#ifdef __cplusplus
extern "C" {
#endif

//Error codes returned by the functions.
#define VERIFIER_VALID_PROOF 0x0
#define VERIFIER_INVALID_PROOF 0x1
#define VERIFIER_ERROR 0x2

/**
* 'proof', 'inputs' and 'verification_key' are null-terminated json strings.
*
* @return error code:
* VERIFIER_VALID_PROOF - in case of valid 'proof'.
* VERIFIER_INVALID_PROOF - in case of invalid 'proof'.
VERIFIER_ERROR - in case of an error
*/

int
groth16_verify(const char *proof,
const char *inputs,
const char *verification_key,
char *error_msg,
unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // VERIFIER_HPP
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#import "verifier.h"
#import "prover.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#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 PROVER_OK in case of success, and the size of public buffer is written to public_size
*/
int
groth16_public_size_for_zkey_buf(const void *zkey_buffer, unsigned long zkey_size,
size_t *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_public_size_for_zkey_file calculates minimum buffer size for
* JSON-formatted public signals. The calculated buffer size is written
* to the public_size variable.
*
* @return error code:
* PROVER_OK (0) - in case of success
* PROVER_ERROR - in case of an error, error_msg contains the error message
*/
int
groth16_public_size_for_zkey_file(const char *zkey_fname,
unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_prover
* @return error code:
* PROVER_OK - in case of success
* PPOVER_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
* @return error code:
* PROVER_OK - in case of success
* PPOVER_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef VERIFIER_HPP
#define VERIFIER_HPP

#ifdef __cplusplus
extern "C" {
#endif

//Error codes returned by the functions.
#define VERIFIER_VALID_PROOF 0x0
#define VERIFIER_INVALID_PROOF 0x1
#define VERIFIER_ERROR 0x2

/**
* 'proof', 'inputs' and 'verification_key' are null-terminated json strings.
*
* @return error code:
* VERIFIER_VALID_PROOF - in case of valid 'proof'.
* VERIFIER_INVALID_PROOF - in case of invalid 'proof'.
VERIFIER_ERROR - in case of an error
*/

int
groth16_verify(const char *proof,
const char *inputs,
const char *verification_key,
char *error_msg,
unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // VERIFIER_HPP
Binary file not shown.
26 changes: 20 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@
import PackageDescription

let package = Package(
name: "rapidsnark-ios",
name: "rapidsnark",
platforms: [
.iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "rapidsnark-ios",
targets: ["rapidsnark-ios"]),
name: "rapidsnark",
targets: ["rapidsnark"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "rapidsnark-ios"),
name: "rapidsnark",
dependencies: ["C"],
path: "Sources/rapidsnark",
sources: ["rapidsnark.swift"]
),
.target(
name: "C",
dependencies: ["Rapidsnark"],
path: "Sources/C"),
.binaryTarget(
name: "Rapidsnark",
path: "Libs/Rapidsnark.xcframework"),
.testTarget(
name: "rapidsnark-iosTests",
dependencies: ["rapidsnark-ios"]),
name: "rapidsnarkTests",
dependencies: ["rapidsnark"])
]
)
Loading

0 comments on commit ee42154

Please sign in to comment.