Documentation

QedShare.Shamir.Combine

Combining shares #

combine k shares checks the shares, then rebuilds each secret byte with Lagrange interpolation at 0. The Lagrange weights depend only on the (public) share indices, so they are computed once.

Checks, in order:

  1. at least k shares,
  2. no share has index 0,
  3. no two shares have the same index,
  4. all payloads have the same length,
  5. consistency (README: Forged shares): every share after the first k lies on the polynomials rebuilt from the first k, i.e. its payload equals interpolateSharesAt x (shares.take k) at its index x.

Check 5 catches a forged or wrong share whenever at least k of the given shares are genuine, so giving combine more than k shares protects against cheating shareholders. With exactly k shares there is nothing to compare against, and the check always passes.

Correctness (combine_split) and forgery detection (combine_detects_forgery) are proved in the proofs/ package, which uses Mathlib (README: Guarantees).

Why combine refused the shares.

  • tooFewShares : CombineError

    Fewer than k shares were given.

  • zeroIndex : CombineError

    A share has index 0, which split never produces.

  • duplicateIndex : CombineError

    Two shares have the same index.

  • lengthMismatch : CombineError

    The share payloads have different lengths.

  • inconsistent : CombineError

    The shares do not all lie on one polynomial of degree < k: at least one of them is wrong or forged (only possible to see with more than k shares).

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

      Rebuild the secret from shares whose indices and payload lengths are already checked: byte b is Σᵢ wᵢ · ysᵢ[b] with the Lagrange weights wᵢ of the indices.

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

        Fast version of interpolateShares, used by compiled code. The specification reads byte b of each payload with List.getD, which walks the list, so the whole rebuild is quadratic in the secret length. Here every payload is turned into an Array once, and Array.getD is constant-time.

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

          The fast rebuild computes exactly the specification. Marked @[csimp], so the compiler runs interpolateSharesFast wherever the code says interpolateShares, while every theorem (including combine_split) stays about the readable interpolateShares.

          The payload that a share at index z would have, rebuilt from shares by Lagrange interpolation at z: byte b is Σᵢ wᵢ(z) · ysᵢ[b].

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

            Fast version of interpolateSharesAt (payloads as arrays), as for interpolateShares.

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

              The fast version computes exactly the specification (@[csimp]: compiled code runs it).

              Equality of two byte lists, without stopping at the first difference: the XOR of each pair is OR-ed into one accumulator, and only the final result is tested. Share payloads are secret, so the time taken should not depend on where they differ.

              Equations
              Instances For
                theorem QedShare.Shamir.foldl_or_eq_zero (l : List UInt8) (acc : UInt8) :
                List.foldl (fun (x1 x2 : UInt8) => x1 ||| x2) acc l = 0 ↔ acc = 0 ∧ ∀ (d : UInt8), d ∈ l → d = 0

                The OR of a list of bytes (starting from acc) is 0 exactly when acc and every byte are 0.

                Does share sh lie on the polynomials rebuilt from base?

                Equations
                Instances For

                  Every share after the first k lies on the polynomials rebuilt from the first k.

                  Equations
                  Instances For

                    Rebuild a secret from shares, with threshold k. Returns an error instead of a wrong answer whenever the shares are obviously unusable.

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

                      combine k shares fails when there are fewer than k shares.

                      theorem QedShare.Shamir.combine_rejects_zero_index (k : Nat) (shares : List Share) (h : ∃ (sh : Share), sh ∈ shares ∧ sh.x = 0) (v : List GF256) :
                      combine k shares ≠ Except.ok v

                      combine never succeeds when a share has index 0.

                      theorem QedShare.Shamir.combine_rejects_duplicates (k : Nat) (shares : List Share) (h : ¬(List.map (fun (x : Share) => x.x) shares).Nodup) (v : List GF256) :
                      combine k shares ≠ Except.ok v

                      combine never succeeds when two shares have the same index.

                      theorem QedShare.Shamir.consistent_of_length_le (k : Nat) (shares : List Share) (h : shares.length ≤ k) :
                      consistent k shares = true

                      With exactly k shares there is nothing to compare, so the consistency check passes.

                      theorem QedShare.Shamir.combine_rejects_inconsistent (k : Nat) (shares : List Share) (sh : Share) (hsh : sh ∈ List.drop k shares) (hfit : interpolateSharesAt sh.x (List.take k shares) ≠ sh.ys) (v : List GF256) :
                      combine k shares ≠ Except.ok v

                      combine never succeeds when a share after the first k does not lie on the polynomials rebuilt from the first k.