snarkVM icon indicating copy to clipboard operation
snarkVM copied to clipboard

Request to rename `read_le_with_unchecked` to `read_le_unchecked`

Open howardwu opened this issue 1 month ago • 2 comments

To keep in line with other *_unchecked methods in snarkVM, I'd like to request that the FromBytes *_with_unchecked methods be renamed to *_unchecked.

I am willing to write this PR if no one else has the bandwidth to.

howardwu avatar Nov 11 '25 00:11 howardwu

If we look at impl<N: Network> FromBytes for Block<N>, we see there is an *_unchecked function, and read_le_with_unchecked keeps the underlying deserialization DRY.

    /// Reads the block from the buffer.
    fn read_le<R: Read>(reader: R) -> IoResult<Self> {
        Self::read_le_with_unchecked(reader, false)
    }

    // Reads the block from the buffer without any checks on the data.
    fn read_le_unchecked<R: Read>(reader: R) -> IoResult<Self> {
        Self::read_le_with_unchecked(reader, true)
    }

There is a limit to which we should abstract, as layers of indirection make maintenance harder. But read_le_with_unchecked seems like a great improvement to me.

The only thing I see to improve is to change the magic true/false by a const DISABLE_DESERIALIZATION_CHECKS: bool;

vicsn avatar Nov 12 '25 10:11 vicsn

I added read_le_with_unchecked, because it made implementing the unchecked versions a lot cleaner. Otherwise, it requires a lot of if branching.

The only thing I see to improve is to change the magic true/false by a const DISABLE_DESERIALIZATION_CHECKS: bool;

I might be even better to use an enum.

enum DeserializationMode {
      WithChecks,
      WithoutChecks,
}

However, we should hold off on further changes until we moved to bincode 2.*.

kaimast avatar Nov 14 '25 20:11 kaimast