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

[Bug] Serde deserialization of u128 numbers in block data defaults to float instead of u128 #2560

Open
iamalwaysuncomfortable opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@iamalwaysuncomfortable
Copy link
Contributor

iamalwaysuncomfortable commented Oct 17, 2024

🐛 Bug Report

Structs with u128 members related to the puzzle are starting to get into sizes that can only be represented in u128 numbers (i.e. the cumulative_weight member of the Header object). As a side effect, Serde based deserializers are starting to have the behavior of interpreting these numbers as floats during deserialization causing Serde deserialization of objects like Block to fail when deserializing from JSON.

For context as to why this happens, the Number enum in serde-json without the arbitraryprecision flag can hold a u64, i64, or f64. Thus without the arbitraryprecision flag, Number isn't capable of holding a u128 directly as an integer type and defaults to storing it as an f64. SnarkVM doesn't handle this explicitly causing deserialization to fail.

This will affect Rust code deserializing Blocks from JSON.

Steps to Reproduce

  1. Use GET request using the reqwest library to download block 1243302
  2. Attempt to deserialize the json object into a Block
  3. A deserialization failure occurs

A workaround for now for libraries deserializing Blocks with using Serde in Rust is to use the arbitrary_precision feature. A longer term fix would be to examine visitor patterns that work over u128 numbers and ensure the logic explicitly deserializes them into u128.

@iamalwaysuncomfortable iamalwaysuncomfortable added the bug Something isn't working label Oct 17, 2024
@iamalwaysuncomfortable iamalwaysuncomfortable changed the title [Bug] Serde Deserialization [Bug] Serde Deserialization of u128 numbers in Blocks defaults to float instead of u128 Oct 17, 2024
@iamalwaysuncomfortable iamalwaysuncomfortable changed the title [Bug] Serde Deserialization of u128 numbers in Blocks defaults to float instead of u128 [Bug] Serde deserialization of u128 numbers in blocks defaults to float instead of u128 Oct 17, 2024
@iamalwaysuncomfortable iamalwaysuncomfortable changed the title [Bug] Serde deserialization of u128 numbers in blocks defaults to float instead of u128 [Bug] Serde deserialization of u128 numbers in block data defaults to float instead of u128 Oct 17, 2024
@vicsn
Copy link
Contributor

vicsn commented Oct 17, 2024

Potentially related: #2559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants