Documentation

CslibFrontier.Crypto.Primitives.Garbling.OneHot

One-hot vectors and truth-table products #

The algebra behind the lookup-table garbling of Heath, Kolesnikov and Ng [HKN24]. A lookup table with rows indexed by ι and outputs indexed by κ is a truth table T : ι → κ → Bool. Multiplying its transpose by the one-hot vector of an index x selects row x (tableMulBits_oneHot, [HKN24], Lemma 1, a fact credited there to [HK21]).

With Free-XOR labels [KS08] the label of bit b on a wire with zero-label G is G + bitOffset Δ b for a global offset Δ. The labelled product tableMul T X sums, for each output u, the labels X j of the rows with T j u = true. It is additive in the labels, and in characteristic two it commutes with offsets (tableMul_bitOffset). Consequently, if the evaluator holds Free-XOR labels of the one-hot vector of x, the product of its labels is a Free-XOR label of row x, whose zero-label is the product of the zero-labels (tableMul_oneHotLabels, the display after Lemma 1 of [HKN24]). Only one row carries the offset, so this form holds in every additive commutative group.

Main definitions #

Main results #

References #

def Cslib.Crypto.Garbling.bitOffset {L : Type} [Zero L] (Δ : L) (b : Bool) :
L

The multiple of the global offset selected by a bit: Δ for true and 0 for false. With Free-XOR, the label of bit b on a wire with zero-label G is G + bitOffset Δ b.

@[simp]
theorem Cslib.Crypto.Garbling.bitOffset_true {L : Type} [Zero L] (Δ : L) :
@[simp]
theorem Cslib.Crypto.Garbling.bitOffset_add_of_add_self {L : Type} [AddCommMonoid L] {Δ : L} (hΔ : Δ + Δ = 0) (a b : Bool) :
bitOffset Δ (a + b) = bitOffset Δ a + bitOffset Δ b

For an element Δ of order at most two, the offset selected by a sum of bits is the sum of the offsets.

theorem Cslib.Crypto.Garbling.bitOffset_add {L : Type} [AddCommGroup L] [Module (ZMod 2) L] (Δ : L) (a b : Bool) :
bitOffset Δ (a + b) = bitOffset Δ a + bitOffset Δ b

In characteristic two, the offset selected by a sum of bits is the sum of the offsets.

In characteristic two, bitOffset Δ is an additive map from Bool with + = xor.

def Cslib.Crypto.Garbling.oneHot {ι : Type} [DecidableEq ι] (x : ι) :
ι → Bool

The one-hot vector of x: true exactly at x.

@[simp]
theorem Cslib.Crypto.Garbling.oneHot_of_ne {ι : Type} [DecidableEq ι] {x j : ι} (h : j ≠ x) :
def Cslib.Crypto.Garbling.tableMulBits {ι κ : Type} [Fintype ι] (T : ι → κ → Bool) (v : ι → Bool) :
κ → Bool

Transposed truth-table product on bits: output u is the sum over GF(2) of v j && T j u. On a one-hot vector it reads one row of T.

def Cslib.Crypto.Garbling.tableMul {ι κ L : Type} [Fintype ι] [AddCommMonoid L] (T : ι → κ → Bool) (X : ι → L) :
κ → L

Transposed truth-table product on labels: output u is the sum of the labels X j over the rows j with T j u = true.

theorem Cslib.Crypto.Garbling.tableMulBits_oneHot {ι κ : Type} [Fintype ι] [DecidableEq ι] (T : ι → κ → Bool) (x : ι) :

One-hot selection ([HKN24], Lemma 1): the transposed truth table times the one-hot vector of x is row x.

theorem Cslib.Crypto.Garbling.tableMul_add {ι κ L : Type} [Fintype ι] [AddCommMonoid L] (T : ι → κ → Bool) (X Y : ι → L) :
tableMul T (X + Y) = tableMul T X + tableMul T Y

The labelled product is additive in the labels.

theorem Cslib.Crypto.Garbling.tableMul_bitOffset {ι κ L : Type} [Fintype ι] [AddCommGroup L] [Module (ZMod 2) L] (T : ι → κ → Bool) (Δ : L) (v : ι → Bool) :
(tableMul T fun (j : ι) => bitOffset Δ (v j)) = fun (u : κ) => bitOffset Δ (tableMulBits T v u)

Free-XOR linearity: in characteristic two, the product of a table with the offsets of a bit vector v is the offset of the product of the table with v.

theorem Cslib.Crypto.Garbling.tableMul_oneHotLabels {ι κ L : Type} [Fintype ι] [DecidableEq ι] [AddCommGroup L] (T : ι → κ → Bool) (G : ι → L) (Δ : L) (x : ι) :
(tableMul T fun (j : ι) => G j + bitOffset Δ (oneHot x j)) = fun (u : κ) => tableMul T G u + bitOffset Δ (T x u)

One-hot selection on labels (the display after Lemma 1 of [HKN24]). If the evaluator holds Free-XOR labels of the one-hot vector of x with zero-labels G, then output u of the product of its labels is the label of bit T x u with zero-label tableMul T G u.