ton-blockchain / ton

Main TON monorepo
Other
2.95k stars 891 forks source link

func compiler generates incorrect FIFT assembly for `*1` multiplication by 1 #142

Closed dosvidos closed 4 years ago

dosvidos commented 4 years ago

The following func code

int flags = 1; ;; pending
int _expires = now() + expires * 3600 * 24 * 1;

is compiled into

        1 PUSHINT
        NOW
        s0 s3 XCHG
        3600 PUSHINT
        MUL
        24 MULCONST
        0 LSHIFT#
        s1 s3 XCHG
        ADD

that fails with an exception

[ 1][t 0][1571041340.665374041][words.cpp:2906] contract.fif:301: LSHIFT#: integer does not fit into cell As TVM doesn't have a command for left shift by 0

ton-blockchain commented 4 years ago

This is indeed a bug in the implementation of multiplication by 1, to be fixed in a subsequent commit. Thanks!

By the way, if you write expires * (3600 * 24 * 1) instead of expires * 3600 * 24 * 1, the resulting code will be more efficient.

dosvidos commented 4 years ago

You're welcome, thanks for the advice!

ton-blockchain commented 4 years ago

Fixed in commit 9c9248a9ae1791152d88c9c36574b4becdf5e8b6