Skip to content

Commit

Permalink
chore(all): fix new warnings in doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Jul 25, 2024
1 parent e654efd commit c6231ed
Show file tree
Hide file tree
Showing 96 changed files with 301 additions and 347 deletions.
8 changes: 4 additions & 4 deletions tfhe/docs/fundamentals/compress.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This example shows how to compress a ciphertext encrypting messages over 16 bits

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, CompressedFheUint16};
use tfhe::{ConfigBuilder, generate_keys, CompressedFheUint16};

fn main() {
let config = ConfigBuilder::default().build();
Expand Down Expand Up @@ -131,7 +131,7 @@ This example shows how to compress the server keys:
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
};

fn main() {
Expand Down Expand Up @@ -176,7 +176,7 @@ This issue has been identified and will be addressed in future releases.

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, CompressedPublicKey};
use tfhe::{ConfigBuilder, generate_keys, FheUint8, CompressedPublicKey};

fn main() {
let config = ConfigBuilder::default().build();
Expand Down Expand Up @@ -204,7 +204,7 @@ This example shows how to use compressed compact public keys:
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, CompactCiphertextList, CompressedCompactPublicKey,
generate_keys, CompactCiphertextList, CompressedCompactPublicKey,
ConfigBuilder, FheUint8,
};

Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/fundamentals/configure-and-generate-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
let config = ConfigBuilder::default().build();


let (client_key, server_key) = generate_keys(config);
let (_client_key, _server_key) = generate_keys(config);
}
```

Expand Down
4 changes: 2 additions & 2 deletions tfhe/docs/fundamentals/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn mul_all(a: &FheUint128, b: &FheUint128, c: &FheUint128) -> FheUint128 {


fn main() {
let (cks, sks) = generate_keys(ConfigBuilder::default().build());
let (_cks, sks) = generate_keys(ConfigBuilder::default().build());

set_server_key(sks);

Expand All @@ -43,7 +43,7 @@ fn main() {

// since all inputs are trivially encrypted, this is going to be
// much faster
let result = mul_all(&a, &b, &c);
let _result = mul_all(&a, &b, &c);
}
```

Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/fundamentals/decrypt-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tfhe::{generate_keys, ConfigBuilder, FheUint8};
fn main() {
let config = ConfigBuilder::default().build();

let (client_key, server_key) = generate_keys(config);
let (client_key, _server_key) = generate_keys(config);

let clear_a = 27u8;
let clear_b = 128u8;
Expand Down
6 changes: 3 additions & 3 deletions tfhe/docs/fundamentals/encrypt-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use tfhe::{generate_keys, ConfigBuilder, FheUint8};
fn main() {
let config = ConfigBuilder::default().build();

let (client_key, server_key) = generate_keys(config);
let (client_key, _server_key) = generate_keys(config);

let clear_a = 27u8;
let clear_b = 128u8;

let a = FheUint8::encrypt(clear_a, &client_key);
let b = FheUint8::encrypt(clear_b, &client_key);
let _a = FheUint8::encrypt(clear_a, &client_key);
let _b = FheUint8::encrypt(clear_b, &client_key);
}
```
11 changes: 4 additions & 7 deletions tfhe/docs/fundamentals/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tfhe::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>>{
let config = ConfigBuilder::default().build();

let ( client_key, server_key) = generate_keys(config);
let (client_key, server_key) = generate_keys(config);

let msg1 = 1;
let msg2 = 0;
Expand Down Expand Up @@ -96,7 +96,6 @@ Here is an example:
// main.rs

use tfhe::conformance::ParameterSetConformant;
use tfhe::integer::parameters::RadixCiphertextConformanceParams;
use tfhe::prelude::*;
use tfhe::safe_deserialization::{safe_deserialize_conformant, safe_serialize};
use tfhe::shortint::parameters::{PARAM_MESSAGE_2_CARRY_2_KS_PBS, PARAM_MESSAGE_2_CARRY_2_PBS_KS};
Expand All @@ -107,14 +106,12 @@ use tfhe::{
};

fn main() {
let config = ConfigBuilder::default().build();

let params_1 = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let params_2 = PARAM_MESSAGE_2_CARRY_2_PBS_KS;

let (client_key, server_key) = generate_keys(
ConfigBuilder::with_custom_parameters(params_1, None).build()
);
let config = ConfigBuilder::with_custom_parameters(params_1, None).build();

let (client_key, _server_key) = generate_keys(config);

let conformance_params_1 = FheUint8ConformanceParams::from(params_1);
let conformance_params_2 = FheUint8ConformanceParams::from(params_2);
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/fundamentals/set-the-server-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tfhe::{ConfigBuilder, generate_keys, set_server_key};
fn main() {
let config = ConfigBuilder::default().build();

let (client_key, server_key) = generate_keys(config);
let (_client_key, server_key) = generate_keys(config);

set_server_key(server_key);
}
Expand Down
10 changes: 5 additions & 5 deletions tfhe/docs/getting_started/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
let mut c = FheUint8::try_encrypt(clear_c, &keys)?;
let c = FheUint8::try_encrypt(clear_c, &keys)?;
let mut d = FheInt8::try_encrypt(clear_d, &keys)?;


Expand Down Expand Up @@ -193,8 +193,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let clear_a: i8 = -121;
let clear_b: i8 = 87;

let mut a = FheInt8::try_encrypt(clear_a, &keys)?;
let mut b = FheInt8::try_encrypt(clear_b, &keys)?;
let a = FheInt8::try_encrypt(clear_a, &keys)?;
let b = FheInt8::try_encrypt(clear_b, &keys)?;

let greater = a.gt(&b);
let greater_or_equal = a.ge(&b);
Expand Down Expand Up @@ -241,8 +241,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let clear_a:u8 = 164;
let clear_b:u8 = 212;

let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
let a = FheUint8::try_encrypt(clear_a, &keys)?;
let b = FheUint8::try_encrypt(clear_b, &keys)?;

let min = a.min(&b);
let max = a.max(&b);
Expand Down
1 change: 1 addition & 0 deletions tfhe/docs/getting_started/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ Refer to the [installation documentation](installation.md) for configuration opt
The `prelude` pattern provides a convenient way to globally import all important **TFHE-rs** traits at once. This approach saves time and avoids confusion.

```rust
#[allow(unused_imports)]
use tfhe::prelude::*;
```
4 changes: 2 additions & 2 deletions tfhe/docs/guides/pbs-stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub fn main() {
set_server_key(sks);

// Compute and get the PBS count for the 32 bits multiplication
let c = &a * &b;
let _c = &a * &b;
let mul_32_count = get_pbs_count();

// Reset the PBS count, and get the PBS count for a 32 bits bitwise AND
reset_pbs_count();
let d = &a & &b;
let _d = &a & &b;
let and_32_count = get_pbs_count();

// Display the result
Expand Down
4 changes: 2 additions & 2 deletions tfhe/docs/guides/public_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This example shows how to use classical public keys.

```rust
use tfhe::prelude::*;
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, PublicKey};
use tfhe::{ConfigBuilder, generate_keys, FheUint8, PublicKey};

