---
# System prepended metadata

title: CIFAR-10

---



## Introduction
[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.

## Timeline
* **March 5, 2024** - Start Date
* **June 5, 2024** - Submission Deadline
* **June 15, 2024** - Prize Awarded

## Challenge Info:
1. **Challenge type**: 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.

## 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 [0, 255]
If you need the data to be packaged in a different way, please open an issue on the [GitHub]().

### 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."
#### 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 | ... |
|---|---|---|---|---|---|---|---|---|---|---|

## Parameters:

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

## Test Environment 

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

**CPU**: 12 core
**RAM**:  54GB

## Submission  
To address this challenge, participants can utilize one of two libraries: OpenFHE or Lattigo.

#### OpenFHE
If the solution is developed using the OpenFHE library, we expect to have CMake project. The CMakeLists.txt file should be positioned in the project's root directory.
Please adhere to the following format when submitting your solution:

1. **File Format:**
   - Your submission should be contained within a ZIP archive.
2. **Structure of the Archive:**
   - Inside the ZIP archive, ensure there is a directory titled `app`.
   - Within the `app` directory, include your main `CMakeLists.txt` file and other necessary source files.

    
```mermaid
graph TD;
    app_zip[app.zip] --> app_folder[app]
    app_folder --> CMakeLists[CMakeLists.txt]
    app_folder --> main.cpp[main.cpp]
    app_folder --> config.json[config.json]
    app_folder --> ...[...]

   ```

#### Config file
User can use config file to set parameters for generating a context on the server for testing the solution.
An example of the config and detailed description of each parameter is given below.

```
{
  "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]
}
```
**indexes_for_rotation_key**: 
If an application requires the use of a rotation key, this option allows to specify indexes for the rotation key. If the rotation key is not used, `indexes_for_rotation_key=[]`  should be equal to empty array.

**mult_depth**:
The user can set the ring dimension. Howeve if a minimum ring dimension is set for the challenge, then the user can only increase this value; decreasing it is not possible.

**scale_mod_size**: 
This parameter is used to configure `ScaleModSize`.
Default value for `scale_mod_size` is 51.

**first_mod_size**: 
This parameter allows to setup FirstModSize. 
Default value for `first_mod_size` is 60.

**batch_size**: 
if bootstrapping is not used, this parameter allows  to set the batch size. Default value is `ring_dimension/2`.

**enable_bootstrapping**: 
If bootstraping is required, this option should be set to `true`.

**levels_available_after_bootstrap**:
If bootstrapping is used, this parameter allows to setup Levels available after boostrapping. Note that the actual number of levels avalailable after bootstrapping before next bootstrapping will be `levels_available_after_bootstrap` - 1 because an additional level is used for scaling the ciphertext before next bootstrapping (in 64-bit CKKS bootstrapping.

**level_budget**:
The bootstrapping procedure needs to consume a few levels to run. This parameter is used to call `EvalBootstrapSetup`. Default value is [4,4].

 
#### Lattigo
If the project is built using the Lattigo library, a Makefile is expected in the root directory of the project.


The project must support the Command Line Interface (CLI) specified in the section below.

## Command-Line Interface

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

- **--input** [path]: Specifies the path to the file containing 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 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 evaluation key and  Galois keys.


## Evaluation Criteria

Submissions will be evaluated based on the following criteria:

1. **Accuracy.**
Will be measured as percentage of correctly classified images.
2. **Execution Time.** 
Will be measured as the average classification time per image. 


## Scorring & Awards

Solutions implemented with OpenFHE and Lattigo libraries will be scorred separately.

Two winners will be chosen in each group(OpenFHE,Lattigo):
1. Fastest solution = solution with minimum execution time with more than 85% accuracy.
2. Most accurate solution = solution with the greatest accuracy. 

The winner in each group and category will be awarded 2500.

One participant can be the winner in all categories.
Total prize fund   10000

## Challenge Committee

* [Gurgen Arakelov](https://www.linkedin.com/in/gurgen-arakelov-943172b9/), Fair Math
* [Jean-Philippe Bossuat](https://www.linkedin.com/in/jean-philippe-bossuat-9136024b/), Lattigo
* [Nikita Kaskov](https://www.linkedin.com/in/nikita-kaskov-07029812a/), Fair Math
* [Yuriy Polyakov](https://www.linkedin.com/in/yuriy-polyakov-796b84a/), Duality


## 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: support@fherma.io
- Ask a question in our [Discord](https://discord.gg/NfhXwyr9M5).
- Open an issue on the [GitHub Repository]().
- Use [OpenFHE Discourse](https://openfhe.discourse.group).

