CosmWasm / wasmvm

Go bindings to the running cosmwasm contracts with wasmer
Apache License 2.0
173 stars 99 forks source link

Protobuf encoding on cosmwasm contract #431

Closed jununifi closed 1 year ago

jununifi commented 1 year ago

We are building ICA cosmwasm contract that connect to icahost port of other Cosmos chain without any specific wasm binding. So far, we were able to create ICA account on other chain through IBC channel creation.

cosmrs package supports Cosmos messages protobuf encoding in rust and was going to use this for ICA tx message broadcasting.

use cosmrs::proto::cosmos::base::v1beta1::Coin as ProtoCoin;
use cosmrs::proto::cosmos::staking::v1beta1::MsgDelegate;

We will need to support infinite number of protobuf encodings that are not default Cosmos messages as well, and it's hard to support all of these messages in wasm binding.

When using cosmrs package we get following issue when trying to deploy the contract.

Error: rpc error: code = Unknown desc = rpc error: code = Unknown desc = failed to execute message; message index: 0: Error calling the VM: Error during static Wasm validation: Wasm contract requires unsupported import: "__wbindgen_placeholder__.__wbindgen_describe". Required imports: {"__wbindgen_externref_xform__.__wbindgen_externref_table_grow", "__wbindgen_externref_xform__.__wbindgen_externref_table_set_null", "__wbindgen_placeholder__.__wbindgen_describe", ... 16 more}. Available imports: ["env.abort", "env.db_read", "env.db_write", "env.db_remove", "env.addr_validate", "env.addr_canonicalize", "env.addr_humanize", "env.secp256k1_verify", "env.secp256k1_recover_pubkey", "env.ed25519_verify", "env.ed25519_batch_verify", "env.debug", "env.query_chain", "env.db_scan", "env.db_next"].: create wasm contract failed [CosmWasm/wasmd@v0.40.0/x/wasm/keeper/keeper.go:182] With gas wanted: '18446744073709551615' and gas used: '2725435' : unknown request

Adding the version info for more details

prost = "0.11"
prost-types = "0.11"
cosmrs = "0.14.0"
cosmwasm-std = { version = "1.2.5", features = ["stargate"] }

wasmd version - v0.40.0 for the chain

Is there any specific way to resolve this issue with version management or is it unsupported?

If it is intended to be supported, we can provide the path to reproduce the issue.

webmaster128 commented 1 year ago

I filed https://github.com/cosmos/cosmos-rust/issues/407 which basically says that in its current form cosmrs cannot be used in CosmWasm. But maybe https://github.com/cosmos/cosmos-rust/tree/main/cosmos-sdk-proto is sufficient? This has fewer dependencies.

webmaster128 commented 1 year ago

Closing as out of scope for this repository. I think cosmos-rust is a better place to discuss the two crates.

In general, wasm-bindgen cannot be used in CosmWasm since it is only for Wasm in a JavaScript environment such as browsers.

ethanfrey commented 1 year ago

The key problematic lines in cosmrs are: https://github.com/cosmos/cosmos-rust/blob/main/cosmrs/Cargo.toml#L31-L32 which brings in randomness.

This is needed to sign a transaction (which is the main purpose of the cosmrs crate). It is not needed to parse a transaction nor to verify a signature. I would suggest looking just at the proto types in cosmos-sdk-proto for parsing, and if a few items are missing (Any lookups), copy one or two files from cosmrs to your local repo.