Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Nowak committed Dec 5, 2023
1 parent 952381e commit 27fb2f2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ swift-bridge-build = "0.1"

[dependencies]
swift-bridge = "0.1"
noir_rs = { git = "https://github.com/visoftsolutions/noir_rs.git" }
noir_rs = { git = "https://github.com/visoftsolutions/aztec-packages.git", branch = "0.16.1", package = "noir_rs" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
7 changes: 7 additions & 0 deletions Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "noir_swift"
type = "bin"
authors = [""]
compiler_version = "0.19.3"

[dependencies]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![GitHub Workflow Status ArcRunner](https://github.com/visoftsolutions/noir_swift/actions/workflows/build&[email protected]/badge.svg)
![GitHub Workflow Status Ubuntu](https://github.com/visoftsolutions/noir_swift/actions/workflows/build&[email protected]/badge.svg)
![GitHub Workflow Status Macos](https://github.com/visoftsolutions/noir_swift/actions/workflows/build&[email protected]/badge.svg)
![Version](https://img.shields.io/badge/version-0.1.0-blue)
![Version](https://img.shields.io/badge/version-0.19.3-blue)

Swift-Bridge connects the Swift ecosystem to the `noir_rs` Rust library. This provides Swift developers with a streamlined experience when integrating `noir_rs`'s zkSNARK proving functionalities on `iOS`, `macOS`, `WatchOS`, and other platforms supported by Swift.

Expand Down
16 changes: 1 addition & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,4 @@ pub fn prove_swift(circuit_bytecode: String, initial_witness_vec_raw: Vec<i32>)
/// - `Option<bool>`: Returns `true` if the proof is valid, `false` otherwise. Returns `None` if the verification process fails.
pub fn verify_swift(circuit_bytecode: String, proof: Proof) -> Option<bool> {
verify(circuit_bytecode, proof.proof, proof.verification_key).ok()
}

#[cfg(test)]
mod tests {
use crate::{prove_swift, verify_swift};

const BYTECODE: &str = "H4sIAAAAAAAA/7WTMRLEIAhFMYkp9ywgGrHbq6yz5v5H2JkdCyaxC9LgWDw+H9gBwMM91p7fPeOzIKdYjEeMLYdGTB8MpUrCmOohJJQkfYMwN4mSSy0ZC0VudKbCZ4cthqzVrsc/yw28dMZeWmrWerfBexnsxD6hJ7jUufr4GvyZFp8xpG0C14Pd8s/q29vPCBXypvmpDx7sD8opnfqIfsM1RNtxBQAA";

#[test]
fn test_prove_verify() {
let proof = prove_swift(String::from(BYTECODE), vec![1_i32, 10_i32]).unwrap();
let verdict = verify_swift(String::from(BYTECODE), proof).unwrap();
assert!(verdict);
}
}
}
13 changes: 13 additions & 0 deletions src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main(y : Field, x : pub Field) {
// y <= 4x^3 + 7x + 1
let x_3 = x * x * x;
assert(y as u32 <= (4 * x_3 + 7 * x + 1) as u32);
}

#[test]
fn test_main() {
main(39, 2);

// Uncomment to make test fail
// main(1, 1);
}
2 changes: 1 addition & 1 deletion swift/build.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
swiftc -L . -lnoir_swift -lbarretenberg -lstdc++ -lssl -lcrypto -import-objc-header bridging-header.h main.swift ../generated/noir_swift/noir_swift.swift ../generated/SwiftBridgeCore.swift -o main.run
swiftc -L . -lnoir_swift -lstdc++ -lssl -lcrypto -import-objc-header bridging-header.h main.swift ../generated/noir_swift/noir_swift.swift ../generated/SwiftBridgeCore.swift -o main.run
12 changes: 7 additions & 5 deletions swift/main.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
let BYTECODE = "H4sIAAAAAAAA/7WTMRLEIAhFMYkp9ywgGrHbq6yz5v5H2JkdCyaxC9LgWDw+H9gBwMM91p7fPeOzIKdYjEeMLYdGTB8MpUrCmOohJJQkfYMwN4mSSy0ZC0VudKbCZ4cthqzVrsc/yw28dMZeWmrWerfBexnsxD6hJ7jUufr4GvyZFp8xpG0C14Pd8s/q29vPCBXypvmpDx7sD8opnfqIfsM1RNtxBQAA"
let BYTECODE = "H4sIAAAAAAAA/+1Y207DMAz1Mna/sCGQEDww9gV127TpG7/Sdt1n8yuwomTLSgYSPZmGwNKUas1O7ONL7D0S0RMdpKPXF70G7YTFDkM4cKMgieMqDSuOOA/CrFAyiGWRKFYsldyEKooqFas0K7I0yDiOKt7KLNpq4C5Oxw8sQZ8FzUUHqLND3bbYbB5sLq702tMfw4uw3r85OOtYz0LvEV/s6ZzAGVnfmd/Prfco4/ckGONqw14tY2vjV40zux7ONlg/TJBQJwhfES7ZeuQncAWYP6TNfQdWEZQbyUWySbnKpSrLLGIO8yRPilBtq0KykmqHWeah2h0X5iVXQZ5UXXIELOELTB+HFdj6DuhQCIQj/vsebKHGOU3+vBYBX84ZeMAdEi7ofdk9xPvIqSui0A094N6QnwKKuoCMnshYGgFjCMmfudBr/Z41h3ZRA8d/bPDBuKkgP8WWMHo6u8mxXif0x7rJ2nC7m6wJWDWUA50Z1/hdwhexW7rsIqblKDHadtFjIH93Z+KvrZ4TYPwDY4aB/B0VPPQUgoyZKf2+KWRK2MvayIz+pxCIc2YecOd02VPIVDsL7CMvU8ikEVgo3Hu67Avc6ImMpWtgDCH5M41grZ9rCjEiwDEA/CuPAY3CfkpwmO5lAlnodUmnJ5C1tf/UBLKm7ycQF87ZJxD7cBTmQhOJLlALwidY7ehVg1t0x+wrqdrq9UDnKfhtp6wF0OYl0BcA/pwFzkc+ovg7VfCa8g4KyrarOR4AAA=="

func testProveVerify() -> Bool {
print("Initializing witness...");
let witness = RustVec<Int32>()
witness.push(value: 1)
witness.push(value: 47)
witness.push(value: 2)

print("Generating proof...");
guard let proof = prove_swift(BYTECODE, witness) else {
return false
}

print("Verifying proof...");
return verify_swift(BYTECODE, proof) ?? false
}

print(testProveVerify())
assert(testProveVerify())
print("Proof correct");

0 comments on commit 27fb2f2

Please sign in to comment.