Documentation

QedShareCli.Fast

A memory-light makeShares for the executable #

makeShares (in Pipeline) is written for the proofs: the random bytes are a List UInt8, they are cut into one coefficient list per secret byte, and all shares are built before any is encoded. A list costs 24 bytes of memory per element, so a 1 MiB secret with threshold 20 needed over 1 GB, and far more for larger thresholds or many shares.

makeSharesBytes computes the same share strings from the random bytes as a ByteArray (1 byte per byte). It reads each coefficient straight from the array while evaluating (hornerAt), and builds and encodes one share at a time.

makeSharesBytes_eq proves that it returns exactly what makeShares returns on the same bytes, for every input. So everything proven about makeShares holds for what the executable runs.

Where the coefficient bytes start in the random bytes: after the AMD key (qs2, qs3) and the token polynomial (qs3).

Equations
Instances For
    def QedShare.Cli.hornerAt (random : ByteArray) (lo : Nat) (x : GF256) :
    Nat → Nat → GF256

    Horner evaluation at x of the polynomial whose c coefficients are the random bytes at positions lo + t, lo + t + 1, …, read straight from the array.

    Equations
    Instances For
      def QedShare.Cli.makeSharesBytes (k n : Nat) (secret : List UInt8) (random : ByteArray) (setIdBytes : List UInt8) (form : ShareForm := ShareForm.hex) (fmt : Encoding.Fmt := Encoding.Fmt.v3) :

      makeShares on random bytes given as a ByteArray, without turning them into lists.

      When every input check passes it builds the shares directly; otherwise (an error, in practice) it falls back to makeShares itself. makeSharesBytes_eq proves both branches equal makeShares.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        makeSharesBytes = makeShares #

        theorem QedShare.Cli.hornerAt_eq (random : ByteArray) (lo : Nat) (x : GF256) (c t : Nat) :
        hornerAt random lo x c t = Poly.eval (List.map (fun (i : Nat) => { val := random.get! (lo + i) }) (List.range' t c)) x

        hornerAt is Poly.eval of the coefficients it reads.

        theorem QedShare.Cli.tagSecret_rest (fmt : Encoding.Fmt) (k : Nat) (secret random : List UInt8) :
        (tagSecret fmt k secret random).snd.snd = List.drop (coeffOffset fmt k) random

        The coefficients tagSecret leaves for the polynomials start at coeffOffset.

        theorem QedShare.Cli.tagSecret_take (fmt : Encoding.Fmt) (k : Nat) (secret random : List UInt8) :
        (tagSecret fmt k secret (List.take (16 + 16 * k) random)).fst = (tagSecret fmt k secret random).fst ∧ (tagSecret fmt k secret (List.take (16 + 16 * k) random)).snd.fst = (tagSecret fmt k secret random).snd.fst

        The bytes to split and the token polynomial depend only on the first 16 + 16k random bytes.

        theorem QedShare.Cli.toList_extract_zero (random : ByteArray) (m : Nat) :
        (random.extract 0 m).data.toList = List.take m random.data.toList

        The first m bytes of a byte array, as a list.

        theorem QedShare.Cli.get!_eq (random : ByteArray) (i : Nat) (h : i < random.size) :
        random.get! i = random.data.toList[i]

        Reading a byte of the array is reading it from the list of its bytes.

        theorem QedShare.Cli.chunk_eq (random : ByteArray) (off b c : Nat) (h : off + b * c + c ≤ random.size) :
        List.map GF256.mk ((List.drop off random.data.toList).toArray.extract (b * c) ((b + 1) * c)).toList = List.map (fun (i : Nat) => { val := random.get! (off + b * c + i) }) (List.range' 0 c)

        Chunk b of the randomness (chunkRandomness), when it lies inside the array, is the bytes hornerAt reads.

        theorem QedShare.Cli.makeSharesBytes_eq (k n : Nat) (secret : List UInt8) (random : ByteArray) (sid : List UInt8) (form : ShareForm) (fmt : Encoding.Fmt) :
        makeSharesBytes k n secret random sid form fmt = makeShares k n secret random.data.toList sid form fmt

        The memory-light path computes exactly makeShares. For every input, makeSharesBytes on a byte array returns what makeShares returns on the list of its bytes.