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

JSON.parse will lead to loss of precision for large integers and interop issues #296

Closed
waynenilsen opened this issue Nov 10, 2022 · 1 comment

Comments

@waynenilsen
Copy link
Contributor

I have noticed several places in Rust code using U128 and U256 for "amount" type fields these are not compatible with MAX_SAFE_INTEGER and on the rust side they'll serialize fine but on the javascript side they will become floats (number) during JSON.parse leading to loss of precision.

We must do something to address the deserialization of large integers that is better than JSON.parse.

Javascript now has a built in bigint class that is perfect for this kind of thing but no real way of integrating that into JSON.parse yet. We may need to write the json tokenizer/parser or re-use some such existing package such as this one.

https://github.com/sidorares/json-bigint

Another alternative is to always serialize integers as strings across the entire ecosystem but that seems unmanageable

@ailisp
Copy link
Member

ailisp commented Nov 14, 2022

Good point! Recently, bigint serialization is added by @petarvujovic98 in #228. test-bigint-serialization.ava.js is a proof of that.

@ailisp ailisp closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants