-
Notifications
You must be signed in to change notification settings - Fork 27
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
no_std
support
#26
no_std
support
#26
Conversation
dzmitry-lahoda
commented
Dec 25, 2022
•
edited
Loading
edited
- requires [2.0] no_std support cosmwasm#1716
2998f84
to
74ffc89
Compare
|
Thank you for working on this. What exactly is your goal with having |
i want to execute party dotsama |
@chipshort i am trying to run CW contracts codebase(serde_json_wasm, sw-plus, cw-std, cw-storage-plus) in Substrate runtime. Currently there is no way to compile any CW stuff to no_std environment. Basically CW really no_std, but import STD stuff. That leads to conflict with no_std libs importing their own alloc stuff. I want to some compile CW codes (for precompiles on top of Substrate modules), but cannot because of
in whole stack. |
likely direct usage of alloc will work, but need to make it to be used in. ok with that. but i am not sure if that will be risk no to work in some case. cw-std and check on CI it does not violates. this will allow to run CW on more chains. @ethanfrey will you accept such patches to ALL packages? you mentioned it is not prio for you to expand CW to other chain previosly. did anything changed? |
@dzmitry-lahoda can you explain your usecase more? https://github.com/ComposableFi/ has written a substrate pallet that runs cosmwasm contracts (the contracts are imported as wasm, and can use the full std... the pallet is no-std) This is the most obvious integration and is already done. It is live on https://www.picasso.xyz But I am guessing you want something else? You want to embed contracts directly in a pallet? Why? As pallets don't allow permissionless uploading, which is a major purpose of cosmwasm. |
In general, I do not want to take on larger patches that increase the maintainability of all packages and users for one niche use case (or someone's personal experiment). If you can convince me this is an important use-case, I would consider. |
technical use case is to create contract which can dispatch scale encoded transaction to pallets, but i cannot compile auch contract if i mix parity and cw crates. other use case, share some code, like ibc or manually coded adapter to imitate contract to real cw contracts. i cannot share code too. have to maintain forks. solution which parity uses is no std feature flags. same can be for other no std like near or solana 9r even offchain wasm cloud stuff. i guess. the thing is that cw does no std, wasm specifically, not in mainline with official rust wasm support. because there is cargo wasm which compiles wasm without std and cannot compile cw contracts which are not std. so cw is really not std, but does not want to collaborate with other more correct no std implementations. |
so use case, hm, running cw somewhere else except cosmos... |
cw is no_std. which is official rust and cargo way of doing not_std. parity follows that rule, cw not, and hence not compatible with cargo wasm tooling and no_std crates. |
btw, i will not have any influence on any contracts as long as they use default features. all compilation will be as before. as i see cw people use default features. so it concerns only 2 packages , cw-std and cw-storage-plus. |
aptos no_std https://github.com/search?q=org%3Aaptos-labs+no_std&type=code no std does not have hash maps with rand, so it will fail to compile bad contracts more explicitly. |
This is not true. We have std (and all memory management there), just not sys calls (like random, time, etc) which would need host functions. When we started writing this in 2019, no_std was lacking on many crates and forcing no_std would have seriously limited external libraries people could import. I see the story is better now. |
The only use case that really convinced me there is that a CosmWasm contract would want to import Polkadot/NEAR code in order to interact with those chains, decode/encode tx, validate headers, etc. I don't assume CosmWasm contracts would be embedded in other Rust code directly, but only as a WASM blob, which could run in various runtimes. So the main purpose (which should be tested along with this) is importing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks solid to me in general. A few points:
- This cannot be merged with a reference to a cosmwasm-std fork. We need to get that merged first.
- CI tests must be updated to run std and no_std versions of everything. (build, test, clippy)
- It would be nice to make a simple test demoing a use case now working well... Only on
#[cfg(not(feature = "std")))]
Like decoding a borsch-encoded message (embed it as raw hex) and then storing into storage-plus (JSON encoded).
I am not the maintainer of cosmwasm repo for the first point, but please link any open PR on that repo and I can ask for it to be reviewed. Points 2 and 3 are needed and I would be happy to give feedback on this PR when those are handled.
Cargo.toml
Outdated
|
||
[lib] | ||
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options | ||
bench = false | ||
|
||
[dependencies] | ||
cosmwasm-std = { version = "1.1.6", default-features = false } | ||
cosmwasm-std = { git = "https://github.com/ComposableFi/cosmwasm.git", rev = "21351cc1ced863b9af7c8a69f923036bc919b3b1", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, before merging this, we would want to get their version merged in somehow, at least their no_std support.
I don't remember seeing a PR on that
schemars = "0.8.3" | ||
serde = { version = "1.0", default-features = false, features = ["derive"] } | ||
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import alloc
only when no std would be better, right?
src/cw_std.rs
Outdated
@@ -0,0 +1,62 @@ | |||
// no_std support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a solid way to implement this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But do we really need this file? I'm pretty sure we can just use the alloc
and core
crates directly, even in std
environment. std
just re-exports them anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to conditionally use them.
I wouldn't use core
libs in std
. It gets all kinds of confusion when you start passing core::Vec
to a lib that expects std::Vec
If we want to support both, such a set of conditional imports seems a proper way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean "confusion" as in: The crate user will get confused? Just asking because alloc::vec::Vec
and std::vec::Vec
are just two names for the same thing, so passing them around works perfectly fine.
But if you prefer importing it from std, then yes, the conditional imports file is the best solution.
src/deque.rs
Outdated
@@ -291,7 +291,7 @@ where | |||
#[cfg(test)] | |||
mod tests { | |||
use crate::deque::Deque; | |||
|
|||
use crate::cw_std::{vec::Vec, string::String}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just replacing this and the above line with use super::*
src/helpers.rs
Outdated
@@ -123,6 +123,7 @@ pub(crate) fn query_raw<Q: CustomQuery>( | |||
#[cfg(test)] | |||
mod test { | |||
use super::*; | |||
use crate::cw_std::prelude::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be unnecessary due to it being defined in super, but the compiler knows better than I
I assume you looked at CosmWasm/cosmwasm#1483 (which is where your git rev comes from, right?)
Their no_std doesn't support |
What no_std does is it improve error messages when you refer to no_std in smart contracts which do not really have js/rand/io, etc, tooling. cw_std wrapper allows this lib easy solve when anybody wants really non core/alloc/std crates to be used for indeed it is true that kind of core/alloc refer same std stuff, but when you compile no_std, there is no std, and it cannot compile. so each lib which is references should have no_std flag to allow whole tree to compile. so it is not only this lib, but each lib in tree. when it appears that no_std and std libs included in same tree, it just tells that there are several panics, or some rand/js unknown things, or several memory hooks - it cannot pick one. so it solves decision for rust. |
for use cases. there are two
|
74ffc89
to
0c08a80
Compare