zerokit
zerokit copied to clipboard
serialization lengths should be u32
Currently in the code we have places where we do this conversion:
usize::try_from( some_u64_value ).unwrap();
// The u64 value might come from a function like u64::from_be_bytes
This will cause an error in 32 bit architectures, since usize max value depends on the architecture. To avoid this, lengths should be stored as u32 instead of u64
This issue was partially discussed in https://github.com/status-im/nwaku/pull/1016#discussion_r905560688. Most of byte lengths converted to usize can be safely assumed to be less than 2^32 bytes, hence we might update RFCs and implementations to deal with length serialized with 4 bytes rather than using 8 bytes were the MSB are set to 0.