fn main() {
let config = ConfigBuilder::default().build();
Expand All @@ -38,7 +38,7 @@ For more information on using compact public keys to encrypt data and generate a
```rust
use tfhe::prelude::*;
use tfhe::{
generate_keys, set_server_key, CompactCiphertextList, CompactPublicKey, ConfigBuilder, FheUint8,
generate_keys, CompactCiphertextList, CompactPublicKey, ConfigBuilder, FheUint8,
};


Expand Down
8 changes: 4 additions & 4 deletions tfhe/docs/guides/rayon_crate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This document describes how to use Rayon for parallel processing in **TFHE-rs**,
The high-level API requires to call `set_server_key` on each thread where computations need to be done. So a first attempt to use Rayon with **TFHE-rs** might look like this:

```rust
use rayon::prelude::*;

use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand All @@ -31,7 +31,7 @@ fn main() {

// set_server_key in each closure as they might be
// running in different threads
let (a, b) = rayon::join(
let (_a, _b) = rayon::join(
|| {
set_server_key(sks.clone());
&xs[0] + &ys[0]
Expand All @@ -51,7 +51,7 @@ However, due to Rayon's work-stealing mechanism and **TFHE-rs'** internals, this
The correct way is to call `rayon::broadcast` as follows:

```rust
use rayon::prelude::*;

use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand Down Expand Up @@ -95,7 +95,7 @@ fn main() {
For applications that need to operate concurrently on data from different clients and require each client to use multiple threads, you need to create separate Rayon thread pools:

```rust
use rayon::prelude::*;

use tfhe::prelude::*;
use tfhe::{ConfigBuilder, set_server_key, FheUint8, generate_keys};

Expand Down
4 changes: 2 additions & 2 deletions tfhe/docs/guides/zk-pok.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
set_server_key(server_key);

// Verify the ciphertexts
let mut expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key)?;
let expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key)?;
let a: tfhe::FheUint64 = expander.get(0).unwrap()?;
let b: tfhe::FheUint64 = expander.get(1).unwrap()?;

Expand Down Expand Up @@ -115,7 +115,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
set_server_key(server_key);

// Verify the ciphertexts
let mut expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key)?;
let expander = proven_compact_list.verify_and_expand(public_zk_params, &public_key)?;
let a: tfhe::FheUint64 = expander.get(0).unwrap()?;
let b: tfhe::FheUint64 = expander.get(1).unwrap()?;

Expand Down
38 changes: 17 additions & 21 deletions tfhe/docs/references/fine-grained-apis/boolean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {

// We generate the client key and the server key,
// using the default parameters:
let (client_key, server_key): (ClientKey, ServerKey) = gen_keys();
let (_client_key, _server_key): (ClientKey, ServerKey) = gen_keys();
}
```

Expand All @@ -44,7 +44,7 @@ fn main() {
//---------------------------- CLIENT SIDE ----------------------------

// We generate a client key and a server key, using the default parameters:
let (client_key, server_key) = gen_keys();
let (_client_key, server_key) = gen_keys();

// We serialize the server key to bytes, and store them in a file:
let encoded: Vec<u8> = bincode::serialize(&server_key).unwrap();
Expand Down Expand Up @@ -76,7 +76,7 @@ fn main() {
file.read_to_end(&mut encoded).expect("failed to read key");

// We deserialize the server key:
let key: ServerKey = bincode::deserialize(&encoded[..])
let _key: ServerKey = bincode::deserialize(&encoded[..])
.expect("failed to deserialize");
}
```
Expand All @@ -99,8 +99,8 @@ fn main() {
let ct_2 = client_key.encrypt(false);

// We serialize the ciphertexts:
let encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();
let _encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let _encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();

// ...
// And we send them to the server somehow
Expand Down Expand Up @@ -128,8 +128,8 @@ fn main() {
let ct_2 = public_key.encrypt(false);

// We serialize the ciphertexts (if not on the server already):
let encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();
let _encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let _encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();

// ...
// And we send them to the server to be deserialized (if not on the server already)
Expand All @@ -142,8 +142,6 @@ fn main() {
Once the encrypted inputs are on the **server side**, the `server_key` can be used to homomorphically execute the desired Boolean circuit:

```rust
use std::fs::File;
use std::io::{Write, Read};
use tfhe::boolean::prelude::*;

fn main() {
Expand All @@ -154,28 +152,28 @@ fn main() {
let encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
let encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();

//---------------------------- ON SERVER SIDE ----------------------------
//---------------------------- ON SERVER SIDE ----------------------------

// We deserialize the ciphertexts:
// We deserialize the ciphertexts:
let ct_1: Ciphertext = bincode::deserialize(&encoded_1[..])
.expect("failed to deserialize");
let ct_2: Ciphertext = bincode::deserialize(&encoded_2[..])
.expect("failed to deserialize");

// We use the server key to execute the boolean circuit:
// if ((NOT ct_2) NAND (ct_1 AND ct_2)) then (NOT ct_2) else (ct_1 AND ct_2)
// We use the server key to execute the boolean circuit:
// if ((NOT ct_2) NAND (ct_1 AND ct_2)) then (NOT ct_2) else (ct_1 AND ct_2)
let ct_3 = server_key.not(&ct_2);
let ct_4 = server_key.and(&ct_1, &ct_2);
let ct_5 = server_key.nand(&ct_3, &ct_4);
let ct_6 = server_key.mux(&ct_5, &ct_3, &ct_4);

// Then we serialize the output of the circuit:
let encoded_output: Vec<u8> = bincode::serialize(&ct_6)
// Then we serialize the output of the circuit:
let _encoded_output: Vec<u8> = bincode::serialize(&ct_6)
.expect("failed to serialize output");

// ...
// And we send the output to the client
// ...
// ...
// And we send the output to the client
// ...
}
```

Expand All @@ -184,13 +182,11 @@ fn main() {
Once the encrypted output is on the client side, the `client_key` can be used to decrypt it:

```rust
use std::fs::File;
use std::io::{Write, Read};
use tfhe::boolean::prelude::*;

fn main() {
// Don't consider the following lines; you should follow the procedure above.
let (client_key, server_key) = gen_keys();
let (client_key, _server_key) = gen_keys();
let ct_6 = client_key.encrypt(true);
let encoded_output: Vec<u8> = bincode::serialize(&ct_6).unwrap();

Expand Down
7 changes: 4 additions & 3 deletions tfhe/docs/references/fine-grained-apis/boolean/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ You can also create your own set of parameters. This is an `unsafe` operation as
use tfhe::boolean::prelude::*;

fn main() {
// WARNING: might be insecure and/or incorrect
// You can create your own set of parameters
let parameters = unsafe {
// WARNING: might be insecure and/or incorrect
// You can create your own set of parameters
#[allow(unused_unsafe)]
let _parameters = unsafe {
BooleanParameters::new(
LweDimension(586),
GlweDimension(2),
Expand Down
Loading

0 comments on commit c6231ed

Please sign in to comment.