diff --git a/compilers/concrete-compiler/compiler/lib/Runtime/simulation.cpp b/compilers/concrete-compiler/compiler/lib/Runtime/simulation.cpp index f89318d535..021f301ac6 100644 --- a/compilers/concrete-compiler/compiler/lib/Runtime/simulation.cpp +++ b/compilers/concrete-compiler/compiler/lib/Runtime/simulation.cpp @@ -183,9 +183,19 @@ void sim_wop_pbs_crt( uint64_t sim_neg_lwe_u64(uint64_t plaintext) { return ~plaintext + 1; } -uint64_t sim_add_lwe_u64(uint64_t lhs, uint64_t rhs) { return lhs + rhs; } +uint64_t sim_add_lwe_u64(uint64_t lhs, uint64_t rhs) { + if (lhs > UINT64_MAX - rhs) { + printf("WARNING: overflow happened during addition in simulation\n"); + } + return lhs + rhs; +} -uint64_t sim_mul_lwe_u64(uint64_t lhs, uint64_t rhs) { return lhs * rhs; } +uint64_t sim_mul_lwe_u64(uint64_t lhs, uint64_t rhs) { + if (rhs != 0 && lhs > UINT64_MAX / rhs) { + printf("WARNING: overflow happened during multiplication in simulation\n"); + } + return lhs * rhs; +} void sim_encode_expand_lut_for_boostrap( uint64_t *out_allocated, uint64_t *out_aligned, uint64_t out_offset,