Skip to content

zkmopro/NoirSwift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Noir Swift

NoirSwift is a Swift package for generating and verifying Noir zero-knowledge proofs using the Barretenberg backend.

The Swift bindings are generated by the mopro CLI using the Noir adapter, which relies on a prebuilt Barretenberg backend.

To learn more about the original Rust implementation before generating bindings, please refer to noir-rs.

How to Import the Package

Option 1: Using Xcode

  1. Open your project in Xcode.

  2. Go to File > Add package dependencies.

  3. In Search or Enter Package URL, enter the URL: https://github.com/zkmopro/NoirSwift

  4. Choose the version and add the package to your project.

Option 2: Using Package.swift

Add the following to your Package.swift dependencies:

let package = Package(
    name: "YourSwiftProject",
    products: [
        //...
    ],
    dependencies: [
        .package(url: "https://github.com/zkmopro/NoirSwift", from: "1.0.0-beta.19")
    ],
    // ...
    targets: [
        .target(
            name: "YourSwiftProject",
            dependencies: [
                .product(name: "NoirSwift", package: "NoirSwift")
            ]
        ),
    ]
)

Option 3: Using CocoaPods

  1. Add the following to your Podfile:
pod 'NoirSwift', :git => 'https://github.com/zkmopro/NoirSwift.git', :branch => 'main'
  1. Run the installation command:
pod install

How to Use the Package

Here is an example of how to integrate and use this package.
For the full test implementation, see Tests/NoirSwiftTests/NoirSwiftTests.swift.

Import the package

import NoirSwift

Load circuit and srs

Please checkout noir-rs to see how to generate the circuit and the srs.

let noirCircuitPath = Bundle.main.path(
    forResource: "noir_multiplier2",
    ofType: "json"
)!

let noirSrsPath = Bundle.module.path(
    forResource: "noir_multiplier2",
    ofType: "srs"
)!

getNoirVerificationKey

let onChain = true
let lowMemoryMode = false
let inputs = ["3", "5"]

let vk = try getNoirVerificationKey(
    circuitPath: noirCircuitPath,
    srsPath: noirSrsPath,
    onChain: onChain,
    lowMemoryMode: lowMemoryMode
)

generateNoirProof

let proofData = try generateNoirProof(
    circuitPath: noirCircuitPath,
    srsPath: noirSrsPath,
    inputs: inputs,
    onChain: onChain,
    vk: vk,
    lowMemoryMode: lowMemoryMode
)

verifyNoirProof

let isValid = try verifyNoirProof(
    circuitPath: noirCircuitPath,
    proof: proofData,
    onChain: onChain,
    vk: vk,
    lowMemoryMode: lowMemoryMode
)

How to Build the Package

  1. Use mopro-cli and choose noir
mopro init

choose noir

mopro build

choose ios and all architectures.

  1. Zip the MoproiOSBindings/MoproBindings.xcframework
cd MoproiOSBindings
zip -r NoirBindings.xcframework.zip MoproBindings.xcframework
  1. Compute the checksum
swift package compute-checksum NoirBindings.xcframework.zip
  1. Upload the NoirBindings.xcframework.zip to some URL

  2. Update Sources/mopro.swift file with MoproiOSBindings/mopro.swift

Test the package

xcodebuild test \
  -scheme NoirSwift \
  -destination 'platform=iOS Simulator,name=iPhone 17 Pro,OS=latest'

Community

  • X account:
  • Telegram group:

Acknowledgements

This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.

About

Swift package for Noir prover with Barretenberg backend

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages