# Half Gate

The Half-Gate optimization further reduces the number of ciphertexts from $3$ to $2$. This is also the protocol used in zkOracles, and more details of this algorithm will be given in this subsection. The algorithm is presented in the ZRE15 paper.

We first describe the basic idea behind half-gate garbling. Let’s say we want to compute the gate $a∧b=c$. With the Free-XOR optimization, let $(X_{a},X_{a}⊕Δ)$ and $(X_{b},X_{b}⊕Δ)$ denote the input wire labels to this gate, and $(X_{c},X_{c}⊕Δ)$ denote the output wire labels, with $X_{a},X_{b},X_{c}$ each encoding $0$.

Half-gate garbling contains two case: when the garbler knows one of the inputs, and when the evaluator knows one of the inputs.

**Garbler half-gate**. Considering the case of an $AND$ gate $a∧b=c$, where $a,b$ are intermediate wires in the circuit and the garbler somehow knows in advance what the value $a$ will be.

When $a=0$, the garbler will garble a unary gate that always outputs $0$. The label table is as follows.

$b$ | $c$ |
---|---|

$X_{b}$ | $X_{c}$ |

$X_{b}⊕Δ$ | $X_{c}$ |

Then the garbler generates two ciphertexts: $H(X_{b})⊕X_{c}$ $H(X_{b}⊕Δ)⊕X_{c}$

When $a=1$, the garbler will garble a unary identity gate. The label table is as follows.

$b$ | $c$ |
---|---|

$X_{b}$ | $X_{c}$ |

$X_{b}⊕Δ$ | $X_{c}⊕Δ$ |

Then the garbler generates two ciphertexts:

$H(X_{b})⊕X_{c}$ $H(X_{b}⊕Δ)⊕X_{c}⊕Δ$

Since $a$ is known to the garbler, the two cases shown above could be unified as follows:

$H(X_{b})⊕X_{c}$ $H(X_{b}⊕Δ)⊕X_{c}⊕a⋅Δ$

These two ciphertexts are then suitably permuted according to the `color`

bits of $X_{b}$. The evaluator takes a hash of its wire label for $X_{b}$ and decrypts the appropriate ciphertext. If $a=0$, he/she obtains output wire label $X_{c}$ in both values of $b$. If $a=1$ the evaluator obtains either $X_{c}$ or $X_{c}⊕Δ$, depending on the bit $b$. Intuitively, the evaluator will never know both $X_{b}$ and $X_{b}⊕Δ$, hence the other ciphertext appears completely random.

By applying the row-reduction optimization, we reduce the number of ciphertexts from $2$ to $1$ as follows. $H(X_{b}⊕Δ)⊕H(X_{b})⊕a⋅Δ$

**Evaluator half-gate**. Considering the case of an $AND$ gate $a∧b=c$, where $a,b$ are intermediate wires in the circuit and the evaluator somehow knows the value $a$ at the time of evaluation. The evaluator can behave differently based on the value of $a$.

When $a=0$, the evaluator should always obtain output wire label $X_{c}$, then the garbled circuit should contains the ciphertext: $H(X_{a})⊕X_{c}$

When $a=1$, it is enough for the evaluator to obtain $R=X_{c}⊕X_{b}$. He/she can then $XOR$ $R$ with the other wire label (either $X_{b}$ or $X_{b}⊕Δ$) to obtain either $X_{c}$ or $X_{c}⊕Δ$. Hence the garbler should provide the ciphertext: $H(X_{a}⊕Δ)⊕X_{c}⊕X_{b}$

Combining the above two case together, the garbler should provide two ciphertexts: $H(X_{a})⊕X_{c}$ $H(X_{a}⊕Δ)⊕X_{c}⊕X_{b}$

Note that these two ciphertext do NOT have to be permuted according to the `color`

bit of $X_{a}$, because the evaluator already knows $a$. If $a=0$, the evaluator uses the wire label $X_{a}$ to decrypt the first ciphertext. If $a=1$, the evaluator uses the wire label $X_{a}⊕Δ$ to decrypt the second ciphertext and $XOR$s the result with the wire label for $b$.

By applying the row-reduction optimization, we reduce the number of ciphertexts from $2$ to $1$ as follows. $H(X_{a}⊕Δ)⊕H(X_{a})⊕X_{b}$

**Two halves make a whole**. Considering the case to garble an $AND$ gate $a∧b=c$, where both inputs are secret. Consider:
$c=a∧b=a∧(r⊕r⊕b)=(a∧r)⊕(a∧(r⊕b))$

Suppose the garbler chooses uniformly random bit $r$. In this case, the first $AND$ gate $(a∧r)$ can be garbled with a garbler-half-gate. If we further arrange for the evaluator to learn the value $r⊕b$, then the second $AND$ gate $(a∧(r⊕b))$ can be garbled with an evaluator-half-gate. Leaking this extra bit $r⊕b$ to the evaluator is safe, as it carries no information about the sensitive value $b$. The remaining $XOR$ gate is free and the total cost is $2$ ciphertexts.

Actually the evaluator could learn $r⊕b$ without any overhead. The garbler choose the `color`

bit of the 0 label $X_{b}$ on wire $b$. Since that `color`

bit is chosen uniformly, it is secure to use it. Then when a particular value $b$ is on that wire, the evaluator will hold a wire label whose `color`

bit is $b⊕r$.

Let $X_{b},X_{b}=X_{b}⊕Δ$ be the labels for $b$, let $p=LSB(X_{b})$. $p$ is the `color`

bit of the wire, is a secret known only to the garbler. When the evaluator holds a wire label for $b$ whose `color`

bit is $s$, the label is $X_{b}$, corresponding to truth value $s⊕p$.