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

f32/f64/usize in cosmwasm(and other no f32/f64 envs) reproduction and fixes #803

Closed
wants to merge 2 commits into from

Conversation

dzmitry-lahoda
Copy link
Contributor

@dzmitry-lahoda dzmitry-lahoda commented Aug 1, 2023

Closes: #800

Description

Requires #790

  1. replaced f64 logic with equivalent u64
  2. forbidden use of f64 (and usize)
  3. usize was replaced by u64, assuming that wasm64 is nearest highest target for mem size. i am ok with safety of thing, so u32/u16 could be better per case (mostly length on names and some history things - sure never u64, but u64 is correct map to usize), so no ideal but working.
  4. replaced weird serde issues (both serde and serde_wasm compile into wasm f64 even if do just strings, had to rip them as could)
  5. added test to test changes (with these there is no validation error)
  6. side change added schema for ChainId (i use in CW)

PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@dzmitry-lahoda
Copy link
Contributor Author

feel free to merge with #790 and run insuction in shell.nix header. try to rollback any change and see effects. serde works exactly only this way i found, other compile with floats

@dzmitry-lahoda
Copy link
Contributor Author

for usize correctness parity uses static assets

substrate/primitives/runtime-interface/src/impls.rs:45:1

so can asset some usize if needed too

@dzmitry-lahoda
Copy link
Contributor Author

pr has issue

"serde-json-wasm 0.5.1 (git+https://github.com/dzmitry-lahoda-forks/serde-json-wasm?rev=8a7e522c0e4de36a6dfb535766f26a9941017d81)",

need to use no-std serde-json-wasm

@dzmitry-lahoda
Copy link
Contributor Author

CosmWasm/serde-json-wasm#58

CosmWasm/serde-json-wasm#56

we trying to get no_std merged for 1 year+ already so

github-merge-queue bot pushed a commit to ComposableFi/composable that referenced this pull request Aug 1, 2023
Some explanation is here cosmos/ibc-rs#803

So wasmd validation in cosmos will not find reference to code (which
never executes) it fails like floats anymore and will success upload.
Any attempt to strip float code failed (likely it anticipates input
which may contain floats in some case, which is not case to handle at
all).

Also had hard times with std because of centauri repo, added CI checks
to ensure we always good.

May be fixes #3952 too.

Required for merge:
- [x] `pr-workflow-check / draft-release-check` is ✅ success
- Other rules GitHub shows you, or can be read in
[configuration](../terraform/github.com/branches.tf)

Makes review faster:
- [x] PR title is my best effort to provide summary of changes and has
clear text to be part of release notes
- [x] I marked PR by `misc` label if it should not be in release notes
- [x] Linked Zenhub/Github/Slack/etc reference if one exists
- [x] I was clear on what type of deployment required to release my
changes (node, runtime, contract, indexer, on chain operation, frontend,
infrastructure) if any in PR title or description
- [x] Added reviewer into `Reviewers`
- [x] I tagged(`@`) or used other form of notification of one person who
I think can handle best review of this PR
- [x] I have proved that PR has no general regressions of relevant
features and processes required to release into production
- [x] Any dependency updates made, was done according guides from
relevant dependency
- Clicking all checkboxes 
- Adding detailed description of changes when it feels appropriate (for
example when PR is big)
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dzmitry-lahoda. This is awesome and much appreciated! 👌🏻
Let’s get it over the finish line. Would you plz apply the following changes:

  1. Merge changes from the main to the PR's branch
  2. Set serde-json-wasm package to use v1.0.0
  3. Add a CI job that does cw_check by running the shell.nix
  4. Add unclog

Then, I will run an integration test against gaia chains in basecoin-rs to make sure using serde-json-wasm we still keep compatibility with both Hermes and basecoin_app (Though, from what I see most probably should be ok)

Let me know if for any of above, I can assist

@dzmitry-lahoda dzmitry-lahoda marked this pull request as draft September 10, 2023 13:51
@Farhad-Shabani
Copy link
Member

Hey @dzmitry-lahoda, Any chance you could wrap up this PR?
I also can assist with this if you select "Allow edits from maintainers".

@@ -15,7 +15,7 @@ use crate::alloc::{borrow::ToOwned, string::String};
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)]
pub struct Amount(
#[cfg_attr(feature = "schema", schemars(with = "String"))]
#[serde(serialize_with = "crate::serializers::serde_string::serialize")]
#[serde(serialize_with = "serialize")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking another peek, the "serialize" function in "amount.rs" seems redundant. Why not use "crate::serializers::serde_string::serialize"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik for some reason it triggered float to be compiled into wasm (seems like just patter matching, but validation tools do not care).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be OK if the ci/cw-check passes with the crate::serializers::serde_string::serialize or still might be the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used only reproducible check to fix issues

@dzmitry-lahoda
Copy link
Contributor Author

hello, some things

  1. I cannot allow edit because i have -forks org I do all forks (to avoid mix of my projects), and there is bug https://github.com/orgs/community/discussions/5634 . I cannot set the value. So I am ok with copy paste or else.
  2. https://github.com/CosmWasm/serde-json-wasm was released version 1.0. they made it no_std afaid and fixed some issue - so this one should be used.
  3. and final one, latest version of CosmWasm wasmd emulated floats (software implementation I guess). But I am not sure it works in no_std or without using their wasmd wasmer host or without using special assembly rewrite hook. So float less wasm still a thing, so for some people may be less prio.

but in general things I tried still holds, for next 1 month i am on ibc for solidity, so will not catch up this minimum this period, i guess company will continue more efforts to no_std versions of ibc in 2-3 month (after evm).

@Farhad-Shabani
Copy link
Member

Thanks a bunch for the tips and updates. 🙏 No worries, I’ll fork yours and open up a new PR.
Just, as for the 3rd point, given another issue we've got here, still we should move away from floats.

Looking forward to hearing about the progress on the no_std versions of IBC.

@Farhad-Shabani
Copy link
Member

Superseded by #894

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

do not use f64/f32/usize as it fails some wasm runtimes (cosmwasm)
2 participants