---
# System prepended metadata

title: SHL

---

# Introduction

The Shift Left `SHL` opcode in the Ethereum Virtual Machine (EVM) performs a bitwise shift left operation on an integer value. This operation is used to shift the bits of an integer to the left by a specified number of positions, effectively multiplying the number by $2^n$ where `n` is the number of positions shifted. This can be particularly useful for various arithmetic operations, encoding, or when dealing with binary data manipulation within smart contracts.

The objective of the challenge is to design an algorithm that performs a logical left shift on input encrypted under BGV or BFV.

## 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:** BGV, BFV.
3. **FHE Library:** [OpenFHE](https://github.com/openfheorg/openfhe-development).
4. **Input Data:** Input data is two values, one is an encrypted value which should be bitwise shifted to the left on number of bits specified in the second input.
    * Encrypted value $x\in [0,2^{16}-1]$. 
    * Encrypted value $n\in [0,16]$ is a number of shifted bits 
5. **Output Data:** The outcome should be an encrypted vector with the response in the first slot.

## Timeline
* **April 26, 2024** - Start Date.
* **June 30, 2024** - Submission Deadline.
* **Jule 15, 2024** - Prize Awarded.

## Parameters of the input
**Packing:** Only the first slot of encrypted vector contains the value.

## Requirements of the output
**Packing:** The first slot should contain the value `y = SHL(x, n) = x << n` which is equal to $x*2^i$.

## Encoding technique
We pack the input value `X` into a ciphertext as a vector with first element equals `X`:
| X | 0 | 0 | ... |
|---|---|---|---|

In the same way we packed `n` into a ciphertext:
| n | 0 | 0 | ... |
|---|---|---|---|

And we expect a result as the first element of a vector 
| X << n | 0 | 0 | ...|
|---|---|---|---|

## Test environment
The following libraries/packages will be used for generating test case data and for testing solutions:
* OpenFHE: v1.1.5
* OpenFHE-Python: v0.8.6

## Submission
Participants should submit a ZIP archive containing an `app` folder. Inside this folder, there should be a `CMakeLists.txt` file for building the solution.

### 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 either your cpp solution (with `CMakeLists.txt` file and other necessary source files) or python solution (with `app.py` as a main file).
  
```mermaid
graph TD;
    app_zip[app.zip] --> app_folder[app]
    app_folder --> CMakeLists[CMakeLists.txt]
    app_folder --> main.cpp[main.cpp]
    app_folder --> ...[...]
   ```

```mermaid
graph TD;
    app_zip[app.zip] --> app_folder[app]
    app_folder --> app[app.py]
    app_folder --> config[config.json]
    app_folder --> ...[...]
   ```

### Config file

Users can use config file to set parameters for generating a context on the server for testing the solution. For example, you must specify the encryption scheme, BFV or BGV.

```
{
  "indexes_for_rotation_key": [1],
  "mult_depth": 5,
  "plaintext_modulus": 65537,
  "max_relin_sk_deg": 5,
  "scheme": "BFV"
}
```
 
The project must support the Command Line Interface (CLI) specified in the section below.

## Command-Line Interface for Application Testing
### OpenFHE
The application should support the following command-line interface (CLI) options:

- **--value** [path]: Specifies the path to the file containing encrypted value.
- **--shift** [path]: Specifies the path to the file containing number of shifted bits.
- **--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.

## Example
The executable will be run as follows:

```
./app --cc cc.bin --key_public pub.bin --key_mult mult.bin --value value.bin --shift shift.bin --output out.bin
```

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

`value = [16, 0, 0, 0, ...]`

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

`shift = [2, 0, 0, 0]`

An example output for this input:

`Output = [64, 0, 0, 0, ...]`

## Evaluation Criteria
Submissions will be evaluated based on the following criteria:

1. **Correctness and accuracy:** The output of the program for valid input (i.e., numbers in the range $[0, 65535]$) **must** be correct.
2. **Execution time:** The running time of the application on the provided input data.

That is, the winner will be the fastest application whose output is correct and accurate.

## Scorring & Awards
The winner of the challenge will be awarded $2500.

## Useful Links
* [Fherma participation guide](https://fherma.io/how_it_works)
* [OpenFHE](https://github.com/openfheorg/openfhe-development)
* [OpenFHE Python](https://github.com/openfheorg/openfhe-python)

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

