zerokit icon indicating copy to clipboard operation
zerokit copied to clipboard

serialization lengths should be u32

Open richard-ramos opened this issue 2 years ago • 1 comments

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

richard-ramos avatar Sep 02 '22 12:09 richard-ramos

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.

s1fr0 avatar Sep 02 '22 12:09 s1fr0