Skip to content

FunC reports overflow in expressions that would not produce overflows at runtime #2803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeshecdom opened this issue Apr 15, 2025 · 0 comments
Labels
activity: found-by-fuzzing Do not add! Issues found by fuzzer by previous project.

Comments

@jeshecdom
Copy link
Contributor

jeshecdom commented Apr 15, 2025

Using the expression fuzzer, we have found a couple of compilation examples where FunC reports an overflow on expressions that would not produce an overflow if executed.
In fact, when such expressions are executed in the interpreter, the interpreter does not report an overflow and produces the correct result.

contract A {

   get fun test(): Int {
      // 2^256 - 45
      let int1 = 115792089237316195423570985008687907853269984665640564039457584007913129639891;
      // false case will execute, and it is less than 2^256-1
      let res = (int1 != int1) ? (int1 + int1) : 33321583122581966542555556347793674561846130234625845898374435335324439320969;  
      return res;
   }
}

with error message:

> A: tact compiler
> A: func compiler
FunC compilation error: cannot generate code for function `$A$_fun_test`:
/test_A.fc:56:43: error: integer overflow
      int $res = (($int1 != $int1) ? ($int1 + $int1) : 33321583122581966542555556347793674561846130234625845898374435335324439320969);
💥 Compilation failed. Skipping packaging

And this other example:

contract A {

   get fun test(): Int {
      // 2^255
      let int1 = 57896044618658097711785492504343953926634992332820282019728792003956564819968;
      // true case will execute
      let res = int1 == int1 ? int1 : int1 + int1;  
      return res;
   }
}

with similar error message:

> A: tact compiler
> A: func compiler
FunC compilation error: cannot generate code for function `$A$_fun_test`:
/test_A.fc:56:51: error: integer overflow
      int $res = (($int1 == $int1) ? $int1 : ($int1 + $int1));
💥 Compilation failed. Skipping packaging

This issue is related to div by zero issue #716, since that issue reports an example where FunC produces a div by zero error on an expression that would not produce a div by zero at runtime.

@anton-trunov anton-trunov added the activity: found-by-fuzzing Do not add! Issues found by fuzzer by previous project. label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
activity: found-by-fuzzing Do not add! Issues found by fuzzer by previous project.
Projects
None yet
Development

No branches or pull requests

2 participants