Skip to content

FunC incorrectly optimizes comparison with >> #1651

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
i582 opened this issue May 7, 2025 · 1 comment
Open

FunC incorrectly optimizes comparison with >> #1651

i582 opened this issue May 7, 2025 · 1 comment

Comments

@i582
Copy link

i582 commented May 7, 2025

Based on tact-lang/tact#2997 and tact-lang/tact#3000

Code to reproduce

int calc(int a) {
    return ((-1 >> a) <= 1);
}

() main() {
    throw_if(10, calc(10));
}

Output Fift

// automatically generated from `main.fc` 
DECLPROC calc
DECLPROC main
calc PROC:<{
+  DROP
+  TRUE
}>
main PROC:<{
  10 PUSHINT
  calc CALLDICT
  10 THROWIF
}>

Actual behavior when executed

calc always returns true.

Expected behavior when executed

Exit code 5.

Expected Fift:

// ((-1 >> $x) <= 1)
-1 PUSHINT
RSHIFTR
1 PUSHINT
GEQ
stack: [ 0 ] 
code cell hash: 834281813603E0B565FBDF8AF01056331FF4A155ADC26ADAD53BB69C2D9E00CA offset: 0
execute SETCP 0
gas remaining: 9999974
stack: [ 0 ] 
code cell hash: 834281813603E0B565FBDF8AF01056331FF4A155ADC26ADAD53BB69C2D9E00CA offset: 16
execute PUSHINT 10
gas remaining: 9999948
stack: [ 0 10 ] 
code cell hash: 834281813603E0B565FBDF8AF01056331FF4A155ADC26ADAD53BB69C2D9E00CA offset: 32
execute PUSHINT -1
gas remaining: 9999930
stack: [ 0 10 -1 ] 
code cell hash: 834281813603E0B565FBDF8AF01056331FF4A155ADC26ADAD53BB69C2D9E00CA offset: 40
execute SHR/MOD 5,-1
handling exception code 5: integer out of range
default exception handler, terminating vm with exit code 5
@jeshecdom
Copy link

The same happens for operators ~>>, ^>>. The following expressions are mapped to TRUE:

((-1 ~>> a) <= 1)
((-1 ^>> a) <= 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants