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

Disallow floats feature #567

Closed
MaksymZavershynskyi opened this issue Sep 11, 2019 · 3 comments
Closed

Disallow floats feature #567

MaksymZavershynskyi opened this issue Sep 11, 2019 · 3 comments

Comments

@MaksymZavershynskyi
Copy link

Motivation:
Many modern day blockchains use Rust smart contracts compiled to WebAssembly. Unfortunately, to enforce determinism they have to scan the compiled *.wasm contract before the execution and check whether it uses floats of float operations. This is not a problem for most of the smart contracts that do not actually use floats. However, if smart contract imports serde_json crate and deserializes a struct the compiler has to include some of the code branches that use f64/f32 even if these branches are never entered by the smart contract execution.

JSON is a fundamental format which is a natural choice for smart contract when they need to interact with the front-end (e.g. written in JS). It is highly desirable for smart contracts to be able to import serde_json crate and use it for deserialization.

Solution:
Have a no_floats feature that comments out certain branches of the code sufficiently enough so that when serde_json deserializer is used in a code that does not use f64/f32 no f64/f32 operations are generated in WebAssembly format. This can be implemented like this: nearprotocol#1 (disregard the added test).

Question:
Do serde-rs/json maintainers want to have it as a feature or they want us (https://nearprotocol.com) to create a permanent fork with this feature?

@dtolnay
Copy link
Member

dtolnay commented Sep 13, 2019

Thanks for the explanation. I would not accept a no_floats feature -- I would prefer if this could be maintained outside of serde-rs/json as a fork.

@webmaster128
Copy link

Many modern day blockchains use Rust smart contracts compiled to WebAssembly

As we're falling into this category as well, I'd appreciate to learn about the current state of this ticket.

I would not accept a no_floats feature -- I would prefer if this could be maintained outside of serde-rs/json as a fork.

Is this still up to date? If so, I think this issue can be closed, right?

@MaksymZavershynskyi
Copy link
Author

Closing the issue.

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

No branches or pull requests

3 participants