Skip to content

Commit 29d09bb

Browse files
chore: update readme (#19)
1 parent 24000df commit 29d09bb

File tree

5 files changed

+222
-125
lines changed

5 files changed

+222
-125
lines changed

COMPILING.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Compiling app dependencies for iOS and Mac simulator
2+
3+
## 1. Install Rust
4+
5+
1. Install the latest Rust release (currently 1.81.0):
6+
```shell
7+
curl https://sh.rustup.rs -sSf | sh
8+
```
9+
10+
2. Install extra target architectures (for iOS devices & iOS simulators running on Apple Silicon Macs):
11+
```shell
12+
rustup target add aarch64-apple-ios aarch64-apple-ios-sim
13+
```
14+
15+
3. Install nightly Rust toolchain (a TFHE-rs requirement):
16+
```shell
17+
rustup toolchain install nightly
18+
```
19+
20+
4. Install Rust source so as to cross compile `std` lib (a TFHE-rs requirement):
21+
```shell
22+
rustup component add rust-src --toolchain nightly-aarch64-apple-darwin
23+
```
24+
25+
## 2. Compile TFHE-rs for use in Swift
26+
27+
1. Get TFHE-rs:
28+
```shell
29+
git clone --branch https://github.com/zama-ai/tfhe-rs.git
30+
```
31+
32+
2. Compile for both iOS and iOS simulator targets:
33+
```shell
34+
RUSTFLAGS="" cargo +nightly build -Zbuild-std --release --features=aarch64-unix,high-level-c-api -p tfhe --target aarch64-apple-ios
35+
RUSTFLAGS="" cargo +nightly build -Zbuild-std --release --features=aarch64-unix,high-level-c-api -p tfhe --target aarch64-apple-ios-sim
36+
```
37+
38+
3. Grab generated headers (.h):
39+
```shell
40+
cp $(TFHE_RS_PATH)/target/release/tfhe.h $(OUTPUT)/include/tfhe.h
41+
cp $(TFHE_RS_PATH)/target/aarch64-apple-ios/release/deps/tfhe-c-api-dynamic-buffer.h $(OUTPUT)/include/tfhe-c-api-dynamic-buffer.h
42+
```
43+
44+
4. Create a Module Map:
45+
```shell
46+
touch $(OUTPUT)/include/module.modulemap
47+
```
48+
49+
```swift
50+
module TFHE {
51+
header "tfhe.h"
52+
header "tfhe-c-api-dynamic-buffer.h"
53+
export *
54+
}
55+
```
56+
57+
5. Grab static librairies (.a):
58+
The iOS simulator library needs to be FAT, even if it contains one slice (you can also add an x86-64 slice later on):
59+
```shell
60+
lipo -create -output $(OUTPUT)/libtfhe-ios-sim.a $(TFHE_RS_PATH)/target/aarch64-apple-ios-sim/release/libtfhe.a
61+
```
62+
63+
The iOS device library can be copied this way:
64+
```shell
65+
cp $(TFHE_RS_PATH)/target/aarch64-apple-ios/release/libtfhe.a $(OUTPUT)/libtfhe-ios.a
66+
```
67+
68+
6. Package everything into an .xcframework:
69+
```shell
70+
xcodebuild -create-xcframework \
71+
-library $(OUTPUT)/libtfhe-ios.a \
72+
-headers $(OUTPUT)/include/ \
73+
-library $(OUTPUT)/libtfhe-ios-sim.a \
74+
-headers $(OUTPUT)/include/ \
75+
-output $(OUTPUT)/TFHE.xcframework
76+
```
77+
78+
Finally, move the `TFHE.xcframework` directory into the root directory of the iOS project.
79+
80+
## 3. Compile Concrete ML Extensions for use in Swift
81+
82+
Follow the [instructions in the Concrete ML Extensions](https://github.com/zama-ai/concrete-ml-extensions?tab=readme-ov-file#from-source-for-ios) package to build additional Swift bindings that are used by **Data Vault**.

Docs/logo_dark.png

28.6 KB
Loading

Docs/logo_light.png

28.5 KB
Loading

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause Clear License
2+
3+
Copyright © 2024 ZAMA.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice, this
13+
list of conditions and the following disclaimer in the documentation and/or other
14+
materials provided with the distribution.
15+
16+
3. Neither the name of ZAMA nor the names of its contributors may be used to endorse
17+
or promote products derived from this software without specific prior written permission.
18+
19+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
20+
THIS SOFTWARE IS PROVIDED BY THE ZAMA AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
21+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23+
ZAMA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 112 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,129 @@
1-
# Welcome to FHE iOS Demo
2-
3-
Implements 3 iOS apps:
4-
1. **Zama Data Vault**: Encrypts sensitive user data (sleep, weight, profile info) using [TFHE-rs](https://github.com/zama-ai/tfhe-rs), and stores encrypted result in a shared folder for consumption by other apps. Clear, sensitive data never leaves device.
5-
2. **FHE Health**: Analyzes encrypted sleep & weight, producing graphs and insights, without ever accessing the clear data.
6-
3. **FHE Health**: Displays targeted ads based on encrypted profile info, without ever accessing the clear data.
7-
8-
In app **FHE Health** and **FHE Health**, analysis and targeting is done privately on Zama's servers; you can monitor its activity at [https://api.zama.ai/logs](https://api.zama.ai/logs).
9-
10-
# Useful Links
11-
- [Miro flow](https://miro.com/app/board/uXjVLpwDx3c=/)
12-
- [Canva screens](https://www.canva.com/design/DAGdBWLkdRE/UGMKBeI8vSnK1R-O5NFH2Q/edit)
13-
- [GitHub iOS Demo](https://github.com/zama-ai/fhe_ios_demo)
14-
- [GitHub DEAI](https://github.com/zama-ai/deai-dot-products)
15-
- [ Developer](https://developer.apple.com/account/)
16-
17-
# References
18-
- [Zama Website](https://www.zama.ai)
19-
- [Zama THFE-rs](https://docs.zama.ai/tfhe-rs/get-started/quick_start)
20-
- [ Learn Swift Guide](https://docs.swift.org/swift-book/documentation/the-swift-programming-language)
21-
- [ Learn Swift UI Guide](https://developer.apple.com/tutorials/swiftui)
22-
- [Canva old exploration](https://www.canva.com/design/DAGUeG30ET0/Yy1lAaapPuLDaMJEukOM3Q/edit)
23-
- [Google Docs UI Feedbacks](https://docs.google.com/document/d/1VOvwO9D7kKKPg0mRWacHJUfFZYBwRZezs_tmD3H6384/)
24-
- [Huggingface Demo](https://huggingface.co/spaces/zama-fhe/encrypted_image_filtering)
25-
- [Tutorial: Calling a Rust library from Swift](https://medium.com/@kennethyoel/a-swiftly-oxidizing-tutorial-44b86e8d84f5)
26-
- [Minimize Rust binary size](https://github.com/johnthagen/min-sized-rust)
27-
- [Using imported C APIs in Swift](https://developer.apple.com/documentation/swift/imported-c-and-objective-c-apis)
1+
<p align="center">
2+
<!-- product name logo -->
3+
<picture>
4+
<source media="(prefers-color-scheme: dark)" srcset="Docs/logo_dark.png">
5+
<source media="(prefers-color-scheme: light)" srcset="Docs/logo_light.png">
6+
<img width=600 alt="Zama Concrete ML iOS Demos">
7+
</picture>
8+
</p>
9+
10+
<hr>
11+
12+
<p align="center">
13+
<a href="https://docs.zama.ai/concrete-ml"> 📒 Documentation</a> | <a href="https://zama.ai/community"> 💛 Community support</a> | <a href="https://github.com/zama-ai/awesome-zama"> 📚 FHE resources by Zama</a>
14+
</p>
15+
16+
<p align="center">
17+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-BSD--3--Clause--Clear-%23ffb243?style=flat-square"></a>
18+
<a href="https://github.com/zama-ai/bounty-program"><img src="https://img.shields.io/badge/Contribute-Zama%20Bounty%20Program-%23ffd208?style=flat-square"></a>
19+
</p>
20+
21+
## About
22+
23+
### What is Concrete ML iOS Demos?
24+
25+
This repository contains iOS applications that demonstrate
26+
how FHE can help users securely get insights based on their personal
27+
data. The applications in this repository run on iPhones and connect to remote services that work with encrypted data. These services are implemented with **Concrete ML**.
28+
29+
**Concrete ML** is a Privacy-Preserving Machine Learning (PPML) open-source set of tools built by [Zama](https://github.com/zama-ai). It simplifies the use of Fully Homomorphic Encryption (FHE) for data scientists so that they can automatically turn machine learning models into their homomorphic equivalents, and use them without knowledge of cryptography.
30+
2831

29-
# Installation Steps
32+
### Main features
3033

31-
## Install Apple Tools
34+
The repository implements the **Data Vault** and several end-user demo applications. **Data Vault** is the main storage of sensitive information and two example apps that use sensitive data encrypted by the **Data Vault**.
35+
36+
The **Data Vault** acts like a secure enclave: it encrypts sensitive user data (sleep, weight, profile info) and stores encrypted result in a shared folder for consumption by other apps. Human readable sensitive data never leaves device or the **Data Vault** app.
37+
38+
To display the insights or results obtained from encrypted data, end-user applications must request that **Data Vault** displays the information in secure widgets.
39+
40+
The following demo end-user applications are available:
41+
42+
1. **FHE Health**: Analyzes sleep quality data and provides statistics about the user's weight, producing graphs and insights. The sleep tracking can be done by an iWatch using the dedicated [Sleep App](https://support.apple.com/guide/watch/track-your-sleep-apd830528336/watchos).
43+
1. **FHE Ads**: Displays targeted ads based on an encrypted user-profile. Internet advertising relies on behavioral profiling through cookies, but tracking user behavior without encryption has privacy risks. With FHE, a user can manually create their profile and ads can be matched to it without actually exposing the user-profile.
44+
45+
For these demo end-user applications, analysis and processing of the encrypted information is done on Zama's servers. Server side functionality for these end-user applications is implemented in the [Server](Server/README.md) directory.
46+
47+
The **Data Vault** uses [TFHE-rs](https://github.com/zama-ai/tfhe-rs) and [Concrete ML Extensions](https://github.com/zama-ai/concrete-ml-extensions) to encrypt and decrypt data.
48+
49+
## Setup
50+
51+
### Install Apple Tools
3252
- macOS 15 Sequoia
3353
- Xcode 16.2 [from AppStore](https://apps.apple.com/fr/app/xcode/id497799835) or [developer.apple.com](https://developer.apple.com/download/applications/)
3454
- iOS 18.2 SDK (additional download from Xcode)
3555

36-
## Install AdImages
56+
### Install AdImages
3757
- Simply unzip `QLAdsExtension/AdImages.zip' in place.
3858

39-
## Having TFHE libraries for iOS and mac simulator
59+
### Compiling app dependencies for iOS and Mac simulator
4060

41-
There are two ways to obtain those libraries:
42-
- the first one is the easiest: ask someone who has already built the libraries to send them to you; we don't store them in GitHub since they are about 340 MB, but clearly not everyone needs to build them
43-
- the second one is needed at least for new TFHE-rs versions, or when one can't receive binaries made from others
61+
#### Building libraries
4462

45-
### Getting libraries from others
63+
The easiest way to build all dependencies is to execute [the dedicated script](./setup_tfhe_xcframework.sh).
4664

47-
Simply save `TFHE.xcframework in the root directory. Inside this framework, there should be:
48-
- `Info.plist`
49-
- `ios-arm64`
50-
- `ios-arm64-simulator`
65+
To manually build the libraries follow the instructions in the [compilation guide](./COMPILING.md). The main steps are:
5166

52-
### Building libraries
53-
54-
There are several steps involved:
55-
- Installing Rust
56-
- Compiling TFHE-rs
57-
58-
#### Installing Rust
59-
60-
- Install latest Rust release (currently 1.81.0):
61-
```shell
62-
curl https://sh.rustup.rs -sSf | sh
63-
```
64-
65-
- Install extra target architectures (for iOS devices & iOS simulators running on Apple Silicon Macs):
66-
```shell
67-
rustup target add aarch64-apple-ios aarch64-apple-ios-sim
68-
```
69-
70-
- Install nightly Rust toolchain (a TFHE-rs requirement):
71-
```shell
72-
rustup toolchain install nightly
73-
```
74-
75-
- Install Rust source so as to cross compile `std` lib (a TFHE-rs requirement):
76-
```shell
77-
rustup component add rust-src --toolchain nightly-aarch64-apple-darwin
78-
```
79-
80-
#### Compiling TFHE-rs for use in Swift.
81-
82-
##### Get TFHE-rs (currently 0.7.3):
83-
```shell
84-
git clone --branch tfhe-rs-0.7.3 https://github.com/zama-ai/tfhe-rs.git
85-
```
86-
87-
##### Compile for both iOS and iOS simulator targets:
88-
```shell
89-
RUSTFLAGS="" cargo +nightly build -Zbuild-std --release --features=aarch64-unix,high-level-c-api -p tfhe --target aarch64-apple-ios
90-
RUSTFLAGS="" cargo +nightly build -Zbuild-std --release --features=aarch64-unix,high-level-c-api -p tfhe --target aarch64-apple-ios-sim
91-
```
92-
93-
##### Grab generated headers (.h):
94-
```shell
95-
cp $(TFHE_RS_PATH)/target/release/tfhe.h $(OUTPUT)/include/tfhe.h
96-
cp $(TFHE_RS_PATH)/target/aarch64-apple-ios/release/deps/tfhe-c-api-dynamic-buffer.h $(OUTPUT)/include/tfhe-c-api-dynamic-buffer.h
97-
```
98-
99-
##### Create a Module Map:
100-
```shell
101-
touch $(OUTPUT)/include/module.modulemap
102-
```
103-
104-
```swift
105-
module TFHE {
106-
header "tfhe.h"
107-
header "tfhe-c-api-dynamic-buffer.h"
108-
export *
109-
}
110-
```
111-
112-
##### Grab Static Librairies (.a):
113-
The iOS simulator library needs to be FAT, even if it contains one slice (you can also add an x86-64 slice later on):
114-
```shell
115-
lipo -create -output $(OUTPUT)/libtfhe-ios-sim.a $(TFHE_RS_PATH)/target/aarch64-apple-ios-sim/release/libtfhe.a
116-
```
117-
118-
The ios device library can be copied as is:
119-
```shell
120-
cp $(TFHE_RS_PATH)/target/aarch64-apple-ios/release/libtfhe.a $(OUTPUT)/libtfhe-ios.a
121-
```
122-
123-
##### Package everything into an .xcframework:
124-
```shell
125-
xcodebuild -create-xcframework \
126-
-library $(OUTPUT)/libtfhe-ios.a \
127-
-headers $(OUTPUT)/include/ \
128-
-library $(OUTPUT)/libtfhe-ios-sim.a \
129-
-headers $(OUTPUT)/include/ \
130-
-output $(OUTPUT)/TFHE.xcframework
131-
```
132-
133-
##### Save
134-
135-
Finally, move the `TFHE.xcframework` directory into the root directory of the iOS project. Inside this directory, there should be:
67+
1. [Install Rust](COMPILING.md#1-install-rust)
68+
1. [Compile TFHE-rs](COMPILING.md#2-compile-tfhe-rs-for-use-in-swift)
69+
1. [Compile Concrete ML Extensions](COMPILING.md#3-compile-concrete-ml-extensions-for-use-in-swift)
70+
71+
#### Using pre-built TFHE-rs libraries
72+
73+
Instead of building the `TFHE.xcframework` from scratch, you can use a previously built version. Simply save `TFHE.xcframework` in the root directory. Inside this framework, there should be:
13674
- `Info.plist`
13775
- `ios-arm64`
13876
- `ios-arm64-simulator`
13977

78+
## Data Vault and end-user application compilation
79+
80+
Now you can open your Xcode IDE, open this directory and start building the apps.
81+
82+
## End-user Application Server
83+
This repo also contains the backend implementations of the end-user applications. See the [server readme](Server/README.md) for more details on how to run these backends.
84+
85+
## Resources
86+
- [Tutorial: Calling a Rust library from Swift](https://medium.com/@kennethyoel/a-swiftly-oxidizing-tutorial-44b86e8d84f5)
87+
- [Minimize Rust binary size](https://github.com/johnthagen/min-sized-rust)
88+
- [Using imported C APIs in Swift](https://developer.apple.com/documentation/swift/imported-c-and-objective-c-apis)
89+
- [Concrete ML Documentation](https://docs.zama.ai/concrete-ml)
90+
91+
## License
92+
93+
This software is distributed under the **BSD-3-Clause-Clear** license. Read [this](LICENSE) for more details.
94+
95+
## FAQ
96+
97+
**Is Zama’s technology free to use?**
98+
99+
> Zama’s libraries are free to use under the BSD 3-Clause Clear license only for development, research, prototyping, and experimentation purposes. However, for any commercial use of Zama's open source code, companies must purchase Zama’s commercial patent license.
100+
>
101+
> All our work is open source and we strive for full transparency about Zama's IP strategy. To know more about what this means for Zama product users, read about how we monetize our open source products in [this blog post](https://www.zama.ai/post/open-source).
102+
103+
**What do I need to do if I want to use Zama’s technology for commercial purposes?**
104+
105+
> To commercially use Zama’s technology you need to be granted Zama’s patent license. Please contact us at hello@zama.ai for more information.
106+
107+
**Do you file IP on your technology?**
108+
109+
> Yes, all of Zama’s technologies are patented.
110+
111+
**Can you customize a solution for my specific use case?**
112+
113+
> We are open to collaborating and advancing the FHE space with our partners. If you have specific needs, please email us at hello@zama.ai.
114+
115+
<p align="right">
116+
<a href="#about" > ↑ Back to top </a>
117+
</p>
118+
119+
## Support
120+
121+
<a target="_blank" href="https://zama.ai/community-channels">
122+
<picture>
123+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/zama-ai/concrete-ml/assets/157474013/86502167-4ea4-49e9-a881-0cf97d141818">
124+
<source media="(prefers-color-scheme: light)" srcset="https://github.com/zama-ai/concrete-ml/assets/157474013/3dcf41e2-1c00-471b-be53-2c804879b8cb">
125+
<img alt="Support">
126+
</picture>
127+
</a>
140128

141-
# Running the Server
142-
Follow steps in Server/README.md
129+
🌟 If you find this project helpful or interesting, please consider giving it a star on GitHub! Your support helps to grow the community and motivates further development.

0 commit comments

Comments
 (0)