Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

wasm Compiled from TcpStream::connect Cannot be Deserialized in Storing #546

Closed
loloicci opened this issue Sep 24, 2020 · 8 comments
Closed
Milestone

Comments

@loloicci
Copy link
Contributor

loloicci commented Sep 24, 2020

wasm compiled from rust code including TcpStream::connect cannot be stored in the chain (this is as expected) and issues "Deserialization error".

create wasm contract failed: Error calling the VM: Error during static Wasm validation: Wasm bytecode could not be deserialized. Deserialization error: "I/O Error: UnexpectedEof"

This error is caused when I try to store the wasm generated by https://github.com/loloicci/cosmwasm-contract-net.

This should be other errors like "Validation error with non-deterministic op-code".

@webmaster128
Copy link
Member

This is interesting because

Wasm bytecode could not be deserialized. Deserialization error: "I/O Error: UnexpectedEof"

means the .wasm file is broken (or at least incompatible to what the VM understand). Can you write down the exact steps build the .wasm file (please update rust-optimizer to 0.9.1 which ships a slightly updated Rust compiler)?

@loloicci
Copy link
Contributor Author

This is happened with

docker run --rm -v "$(pwd)":/code \                                                                                          
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.9.0

When I use 0.9.1, it does not happen.

However, It can be stored and when I execute update (uses TcpStream::connect), it looks always fail to connect (returns Err(some)).
Is this behavior as expected? I think this should be judged as an invalid contract and not be stored.

@loloicci
Copy link
Contributor Author

When I use ureq in code and compile with rust-optimizer 0.9.1, the same issue (Deserialization error) is reproduced.

https://github.com/loloicci/cosmwasm-contract-net/tree/ureq

@webmaster128
Copy link
Member

webmaster128 commented Sep 24, 2020

Is this behavior as expected? I think this should be judged as an invalid contract and not be stored.

It is very well possible that the missing system calls are compiled to panics or traps when the target architecture is Wasm. The Wasm sandbox does not provide access to system APIs that would cause undeterministic behaviour. There are no Wasm ops codes for such calls, so we cannot detect that statically. In this case, the primary problem is #501.

Deserialization errors is a different story. This smells like a problem.

@loloicci
Copy link
Contributor Author

loloicci commented Sep 24, 2020

There are no Wasm ops codes for such calls, so we cannot detect that statically. In this case, the primary problem is #501.

Thank you. I did not know that. This sounds related to #530 .

However, it looks there are some differences between #530 and this.
wasmer issues error in #530 and Err(Something) is returned in this case.
Is it a natural thing?

@ethanfrey ethanfrey added this to the 0.12.0 milestone Sep 27, 2020
@loloicci
Copy link
Contributor Author

I found that too large wasm binary causes the same error. (UnexpectedEof)

When I use ureq in code and compile with rust-optimizer 0.9.1, the same issue (Deserialization error) is reproduced.

It may due to the size of the output wasm is too large.

Does anyone know the maximum size wasmd can treat? This is maybe about 410KB as far as I tried.

@webmaster128
Copy link
Member

webmaster128 commented Oct 14, 2020

We discovertred recently that wasmd has a bug which truncates wasm blobs after 400 KB without an error message. See CosmWasm/wasmd#287. If your wasm was larger than that, this explains the

Deserialization error: "I/O Error: UnexpectedEof"

It will be fixed in wasmd. Can this issue be closed or is there anything else left?

@loloicci
Copy link
Contributor Author

It will be fixed in wasmd. Can this issue be closed or is there anything else left?

All of this is solved. Thank you! We can close this issue.

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

No branches or pull requests

3 participants