-
Notifications
You must be signed in to change notification settings - Fork 39
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
make rand/getrandom
dependency explicit with a feature
#37
Conversation
Hello, I am working my way through porting arkworks crates in an wasm environment where developers can leverage rust features to opt-in/opt-out the dependency on |
rand/getrandom
dependency explicit with a feature
[features] | ||
default = [ "std" ] | ||
std = [ "rand/std" ] | ||
std = [] |
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.
Is there a reason to disable rand/std
when std
is on? That's not supported in wasm anyway, right? Or does wasm support std?
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.
I haven't done any in-depth research, but, while working on this wasm contract, I can tell you that many things from std are compatible with wasm.
std::collections
likeVec
orHashmap
are okOption
andResult
work just fine- So far, never hit any issue working with
String
andstr
array
andslice
s are 👌
AFAIK there isn't any particular issue using std
in wasm environment, except probably IO and multi-thread stuff.
The issue with using the current version of ark-std
in wasm for smart contracts is getrandom
crate: there is no way a blockchain EVM can provide you with functions that generate randomness.
This change aims at making the dependency over getrandom
optional. So crates that sit above ark-std
like all the algebra
crates, crypto-primitives
, crates in curve
, etc..., they can still rely on re-exported traits from ark_std::rand
, while gaining wasm compatibility for free.
Side Note: all the no-std
gears are dedicated more to the embedded world, rather than to wasm.
Thanks for the PR =) |
In the effort to make the arkworks framework available for compilation in wasm environment, we need to make ``getrandom`` indirect dependency an opt-in feature. ``rand/std`` feature triggers the dependency over ``getrandom``, so it can't be included in the ``std`` feature. It must be separated in an extra feature that we named ``getrandom``
b26b5d6
to
d6c9787
Compare
You may need to do a The failure regarding "check no_std" is that it still tries to invoke |
Let me have a try locally... |
I used
|
Another thing from our discussion is that maybe the cleanliest way is to just avoid
The bypass used in arkworks is to use things from |
getrandom being a dev-dependency makes cargo trying to include it in the build even when we are trying to build with no-std. Setting the resolver = "2" fixes the issue as Cargo is forced to recompute all the dependencies.
Hi @weikengchen , |
@Pratyush The resolver 2 is the default for edition=2021. I think we may need to prepare to migrate to 1.56 as well as edition 2021. |
(we still need |
rand/getrandom
dependency explicit with a featurerand/getrandom
dependency explicit with a feature
Description
In the effort to make the arkworks framework available for compilation
in wasm environment, we need to make
getrandom
indirect dependency anopt-in feature.
rand/std
feature triggers the dependency overgetrandom
, so it can't beincluded in the
std
feature. It must be separated in an extrafeature that we named
getrandom