Skip to content
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

Error happened while deserializing the module (stop using parity_wasm) #8358

Open
petersalomonsen opened this issue Jan 14, 2023 · 3 comments
Labels
community Issues created by community

Comments

@petersalomonsen
Copy link

petersalomonsen commented Jan 14, 2023

Describe the bug

When calling any contract deployed with emscripten or optimized by binaryen after the WebAssembly sign-ext features where introduced you'll get the error "Error happened while deserializing the module"

This is because nearvm use of parity_wasm parser which does not recognize the sign-ext WebAssembly opcodes.

To Reproduce
Deploy a contract with wasm opcode 192 (0xC0) i32.extend8_s

Expected behavior
nearvm should not fail to deserialize the module

Screenshots
image

Version (please complete the following information):

  • testnet as of 2023-01-14

Additional context
To mitigate the problem for now it's possible to use wasm-opt (from binaryen) on the WebAssembly binary file with the --signext-lowering option.

See how it was mitigated in my use case here:

image

petersalomonsen/quickjs-rust-near@8168133

@nagisa
Copy link
Collaborator

nagisa commented Jan 15, 2023

Currently we only support the wasm-core-1 specification and nothing more. This is true across the runtime stack and isn’t a limitation imposed by just pwasm_utils/parity_wasm alone.

I would expect the compilers to provide the options on which extensions are usable by the target. Rust/LLVM, for example, allow toggling many of them pretty much arbitrarily (exceptions are things like the threads proposal which affects how the standard library is compiled and requires a new target). As far as Emscripten is concerned, there appears to be a -msimd128 to enable the SIMD proposal and I would imagine -mno-simd128 to disable it. I would be surprised if there isn’t something similar for signext proposal too.

The finite-wasm work that we’re looking to land this upcoming quarter (so~on) will replace pwasm-utils code and does have the code to support many more webassembly extensions, but we'll still need to implement the proposals throughout the rest of the pipeline. Doing so may require NEPs for each extension and thus the process may end up taking a significant amount of time while those processes conclude.

@petersalomonsen
Copy link
Author

thanks! I noticed that both wasmparser and parity_wasm is used for deserializing the contract and without checking further thought that parity_wasm (which seems to be archived) was something left from earlier days. But if it is as you say that the wasm runtime used does not support these instructions then I understand it's a bit more work involved.

For the sign-ext opcodes, it seems quite easy to mitigate using wasm-opt with the --signext-lowering option.

petersalomonsen added a commit to petersalomonsen/quickjs-rust-near that referenced this issue Jan 27, 2023
NFT webapp: show nft owner thumbnail from near.social
smaller quickjs libraries for smaller contract
signext lowering for targeting wasm 1.0 spec ( near/nearcore#8358 )
@MantisClone
Copy link

I searched for ways to disable the sign-ext opcodes on the compiler and ran across this issue that seems to indicate that the option to disable sign-ext exists 👍 but that it's not working. 😢 rust-lang/rust#109807

Thus, I will likely pursue the wasm-opt --signext-lowering approach.

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

No branches or pull requests

4 participants