Little-endian byte encodings of naturals #
The one encoder every fixed-width serialization in CompPoly is built from: a natural number
becomes exactly w bytes, least significant first, and w bytes become a natural.
toListLE w n/ofListLEonList UInt8, with the round-trip lawsofListLE_toListLE(asn % 256 ^ w, hence exact below256 ^ w) andtoListLE_ofListLE, and the concatenation lawofListLE_append.toVecLE/ofVecLEandtoByteArrayLE/ofByteArrayLE, the same maps onVector UInt8 wandByteArray.bytesFor bound, the number of bytes needed to hold every natural belowbound, withle_pow_bytesFor : bound ≤ 256 ^ bytesFor bound. It isNat.log2-based so that the kernel evaluates it on numerals bydecide.
The layout is the one arkworks and plonky3 use for field elements: the canonical integer, little-endian, padded to a fixed width.
Lists #
The natural with the given little-endian bytes.
Instances For
Widths #
The number of bytes needed to hold every natural below bound: one byte for bound ≤ 256,
and in general the least w with bound ≤ 256 ^ w, except that bound ≤ 1 still takes one
byte. Defined through Nat.log2 so that the kernel evaluates it on numerals.
Instances For
Vectors #
The w little-endian bytes of n as a vector.
Instances For
Byte arrays #
The w little-endian bytes of n as a ByteArray.
Instances For
The natural with the given little-endian bytes.
Instances For
@[simp]
theorem
CompPoly.Bytes.toByteArrayLE_inj_of_lt
{w n m : ℕ}
(hn : n < 256 ^ w)
(hm : m < 256 ^ w)
(h : toByteArrayLE w n = toByteArrayLE w m)
: