Skip to content

Commit

Permalink
feat(compiler): warn when there is overflow in simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Apr 4, 2024
1 parent e9dcc20 commit 5abf580
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions compilers/concrete-compiler/compiler/lib/Runtime/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5abf580

Please sign in to comment.