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.
-
Open your project in Xcode.
-
Go to File > Add package dependencies.
-
In Search or Enter Package URL, enter the URL:
https://github.com/zkmopro/NoirSwift -
Choose the version and add the package to your project.
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")
]
),
]
)- Add the following to your
Podfile:
pod 'NoirSwift', :git => 'https://github.com/zkmopro/NoirSwift.git', :branch => 'main'
- Run the installation command:
pod installHere is an example of how to integrate and use this package.
For the full test implementation, see Tests/NoirSwiftTests/NoirSwiftTests.swift.
import NoirSwiftPlease 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"
)!let onChain = true
let lowMemoryMode = false
let inputs = ["3", "5"]
let vk = try getNoirVerificationKey(
circuitPath: noirCircuitPath,
srsPath: noirSrsPath,
onChain: onChain,
lowMemoryMode: lowMemoryMode
)let proofData = try generateNoirProof(
circuitPath: noirCircuitPath,
srsPath: noirSrsPath,
inputs: inputs,
onChain: onChain,
vk: vk,
lowMemoryMode: lowMemoryMode
)let isValid = try verifyNoirProof(
circuitPath: noirCircuitPath,
proof: proofData,
onChain: onChain,
vk: vk,
lowMemoryMode: lowMemoryMode
)- Use
mopro-cliand choosenoir
mopro initchoose noir
mopro buildchoose ios and all architectures.
- Zip the
MoproiOSBindings/MoproBindings.xcframework
cd MoproiOSBindings
zip -r NoirBindings.xcframework.zip MoproBindings.xcframework- Compute the checksum
swift package compute-checksum NoirBindings.xcframework.zip-
Upload the
NoirBindings.xcframework.zipto some URL -
Update
Sources/mopro.swiftfile withMoproiOSBindings/mopro.swift
xcodebuild test \
-scheme NoirSwift \
-destination 'platform=iOS Simulator,name=iPhone 17 Pro,OS=latest'This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.