Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 docs add placeholders of the planned components #8

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Placeholders for new challenges
  • Loading branch information
alexandra-mara committed Mar 22, 2024
commit b209c6844dfa2dfb0af71c8bfa0a099e34d97e18
125 changes: 125 additions & 0 deletions cpp/include/cifar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# CIFAR-10 Image Classification component

*This is a stub repository for the FHERMA CIFAR-10 Image Classification challenge https://fherma.io/challenges/652bf663485c878710fd0209 which is live March-Jun 2024.*

---

## Overview

[CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.html) is a widely recognized dataset comprising 60,000 color images of size 32x32 pixels, categorized into 10 classes (such as automobiles, airplanes, dogs, etc.).
This dataset serves as a standard benchmark for machine learning algorithms in computer vision.

The goal of the challenge is to develop and implement a machine-learning model capable of efficiently classifying encrypted CIFAR-10 images without decrypting them.

## Challenge Info:

1. **Challenge type**: This challenge is a White Box.
The project with source code is required.
2. **Encryption Scheme**: CKKS.
3. **Supported libraries**: [OpenFHE](https://github.com/openfheorg/openfhe-development), [Lattigo](https://github.com/tuneinsight/lattigo).
4. **Input**:
- Encrypted image
- Cryptocontext
- Public key
- Multiplication key
- Galois keys
5. **Output**: Encrypted classification result.

## How to Participate

This is a **White Box** challenge.
We've prepared a guide on how to participate in these types of challenges, please see our [User Guide](https://fherma.io/how_it_works).

## Encoding Technique

We utilize the following class indexing for the CIFAR-10 dataset.

| Index | Class|
| -------- | -------- |
| 0 | Airplane |
| 1 | Automobile |
| 2 | Bird |
| 3 | Cat |
| 4 | Deer |
| 5 | Dog |
| 6 | Frog |
| 7 | Horse |
| 8 | Ship |
| 9 | Truck |

### Input

Each image is encoded as a real vector with a dimension of 3072=3x1024.
The initial 1024 slots denote the red channel, the subsequent ones denote green, and the final segment denotes blue.
Each slot stores value in the range of [0, 255].

If you need the data to be packaged in a different way, please open an issue on the [GitHub](https://github.com/Fherma-challenges/cifar-10).

### Output

The outcome of the computation is governed by the initial 10 slots in the resultant ciphertext.
If the input image belongs to class "i", then within the first 10 slots of the resultant vector, the maximum value must be located in slot "i."

## Parameters

Parameters used to generate cryptocontext, keys and ciphertext can be changed through the `config.json` file located in the project root.
Parameters must provide security of at least 128 bits.

## Implementation

Your implementation could be here!

## Test Environment

The solution will be tested inside a docker container.
The following libraries/packages will be used in the testing environment:
- **OpenFHE**: v1.1.2
- **OpenFHE-Python**: v0.8.4
- **Lattigo**: v5.0.2

### Command-Line Interface for Application Testing

#### OpenFHE
The application should support the following command-line interface (CLI) options:

- **--input** [path]: Specifies the path to the file containing the encrypted test image.
- **--output** [path]: Specifies the path to the file where the result should be written.
- **--cc** [path]: Indicates the path to the Cryptocontext file serialized in **BINARY** form.
- **--key_public** [path]: Specifies the path to the Public Key file.
- **--key_mult** [path]: Specifies the path to the Evaluation (Multiplication) Key file.
- **--key_rot** [path]: Specifies the path to the Rotation Key file.

#### Lattigo
The application should support the following command-line interface (CLI) options:

- **--input** [path]: Specifies the path to the file containing the encrypted test image.
- **--output** [path]: Specifies the path to the file where the result should be written.
- **--cc** [path]: Indicates the path to the Cryptocontext file serialized in **BINARY** form.
- **--key_eval** [path]: defines the path to the file where `MemEvaluationKeySet` object is serialized. `MemEvaluationKeySet` contains the evaluation key and Galois keys.

## Example

If the input image is classified as airplane (class 0), then the following outcomes are considered correct:

| 0.78 | 0.23 | 0.56 | 0.75 | 0 | 0.1 | 0.23 | 0.56 | 0.43 | 0.3 | ... |
|---|---|---|---|---|---|---|---|---|---|---|

| 0.98 | 0.23 | 0.26 | 0.93 | 0 | 0.1 | 0.23 | 0.56 | 0.43 | 0.3 | ... |
|---|---|---|---|---|---|---|---|---|---|--- |

| 0.48 | 0.23 | 0.16 | 0.17 | 0 | 0.1 | 0.23 | 0.26 | 0.43 | 0.3 | ... |
|---|---|---|---|---|---|---|---|---|---|---|

## Useful Links

* [OpenFHE](https://github.com/openfheorg/openfhe-development)
* [OpenFHE Python](https://github.com/openfheorg/openfhe-python)
* [Lattigo](https://github.com/tuneinsight/lattigo)

## Help

If you have any questions, you can:
* Contact us by email: [email protected]
* Ask a question in our [Discord](https://discord.gg/NfhXwyr9M5).
* Open an issue in the [GitHub Repository](https://github.com/Fherma-challenges/cifar-10).
* Use [OpenFHE Discourse](https://openfhe.discourse.group).
34 changes: 34 additions & 0 deletions cpp/include/cifar/cifar_ckks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "openfhe.h"

#include "ciphertext-ser.h"
#include "cryptocontext-ser.h"
#include "key/key-ser.h"
#include "scheme/ckksrns/ckksrns-ser.h"

using namespace lbcrypto;

class CIFAR10CKKS {
CryptoContext<DCRTPoly> m_cc;
PublicKey<DCRTPoly> m_PublicKey;
Ciphertext<DCRTPoly> m_InputC;
Ciphertext<DCRTPoly> m_OutputC;
std::string m_PubKeyLocation;
std::string m_MultKeyLocation;
std::string m_RotKeyLocation;
std::string m_CCLocation;
std::string m_InputLocation;
std::string m_OutputLocation;

public:
CIFAR10CKKS(std::string ccLocation, std::string pubKeyLocation, std::string multKeyLocation,
std::string rotKeyLocation,
std::string inputLocation,
std::string outputLocation);

void initCC();

void eval();

void serializeOutput();

};
13 changes: 13 additions & 0 deletions cpp/include/cifar/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"indexes_for_rotation_key": [
1,
2,
3,
4,
5
],
"ring_dimension": 32768,
"mult_depth": 10,
"batch_size": 16384,
"scale_mod_size": 48
}
97 changes: 97 additions & 0 deletions cpp/include/parity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Parity component

*This is a stub repository for the future Parity component from the IBM challenge on FHERMA https://fherma.io/challenges/65ef8c4c5428d672bcc3977b which is live on March-Jun 2024.*

*Link to the template repository: https://github.com/Fherma-challenges/parity*

---

## Overview

This challenge was developed by [IBM Research](https://research.ibm.com).
The objective of the challenge is to design an algorithm that evaluates the function `parity(x)` under CKKS.
The function `parity(x)` gets an integer and returns its least significant bit (LSB). In other words,

$$parity(x) = x \mod 2,$$

where $x \in \mathbb{Z}.$

The `parity` function is closely related to the bit extraction problem, where given an integer $x$ the goal is to find its bit representation $x =\sum 2^i b_i$ which is useful in many cases, e.g., comparisons.
Thus, an efficient implementation of `parity(x)` would lead to an efficient implementation of bit extraction.

## Challenge Info:

1. **Challenge type:** This challenge is a White Box challenge.
Participants are required to submit the project with their source code.
2. **Encryption Scheme:** CKKS.
3. **FHE Library:** OpenFHE, Lattigo.
4. **Input Data:** Encrypted vector $x = (x_1, \ldots)$, where $x_i \in [0,255]$.
5. **Output Data:** The outcome should be an encrypted vector $parity(x)= \left(parity\left(x_1\right), \ldots\right)$.

## How to Participate

This is a **White Box** challenge.
We've prepared a guide on how to participate in these types of challenges, please see our [User Guide](https://fherma.io/how_it_works).

## Parameters of the Key

1. **Bootstrapping:** The key will support bootstrapping.
2. **Number of slots:** $2^{16}$.
3. **Multiplication depth:** 29.
4. **Fractional part precision (ScaleModSize):** 59 bits.
5. **First Module Size:** 60 bits.

## Parameters of the input

1. **Packing:** Each slot will contain one value $x_i$.
2. **Input range:** For each element $x_i=n_i + e_i$, where $n_i\in [0,255]$ is an integer, and $|e_i| < 10^{-5}$ is a small noise.

## Requirements of the output

1. **Packing:** Each slot will contain one value $y_i = parity(x_i)$, the parity of the corresponding slot in the input.
2. **Ouput range:** For each element $y_i=b_i + E_i$, where $y_i\in [0,1]$ is an integer, and $|E_i| < 10^{-2}$ is a small noise.

## Implementation

Your implementation could be here!

## Test Environment

Submissions will be evaluated on a single-core CPU.
The following libraries/packages will be used for generating test case data and for testing solutions:

- **OpenFHE:** v1.1.4
- **OpenFHE-Python:** v0.8.6
- **Lattigo:** v5.0.2
- **HElayers:** v1.5.3.1 [Download](https://ibm.github.io/helayers/ 'Download HElayers')
- **pyhelayers:** v1.5.3.1 [Download](https://ibm.github.io/helayers/ 'Download pyhelayers')

## Example

The executable will be run as follows:

```
./app --cc cc.bin --key_public pub.bin --key_mult mult.bin --input in.bin --output out.bin
```

An example of the message encrypted in `in.bin`:

`Input = [203.0000005, 102.0000008, 3.0000002, 56.9999994, 77.9999993, ...]`

An example output for this input:

`Output = [0.995, 0.008, 1.002, 1.004, -0.003, ...]`

## Useful Links

* [OpenFHE](https://github.com/openfheorg/openfhe-development)
* [OpenFHE Python](https://github.com/openfheorg/openfhe-python)
* [Lattigo](https://github.com/tuneinsight/lattigo)

## Help

If you have any questions, you can:
* Contact us by email: [email protected]
* Ask a question in our [Discord](https://discord.gg/NfhXwyr9M5).
* Open an issue in the [GitHub Repository](https://github.com/Fherma-challenges/parity/issues).
* Use [OpenFHE Discourse](https://openfhe.discourse.group).
16 changes: 16 additions & 0 deletions cpp/include/parity/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"indexes_for_rotation_key": [
1
],
"mult_depth": 29,
"ring_dimension": 131072,
"scale_mod_size": 59,
"first_mod_size": 60,
"batch_size": 65536,
"enable_bootstrapping": false,
"levels_available_after_bootstrap": 10,
"level_budget": [
4,
4
]
}
31 changes: 31 additions & 0 deletions cpp/include/parity/parity_ckks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "openfhe.h"

#include "ciphertext-ser.h"
#include "cryptocontext-ser.h"
#include "key/key-ser.h"
#include "scheme/ckksrns/ckksrns-ser.h"

using namespace lbcrypto;

class ParityCKKS {
CryptoContext<DCRTPoly> m_cc;
PublicKey<DCRTPoly> m_PublicKey;
Ciphertext<DCRTPoly> m_InputC;
Ciphertext<DCRTPoly> m_OutputC;
std::string m_PubKeyLocation;
std::string m_MultKeyLocation;
std::string m_RotKeyLocation;
std::string m_CCLocation;
std::string m_InputLocation;
std::string m_OutputLocation;

public:
ParityCKKS(std::string ccLocation, std::string pubKeyLocation, std::string multKeyLocation,
std::string rotKeyLocation, std::string inputLocation, std::string outputLocation);

void initCC();

void eval();

void serializeOutput();
};
Loading