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

Compiling Wasm with Rust 1.70 leads to unsupported Wasm opcodes #1727

Closed
webmaster128 opened this issue Jun 15, 2023 · 10 comments
Closed

Compiling Wasm with Rust 1.70 leads to unsupported Wasm opcodes #1727

webmaster128 opened this issue Jun 15, 2023 · 10 comments
Milestone

Comments

@webmaster128
Copy link
Member

When compiling a CosmWasm contract with Rust 1.70 (and above?) to Wasm, instructions are emitted that cause the following error:

Wasm bytecode could not be deserialized. Deserialization error: "Unknown opcode 192"

or

Wasm bytecode could not be deserialized. Deserialization error: "Unknown opcode 194"

This referes to C0-C4 in this overview, i.e. the sign extension of Wasm.

See also use-ink/cargo-contract#1139.

Until this resolved, using Rust 1.69.0 is the recommended way. This is also the version used in the latest rust-optimizer/workspace-optimizer.

@hashedone
Copy link
Contributor

Also, keep an eye on: rust-lang/rust#109807

@aeryz
Copy link

aeryz commented Jun 19, 2023

We had this issue with the compiler versions 1.70+ but compiling with this command seem to fix it:

RUSTFLAGS='-C target-feature=-sign-ext -C link-arg=-s -C target-cpu=mvp' cargo -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort build --release --lib --target wasm32-unknown-unknown

@webmaster128
Copy link
Member Author

I think we just make sure to support the sign extension from 1.3 onwards

@mikedotexe
Copy link

mikedotexe commented Jun 19, 2023

Since I rarely do toolchain customization, thought I'd drop a comment on how I'm dealing with this. Perhaps saves someone a couple minutes:

rustup install 1.69.0
rustup default 1.69.0

# Then when things are ironed out, set it back
rustup default stable

@webmaster128
Copy link
Member Author

Can you confirm that 1.69.0 works well? I just realized that the current rust-optimizer is on 1.68.2 and not yet 1.69.0. Is it safe to bump it to 1.69.0?

@mikedotexe
Copy link

Is it safe to bump it to 1.69.0?

Yes, I just double-checked on Juno testnet with a simple contract juno1vll4rksrtkemyvqxmff5a2r9s68px4alqud9wafvzm3m0c5ldm2s2ly243 using the 0.13.0 version from here https://hub.docker.com/layers/cosmwasm/rust-optimizer/0.13.0/images/sha256-2658caa839184c90b93e3ef5d5da0ab091f9e773492faa4b41b30f8973c62651?context=explore

Tested by optimizing, storing, instantiating, doing a contract execution and query, and confirming state changed as I expected.

shapeshed added a commit to InstrumentalFi/instrumental-contracts that referenced this issue Jun 21, 2023
shapeshed added a commit to InstrumentalFi/instrumental-contracts that referenced this issue Jun 23, 2023
* Add osmosis implementation

* Working instantiation

* Update instantiation test

* Add deposit test

* Set rust version to 1.69

CosmWasm/cosmwasm#1727

* Revert "Set rust version to 1.69"

This reverts commit 96871d4.

* Set toolchain version to 1.69.0

* Add additional deposit test

* Add failing test

* Fix fmt errors

* commit

* Add rewards test

* Remove summary

* Add further tests

---------

Co-authored-by: Max <[email protected]>
@webmaster128
Copy link
Member Author

Done in #1743. Will be shipped as part of 1.3.

@webmaster128
Copy link
Member Author

webmaster128 commented Jul 22, 2023

A workaround for CosmWasm < 1.3 is using --signext-lowering in wasm-opt. rust-optimizer does not do that yet but could do so.

assafmo added a commit to scrtlabs/SecretNetwork that referenced this issue Aug 6, 2023
Starting from v1.70, Rust uses the Wasm sign extenstion opcodes when comipling to Wasm. Our Wasm parser for static analysis had to be updated in order to correctly parse these opcodes.

Refs:
- https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md
- CosmWasm/cosmwasm#1727
- CosmWasm/cosmwasm#1743
assafmo added a commit to scrtlabs/SecretNetwork that referenced this issue Aug 6, 2023
Starting from v1.70, Rust uses the Wasm sign extension opcodes when compiling to Wasm. Our Wasm parser for static analysis had to be updated in order to correctly parse these opcodes.

