Documentation

CompPoly.Data.Bytes.LittleEndian

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.

The layout is the one arkworks and plonky3 use for field elements: the canonical integer, little-endian, padded to a fixed width.

Lists #

The w little-endian bytes of n; bits above 8 * w are dropped.

Instances For

    The natural with the given little-endian bytes.

    Instances For
      @[simp]
      theorem CompPoly.Bytes.toListLE_succ (w n : ) :
      toListLE (w + 1) n = UInt8.ofNat (n % 256) :: toListLE w (n / 256)
      @[simp]
      theorem CompPoly.Bytes.ofListLE_cons (b : UInt8) (bs : List UInt8) :
      ofListLE (b :: bs) = b.toNat + 256 * ofListLE bs
      @[simp]
      theorem CompPoly.Bytes.ofListLE_toListLE_of_lt {w n : } (h : n < 256 ^ w) :
      theorem CompPoly.Bytes.toListLE_inj_of_lt {w n m : } (hn : n < 256 ^ w) (hm : m < 256 ^ w) (h : toListLE w n = toListLE w m) :
      n = m
      theorem CompPoly.Bytes.ofListLE_append (l₁ l₂ : List UInt8) :
      ofListLE (l₁ ++ l₂) = ofListLE l₁ + 256 ^ l₁.length * ofListLE l₂

      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
        theorem CompPoly.Bytes.bytesFor_pos (bound : ) :
        0 < bytesFor bound
        theorem CompPoly.Bytes.le_pow_bytesFor (bound : ) :
        bound 256 ^ bytesFor bound
        theorem CompPoly.Bytes.bytesFor_two_pow {k : } (hk : 0 < k) :
        bytesFor (2 ^ k) = (k + 7) / 8

        The width of a power of two: k bits need ⌈k / 8⌉ bytes. Stated so that a bit-pattern type's width is a small numeral computation rather than a kernel evaluation of 2 ^ k.

        Vectors #

        The w little-endian bytes of n as a vector.

        Instances For

          The natural with the given little-endian bytes.

          Instances For
            @[simp]
            theorem CompPoly.Bytes.ofVecLE_toVecLE_of_lt {w n : } (h : n < 256 ^ w) :
            ofVecLE (toVecLE w n) = n
            theorem CompPoly.Bytes.ofVecLE_lt {w : } (v : Vector UInt8 w) :
            ofVecLE v < 256 ^ w
            theorem CompPoly.Bytes.toVecLE_inj_of_lt {w n m : } (hn : n < 256 ^ w) (hm : m < 256 ^ w) (h : toVecLE w n = toVecLE w m) :
            n = m

            Byte arrays #

            The w little-endian bytes of n as a ByteArray.

            Instances For

              The natural with the given little-endian bytes.

              Instances For
                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) :
                n = m