ton icon indicating copy to clipboard operation
ton copied to clipboard

WASM version of FunC chokes on large enough contracts

Open anton-trunov opened this issue 1 year ago • 1 comments
trafficstars

I'm using the func-js NPM package (version 0.7) to demonstrate the issue with the WASM build of FunC:

❯ npx func-js --fift test.fif test.fc 
Compiling using func v0.4.4
File not found
❯ echo $?
1
❯ ls test.fif                
"test.fif": No such file or directory (os error 2)

I expect this to compile just fine, because the binary version of FunC 0.4.4 does it (I got it here: https://github.com/ton-blockchain/ton/releases/download/v2024.04/func-mac-arm64):

❯ func -o test.fif test.fc
❯ echo $?
0
❯ ls test.fif 
test.fif

Here is the link to the GitHub gist with test.fc from above: https://gist.github.com/anton-trunov/3fc93a6f4fd36a6e2c07971d907c54e5.

I managed to find a workaround for this issue for Tact: https://github.com/tact-lang/tact/pull/297. I compiled a patched version of funcfiftlib by changing the argument to PSTRING() here: https://github.com/ton-blockchain/ton/blob/4cfe1d1a96acf956e28e2bbc696a143489e23631/crypto/fift/utils.cpp#L215-L216. Instead of using the << operator to concatenate those strings I did that using std::string's concatenation operator. I did that because when debugging the issue I discovered that create_source_lookup gets a truncated string with Fift code (compared to the one we get in the asm_code function parameter).

anton-trunov avatar Apr 25 '24 12:04 anton-trunov

@tolk-vm This issue still persists for FunC 0.4.6:

❯ npx func-js --fift wasm_test.fif wasm_test.fc
Compiling using func v0.4.6
wasm://wasm/0150db3e:1


RuntimeError: table index is out of bounds
    at wasm://wasm/0150db3e:wasm-function[4278]:0x190c4c
    at invoke_iiiiii (/usr/local/lib/node_modules/@ton-community/func-js/node_modules/@ton-community/func-js-bin/dist/funcfiftlib.js:8:111218)
    at wasm://wasm/0150db3e:wasm-function[198]:0x11ab4
    at wasm://wasm/0150db3e:wasm-function[1306]:0x6739e
    at invoke_iii (/usr/local/lib/node_modules/@ton-community/func-js/node_modules/@ton-community/func-js-bin/dist/funcfiftlib.js:8:110914)
    at wasm://wasm/0150db3e:wasm-function[7528]:0x2344de
    at invoke_viiiii (/usr/local/lib/node_modules/@ton-community/func-js/node_modules/@ton-community/func-js-bin/dist/funcfiftlib.js:8:110125)
    at wasm://wasm/0150db3e:wasm-function[6503]:0x1efefc
    at invoke_iii (/usr/local/lib/node_modules/@ton-community/func-js/node_modules/@ton-community/func-js-bin/dist/funcfiftlib.js:8:110914)
    at wasm://wasm/0150db3e:wasm-function[6502]:0x1ebbad

Node.js v22.2.0

You can reproduce it using the updated version (0.4.4 -> 0.4.6) of the test case in the original post: https://gist.github.com/anton-trunov/3fc93a6f4fd36a6e2c07971d907c54e5

anton-trunov avatar Dec 22 '24 13:12 anton-trunov