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

Remove serde_json arbitrary precision feature #691

Closed
trevor-crypto opened this issue Sep 9, 2024 · 6 comments
Closed

Remove serde_json arbitrary precision feature #691

trevor-crypto opened this issue Sep 9, 2024 · 6 comments
Milestone

Comments

@trevor-crypto
Copy link
Contributor

Is it possible to revert or modify the changes in this commit so that the serde_json arbitrary_precision feature is not enabled?

This can cause problems when using cardano-serialization-lib alongside other crates that also depend on serde_json but do not need the arbitrary_precision. The Rust feature resolver cannot compile two separate versions of serde_json, one with the feature and one without.

@lisicky
Copy link
Contributor

lisicky commented Sep 9, 2024

Hi @trevor-crypto ! Unfortunately a plutus data integer size can be up to 64 bytes (not bits) and serde can't serialize values bigger than u64(8 bytes) without this feature. If you just have serde_json versions conflict you can override serde version for specific package in .toml file of your project.
If you provide more details we might help you to find solution for your issue.

@trevor-crypto
Copy link
Contributor Author

If you just have serde_json versions conflict you can override serde version for specific package in .toml file of your project.

There's no way to do this because when you're using a workspace, the feature is enabled across the whole workspace, so every dependency and their dependencies get a compiled serde_json with arbitrary_precision enabled. The compiler doesn't compile two separate versions of serde_json, one with and one without arbitrary_precision.

Since serde_json is a common dependency of a lot of crates, this causes "feature leak" across the whole project.

Ex.

my_crate
|
- cardano-serialization-lib
  |
   - serde_json (with `arbitrary_precision`)
- other-blockchain-lib
  | 
   - serde_json (without `arbitrary_precision` but gets it anyway!)

@trevor-crypto
Copy link
Contributor Author

@lisicky Can you explain this more or show me a test that checks this? It should be possible with your own deserializer/serializer that can handle a string <-> BitInt.

Unfortunately a plutus data integer size can be up to 64 bytes (not bits) and serde can't serialize values bigger than u64(8 bytes) without this feature.

@lisicky
Copy link
Contributor

lisicky commented Sep 10, 2024

@trevor-crypto I have pushed a test 85398ed

It should be possible with your own deserializer/serializer that can handle a string <-> BitInt.

What do you mean ? We do not implement a serializer to a rust structure<->json serialization, we use serde for it

@lisicky
Copy link
Contributor

lisicky commented Sep 10, 2024

We will add "arbitrary-precision-json" ( you can see it in the test ) feature into our crate, it enables "arbitrary_precision" for serde_json and it's default feature but you can just disable it in your project

@trevor-crypto
Copy link
Contributor Author

@lisicky I understand now. So the BigInt cannot be a String and must be a Number in JSON format.

That fix works for me. Thanks!

@lisicky lisicky added this to the 12.1.0 milestone Sep 10, 2024
@lisicky lisicky closed this as completed Sep 10, 2024
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