[Bug] Serde deserialization of u128 numbers in block data defaults to float instead of u128
Opened this issue ยท 1 comments
๐ 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
- Use
GET
request using thereqwest
library to download block1243302
- Attempt to deserialize the json object into a Block
- 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.