From 456e1952f58a5aa23e44e55ecf72484fd6003e71 Mon Sep 17 00:00:00 2001 From: rudy Date: Thu, 12 Jan 2023 10:31:27 +0100 Subject: [PATCH] fix: not private side effect in woppbs wrapper Fix #865 --- compiler/lib/Runtime/wrappers.cpp | 6 +++++- .../end_to_end_fixture/tests_cpu/bug_865.yaml | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 compiler/tests/end_to_end_fixture/tests_cpu/bug_865.yaml diff --git a/compiler/lib/Runtime/wrappers.cpp b/compiler/lib/Runtime/wrappers.cpp index de7ca1c29..30a6ab429 100644 --- a/compiler/lib/Runtime/wrappers.cpp +++ b/compiler/lib/Runtime/wrappers.cpp @@ -536,13 +536,17 @@ void memref_wop_pbs_crt_buffer( auto extract_bits_output_buffer = new uint64_t[lwe_small_size * total_number_of_bits_per_block]{0}; + // We make a private copy to apply a subtraction on the body + auto first_cyphertext = in_aligned + in_offset; + auto copy_size = crt_decomp_size * lwe_big_size; + std::vector in_copy(first_cyphertext, first_cyphertext + copy_size); // Extraction of each bit for each block for (int64_t i = crt_decomp_size - 1, extract_bits_output_offset = 0; i >= 0; extract_bits_output_offset += number_of_bits_per_block[i--]) { auto nb_bits_to_extract = number_of_bits_per_block[i]; auto delta_log = 64 - nb_bits_to_extract; - auto in_block = &in_aligned[lwe_big_size * i + in_offset]; + auto in_block = &in_copy[lwe_big_size * i]; // trick ( ct - delta/2 + delta/2^4 ) uint64_t sub = (uint64_t(1) << (uint64_t(64) - nb_bits_to_extract - 1)) - diff --git a/compiler/tests/end_to_end_fixture/tests_cpu/bug_865.yaml b/compiler/tests/end_to_end_fixture/tests_cpu/bug_865.yaml new file mode 100644 index 000000000..5f3191325 --- /dev/null +++ b/compiler/tests/end_to_end_fixture/tests_cpu/bug_865.yaml @@ -0,0 +1,16 @@ +description: bug_865_due_to_side_effect_in_woppbs +program: | + func.func @main(%arg0: !FHE.eint<16>, %arg1: !FHE.eint<16>) -> !FHE.eint<16> { + %cst = arith.constant dense<0> : tensor<65536xi64> + %0 = "FHE.apply_lookup_table"(%arg0, %cst) : (!FHE.eint<16>, tensor<65536xi64>) -> !FHE.eint<16> + %1 = "FHE.add_eint"(%0, %arg0) : (!FHE.eint<16>, !FHE.eint<16>) -> !FHE.eint<16> + %2 = "FHE.apply_lookup_table"(%1, %cst) : (!FHE.eint<16>, tensor<65536xi64>) -> !FHE.eint<16> + return %2 : !FHE.eint<16> + } +encoding: crt +tests: + - inputs: + - scalar: 0 + - scalar: 0 + outputs: + - scalar: 0