---
# System prepended metadata

title: CKKS workshop

---

# CKKS workshop

## Endpoints

### Provider

1. /ckks/provider/init
2. /ckks/provider/encrypt/{uuid}
3. /ckks/provider/decrypt/{uuid}

### Computation (consumer)

1. /ckks/computation/encode/{uuid}
2. /ckks/computation/lut/{uuid}
3. /ckks/computation/mul_add/{uuid}
4. /ckks/computation/add_clean/{uuid}

## Now

3 files are used:
- _data.dat
- _provider_data.dat
- _computed_data.dat  <--- op computation

## Algo call

```python
    subscription_fee = gen_or_import()
    for i in 0..31:
        kwh_costs[i] = gen_or_import()
    proc_valo_conso(subscription_fee, kwh_costs)
```
## Pseudo Algo

```rust
input: ENC - provider_price_option, provider_conso, provider_subscr
       CLEAR - plain_kwh[31], plain_subscr[1]

for i in 0..31 [Parallel]
    // add this comment to Jupyter: this encode can be done outside this algorithm
    // this is totally independant from provider parameters
    enc_kwh: Vec<u8> = encode(plain_kwh[i])
    lut_kwh[i] = lut(enc_kwh, provider_price_option) // mul + sum

kwh_cost = none;
for i in 0..31 [Maybe parallel]
    // rotate + mul + potential add
    kwh_cost = mul_add(i, kwh_cost, lut_kwh[i], provider_conso)

// add this comment to Jupyter: this encode can be done outside this algorithm
// this is totally independant from provider parameters
enc_subscr = encode(plain_subscr)
lut_subscr = lut(enc_subscr, provider_subscr)

return clean_add(kwh_cost, lut_subscr)
```
    
    
## Ideas
- high level Python fn to hide vector generation
```python
	make_choice(power_option=2, price_option=2, web_option=1)
		--> input_lut_subscription_fee = np.zeros((8, 7, 2))
		--> input_lut_subscription_fee[power_option][price_option][web_option] = 1
```

- no need of zeros-vec, we don't need to encrypt, we just need to encode