Refs:
- CosmWasm/cosmwasm#1727
- CosmWasm/cosmwasm#1743
- https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md
assafmo added a commit to scrtlabs/SecretNetwork that referenced this issue Aug 8, 2023
Starting from v1.70, Rust uses the Wasm sign extenstion opcodes when comipling to Wasm. Our Wasm parser for static analysis had to be updated in order to correctly parse these opcodes.

Refs:
- https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md
- CosmWasm/cosmwasm#1727
- CosmWasm/cosmwasm#1743
assafmo added a commit to scrtlabs/SecretNetwork that referenced this issue Aug 8, 2023
Starting from v1.70, Rust uses the Wasm sign extenstion opcodes when comipling to Wasm. Our Wasm parser for static analysis had to be updated in order to correctly parse these opcodes.

Refs:
- https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md
- CosmWasm/cosmwasm#1727
- CosmWasm/cosmwasm#1743
@apollo-sturdy
Copy link

I'm still getting this issue when compiling with cargo build --release --lib --target wasm32-unknown-unknown. What's the proper way to deal with this when not using rust-optimizer?

@webmaster128
Copy link
Member Author

What's the proper way to deal with this when not using rust-optimizer?

One of:

  • Upgrade your chain to wasmd that includes wasmvm 1.3 or 1.4 to support the new instructions
  • Run .wasm file through wasm-opt with --signext-lowering (e.g. here) to avoid the new instructions

taitruong added a commit to arkprotocol/cw-nfts that referenced this issue Jun 13, 2024
seinj0312 added a commit to seinj0312/cw-nft that referenced this issue Jun 30, 2024
dirtyshab added a commit to palletexchange/cw-nfts-ALPAC-4 that referenced this issue Jul 8, 2024
* rename states: tokens -> nft_info, contract_info -> collection_info

* renamed structs and deprecate: TokenInfo -> NftInfo, ContractInfo -> CollectionInfo, ContractInfoResponse -> CollectionInfoResponse

* cargo schema

* change storage keys for collection info and nft info, consider in migration and keep legacy data for backward migration

* use PA repo for `cw-ownable`

* rename generics and make more readable

* CollectionInfoResponse -> CollectionInfo

* add CollectionInfoExtension with RoyaltyInfo

* cargo schema

* typo

* cleanup

* rename

* cargo schema

* cleanup

* creator and owner changes:
- new query GetMinterOwnership and GetCreatorOwnership, deprecated Ownership
- new execute UpdateMinterOwnership and UpdateCreatorOwnership, deprecate UpdateOwnership
- dedicated stores for minter and creator, where creator usess by default cw_ownable singleton!
- new migrate msg allowing to reset creator and minter
- cleanup migration and split legacy part to dedicated functions
- also make sure using decicated CREATOR and MINTER stores and NOT use cw_ownable::...

* refactor and move key logic to cw721 package:
- move logic from cw721-base to cw721
- merge cw721-base and cw721-metadata-onchain into one, distinction is: `extension: T` where T for base contract is `type DefaultMetadataExtension = Option<Metadata>`
- all logic now in default implementation for traits Cw721Execute and Cw721Query

* fix ci

* cargo fmt

* cargo fmt + clippy

* cargo fmt

* cargo schema

* cargo clippy

* undo: do not rename token keys

* fix unit test

* remove useless generic `TMetadataResponse`

* remove response structs to msg.rs

* cargo schema

* move to dedicated fn

* docs

* rename

* cargo clippy

* add build script

* undo collection info extension and royalty info additions, will be added in next pr

* cleanup

* generate schemas for entry points, cleanup

* update rustc 1.65 -> 1.71

* update cosmwasm version 1.2 -> 1.5, due to rustc compiler issues
see also: CosmWasm/cosmwasm#1727

* update optimizer

* update rustc 1.71 -> 1.78

* use optimizer

* formatting

* install rustup first

* set $HOME/.cargo/env

* install libgcc

* install build-base

* cleanup

* cleanup

* Sync cw1155 with upstream (#5)

* wip: sync up cw1155 with upstream improvements from cw-awesome

* fix build errors/tests

---------

Co-authored-by: mr-t <[email protected]>
M-Killer-dev added a commit to M-Killer-dev/cosmwasm-nft that referenced this issue Sep 9, 2024
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

5 participants